QGIS API Documentation  2.9.0-Master
qgsdatadefinedbutton.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatadefinedbutton.h - 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 #ifndef QGSDATADEFINEDBUTTON_H
16 #define QGSDATADEFINEDBUTTON_H
17 
18 #include <QDialog>
19 #include <QFlags>
20 #include <QMap>
21 #include <QPointer>
22 #include <QToolButton>
23 #include <QScopedPointer>
24 
25 class QgsVectorLayer;
26 class QgsDataDefined;
27 
35 class GUI_EXPORT QgsDataDefinedAssistant: public QDialog
36 {
37  public:
38  virtual QgsDataDefined dataDefined() const = 0;
39 };
40 
46 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
47 {
48  Q_OBJECT
49  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
50 
51  public:
52  enum DataType
53  {
54  String = 1,
55  Int = 2,
56  Double = 4,
57  AnyType = String | Int | Double
58  };
59  Q_DECLARE_FLAGS( DataTypes, DataType )
60 
61 
70  QgsDataDefinedButton( QWidget* parent = 0,
71  const QgsVectorLayer* vl = 0,
72  const QgsDataDefined* datadefined = 0,
73  DataTypes datatypes = AnyType,
74  QString description = "" );
76 
85  void init( const QgsVectorLayer* vl,
86  const QgsDataDefined* datadefined = 0,
87  DataTypes datatypes = AnyType,
88  QString description = QString( "" ) );
89 
90  QMap< QString, QString > definedProperty() const { return mProperty; }
91 
97  void updateDataDefined( QgsDataDefined* dd ) const;
98 
104  QgsDataDefined currentDataDefined() const;
105 
109  bool isActive() const { return mProperty.value( "active" ).toInt(); }
110 
114  bool useExpression() const { return mProperty.value( "useexpr" ).toInt(); }
115 
119  QString getExpression() const { return mProperty.value( "expression" ); }
120 
124  QString getField() const { return mProperty.value( "field" ); }
125 
130  QString currentDefinition() const { return mCurrentDefinition; }
131 
136  const DataTypes& validDataTypes() const { return mDataTypes; }
137 
141  QString fullDescription() const { return mFullDescription; }
142 
146  QString usageInfo() const { return mUsageInfo; }
147 
151  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
152 
156  void registerEnabledWidgets( QList<QWidget*> wdgts );
157 
161  void registerEnabledWidget( QWidget* wdgt );
162 
168  QList<QWidget*> registeredEnabledWidgets();
169 
173  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
174 
178  void registerCheckedWidgets( QList<QWidget*> wdgts );
179 
183  void registerCheckedWidget( QWidget* wdgt );
184 
190  QList<QWidget*> registeredCheckedWidgets();
191 
195  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
196 
204  void setAssistant( QgsDataDefinedAssistant * assistant );
205 
209  static QString trString();
210  static QString charDesc();
211  static QString boolDesc();
212  static QString anyStringDesc();
213  static QString intDesc();
214  static QString intPosDesc();
215  static QString intPosOneDesc();
216  static QString doubleDesc();
217  static QString doublePosDesc();
218  static QString double0to1Desc();
219  static QString doubleXYDesc();
220  static QString double180RotDesc();
221  static QString intTranspDesc();
222  static QString unitsMmMuDesc();
223  static QString unitsMmMuPercentDesc();
224  static QString colorNoAlphaDesc();
225  static QString colorAlphaDesc();
226  static QString textHorzAlignDesc();
227  static QString textVertAlignDesc();
228  static QString penJoinStyleDesc();
229  static QString blendModesDesc();
230  static QString svgPathDesc();
231  static QString filePathDesc();
232  static QString paperSizeDesc();
233  static QString paperOrientationDesc();
234  static QString horizontalAnchorDesc();
235  static QString verticalAnchorDesc();
236  static QString gradientTypeDesc();
237  static QString gradientCoordModeDesc();
238  static QString gradientSpreadDesc();
239  static QString lineStyleDesc();
240  static QString capStyleDesc();
241  static QString fillStyleDesc();
242  static QString markerStyleDesc();
243  static QString customDashDesc();
244 
245  public slots:
249  void setActive( bool active );
250 
254  void disableEnabledWidgets( bool disable );
255 
259  void checkCheckedWidgets( bool check );
260 
261  signals:
266  void dataDefinedChanged( const QString& definition );
267 
272  void dataDefinedActivated( bool active );
273 
274  protected:
275  void mouseReleaseEvent( QMouseEvent *event ) override;
276 
280  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
281 
285  void setExpression( QString exp ) { mProperty.insert( "expression", exp ); }
286 
290  void setField( QString field ) { mProperty.insert( "field", field ); }
291 
292  private:
293  void showDescriptionDialog();
294  void showExpressionDialog();
295  void showAssistant();
296  void updateGui();
297 
298  const QgsVectorLayer* mVectorLayer;
299  QStringList mFieldNameList;
300  QStringList mFieldTypeList;
301  QMap< QString, QString > mProperty;
302  QList< QPointer<QWidget> > mEnabledWidgets;
303  QList< QPointer<QWidget> > mCheckedWidgets;
304 
305  QMenu* mDefineMenu;
306  QAction* mActionDataTypes;
307  QMenu* mFieldsMenu;
308 
309  QAction* mActionActive;
310  QAction* mActionDescription;
311  QAction* mActionExpDialog;
312  QAction* mActionExpression;
313  QAction* mActionPasteExpr;
314  QAction* mActionCopyExpr;
315  QAction* mActionClearExpr;
316  QAction* mActionAssistant;
317 
318  DataTypes mDataTypes;
319  QString mDataTypesString;
320  QString mInputDescription;
321  QString mFullDescription;
322  QString mUsageInfo;
323  QString mCurrentDefinition;
324 
325  QScopedPointer<QgsDataDefinedAssistant> mAssistant;
326 
327  static QIcon mIconDataDefine;
328  static QIcon mIconDataDefineOn;
329  static QIcon mIconDataDefineError;
330  static QIcon mIconDataDefineExpression;
331  static QIcon mIconDataDefineExpressionOn;
332  static QIcon mIconDataDefineExpressionError;
333 
334  private slots:
335  void aboutToShowMenu();
336  void menuActionTriggered( QAction* action );
337 };
338 
339 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
340 
341 
342 #endif // QGSDATADEFINEDBUTTON_H
void clearEnabledWidgets()
Clears list of sibling widgets.
An assistant (wizard) dialog, accessible from a QgsDataDefinedButton.
void setExpression(QString exp)
Set the current defined expression.
void setField(QString field)
Set the current defined field.
A container class for data source field mapping or expression.
void clearCheckedWidgets()
Clears list of checkable sibling widgets.
QString fullDescription() const
The full definition description and current definition (internally generated on a contextual basis) ...
QString getExpression() const
The current defined expression.
A button for defining data source field mappings or expressions.
QString getField() const
The current defined field.
void setUseExpression(bool use)
Set whether the current expression is to be used instead of field mapping.
QString usageInfo() const
The usage information about this data definition.
const DataTypes & validDataTypes() const
The valid data types that will work for the definition (QVariant-coercible to expected type) Compared...
bool isActive() const
Whether the current data definition or expression is to be used.
void setUsageInfo(const QString &info)
Set the usage information about this data definition.
bool useExpression() const
Whether the current expression is to be used instead of field mapping.
QString currentDefinition() const
The current definition.
Represents a vector layer which manages a vector based data sets.