QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 <QFlags>
20 #include <QMap>
21 #include <QPointer>
22 #include <QToolButton>
23 
24 class QgsVectorLayer;
25 class QgsDataDefined;
26 
32 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
33 {
34  Q_OBJECT
35  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
36 
37  public:
38  enum DataType
39  {
40  String = 1,
41  Int = 2,
42  Double = 4,
43  AnyType = String | Int | Double
44  };
45  Q_DECLARE_FLAGS( DataTypes, DataType )
46 
47 
56  QgsDataDefinedButton( QWidget* parent = 0,
57  const QgsVectorLayer* vl = 0,
58  const QgsDataDefined* datadefined = 0,
59  DataTypes datatypes = AnyType,
60  QString description = "" );
62 
71  void init( const QgsVectorLayer* vl,
72  const QgsDataDefined* datadefined = 0,
73  DataTypes datatypes = AnyType,
74  QString description = QString( "" ) );
75 
76  QMap< QString, QString > definedProperty() const { return mProperty; }
77 
81  bool isActive() { return mProperty.value( "active" ).toInt(); }
82 
86  bool useExpression() { return mProperty.value( "useexpr" ).toInt(); }
87 
91  QString getExpression() const { return mProperty.value( "expression" ); }
92 
96  QString getField() const { return mProperty.value( "field" ); }
97 
102  QString currentDefinition() const { return mCurrentDefinition; }
103 
108  const DataTypes& validDataTypes() const { return mDataTypes; }
109 
113  QString fullDescription() const { return mFullDescription; }
114 
118  QString usageInfo() const { return mUsageInfo; }
119 
123  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
124 
128  void registerEnabledWidgets( QList<QWidget*> wdgts );
129 
133  void registerEnabledWidget( QWidget* wdgt );
134 
140  QList<QWidget*> registeredEnabledWidgets();
141 
145  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
146 
150  void registerCheckedWidgets( QList<QWidget*> wdgts );
151 
155  void registerCheckedWidget( QWidget* wdgt );
156 
162  QList<QWidget*> registeredCheckedWidgets();
163 
167  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
168 
172  static QString trString();
173  static QString boolDesc();
174  static QString anyStringDesc();
175  static QString intDesc();
176  static QString intPosDesc();
177  static QString intPosOneDesc();
178  static QString doubleDesc();
179  static QString doublePosDesc();
180  static QString double0to1Desc();
181  static QString doubleXYDesc();
182  static QString double180RotDesc();
183  static QString intTranspDesc();
184  static QString unitsMmMuDesc();
185  static QString unitsMmMuPercentDesc();
186  static QString colorNoAlphaDesc();
187  static QString colorAlphaDesc();
188  static QString textHorzAlignDesc();
189  static QString textVertAlignDesc();
190  static QString penJoinStyleDesc();
191  static QString blendModesDesc();
192  static QString svgPathDesc();
193  static QString filePathDesc();
194  static QString paperSizeDesc();
195  static QString paperOrientationDesc();
196  static QString horizontalAnchorDesc();
197  static QString verticalAnchorDesc();
198  static QString gradientTypeDesc();
199  static QString gradientCoordModeDesc();
200  static QString gradientSpreadDesc();
201  static QString lineStyleDesc();
202  static QString capStyleDesc();
203  static QString fillStyleDesc();
204  static QString markerStyleDesc();
205  static QString customDashDesc();
206 
207  public slots:
211  void setActive( bool active );
212 
216  void disableEnabledWidgets( bool disable );
217 
221  void checkCheckedWidgets( bool check );
222 
223  signals:
228  void dataDefinedChanged( const QString& definition );
229 
234  void dataDefinedActivated( bool active );
235 
236  protected:
237  void mouseReleaseEvent( QMouseEvent *event ) override;
238 
242  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
243 
247  void setExpression( QString exp ) { mProperty.insert( "expression", exp ); }
248 
252  void setField( QString field ) { mProperty.insert( "field", field ); }
253 
254  private:
255  void showDescriptionDialog();
256  void showExpressionDialog();
257  void updateGui();
258 
259  const QgsVectorLayer* mVectorLayer;
260  QgsFields mFields;
261  QStringList mFieldNameList;
262  QStringList mFieldTypeList;
263  QMap< QString, QString > mProperty;
264  QList< QPointer<QWidget> > mEnabledWidgets;
265  QList< QPointer<QWidget> > mCheckedWidgets;
266 
267  QMenu* mDefineMenu;
268  QAction* mActionDataTypes;
269  QMenu* mFieldsMenu;
270 
271  QAction* mActionActive;
272  QAction* mActionDescription;
273  QAction* mActionExpDialog;
274  QAction* mActionExpression;
275  QAction* mActionPasteExpr;
276  QAction* mActionCopyExpr;
277  QAction* mActionClearExpr;
278 
279  DataTypes mDataTypes;
280  QString mDataTypesString;
281  QString mInputDescription;
282  QString mFullDescription;
283  QString mUsageInfo;
284  QString mCurrentDefinition;
285 
286  static QIcon mIconDataDefine;
287  static QIcon mIconDataDefineOn;
288  static QIcon mIconDataDefineError;
289  static QIcon mIconDataDefineExpression;
290  static QIcon mIconDataDefineExpressionOn;
291  static QIcon mIconDataDefineExpressionError;
292 
293  private slots:
294  void aboutToShowMenu();
295  void menuActionTriggered( QAction* action );
296 };
297 
298 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
299 
300 
301 #endif // QGSDATADEFINEDBUTTON_H
void clearEnabledWidgets()
Clears list of sibling widgets.
void setExpression(QString exp)
Set the current defined expression.
void setField(QString field)
Set the current defined field.
bool isActive()
Whether the current data definition or expression is to be used.
A container class for data source field mapping or expression.
void clearCheckedWidgets()
Clears list of checkable sibling widgets.
Container of fields for a vector layer.
Definition: qgsfield.h:172
bool useExpression()
Whether the current expression is to be used instead of field mapping.
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...
void setUsageInfo(const QString &info)
Set the usage information about this data definition.
QString currentDefinition() const
The current definition.
Represents a vector layer which manages a vector based data sets.