QGIS API Documentation  2.17.0-Master (0497e4a)
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 class QgsMapCanvas;
29 
37 class GUI_EXPORT QgsDataDefinedAssistant: public QDialog
38 {
39  Q_OBJECT
40 
41  public:
42  QgsDataDefinedAssistant() : mMapCanvas( nullptr ) {}
43 
44  virtual QgsDataDefined dataDefined() const = 0;
45 
52  virtual void setMapCanvas( QgsMapCanvas* canvas ) { mMapCanvas = canvas; }
53 
58  const QgsMapCanvas* mapCanvas() const { return mMapCanvas; }
59 
60  protected:
61 
63 };
64 
70 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
71 {
72  Q_OBJECT
73  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
74 
75  public:
76  enum DataType
77  {
78  String = 1,
79  Int = 2,
80  Double = 4,
81  AnyType = String | Int | Double
82  };
83  Q_DECLARE_FLAGS( DataTypes, DataType )
84 
85 
94  QgsDataDefinedButton( QWidget* parent = nullptr,
95  const QgsVectorLayer* vl = nullptr,
96  const QgsDataDefined* datadefined = nullptr,
97  const QgsDataDefinedButton::DataTypes& datatypes = AnyType,
98  const QString& description = QString() );
100 
109  void init( const QgsVectorLayer* vl,
110  const QgsDataDefined* datadefined = nullptr,
111  const QgsDataDefinedButton::DataTypes& datatypes = AnyType,
112  const QString& description = QString() );
113 
114  QMap< QString, QString > definedProperty() const { return mProperty; }
115 
121  void updateDataDefined( QgsDataDefined* dd ) const;
122 
128  QgsDataDefined currentDataDefined() const;
129 
133  bool isActive() const { return mProperty.value( "active" ).toInt(); }
134 
138  bool useExpression() const { return mProperty.value( "useexpr" ).toInt(); }
139 
143  QString getExpression() const { return mProperty.value( "expression" ); }
144 
148  QString getField() const { return mProperty.value( "field" ); }
149 
154  QString currentDefinition() const { return mCurrentDefinition; }
155 
160  const DataTypes& validDataTypes() const { return mDataTypes; }
161 
165  QString fullDescription() const { return mFullDescription; }
166 
170  QString usageInfo() const { return mUsageInfo; }
171 
175  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
176 
180  void registerEnabledWidgets( const QList<QWidget*>& wdgts );
181 
185  void registerEnabledWidget( QWidget* wdgt );
186 
192  QList<QWidget*> registeredEnabledWidgets();
193 
197  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
198 
202  void registerCheckedWidgets( const QList<QWidget*>& wdgts );
203 
207  void registerCheckedWidget( QWidget* wdgt );
208 
214  QList<QWidget*> registeredCheckedWidgets();
215 
219  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
220 
222  typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context );
223 
231  void registerGetExpressionContextCallback( ExpressionContextCallback fnGetExpressionContext, const void* context );
232 
242  void setAssistant( const QString& title, QgsDataDefinedAssistant * assistant );
243 
248  QgsDataDefinedAssistant* assistant();
249 
253  static QString trString();
254  static QString charDesc();
255  static QString boolDesc();
256  static QString anyStringDesc();
257  static QString intDesc();
258  static QString intPosDesc();
259  static QString intPosOneDesc();
260  static QString doubleDesc();
261  static QString doublePosDesc();
262  static QString double0to1Desc();
263  static QString doubleXYDesc();
264  static QString double180RotDesc();
265  static QString intTranspDesc();
266  static QString unitsMmMuDesc();
267  static QString unitsMmMuPercentDesc();
268  static QString colorNoAlphaDesc();
269  static QString colorAlphaDesc();
270  static QString textHorzAlignDesc();
271  static QString textVertAlignDesc();
272  static QString penJoinStyleDesc();
273  static QString blendModesDesc();
274  static QString svgPathDesc();
275  static QString filePathDesc();
276  static QString paperSizeDesc();
277  static QString paperOrientationDesc();
278  static QString horizontalAnchorDesc();
279  static QString verticalAnchorDesc();
280  static QString gradientTypeDesc();
281  static QString gradientCoordModeDesc();
282  static QString gradientSpreadDesc();
283  static QString lineStyleDesc();
284  static QString capStyleDesc();
285  static QString fillStyleDesc();
286  static QString markerStyleDesc();
287  static QString customDashDesc();
288 
289  public slots:
293  void setActive( bool active );
294 
298  void disableEnabledWidgets( bool disable );
299 
303  void checkCheckedWidgets( bool check );
304 
305  signals:
310  void dataDefinedChanged( const QString& definition );
311 
316  void dataDefinedActivated( bool active );
317 
318  protected:
319  void mouseReleaseEvent( QMouseEvent *event ) override;
320 
324  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
325 
329  void setExpression( const QString& exp ) { mProperty.insert( "expression", exp ); }
330 
334  void setField( const QString& field ) { mProperty.insert( "field", field ); }
335 
336  private:
337  void showDescriptionDialog();
338  void showExpressionDialog();
339  void showAssistant();
340  void updateGui();
341  void updateFieldLists();
342 
343  const QgsVectorLayer* mVectorLayer;
344  QStringList mFieldNameList;
345  QStringList mFieldTypeList;
346  QMap< QString, QString > mProperty;
347  QList< QPointer<QWidget> > mEnabledWidgets;
348  QList< QPointer<QWidget> > mCheckedWidgets;
349 
350  QMenu* mDefineMenu;
351  QAction* mActionDataTypes;
352  QMenu* mFieldsMenu;
353  QMenu* mVariablesMenu;
354  QAction* mActionVariables;
355 
356  QAction* mActionActive;
357  QAction* mActionDescription;
358  QAction* mActionExpDialog;
359  QAction* mActionExpression;
360  QAction* mActionPasteExpr;
361  QAction* mActionCopyExpr;
362  QAction* mActionClearExpr;
363  QAction* mActionAssistant;
364 
365  DataTypes mDataTypes;
366  QString mDataTypesString;
367  QString mInputDescription;
368  QString mFullDescription;
369  QString mUsageInfo;
370  QString mCurrentDefinition;
371 
373 
374  QIcon mIconDataDefine;
375  QIcon mIconDataDefineOn;
376  QIcon mIconDataDefineError;
377  QIcon mIconDataDefineExpression;
378  QIcon mIconDataDefineExpressionOn;
379  QIcon mIconDataDefineExpressionError;
380 
381  ExpressionContextCallback mExpressionContextCallback;
382  const void* mExpressionContextCallbackContext;
383 
384  private slots:
385  void aboutToShowMenu();
386  void menuActionTriggered( QAction* action );
387 };
388 
389 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
390 
391 
392 #endif // QGSDATADEFINEDBUTTON_H
void clearEnabledWidgets()
Clears list of sibling widgets.
An assistant (wizard) dialog, accessible from a QgsDataDefinedButton.
void setField(const QString &field)
Set the current defined field.
A container class for data source field mapping or expression.
bool useExpression() const
Whether the current expression is to be used instead of field mapping.
const QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void clearCheckedWidgets()
Clears list of checkable sibling widgets.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
void setExpression(const QString &exp)
Set the current defined expression.
QString fullDescription() const
The full definition description and current definition (internally generated on a contextual basis) ...
bool isActive() const
Whether the current data definition or expression is to be used.
virtual void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QString getField() const
The current defined field.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
const DataTypes & validDataTypes() const
The valid data types that will work for the definition (QVariant-coercible to expected type) Compared...
virtual void mouseReleaseEvent(QMouseEvent *e)
QString currentDefinition() const
The current definition.
QString usageInfo() const
The usage information about this data definition.
A button for defining data source field mappings or expressions.
void setUseExpression(bool use)
Set whether the current expression is to be used instead of field mapping.
void setUsageInfo(const QString &info)
Set the usage information about this data definition.
QString getExpression() const
The current defined expression.
Represents a vector layer which manages a vector based data sets.