QGIS API Documentation  2.12.0-Lyon
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  public:
40  QgsDataDefinedAssistant() : mMapCanvas( 0 ) {}
41 
42  virtual QgsDataDefined dataDefined() const = 0;
43 
50  virtual void setMapCanvas( QgsMapCanvas* canvas ) { mMapCanvas = canvas; }
51 
56  const QgsMapCanvas* mapCanvas() const { return mMapCanvas; }
57 
58  protected:
59 
61 };
62 
68 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
69 {
70  Q_OBJECT
71  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
72 
73  public:
74  enum DataType
75  {
76  String = 1,
77  Int = 2,
78  Double = 4,
79  AnyType = String | Int | Double
80  };
81  Q_DECLARE_FLAGS( DataTypes, DataType )
82 
83 
92  QgsDataDefinedButton( QWidget* parent = 0,
93  const QgsVectorLayer* vl = 0,
94  const QgsDataDefined* datadefined = 0,
95  const QgsDataDefinedButton::DataTypes& datatypes = AnyType,
96  const QString& description = QString() );
98 
107  void init( const QgsVectorLayer* vl,
108  const QgsDataDefined* datadefined = 0,
109  const QgsDataDefinedButton::DataTypes& datatypes = AnyType,
110  const QString& description = QString() );
111 
112  QMap< QString, QString > definedProperty() const { return mProperty; }
113 
119  void updateDataDefined( QgsDataDefined* dd ) const;
120 
126  QgsDataDefined currentDataDefined() const;
127 
131  bool isActive() const { return mProperty.value( "active" ).toInt(); }
132 
136  bool useExpression() const { return mProperty.value( "useexpr" ).toInt(); }
137 
141  QString getExpression() const { return mProperty.value( "expression" ); }
142 
146  QString getField() const { return mProperty.value( "field" ); }
147 
152  QString currentDefinition() const { return mCurrentDefinition; }
153 
158  const DataTypes& validDataTypes() const { return mDataTypes; }
159 
163  QString fullDescription() const { return mFullDescription; }
164 
168  QString usageInfo() const { return mUsageInfo; }
169 
173  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
174 
178  void registerEnabledWidgets( const QList<QWidget*>& wdgts );
179 
183  void registerEnabledWidget( QWidget* wdgt );
184 
190  QList<QWidget*> registeredEnabledWidgets();
191 
195  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
196 
200  void registerCheckedWidgets( const QList<QWidget*>& wdgts );
201 
205  void registerCheckedWidget( QWidget* wdgt );
206 
212  QList<QWidget*> registeredCheckedWidgets();
213 
217  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
218 
220  typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context );
221 
229  void registerGetExpressionContextCallback( ExpressionContextCallback fnGetExpressionContext, const void* context );
230 
240  void setAssistant( const QString& title, QgsDataDefinedAssistant * assistant );
241 
246  QgsDataDefinedAssistant* assistant();
247 
251  static QString trString();
252  static QString charDesc();
253  static QString boolDesc();
254  static QString anyStringDesc();
255  static QString intDesc();
256  static QString intPosDesc();
257  static QString intPosOneDesc();
258  static QString doubleDesc();
259  static QString doublePosDesc();
260  static QString double0to1Desc();
261  static QString doubleXYDesc();
262  static QString double180RotDesc();
263  static QString intTranspDesc();
264  static QString unitsMmMuDesc();
265  static QString unitsMmMuPercentDesc();
266  static QString colorNoAlphaDesc();
267  static QString colorAlphaDesc();
268  static QString textHorzAlignDesc();
269  static QString textVertAlignDesc();
270  static QString penJoinStyleDesc();
271  static QString blendModesDesc();
272  static QString svgPathDesc();
273  static QString filePathDesc();
274  static QString paperSizeDesc();
275  static QString paperOrientationDesc();
276  static QString horizontalAnchorDesc();
277  static QString verticalAnchorDesc();
278  static QString gradientTypeDesc();
279  static QString gradientCoordModeDesc();
280  static QString gradientSpreadDesc();
281  static QString lineStyleDesc();
282  static QString capStyleDesc();
283  static QString fillStyleDesc();
284  static QString markerStyleDesc();
285  static QString customDashDesc();
286 
287  public slots:
291  void setActive( bool active );
292 
296  void disableEnabledWidgets( bool disable );
297 
301  void checkCheckedWidgets( bool check );
302 
303  signals:
308  void dataDefinedChanged( const QString& definition );
309 
314  void dataDefinedActivated( bool active );
315 
316  protected:
317  void mouseReleaseEvent( QMouseEvent *event ) override;
318 
322  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
323 
327  void setExpression( const QString& exp ) { mProperty.insert( "expression", exp ); }
328 
332  void setField( const QString& field ) { mProperty.insert( "field", field ); }
333 
334  private:
335  void showDescriptionDialog();
336  void showExpressionDialog();
337  void showAssistant();
338  void updateGui();
339 
340  const QgsVectorLayer* mVectorLayer;
341  QStringList mFieldNameList;
342  QStringList mFieldTypeList;
343  QMap< QString, QString > mProperty;
344  QList< QPointer<QWidget> > mEnabledWidgets;
345  QList< QPointer<QWidget> > mCheckedWidgets;
346 
347  QMenu* mDefineMenu;
348  QAction* mActionDataTypes;
349  QMenu* mFieldsMenu;
350  QMenu* mVariablesMenu;
351  QAction* mActionVariables;
352 
353  QAction* mActionActive;
354  QAction* mActionDescription;
355  QAction* mActionExpDialog;
356  QAction* mActionExpression;
357  QAction* mActionPasteExpr;
358  QAction* mActionCopyExpr;
359  QAction* mActionClearExpr;
360  QAction* mActionAssistant;
361 
362  DataTypes mDataTypes;
363  QString mDataTypesString;
364  QString mInputDescription;
365  QString mFullDescription;
366  QString mUsageInfo;
367  QString mCurrentDefinition;
368 
370 
371  static QIcon mIconDataDefine;
372  static QIcon mIconDataDefineOn;
373  static QIcon mIconDataDefineError;
374  static QIcon mIconDataDefineExpression;
375  static QIcon mIconDataDefineExpressionOn;
376  static QIcon mIconDataDefineExpressionError;
377 
378  ExpressionContextCallback mExpressionContextCallback;
379  const void* mExpressionContextCallbackContext;
380 
381  private slots:
382  void aboutToShowMenu();
383  void menuActionTriggered( QAction* action );
384 };
385 
386 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
387 
388 
389 #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:107
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.