QGIS API Documentation
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 
342  const QgsVectorLayer* mVectorLayer;
343  QStringList mFieldNameList;
344  QStringList mFieldTypeList;
345  QMap< QString, QString > mProperty;
346  QList< QPointer<QWidget> > mEnabledWidgets;
347  QList< QPointer<QWidget> > mCheckedWidgets;
348 
349  QMenu* mDefineMenu;
350  QAction* mActionDataTypes;
351  QMenu* mFieldsMenu;
352  QMenu* mVariablesMenu;
353  QAction* mActionVariables;
354 
355  QAction* mActionActive;
356  QAction* mActionDescription;
357  QAction* mActionExpDialog;
358  QAction* mActionExpression;
359  QAction* mActionPasteExpr;
360  QAction* mActionCopyExpr;
361  QAction* mActionClearExpr;
362  QAction* mActionAssistant;
363 
364  DataTypes mDataTypes;
365  QString mDataTypesString;
366  QString mInputDescription;
367  QString mFullDescription;
368  QString mUsageInfo;
369  QString mCurrentDefinition;
370 
372 
373  QIcon mIconDataDefine;
374  QIcon mIconDataDefineOn;
375  QIcon mIconDataDefineError;
376  QIcon mIconDataDefineExpression;
377  QIcon mIconDataDefineExpressionOn;
378  QIcon mIconDataDefineExpressionError;
379 
380  ExpressionContextCallback mExpressionContextCallback;
381  const void* mExpressionContextCallbackContext;
382 
383  private slots:
384  void aboutToShowMenu();
385  void menuActionTriggered( QAction* action );
386 };
387 
388 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
389 
390 
391 #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.
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:105
QString fullDescription() const
The full definition description and current definition (internally generated on a contextual basis) ...
void setExpression(const QString &exp)
Set the current defined expression.
virtual void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
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.
const QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
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.