QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsdatadefinedbutton.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatadefinedbutton.cpp - Data defined selector button
3  --------------------------------------
4  Date : 27-April-2013
5  Copyright : (C) 2013 by Larry Shaffer
6  Email : larrys at dakcarto dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsdatadefinedbutton.h"
17 
18 #include <qgsapplication.h>
19 #include <qgsdatadefined.h>
21 #include <qgsexpression.h>
22 #include <qgsmessageviewer.h>
23 #include <qgsvectorlayer.h>
24 
25 #include <QClipboard>
26 #include <QMenu>
27 #include <QMouseEvent>
28 #include <QPointer>
29 
30 
31 QIcon QgsDataDefinedButton::mIconDataDefine;
32 QIcon QgsDataDefinedButton::mIconDataDefineOn;
33 QIcon QgsDataDefinedButton::mIconDataDefineError;
34 QIcon QgsDataDefinedButton::mIconDataDefineExpression;
35 QIcon QgsDataDefinedButton::mIconDataDefineExpressionOn;
36 QIcon QgsDataDefinedButton::mIconDataDefineExpressionError;
37 
39  const QgsVectorLayer* vl,
40  const QgsDataDefined* datadefined,
41  DataTypes datatypes,
42  QString description )
43  : QToolButton( parent )
44 {
45  // set up static icons
46  if ( mIconDataDefine.isNull() )
47  {
48  mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" );
49  mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" );
50  mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" );
51  mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" );
52  mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" );
53  mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" );
54  }
55 
56  setFocusPolicy( Qt::StrongFocus );
57 
58  // set default tool button icon properties
59  setFixedSize( 30, 26 );
60  setStyleSheet( QString( "QToolButton{ background: none; border: 1px solid rgba(0, 0, 0, 0%);} QToolButton:focus { border: 1px solid palette(highlight); }" ) );
61  setIconSize( QSize( 24, 24 ) );
62  setPopupMode( QToolButton::InstantPopup );
63 
64  mDefineMenu = new QMenu( this );
65  connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) );
66  connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) );
67  setMenu( mDefineMenu );
68 
69  mFieldsMenu = new QMenu( this );
70 
71  mActionDataTypes = new QAction( this );
72  // list fields and types in submenu, since there may be many
73  mActionDataTypes->setMenu( mFieldsMenu );
74 
75  mActionActive = new QAction( this );
76  QFont f = mActionActive->font();
77  f.setBold( true );
78  mActionActive->setFont( f );
79 
80  mActionDescription = new QAction( tr( "Description..." ), this );
81 
82  mActionExpDialog = new QAction( tr( "Edit..." ), this );
83  mActionExpression = 0;
84  mActionPasteExpr = new QAction( tr( "Paste" ), this );
85  mActionCopyExpr = new QAction( tr( "Copy" ), this );
86  mActionClearExpr = new QAction( tr( "Clear" ), this );
87  mActionAssistant = new QAction( tr( "Assistant..." ), this );
88  QFont assistantFont = mActionAssistant->font();
89  assistantFont.setBold( true );
90  mActionAssistant->setFont( assistantFont );
91  mDefineMenu->addAction( mActionAssistant );
92 
93  // set up sibling widget connections
94  connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) );
95  connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) );
96 
97  init( vl, datadefined, datatypes, description );
98 }
99 
101 {
102  mEnabledWidgets.clear();
103  mCheckedWidgets.clear();
104 }
105 
107  const QgsDataDefined* datadefined,
108  DataTypes datatypes,
109  QString description )
110 {
111  mVectorLayer = vl;
112  // construct default property if none or incorrect passed in
113  if ( !datadefined )
114  {
115  mProperty.insert( "active", "0" );
116  mProperty.insert( "useexpr", "0" );
117  mProperty.insert( "expression", "" );
118  mProperty.insert( "field", "" );
119  }
120  else
121  {
122  mProperty.insert( "active", datadefined->isActive() ? "1" : "0" );
123  mProperty.insert( "useexpr", datadefined->useExpression() ? "1" : "0" );
124  mProperty.insert( "expression", datadefined->expressionString() );
125  mProperty.insert( "field", datadefined->field() );
126  }
127 
128  mDataTypes = datatypes;
129  mFieldNameList.clear();
130  mFieldTypeList.clear();
131 
132  mInputDescription = description;
133  mFullDescription = QString( "" );
134  mUsageInfo = QString( "" );
135  mCurrentDefinition = QString( "" );
136 
137  // set up data types string
138  mDataTypesString = QString( "" );
139 
140  QStringList ts;
141  if ( mDataTypes.testFlag( String ) )
142  {
143  ts << tr( "string" );
144  }
145  if ( mDataTypes.testFlag( Int ) )
146  {
147  ts << tr( "int" );
148  }
149  if ( mDataTypes.testFlag( Double ) )
150  {
151  ts << tr( "double" );
152  }
153 
154  if ( !ts.isEmpty() )
155  {
156  mDataTypesString = ts.join( ", " );
157  mActionDataTypes->setText( tr( "Field type: " ) + mDataTypesString );
158  }
159 
160  if ( mVectorLayer )
161  {
162  // store just a list of fields of unknown type or those that match the expected type
163  const QgsFields& fields = mVectorLayer->pendingFields();
164  for ( int i = 0; i < fields.count(); ++i )
165  {
166  const QgsField& f = fields.at( i );
167  bool fieldMatch = false;
168  // NOTE: these are the only QVariant enums supported at this time (see QgsField)
169  QString fieldType;
170  switch ( f.type() )
171  {
172  case QVariant::String:
173  fieldMatch = mDataTypes.testFlag( String );
174  fieldType = tr( "string" );
175  break;
176  case QVariant::Int:
177  fieldMatch = mDataTypes.testFlag( Int ) || mDataTypes.testFlag( Double );
178  fieldType = tr( "integer" );
179  break;
180  case QVariant::Double:
181  fieldMatch = mDataTypes.testFlag( Double );
182  fieldType = tr( "double" );
183  break;
184  case QVariant::Invalid:
185  default:
186  fieldMatch = true; // field type is unknown
187  fieldType = tr( "unknown type" );
188  }
189  if ( fieldMatch || mDataTypes.testFlag( AnyType ) )
190  {
191  mFieldNameList << f.name();
192  mFieldTypeList << fieldType;
193  }
194  }
195  }
196 
197  updateGui();
198 }
199 
201 {
202  if ( !dd )
203  return;
204 
205  dd->setActive( isActive() );
208  dd->setField( getField() );
209 }
210 
212 {
213  QgsDataDefined dd;
214  updateDataDefined( &dd );
215  return dd;
216 }
217 
219 {
220  // Ctrl-click to toggle activated state
221  if (( event->modifiers() & ( Qt::ControlModifier ) )
222  || event->button() == Qt::RightButton )
223  {
224  setActive( !isActive() );
225  updateGui();
226  event->ignore();
227  return;
228  }
229 
230  // pass to default behaviour
232 }
233 
234 void QgsDataDefinedButton::aboutToShowMenu()
235 {
236  mDefineMenu->clear();
237 
238  bool hasExp = !getExpression().isEmpty();
239  bool hasField = !getField().isEmpty();
240  QString ddTitle = tr( "Data defined override" );
241 
242  QAction* ddTitleAct = mDefineMenu->addAction( ddTitle );
243  QFont titlefont = ddTitleAct->font();
244  titlefont.setItalic( true );
245  ddTitleAct->setFont( titlefont );
246  ddTitleAct->setEnabled( false );
247 
248  bool addActiveAction = false;
249  if ( useExpression() && hasExp )
250  {
251  QgsExpression exp( getExpression() );
252  // whether expression is parse-able
253  addActiveAction = !exp.hasParserError();
254  }
255  else if ( !useExpression() && hasField )
256  {
257  // whether field exists
258  addActiveAction = mFieldNameList.contains( getField() );
259  }
260 
261  if ( addActiveAction )
262  {
263  ddTitleAct->setText( ddTitle + " (" + ( useExpression() ? tr( "expression" ) : tr( "field" ) ) + ")" );
264  mDefineMenu->addAction( mActionActive );
265  mActionActive->setText( isActive() ? tr( "Deactivate" ) : tr( "Activate" ) );
266  mActionActive->setData( QVariant( isActive() ? false : true ) );
267  }
268 
269  if ( !mFullDescription.isEmpty() )
270  {
271  mDefineMenu->addAction( mActionDescription );
272  }
273 
274  mDefineMenu->addSeparator();
275 
276  bool fieldActive = false;
277  if ( !mDataTypesString.isEmpty() )
278  {
279  QAction* fieldTitleAct = mDefineMenu->addAction( tr( "Attribute field" ) );
280  fieldTitleAct->setFont( titlefont );
281  fieldTitleAct->setEnabled( false );
282 
283  mDefineMenu->addAction( mActionDataTypes );
284 
285  mFieldsMenu->clear();
286 
287  if ( mFieldNameList.size() > 0 )
288  {
289 
290  for ( int j = 0; j < mFieldNameList.count(); ++j )
291  {
292  QString fldname = mFieldNameList.at( j );
293  QAction* act = mFieldsMenu->addAction( fldname + " (" + mFieldTypeList.at( j ) + ")" );
294  act->setData( QVariant( fldname ) );
295  if ( getField() == fldname )
296  {
297  act->setCheckable( true );
298  act->setChecked( !useExpression() );
299  fieldActive = !useExpression();
300  }
301  }
302  }
303  else
304  {
305  QAction* act = mFieldsMenu->addAction( tr( "No matching field types found" ) );
306  act->setEnabled( false );
307  }
308 
309  mDefineMenu->addSeparator();
310  }
311 
312  mFieldsMenu->menuAction()->setCheckable( true );
313  mFieldsMenu->menuAction()->setChecked( fieldActive );
314 
315  QAction* exprTitleAct = mDefineMenu->addAction( tr( "Expression" ) );
316  exprTitleAct->setFont( titlefont );
317  exprTitleAct->setEnabled( false );
318 
319  if ( hasExp )
320  {
321  QString expString = getExpression();
322  if ( expString.length() > 35 )
323  {
324  expString.truncate( 35 );
325  expString.append( "..." );
326  }
327 
328  expString.prepend( tr( "Current: " ) );
329 
330  if ( !mActionExpression )
331  {
332  mActionExpression = new QAction( expString, this );
333  mActionExpression->setCheckable( true );
334  }
335  else
336  {
337  mActionExpression->setText( expString );
338  }
339  mDefineMenu->addAction( mActionExpression );
340  mActionExpression->setChecked( useExpression() );
341 
342  mDefineMenu->addAction( mActionExpDialog );
343  mDefineMenu->addAction( mActionCopyExpr );
344  mDefineMenu->addAction( mActionPasteExpr );
345  mDefineMenu->addAction( mActionClearExpr );
346  }
347  else
348  {
349  mDefineMenu->addAction( mActionExpDialog );
350  mDefineMenu->addAction( mActionPasteExpr );
351  }
352 
353  if ( mAssistant.data() )
354  {
355  mDefineMenu->addSeparator();
356  mDefineMenu->addAction( mActionAssistant );
357  }
358 }
359 
360 void QgsDataDefinedButton::menuActionTriggered( QAction* action )
361 {
362  if ( action == mActionActive )
363  {
364  setActive( mActionActive->data().toBool() );
365  updateGui();
366  }
367  else if ( action == mActionDescription )
368  {
369  showDescriptionDialog();
370  }
371  else if ( action == mActionExpDialog )
372  {
373  showExpressionDialog();
374  }
375  else if ( action == mActionExpression )
376  {
377  setUseExpression( true );
378  setActive( true );
379  updateGui();
380  }
381  else if ( action == mActionCopyExpr )
382  {
384  }
385  else if ( action == mActionPasteExpr )
386  {
387  QString exprString = QApplication::clipboard()->text();
388  if ( !exprString.isEmpty() )
389  {
390  setExpression( exprString );
391  setUseExpression( true );
392  setActive( true );
393  updateGui();
394  }
395  }
396  else if ( action == mActionClearExpr )
397  {
398  // only deactivate if defined expression is being used
399  if ( isActive() && useExpression() )
400  {
401  setUseExpression( false );
402  setActive( false );
403  }
404  setExpression( QString( "" ) );
405  updateGui();
406  }
407  else if ( action == mActionAssistant )
408  {
409  showAssistant();
410  }
411  else if ( mFieldsMenu->actions().contains( action ) ) // a field name clicked
412  {
413  if ( action->isEnabled() )
414  {
415  if ( getField() != action->text() )
416  {
417  setField( action->data().toString() );
418  }
419  setUseExpression( false );
420  setActive( true );
421  updateGui();
422  }
423  }
424 }
425 
426 void QgsDataDefinedButton::showDescriptionDialog()
427 {
428  QgsMessageViewer* mv = new QgsMessageViewer( this );
429  mv->setWindowTitle( tr( "Data definition description" ) );
430  mv->setMessageAsHtml( mFullDescription );
431  mv->exec();
432 }
433 
434 void QgsDataDefinedButton::showAssistant()
435 {
436  if ( !mAssistant.data() )
437  return;
438 
439  if ( mAssistant->exec() == QDialog::Accepted )
440  {
441  QgsDataDefined dd = mAssistant->dataDefined();
443  setActive( dd.isActive() );
444  if ( dd.isActive() && dd.useExpression() )
446  else if ( dd.isActive() )
447  setField( dd.field() );
448  updateGui();
449  }
450  activateWindow(); // reset focus to parent window
451 }
452 
453 void QgsDataDefinedButton::showExpressionDialog()
454 {
455  QgsExpressionBuilderDialog d( const_cast<QgsVectorLayer*>( mVectorLayer ), getExpression() );
456  if ( d.exec() == QDialog::Accepted )
457  {
458  QString newExp = d.expressionText();
459  setExpression( d.expressionText().trimmed() );
460  bool hasExp = !newExp.isEmpty();
461 
462  setUseExpression( hasExp );
463  setActive( hasExp );
464  updateGui();
465  }
466  activateWindow(); // reset focus to parent window
467 }
468 
469 void QgsDataDefinedButton::updateGui()
470 {
471  QString oldDef = mCurrentDefinition;
472  QString newDef( "" );
473  bool hasExp = !getExpression().isEmpty();
474  bool hasField = !getField().isEmpty();
475 
476  if ( useExpression() && !hasExp )
477  {
478  setActive( false );
479  setUseExpression( false );
480  }
481  else if ( !useExpression() && !hasField )
482  {
483  setActive( false );
484  }
485 
486  QIcon icon = mIconDataDefine;
487  QString deftip = tr( "undefined" );
488  if ( useExpression() && hasExp )
489  {
490  icon = isActive() ? mIconDataDefineExpressionOn : mIconDataDefineExpression;
491  newDef = deftip = getExpression();
492 
493  QgsExpression exp( getExpression() );
494  if ( exp.hasParserError() )
495  {
496  setActive( false );
497  icon = mIconDataDefineExpressionError;
498  deftip = tr( "Parse error: %1" ).arg( exp.parserErrorString() );
499  newDef = "";
500  }
501  }
502  else if ( !useExpression() && hasField )
503  {
504  icon = isActive() ? mIconDataDefineOn : mIconDataDefine;
505  newDef = deftip = getField();
506 
507  if ( !mFieldNameList.contains( getField() ) )
508  {
509  setActive( false );
510  icon = mIconDataDefineError;
511  deftip = tr( "'%1' field missing" ).arg( getField() );
512  newDef = "";
513  }
514  }
515 
516  setIcon( icon );
517 
518  // update and emit current definition
519  if ( newDef != oldDef )
520  {
521  mCurrentDefinition = newDef;
522  emit dataDefinedChanged( mCurrentDefinition );
523  }
524 
525  // build full description for tool tip and popup dialog
526  mFullDescription = tr( "<b><u>Data defined override</u></b><br>" );
527 
528  mFullDescription += tr( "<b>Active: </b>%1&nbsp;&nbsp;&nbsp;<i>(ctrl|right-click toggles)</i><br>" ).arg( isActive() ? tr( "yes" ) : tr( "no" ) );
529 
530  if ( !mUsageInfo.isEmpty() )
531  {
532  mFullDescription += tr( "<b>Usage:</b><br>%1<br>" ).arg( mUsageInfo );
533  }
534 
535  if ( !mInputDescription.isEmpty() )
536  {
537  mFullDescription += tr( "<b>Expected input:</b><br>%1<br>" ).arg( mInputDescription );
538  }
539 
540  if ( !mDataTypesString.isEmpty() )
541  {
542  mFullDescription += tr( "<b>Valid input types:</b><br>%1<br>" ).arg( mDataTypesString );
543  }
544 
545  QString deftype( "" );
546  if ( deftip != tr( "undefined" ) )
547  {
548  deftype = QString( " (%1)" ).arg( useExpression() ? tr( "expression" ) : tr( "field" ) );
549  }
550 
551  // truncate long expressions, or tool tip may be too wide for screen
552  if ( deftip.length() > 75 )
553  {
554  deftip.truncate( 75 );
555  deftip.append( "..." );
556  }
557 
558  mFullDescription += tr( "<b>Current definition %1:</b><br>%2" ).arg( deftype ).arg( deftip );
559 
560  setToolTip( mFullDescription );
561 
562 }
563 
565 {
566  if ( isActive() != active )
567  {
568  mProperty.insert( "active", active ? "1" : "0" );
569  emit dataDefinedActivated( active );
570  }
571 }
572 
574 {
575  for ( int i = 0; i < wdgts.size(); ++i )
576  {
577  registerEnabledWidget( wdgts.at( i ) );
578  }
579 }
580 
582 {
583  QPointer<QWidget> wdgtP( wdgt );
584  if ( !mEnabledWidgets.contains( wdgtP ) )
585  {
586  mEnabledWidgets.append( wdgtP );
587  }
588 }
589 
591 {
592  QList<QWidget*> wdgtList;
593  for ( int i = 0; i < mEnabledWidgets.size(); ++i )
594  {
595  wdgtList << mEnabledWidgets.at( i );
596  }
597  return wdgtList;
598 }
599 
601 {
602  for ( int i = 0; i < mEnabledWidgets.size(); ++i )
603  {
604  mEnabledWidgets.at( i )->setDisabled( disable );
605  }
606 }
607 
609 {
610  for ( int i = 0; i < wdgts.size(); ++i )
611  {
612  registerCheckedWidget( wdgts.at( i ) );
613  }
614 }
615 
617 {
618  QPointer<QWidget> wdgtP( wdgt );
619  if ( !mCheckedWidgets.contains( wdgtP ) )
620  {
621  mCheckedWidgets.append( wdgtP );
622  }
623 }
624 
626 {
627  QList<QWidget*> wdgtList;
628  for ( int i = 0; i < mCheckedWidgets.size(); ++i )
629  {
630  wdgtList << mCheckedWidgets.at( i );
631  }
632  return wdgtList;
633 }
634 
636 {
637  mActionAssistant->setText( title.isEmpty() ? tr( "Assistant..." ) : title );
638  mAssistant.reset( assistant );
639  mAssistant.data()->setParent( this, Qt::Dialog );
640 }
641 
643 {
644  // don't uncheck, only set to checked
645  if ( !check )
646  {
647  return;
648  }
649  for ( int i = 0; i < mCheckedWidgets.size(); ++i )
650  {
651  QAbstractButton *btn = qobject_cast< QAbstractButton * >( mCheckedWidgets.at( i ) );
652  if ( btn && btn->isCheckable() )
653  {
654  btn->setChecked( true );
655  continue;
656  }
657  QGroupBox *grpbx = qobject_cast< QGroupBox * >( mCheckedWidgets.at( i ) );
658  if ( grpbx && grpbx->isCheckable() )
659  {
660  grpbx->setChecked( true );
661  }
662  }
663 }
664 
666 {
667  // just something to reduce translation redundancy
668  return tr( "string " );
669 }
670 
672 {
673  return tr( "single character" );
674 }
675 
677 {
678  return tr( "bool [<b>1</b>=True|<b>0</b>=False]" );
679 }
680 
682 {
683  return tr( "string of variable length" );
684 }
685 
687 {
688  return tr( "int [&lt;= 0 =&gt;]" );
689 }
690 
692 {
693  return tr( "int [&gt;= 0]" );
694 }
695 
697 {
698  return tr( "int [&gt;= 1]" );
699 }
700 
702 {
703  return tr( "double [&lt;= 0.0 =&gt;]" );
704 }
705 
707 {
708  return tr( "double [&gt;= 0.0]" );
709 }
710 
712 {
713  return tr( "double [0.0-1.0]" );
714 }
715 
717 {
718  return tr( "double coord [<b>X,Y</b>] as &lt;= 0.0 =&gt;" );
719 }
720 
722 {
723  return tr( "double [-180.0 - 180.0]" );
724 }
725 
727 {
728  return tr( "int [0-100]" );
729 }
730 
732 {
733  return trString() + "[<b>MM</b>|<b>MapUnit</b>]";
734 }
735 
737 {
738  return trString() + "[<b>MM</b>|<b>MapUnit</b>|<b>Percent</b>]";
739 }
740 
742 {
743  return tr( "string [<b>r,g,b</b>] as int 0-255" );
744 }
745 
747 {
748  return tr( "string [<b>r,g,b,a</b>] as int 0-255" );
749 }
750 
752 {
753  return trString() + "[<b>Left</b>|<b>Center</b>|<b>Right</b>]";
754 }
755 
757 {
758  return trString() + "[<b>Bottom</b>|<b>Middle</b>|<b>Top</b>]";
759 }
760 
762 {
763  return trString() + "[<b>bevel</b>|<b>miter</b>|<b>round</b>]";
764 }
765 
767 {
768  return trString() + QString( "[<b>Normal</b>|<b>Lighten</b>|<b>Screen</b>|<b>Dodge</b>|<br>"
769  "<b>Addition</b>|<b>Darken</b>|<b>Multiply</b>|<b>Burn</b>|<b>Overlay</b>|<br>"
770  "<b>SoftLight</b>|<b>HardLight</b>|<b>Difference</b>|<b>Subtract</b>]" );
771 }
772 
774 {
775  return trString() + QString( "[<b>filepath</b>] as<br>"
776  "<b>''</b>=empty|absolute|search-paths-relative|<br>"
777  "project-relative|URL" );
778 }
779 
781 {
782  return tr( "string [<b>filepath</b>]" );
783 }
784 
786 {
787  return trString() + QString( "[<b>A5</b>|<b>A4</b>|<b>A3</b>|<b>A2</b>|<b>A1</b>|<b>A0</b>"
788  "<b>B5</b>|<b>B4</b>|<b>B3</b>|<b>B2</b>|<b>B1</b>|<b>B0</b>"
789  "<b>Legal</b>|<b>Ansi A</b>|<b>Ansi B</b>|<b>Ansi C</b>|<b>Ansi D</b>|<b>Ansi E</b>"
790  "<b>Arch A</b>|<b>Arch B</b>|<b>Arch C</b>|<b>Arch D</b>|<b>Arch E</b>|<b>Arch E1</b>]"
791  );
792 }
793 
795 {
796  return trString() + QString( "[<b>portrait</b>|<b>landscape</b>]" );
797 }
798 
800 {
801  return trString() + QString( "[<b>left</b>|<b>center</b>|<b>right</b>]" );
802 }
803 
805 {
806  return trString() + QString( "[<b>top</b>|<b>center</b>|<b>bottom</b>]" );
807 }
808 
810 {
811  return trString() + QString( "[<b>linear</b>|<b>radial</b>|<b>conical</b>]" );
812 }
813 
815 {
816  return trString() + QString( "[<b>feature</b>|<b>viewport</b>]" );
817 }
818 
820 {
821  return trString() + QString( "[<b>pad</b>|<b>repeat</b>|<b>reflect</b>]" );
822 }
823 
825 {
826  return trString() + QString( "[<b>no</b>|<b>solid</b>|<b>dash</b>|<b>dot</b>|<b>dash dot</b>|<b>dash dot dot</b>]" );
827 }
828 
830 {
831  return trString() + QString( "[<b>square</b>|<b>flat</b>|<b>round</b>]" );
832 }
833 
835 {
836  return trString() + QString( "[<b>solid</b>|<b>horizontal</b>|<b>vertical</b>|<b>cross</b>|<b>b_diagonal</b>|<b>f_diagonal"
837  "</b>|<b>diagonal_x</b>|<b>dense1</b>|<b>dense2</b>|<b>dense3</b>|<b>dense4</b>|<b>dense5"
838  "</b>|<b>dense6</b>|<b>dense7</b>|<b>no]" );
839 }
840 
842 {
843  return trString() + QString( "[<b>circle</b>|<b>rectangle</b>|<b>cross</b>|<b>triangle</b>]" );
844 }
845 
847 {
848  return tr( "[<b><dash>;<space></b>] e.g. '8;2;1;2'" );
849 }
void setText(const QString &text)
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:86
const QString & name() const
Gets the name of the field.
Definition: qgsfield.cpp:69
void clear()
void setActive(bool active)
void setStyleSheet(const QString &styleSheet)
static QString gradientSpreadDesc()
An assistant (wizard) dialog, accessible from a QgsDataDefinedButton.
QString & append(QChar ch)
void setMenu(QMenu *menu)
void setExpression(QString exp)
Set the current defined expression.
void setField(QString field)
Set the current defined field.
void truncate(int position)
A container class for data source field mapping or expression.
static QString doublePosDesc()
static QString colorNoAlphaDesc()
static QString textVertAlignDesc()
QString field() const
QList< QWidget * > registeredEnabledWidgets()
Return widget siblings that get disabled/enabled when data definition or expression is set/unset...
static QString paperOrientationDesc()
void setFocusPolicy(Qt::FocusPolicy policy)
void dataDefinedChanged(const QString &definition)
Emitted when data definition or expression is changed.
void setChecked(bool)
QString & prepend(QChar ch)
QVariant data() const
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
const T & at(int i) const
void addAction(QAction *action)
bool contains(const QString &str, Qt::CaseSensitivity cs) const
static QString unitsMmMuDesc()
void registerCheckedWidgets(QList< QWidget * > wdgts)
Register list of sibling widgets that get checked when data definition or expression is active...
static QString anyStringDesc()
int exec()
Container of fields for a vector layer.
Definition: qgsfield.h:173
void disableEnabledWidgets(bool disable)
Set siblings' enabled property when data definition or expression is set/unset.
void setMenu(QMenu *menu)
static QString lineStyleDesc()
QString expressionString() const
void updateDataDefined(QgsDataDefined *dd) const
Updates a QgsDataDefined with the current settings from the button.
QString join(const QString &separator) const
void init(const QgsVectorLayer *vl, const QgsDataDefined *datadefined=0, DataTypes datatypes=AnyType, QString description=QString(""))
Initialize a newly constructed data defined button (useful if button already included from form layou...
static QString horizontalAnchorDesc()
void triggered(QAction *action)
QIcon icon() const
QString tr(const char *sourceText, const char *disambiguation, int n)
int size() const
void mouseReleaseEvent(QMouseEvent *event) override
void reset(T *other)
void setBold(bool enable)
void setMessageAsHtml(const QString &msg)
void clear()
void setUseExpression(bool use)
void setActive(bool active)
Set whether the current data definition or expression is to be used.
static QString unitsMmMuPercentDesc()
int count(const T &value) const
void registerEnabledWidget(QWidget *wdgt)
Register a sibling widget that gets disabled/enabled when data definition or expression is set/unset...
void append(const T &value)
static QString textHorzAlignDesc()
void setChecked(bool checked)
static QString penJoinStyleDesc()
virtual void mousePressEvent(QMouseEvent *e)
static QString double180RotDesc()
QClipboard * clipboard()
static QString gradientTypeDesc()
void setField(const QString &field)
void setIconSize(const QSize &size)
static QString intTranspDesc()
bool isEmpty() const
bool isEmpty() const
QString getExpression() const
The current defined expression.
int count() const
Return number of items.
Definition: qgsfield.cpp:283
bool isCheckable() const
QAction * addSeparator()
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:38
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfield.cpp:303
bool useExpression() const
Qt::KeyboardModifiers modifiers() const
T * data() const
void setData(const QVariant &userData)
void registerEnabledWidgets(QList< QWidget * > wdgts)
Register list of sibling widgets that get disabled/enabled when data definition or expression is set/...
void setFixedSize(const QSize &s)
QList< QWidget * > registeredCheckedWidgets()
Return widget siblings that get checked when data definition or expression is active.
static QString markerStyleDesc()
bool contains(const T &value) const
void dataDefinedActivated(bool active)
Emitted when active state changed.
void setCheckable(bool)
void setItalic(bool enable)
static QString blendModesDesc()
static QString gradientCoordModeDesc()
void setChecked(bool)
QString text(Mode mode) const
static QString trString()
Common descriptions for expected input values.
void registerCheckedWidget(QWidget *wdgt)
Register a sibling widget that get checked when data definition or expression is active.
QString getField() const
The current defined field.
void setAssistant(const QString &title, QgsDataDefinedAssistant *assistant)
Sets an assistant used to define the data defined object properties.
void activateWindow()
bool isCheckable() const
bool isNull() const
static QString verticalAnchorDesc()
void setWindowTitle(const QString &)
void setPopupMode(ToolButtonPopupMode mode)
static QString fillStyleDesc()
static QString paperSizeDesc()
void setUseExpression(bool use)
Set whether the current expression is to be used instead of field mapping.
void checkCheckedWidgets(bool check)
Set siblings' checked property when data definition or expression is active.
A generic message view for displaying QGIS messages.
int length() const
bool toBool() const
static QString intPosOneDesc()
iterator insert(const Key &key, const T &value)
void setText(const QString &text, Mode mode)
QAction * menuAction() const
bool isActive() const
Whether the current data definition or expression is to be used.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
void setToolTip(const QString &)
bool useExpression() const
Whether the current expression is to be used instead of field mapping.
QgsDataDefined currentDataDefined() const
Returns a QgsDataDefined which reflects the current settings from the button.
QgsDataDefinedButton(QWidget *parent=0, const QgsVectorLayer *vl=0, const QgsDataDefined *datadefined=0, DataTypes datatypes=AnyType, QString description="")
Construct a new data defined button.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QList< QAction * > actions() const
static QString customDashDesc()
Represents a vector layer which manages a vector based data sets.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
void setExpressionString(const QString &expr)
bool isActive() const
A generic dialog for building expression strings.
void setEnabled(bool)
static QString double0to1Desc()
static QString colorAlphaDesc()
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:74