QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <qgsfield.h>
19 #include <qgsdatadefined.h>
20 
21 #include <QFlags>
22 #include <QMap>
23 #include <QPointer>
24 #include <QToolButton>
25 
26 class QgsVectorLayer;
27 
33 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
34 {
35  Q_OBJECT
36  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
37 
38  public:
39  enum DataType
40  {
41  String = 1,
42  Int = 2,
43  Double = 4,
44  AnyType = String | Int | Double
45  };
46  Q_DECLARE_FLAGS( DataTypes, DataType )
47 
48 
57  QgsDataDefinedButton( QWidget* parent = 0,
58  const QgsVectorLayer* vl = 0,
59  const QgsDataDefined* datadefined = 0,
60  DataTypes datatypes = AnyType,
61  QString description = "" );
63 
72  void init( const QgsVectorLayer* vl,
73  const QgsDataDefined* datadefined = 0,
74  DataTypes datatypes = AnyType,
75  QString description = QString( "" ) );
76 
77  QMap< QString, QString > definedProperty() const { return mProperty; }
78 
82  bool isActive() { return mProperty.value( "active" ).toInt(); }
83 
87  bool useExpression() { return mProperty.value( "useexpr" ).toInt(); }
88 
92  QString getExpression() const { return mProperty.value( "expression" ); }
93 
97  QString getField() const { return mProperty.value( "field" ); }
98 
103  QString currentDefinition() const { return mCurrentDefinition; }
104 
109  const DataTypes& validDataTypes() const { return mDataTypes; }
110 
114  QString fullDescription() const { return mFullDescription; }
115 
119  QString usageInfo() const { return mUsageInfo; }
120 
124  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
125 
129  void registerEnabledWidgets( QList<QWidget*> wdgts );
130 
134  void registerEnabledWidget( QWidget* wdgt );
135 
141  QList<QWidget*> registeredEnabledWidgets();
142 
146  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
147 
151  void registerCheckedWidgets( QList<QWidget*> wdgts );
152 
156  void registerCheckedWidget( QWidget* wdgt );
157 
163  QList<QWidget*> registeredCheckedWidgets();
164 
168  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
169 
173  static QString trString();
174  static QString boolDesc();
175  static QString anyStringDesc();
176  static QString intDesc();
177  static QString intPosDesc();
178  static QString intPosOneDesc();
179  static QString doubleDesc();
180  static QString doublePosDesc();
181  static QString double0to1Desc();
182  static QString doubleXYDesc();
183  static QString double180RotDesc();
184  static QString intTranspDesc();
185  static QString unitsMmMuDesc();
186  static QString unitsMmMuPercentDesc();
187  static QString colorNoAlphaDesc();
188  static QString colorAlphaDesc();
189  static QString textHorzAlignDesc();
190  static QString textVertAlignDesc();
191  static QString penJoinStyleDesc();
192  static QString blendModesDesc();
193  static QString svgPathDesc();
194  static QString filePathDesc();
195  static QString paperSizeDesc();
196  static QString paperOrientationDesc();
197  static QString horizontalAnchorDesc();
198  static QString verticalAnchorDesc();
199  static QString gradientTypeDesc();
200  static QString gradientCoordModeDesc();
201  static QString gradientSpreadDesc();
202  static QString lineStyleDesc();
203  static QString capStyleDesc();
204  static QString fillStyleDesc();
205  static QString markerStyleDesc();
206  static QString customDashDesc();
207 
208  public slots:
212  void setActive( bool active );
213 
217  void disableEnabledWidgets( bool disable );
218 
222  void checkCheckedWidgets( bool check );
223 
224  signals:
229  void dataDefinedChanged( const QString& definition );
230 
235  void dataDefinedActivated( bool active );
236 
237  protected:
238  void mouseReleaseEvent( QMouseEvent *event ) override;
239 
243  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
244 
248  void setExpression( QString exp ) { mProperty.insert( "expression", exp ); }
249 
253  void setField( QString field ) { mProperty.insert( "field", field ); }
254 
255  private:
256  void showDescriptionDialog();
257  void showExpressionDialog();
258  void updateGui();
259 
260  const QgsVectorLayer* mVectorLayer;
261  QgsFields mFields;
262  QStringList mFieldNameList;
263  QStringList mFieldTypeList;
264  QMap< QString, QString > mProperty;
265  QList< QPointer<QWidget> > mEnabledWidgets;
266  QList< QPointer<QWidget> > mCheckedWidgets;
267 
268  QMenu* mDefineMenu;
269  QAction* mActionDataTypes;
270  QMenu* mFieldsMenu;
271 
272  QAction* mActionActive;
273  QAction* mActionDescription;
274  QAction* mActionExpDialog;
275  QAction* mActionExpression;
276  QAction* mActionPasteExpr;
277  QAction* mActionCopyExpr;
278  QAction* mActionClearExpr;
279 
280  DataTypes mDataTypes;
281  QString mDataTypesString;
282  QString mInputDescription;
283  QString mFullDescription;
284  QString mUsageInfo;
285  QString mCurrentDefinition;
286 
287  static QIcon mIconDataDefine;
288  static QIcon mIconDataDefineOn;
289  static QIcon mIconDataDefineError;
290  static QIcon mIconDataDefineExpression;
291  static QIcon mIconDataDefineExpressionOn;
292  static QIcon mIconDataDefineExpressionError;
293 
294  private slots:
295  void aboutToShowMenu();
296  void menuActionTriggered( QAction* action );
297 };
298 
299 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
300 
301 
302 #endif // QGSDATADEFINEDBUTTON_H