QGIS API Documentation  2.11.0-Master
 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 <QDialog>
19 #include <QFlags>
20 #include <QMap>
21 #include <QPointer>
22 #include <QToolButton>
23 #include <QScopedPointer>
24 #include "qgsexpressioncontext.h"
25 
26 class QgsVectorLayer;
27 class QgsDataDefined;
28 
36 class GUI_EXPORT QgsDataDefinedAssistant: public QDialog
37 {
38  public:
39  virtual QgsDataDefined dataDefined() const = 0;
40 };
41 
47 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
48 {
49  Q_OBJECT
50  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
51 
52  public:
53  enum DataType
54  {
55  String = 1,
56  Int = 2,
57  Double = 4,
58  AnyType = String | Int | Double
59  };
60  Q_DECLARE_FLAGS( DataTypes, DataType )
61 
62 
71  QgsDataDefinedButton( QWidget* parent = 0,
72  const QgsVectorLayer* vl = 0,
73  const QgsDataDefined* datadefined = 0,
74  DataTypes datatypes = AnyType,
75  QString description = "" );
77 
86  void init( const QgsVectorLayer* vl,
87  const QgsDataDefined* datadefined = 0,
88  DataTypes datatypes = AnyType,
89  QString description = QString( "" ) );
90 
91  QMap< QString, QString > definedProperty() const { return mProperty; }
92 
98  void updateDataDefined( QgsDataDefined* dd ) const;
99 
105  QgsDataDefined currentDataDefined() const;
106 
110  bool isActive() const { return mProperty.value( "active" ).toInt(); }
111 
115  bool useExpression() const { return mProperty.value( "useexpr" ).toInt(); }
116 
120  QString getExpression() const { return mProperty.value( "expression" ); }
121 
125  QString getField() const { return mProperty.value( "field" ); }
126 
131  QString currentDefinition() const { return mCurrentDefinition; }
132 
137  const DataTypes& validDataTypes() const { return mDataTypes; }
138 
142  QString fullDescription() const { return mFullDescription; }
143 
147  QString usageInfo() const { return mUsageInfo; }
148 
152  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
153 
157  void registerEnabledWidgets( QList<QWidget*> wdgts );
158 
162  void registerEnabledWidget( QWidget* wdgt );
163 
169  QList<QWidget*> registeredEnabledWidgets();
170 
174  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
175 
179  void registerCheckedWidgets( QList<QWidget*> wdgts );
180 
184  void registerCheckedWidget( QWidget* wdgt );
185 
191  QList<QWidget*> registeredCheckedWidgets();
192 
196  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
197 
199  typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context );
200 
208  void registerGetExpressionContextCallback( ExpressionContextCallback fnGetExpressionContext, const void* context );
209 
218  void setAssistant( const QString& title, QgsDataDefinedAssistant * assistant );
219 
223  static QString trString();
224  static QString charDesc();
225  static QString boolDesc();
226  static QString anyStringDesc();
227  static QString intDesc();
228  static QString intPosDesc();
229  static QString intPosOneDesc();
230  static QString doubleDesc();
231  static QString doublePosDesc();
232  static QString double0to1Desc();
233  static QString doubleXYDesc();
234  static QString double180RotDesc();
235  static QString intTranspDesc();
236  static QString unitsMmMuDesc();
237  static QString unitsMmMuPercentDesc();
238  static QString colorNoAlphaDesc();
239  static QString colorAlphaDesc();
240  static QString textHorzAlignDesc();
241  static QString textVertAlignDesc();
242  static QString penJoinStyleDesc();
243  static QString blendModesDesc();
244  static QString svgPathDesc();
245  static QString filePathDesc();
246  static QString paperSizeDesc();
247  static QString paperOrientationDesc();
248  static QString horizontalAnchorDesc();
249  static QString verticalAnchorDesc();
250  static QString gradientTypeDesc();
251  static QString gradientCoordModeDesc();
252  static QString gradientSpreadDesc();
253  static QString lineStyleDesc();
254  static QString capStyleDesc();
255  static QString fillStyleDesc();
256  static QString markerStyleDesc();
257  static QString customDashDesc();
258 
259  public slots:
263  void setActive( bool active );
264 
268  void disableEnabledWidgets( bool disable );
269 
273  void checkCheckedWidgets( bool check );
274 
275  signals:
280  void dataDefinedChanged( const QString& definition );
281 
286  void dataDefinedActivated( bool active );
287 
288  protected:
289  void mouseReleaseEvent( QMouseEvent *event ) override;
290 
294  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
295 
299  void setExpression( QString exp ) { mProperty.insert( "expression", exp ); }
300 
304  void setField( QString field ) { mProperty.insert( "field", field ); }
305 
306  private:
307  void showDescriptionDialog();
308  void showExpressionDialog();
309  void showAssistant();
310  void updateGui();
311 
312  const QgsVectorLayer* mVectorLayer;
313  QStringList mFieldNameList;
314  QStringList mFieldTypeList;
315  QMap< QString, QString > mProperty;
316  QList< QPointer<QWidget> > mEnabledWidgets;
317  QList< QPointer<QWidget> > mCheckedWidgets;
318 
319  QMenu* mDefineMenu;
320  QAction* mActionDataTypes;
321  QMenu* mFieldsMenu;
322  QMenu* mVariablesMenu;
323  QAction* mActionVariables;
324 
325  QAction* mActionActive;
326  QAction* mActionDescription;
327  QAction* mActionExpDialog;
328  QAction* mActionExpression;
329  QAction* mActionPasteExpr;
330  QAction* mActionCopyExpr;
331  QAction* mActionClearExpr;
332  QAction* mActionAssistant;
333 
334  DataTypes mDataTypes;
335  QString mDataTypesString;
336  QString mInputDescription;
337  QString mFullDescription;
338  QString mUsageInfo;
339  QString mCurrentDefinition;
340 
342 
343  static QIcon mIconDataDefine;
344  static QIcon mIconDataDefineOn;
345  static QIcon mIconDataDefineError;
346  static QIcon mIconDataDefineExpression;
347  static QIcon mIconDataDefineExpressionOn;
348  static QIcon mIconDataDefineExpressionError;
349 
350  ExpressionContextCallback mExpressionContextCallback;
351  const void* mExpressionContextCallbackContext;
352 
353  private slots:
354  void aboutToShowMenu();
355  void menuActionTriggered( QAction* action );
356 };
357 
358 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
359 
360 
361 #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) ...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual void mouseReleaseEvent(QMouseEvent *e)
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.