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 <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 boolDesc();
211  static QString anyStringDesc();
212  static QString intDesc();
213  static QString intPosDesc();
214  static QString intPosOneDesc();
215  static QString doubleDesc();
216  static QString doublePosDesc();
217  static QString double0to1Desc();
218  static QString doubleXYDesc();
219  static QString double180RotDesc();
220  static QString intTranspDesc();
221  static QString unitsMmMuDesc();
222  static QString unitsMmMuPercentDesc();
223  static QString colorNoAlphaDesc();
224  static QString colorAlphaDesc();
225  static QString textHorzAlignDesc();
226  static QString textVertAlignDesc();
227  static QString penJoinStyleDesc();
228  static QString blendModesDesc();
229  static QString svgPathDesc();
230  static QString filePathDesc();
231  static QString paperSizeDesc();
232  static QString paperOrientationDesc();
233  static QString horizontalAnchorDesc();
234  static QString verticalAnchorDesc();
235  static QString gradientTypeDesc();
236  static QString gradientCoordModeDesc();
237  static QString gradientSpreadDesc();
238  static QString lineStyleDesc();
239  static QString capStyleDesc();
240  static QString fillStyleDesc();
241  static QString markerStyleDesc();
242  static QString customDashDesc();
243 
244  public slots:
248  void setActive( bool active );
249 
253  void disableEnabledWidgets( bool disable );
254 
258  void checkCheckedWidgets( bool check );
259 
260  signals:
265  void dataDefinedChanged( const QString& definition );
266 
271  void dataDefinedActivated( bool active );
272 
273  protected:
274  void mouseReleaseEvent( QMouseEvent *event ) override;
275 
279  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
280 
284  void setExpression( QString exp ) { mProperty.insert( "expression", exp ); }
285 
289  void setField( QString field ) { mProperty.insert( "field", field ); }
290 
291  private:
292  void showDescriptionDialog();
293  void showExpressionDialog();
294  void showAssistant();
295  void updateGui();
296 
297  const QgsVectorLayer* mVectorLayer;
298  QStringList mFieldNameList;
299  QStringList mFieldTypeList;
300  QMap< QString, QString > mProperty;
301  QList< QPointer<QWidget> > mEnabledWidgets;
302  QList< QPointer<QWidget> > mCheckedWidgets;
303 
304  QMenu* mDefineMenu;
305  QAction* mActionDataTypes;
306  QMenu* mFieldsMenu;
307 
308  QAction* mActionActive;
309  QAction* mActionDescription;
310  QAction* mActionExpDialog;
311  QAction* mActionExpression;
312  QAction* mActionPasteExpr;
313  QAction* mActionCopyExpr;
314  QAction* mActionClearExpr;
315  QAction* mActionAssistant;
316 
317  DataTypes mDataTypes;
318  QString mDataTypesString;
319  QString mInputDescription;
320  QString mFullDescription;
321  QString mUsageInfo;
322  QString mCurrentDefinition;
323 
324  QScopedPointer<QgsDataDefinedAssistant> mAssistant;
325 
326  static QIcon mIconDataDefine;
327  static QIcon mIconDataDefineOn;
328  static QIcon mIconDataDefineError;
329  static QIcon mIconDataDefineExpression;
330  static QIcon mIconDataDefineExpressionOn;
331  static QIcon mIconDataDefineExpressionError;
332 
333  private slots:
334  void aboutToShowMenu();
335  void menuActionTriggered( QAction* action );
336 };
337 
338 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
339 
340 
341 #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.