QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
25 class QgsVectorLayer;
26 class QgsDataDefined;
27 
35 class GUI_EXPORT QgsDataDefinedAssistant: public QDialog
36 {
37  public:
38  virtual QgsDataDefined dataDefined() const = 0;
39 };
40 
46 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
47 {
48  Q_OBJECT
49  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
50 
51  public:
52  enum DataType
53  {
54  String = 1,
55  Int = 2,
56  Double = 4,
57  AnyType = String | Int | Double
58  };
59  Q_DECLARE_FLAGS( DataTypes, DataType )
60 
61 
70  QgsDataDefinedButton( QWidget* parent = 0,
71  const QgsVectorLayer* vl = 0,
72  const QgsDataDefined* datadefined = 0,
73  DataTypes datatypes = AnyType,
74  QString description = "" );
76 
85  void init( const QgsVectorLayer* vl,
86  const QgsDataDefined* datadefined = 0,
87  DataTypes datatypes = AnyType,
88  QString description = QString( "" ) );
89 
90  QMap< QString, QString > definedProperty() const { return mProperty; }
91 
97  void updateDataDefined( QgsDataDefined* dd ) const;
98 
104  QgsDataDefined currentDataDefined() const;
105 
109  bool isActive() const { return mProperty.value( "active" ).toInt(); }
110 
114  bool useExpression() const { return mProperty.value( "useexpr" ).toInt(); }
115 
119  QString getExpression() const { return mProperty.value( "expression" ); }
120 
124  QString getField() const { return mProperty.value( "field" ); }
125 
130  QString currentDefinition() const { return mCurrentDefinition; }
131 
136  const DataTypes& validDataTypes() const { return mDataTypes; }
137 
141  QString fullDescription() const { return mFullDescription; }
142 
146  QString usageInfo() const { return mUsageInfo; }
147 
151  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
152 
156  void registerEnabledWidgets( QList<QWidget*> wdgts );
157 
161  void registerEnabledWidget( QWidget* wdgt );
162 
168  QList<QWidget*> registeredEnabledWidgets();
169 
173  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
174 
178  void registerCheckedWidgets( QList<QWidget*> wdgts );
179 
183  void registerCheckedWidget( QWidget* wdgt );
184 
190  QList<QWidget*> registeredCheckedWidgets();
191 
195  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
196 
205  void setAssistant( const QString& title, QgsDataDefinedAssistant * assistant );
206 
210  static QString trString();
211  static QString charDesc();
212  static QString boolDesc();
213  static QString anyStringDesc();
214  static QString intDesc();
215  static QString intPosDesc();
216  static QString intPosOneDesc();
217  static QString doubleDesc();
218  static QString doublePosDesc();
219  static QString double0to1Desc();
220  static QString doubleXYDesc();
221  static QString double180RotDesc();
222  static QString intTranspDesc();
223  static QString unitsMmMuDesc();
224  static QString unitsMmMuPercentDesc();
225  static QString colorNoAlphaDesc();
226  static QString colorAlphaDesc();
227  static QString textHorzAlignDesc();
228  static QString textVertAlignDesc();
229  static QString penJoinStyleDesc();
230  static QString blendModesDesc();
231  static QString svgPathDesc();
232  static QString filePathDesc();
233  static QString paperSizeDesc();
234  static QString paperOrientationDesc();
235  static QString horizontalAnchorDesc();
236  static QString verticalAnchorDesc();
237  static QString gradientTypeDesc();
238  static QString gradientCoordModeDesc();
239  static QString gradientSpreadDesc();
240  static QString lineStyleDesc();
241  static QString capStyleDesc();
242  static QString fillStyleDesc();
243  static QString markerStyleDesc();
244  static QString customDashDesc();
245 
246  public slots:
250  void setActive( bool active );
251 
255  void disableEnabledWidgets( bool disable );
256 
260  void checkCheckedWidgets( bool check );
261 
262  signals:
267  void dataDefinedChanged( const QString& definition );
268 
273  void dataDefinedActivated( bool active );
274 
275  protected:
276  void mouseReleaseEvent( QMouseEvent *event ) override;
277 
281  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
282 
286  void setExpression( QString exp ) { mProperty.insert( "expression", exp ); }
287 
291  void setField( QString field ) { mProperty.insert( "field", field ); }
292 
293  private:
294  void showDescriptionDialog();
295  void showExpressionDialog();
296  void showAssistant();
297  void updateGui();
298 
299  const QgsVectorLayer* mVectorLayer;
300  QStringList mFieldNameList;
301  QStringList mFieldTypeList;
302  QMap< QString, QString > mProperty;
303  QList< QPointer<QWidget> > mEnabledWidgets;
304  QList< QPointer<QWidget> > mCheckedWidgets;
305 
306  QMenu* mDefineMenu;
307  QAction* mActionDataTypes;
308  QMenu* mFieldsMenu;
309 
310  QAction* mActionActive;
311  QAction* mActionDescription;
312  QAction* mActionExpDialog;
313  QAction* mActionExpression;
314  QAction* mActionPasteExpr;
315  QAction* mActionCopyExpr;
316  QAction* mActionClearExpr;
317  QAction* mActionAssistant;
318 
319  DataTypes mDataTypes;
320  QString mDataTypesString;
321  QString mInputDescription;
322  QString mFullDescription;
323  QString mUsageInfo;
324  QString mCurrentDefinition;
325 
327 
328  static QIcon mIconDataDefine;
329  static QIcon mIconDataDefineOn;
330  static QIcon mIconDataDefineError;
331  static QIcon mIconDataDefineExpression;
332  static QIcon mIconDataDefineExpressionOn;
333  static QIcon mIconDataDefineExpressionError;
334 
335  private slots:
336  void aboutToShowMenu();
337  void menuActionTriggered( QAction* action );
338 };
339 
340 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
341 
342 
343 #endif // QGSDATADEFINEDBUTTON_H
void clearEnabledWidgets()
Clears list of sibling widgets.
An assistant (wizard) dialog, accessible from a QgsDataDefinedButton.
void setExpression(QString exp)
Set the current defined expression.
void setField(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.
QString fullDescription() const
The full definition description and current definition (internally generated on a contextual basis) ...
virtual void mouseReleaseEvent(QMouseEvent *e)
QString getExpression() const
The current defined expression.
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.