QGIS API Documentation  2.99.0-Master (8ec3eaf)
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>
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 
48  virtual QgsDataDefined dataDefined() const = 0;
49 
56  virtual void setMapCanvas( QgsMapCanvas* canvas ) { mMapCanvas = canvas; }
57 
62  const QgsMapCanvas* mapCanvas() const { return mMapCanvas; }
63 
64  protected:
65 
67 };
68 
74 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
75 {
76  Q_OBJECT
77  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
78 
79  public:
80  enum DataType
81  {
82  String = 1,
83  Int = 2,
84  Double = 4,
85  AnyType = String | Int | Double
86  };
87  Q_DECLARE_FLAGS( DataTypes, DataType )
88 
89 
98  QgsDataDefinedButton( QWidget* parent = nullptr,
99  const QgsVectorLayer* vl = nullptr,
100  const QgsDataDefined* datadefined = nullptr,
101  QgsDataDefinedButton::DataTypes datatypes = AnyType,
102  const QString& description = QString() );
104 
113  void init( const QgsVectorLayer* vl,
114  const QgsDataDefined* datadefined = nullptr,
115  QgsDataDefinedButton::DataTypes datatypes = AnyType,
116  const QString& description = QString() );
117 
118  QMap< QString, QString > definedProperty() const { return mProperty; }
119 
125  void updateDataDefined( QgsDataDefined* dd ) const;
126 
132  QgsDataDefined currentDataDefined() const;
133 
139  void setVectorLayer( QgsVectorLayer* layer );
140 
144  bool isActive() const { return mProperty.value( QStringLiteral( "active" ) ).toInt(); }
145 
149  bool useExpression() const { return mProperty.value( QStringLiteral( "useexpr" ) ).toInt(); }
150 
154  QString getExpression() const { return mProperty.value( QStringLiteral( "expression" ) ); }
155 
159  QString getField() const { return mProperty.value( QStringLiteral( "field" ) ); }
160 
165  QString currentDefinition() const { return mCurrentDefinition; }
166 
171  const DataTypes& validDataTypes() const { return mDataTypes; }
172 
176  QString fullDescription() const { return mFullDescription; }
177 
181  QString usageInfo() const { return mUsageInfo; }
182 
186  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
187 
191  void registerEnabledWidgets( const QList<QWidget*>& wdgts );
192 
196  void registerEnabledWidget( QWidget* wdgt );
197 
203  QList<QWidget*> registeredEnabledWidgets();
204 
208  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
209 
213  void registerCheckedWidgets( const QList<QWidget*>& wdgts );
214 
218  void registerCheckedWidget( QWidget* wdgt );
219 
225  QList<QWidget*> registeredCheckedWidgets();
226 
230  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
231 
239  void registerExpressionContextGenerator( QgsExpressionContextGenerator* generator );
240 
250  void setAssistant( const QString& title, QgsDataDefinedAssistant * assistant );
251 
256  QgsDataDefinedAssistant* assistant();
257 
261  static QString trString();
262  static QString charDesc();
263  static QString boolDesc();
264  static QString anyStringDesc();
265  static QString intDesc();
266  static QString intPosDesc();
267  static QString intPosOneDesc();
268  static QString doubleDesc();
269  static QString doublePosDesc();
270  static QString double0to1Desc();
271  static QString doubleXYDesc();
272  static QString double180RotDesc();
273  static QString intTranspDesc();
274  static QString unitsMmMuDesc();
275  static QString unitsMmMuPercentDesc();
276  static QString colorNoAlphaDesc();
277  static QString colorAlphaDesc();
278  static QString textHorzAlignDesc();
279  static QString textVertAlignDesc();
280  static QString penJoinStyleDesc();
281  static QString blendModesDesc();
282  static QString svgPathDesc();
283  static QString filePathDesc();
284  static QString paperSizeDesc();
285  static QString paperOrientationDesc();
286  static QString horizontalAnchorDesc();
287  static QString verticalAnchorDesc();
288  static QString gradientTypeDesc();
289  static QString gradientCoordModeDesc();
290  static QString gradientSpreadDesc();
291  static QString lineStyleDesc();
292  static QString capStyleDesc();
293  static QString fillStyleDesc();
294  static QString markerStyleDesc();
295  static QString customDashDesc();
296 
297  public slots:
298 
302  void setActive( bool active );
303 
307  void disableEnabledWidgets( bool disable );
308 
312  void checkCheckedWidgets( bool check );
313 
314  signals:
315 
320  void dataDefinedChanged( const QString& definition );
321 
326  void dataDefinedActivated( bool active );
327 
328  protected:
329  void mouseReleaseEvent( QMouseEvent *event ) override;
330 
334  void setUseExpression( bool use ) { mProperty.insert( QStringLiteral( "useexpr" ), use ? "1" : "0" ); }
335 
339  void setExpression( const QString& exp ) { mProperty.insert( QStringLiteral( "expression" ), exp ); }
340 
344  void setField( const QString& field ) { mProperty.insert( QStringLiteral( "field" ), field ); }
345 
346  private:
347  void showDescriptionDialog();
348  void showExpressionDialog();
349  void showAssistant();
350  void updateGui();
351  void updateFieldLists();
352 
353  const QgsVectorLayer* mVectorLayer;
354  QStringList mFieldNameList;
355  QStringList mFieldTypeList;
356  QMap< QString, QString > mProperty;
357  QList< QPointer<QWidget> > mEnabledWidgets;
358  QList< QPointer<QWidget> > mCheckedWidgets;
359 
360  QMenu* mDefineMenu;
361  QAction* mActionDataTypes;
362  QMenu* mFieldsMenu;
363  QMenu* mVariablesMenu;
364  QAction* mActionVariables;
365 
366  QAction* mActionActive;
367  QAction* mActionDescription;
368  QAction* mActionExpDialog;
369  QAction* mActionExpression;
370  QAction* mActionPasteExpr;
371  QAction* mActionCopyExpr;
372  QAction* mActionClearExpr;
373  QAction* mActionAssistant;
374 
375  DataTypes mDataTypes;
376  QString mDataTypesString;
377  QString mInputDescription;
378  QString mFullDescription;
379  QString mUsageInfo;
380  QString mCurrentDefinition;
381 
382  QScopedPointer<QgsDataDefinedAssistant> mAssistant;
383 
384  QIcon mIconDataDefine;
385  QIcon mIconDataDefineOn;
386  QIcon mIconDataDefineError;
387  QIcon mIconDataDefineExpression;
388  QIcon mIconDataDefineExpressionOn;
389  QIcon mIconDataDefineExpressionError;
390 
391  QgsExpressionContextGenerator* mExpressionContextGenerator;
392 
393  private slots:
394  void aboutToShowMenu();
395  void menuActionTriggered( QAction* action );
396 };
397 
398 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
399 
400 
401 #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:106
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.
const DataTypes & validDataTypes() const
The valid data types that will work for the definition (QVariant-coercible to expected type) Compared...
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.
Abstract interface for generating an expression context.
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.