QGIS API Documentation  2.99.0-Master (7fe5405)
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 #include "qgis_gui.h"
26 
27 class QgsVectorLayer;
28 class QgsDataDefined;
29 class QgsMapCanvas;
30 
38 class GUI_EXPORT QgsDataDefinedAssistant: public QDialog
39 {
40  Q_OBJECT
41 
42  public:
43  QgsDataDefinedAssistant() : mMapCanvas( nullptr ) {}
44 
49  virtual QgsDataDefined dataDefined() const = 0;
50 
57  virtual void setMapCanvas( QgsMapCanvas* canvas ) { mMapCanvas = canvas; }
58 
63  const QgsMapCanvas* mapCanvas() const { return mMapCanvas; }
64 
65  protected:
66 
68 };
69 
75 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
76 {
77  Q_OBJECT
78  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
79 
80  public:
81  enum DataType
82  {
83  String = 1,
84  Int = 2,
85  Double = 4,
86  AnyType = String | Int | Double
87  };
88  Q_DECLARE_FLAGS( DataTypes, DataType )
89 
90 
99  QgsDataDefinedButton( QWidget* parent = nullptr,
100  const QgsVectorLayer* vl = nullptr,
101  const QgsDataDefined* datadefined = nullptr,
102  QgsDataDefinedButton::DataTypes datatypes = AnyType,
103  const QString& description = QString() );
105 
114  void init( const QgsVectorLayer* vl,
115  const QgsDataDefined* datadefined = nullptr,
116  QgsDataDefinedButton::DataTypes datatypes = AnyType,
117  const QString& description = QString() );
118 
119  QMap< QString, QString > definedProperty() const { return mProperty; }
120 
126  void updateDataDefined( QgsDataDefined* dd ) const;
127 
133  QgsDataDefined currentDataDefined() const;
134 
140  void setVectorLayer( QgsVectorLayer* layer );
141 
145  bool isActive() const { return mProperty.value( QStringLiteral( "active" ) ).toInt(); }
146 
150  bool useExpression() const { return mProperty.value( QStringLiteral( "useexpr" ) ).toInt(); }
151 
155  QString getExpression() const { return mProperty.value( QStringLiteral( "expression" ) ); }
156 
160  QString getField() const { return mProperty.value( QStringLiteral( "field" ) ); }
161 
166  QString currentDefinition() const { return mCurrentDefinition; }
167 
172  const DataTypes& validDataTypes() const { return mDataTypes; }
173 
177  QString fullDescription() const { return mFullDescription; }
178 
182  QString usageInfo() const { return mUsageInfo; }
183 
187  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
188 
192  void registerEnabledWidgets( const QList<QWidget*>& wdgts );
193 
197  void registerEnabledWidget( QWidget* wdgt );
198 
204  QList<QWidget*> registeredEnabledWidgets();
205 
209  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
210 
214  void registerCheckedWidgets( const QList<QWidget*>& wdgts );
215 
219  void registerCheckedWidget( QWidget* wdgt );
220 
226  QList<QWidget*> registeredCheckedWidgets();
227 
231  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
232 
240  void registerExpressionContextGenerator( QgsExpressionContextGenerator* generator );
241 
251  void setAssistant( const QString& title, QgsDataDefinedAssistant * assistant );
252 
257  QgsDataDefinedAssistant* assistant();
258 
262  static QString trString();
263  static QString charDesc();
264  static QString boolDesc();
265  static QString anyStringDesc();
266  static QString intDesc();
267  static QString intPosDesc();
268  static QString intPosOneDesc();
269  static QString doubleDesc();
270  static QString doublePosDesc();
271  static QString double0to1Desc();
272  static QString doubleXYDesc();
273  static QString double180RotDesc();
274  static QString intTranspDesc();
275  static QString unitsMmMuDesc();
276  static QString unitsMmMuPercentDesc();
277  static QString colorNoAlphaDesc();
278  static QString colorAlphaDesc();
279  static QString textHorzAlignDesc();
280  static QString textVertAlignDesc();
281  static QString penJoinStyleDesc();
282  static QString blendModesDesc();
283  static QString svgPathDesc();
284  static QString filePathDesc();
285  static QString paperSizeDesc();
286  static QString paperOrientationDesc();
287  static QString horizontalAnchorDesc();
288  static QString verticalAnchorDesc();
289  static QString gradientTypeDesc();
290  static QString gradientCoordModeDesc();
291  static QString gradientSpreadDesc();
292  static QString lineStyleDesc();
293  static QString capStyleDesc();
294  static QString fillStyleDesc();
295  static QString markerStyleDesc();
296  static QString customDashDesc();
297 
298  public slots:
299 
303  void setActive( bool active );
304 
308  void disableEnabledWidgets( bool disable );
309 
313  void checkCheckedWidgets( bool check );
314 
315  signals:
316 
321  void dataDefinedChanged( const QString& definition );
322 
327  void dataDefinedActivated( bool active );
328 
329  protected:
330  void mouseReleaseEvent( QMouseEvent *event ) override;
331 
335  void setUseExpression( bool use ) { mProperty.insert( QStringLiteral( "useexpr" ), use ? "1" : "0" ); }
336 
340  void setExpression( const QString& exp ) { mProperty.insert( QStringLiteral( "expression" ), exp ); }
341 
345  void setField( const QString& field ) { mProperty.insert( QStringLiteral( "field" ), field ); }
346 
347  private:
348  void showDescriptionDialog();
349  void showExpressionDialog();
350  void showAssistant();
351  void updateGui();
352  void updateFieldLists();
353 
354  const QgsVectorLayer* mVectorLayer;
355  QStringList mFieldNameList;
356  QStringList mFieldTypeList;
357  QMap< QString, QString > mProperty;
358  QList< QPointer<QWidget> > mEnabledWidgets;
359  QList< QPointer<QWidget> > mCheckedWidgets;
360 
361  QMenu* mDefineMenu;
362  QAction* mActionDataTypes;
363  QMenu* mFieldsMenu;
364  QMenu* mVariablesMenu;
365  QAction* mActionVariables;
366 
367  QAction* mActionActive;
368  QAction* mActionDescription;
369  QAction* mActionExpDialog;
370  QAction* mActionExpression;
371  QAction* mActionPasteExpr;
372  QAction* mActionCopyExpr;
373  QAction* mActionClearExpr;
374  QAction* mActionAssistant;
375 
376  DataTypes mDataTypes;
377  QString mDataTypesString;
378  QString mInputDescription;
379  QString mFullDescription;
380  QString mUsageInfo;
381  QString mCurrentDefinition;
382 
383  QScopedPointer<QgsDataDefinedAssistant> mAssistant;
384 
385  QIcon mIconDataDefine;
386  QIcon mIconDataDefineOn;
387  QIcon mIconDataDefineError;
388  QIcon mIconDataDefineExpression;
389  QIcon mIconDataDefineExpressionOn;
390  QIcon mIconDataDefineExpressionError;
391 
392  QgsExpressionContextGenerator* mExpressionContextGenerator;
393 
394  private slots:
395  void aboutToShowMenu();
396  void menuActionTriggered( QAction* action );
397 };
398 
399 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
400 
401 
402 #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.
QMap< QString, QString > definedProperty() const
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:74
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.