QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 <qgsfield.h>
19 #include <qgsdatadefined.h>
20 
21 #include <QFlags>
22 #include <QMap>
23 #include <QPointer>
24 #include <QToolButton>
25 
26 class QgsVectorLayer;
27 
34 class GUI_EXPORT QgsDataDefinedButton: public QToolButton
35 {
36  Q_OBJECT
37  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
38 
39  public:
40  enum DataType
41  {
42  String = 1,
43  Int = 2,
44  Double = 4,
45  AnyType = String | Int | Double
46  };
47  Q_DECLARE_FLAGS( DataTypes, DataType )
48 
49 
58  QgsDataDefinedButton( QWidget* parent = 0,
59  const QgsVectorLayer* vl = 0,
60  const QgsDataDefined* datadefined = 0,
61  DataTypes datatypes = AnyType,
62  QString description = QString( "" ) );
64 
73  void init( const QgsVectorLayer* vl,
74  const QgsDataDefined* datadefined = 0,
75  DataTypes datatypes = AnyType,
76  QString description = QString( "" ) );
77 
78  QMap< QString, QString > definedProperty() const { return mProperty; }
79 
83  bool isActive() { return mProperty.value( "active" ).toInt(); }
84 
88  bool useExpression() { return mProperty.value( "useexpr" ).toInt(); }
89 
93  QString getExpression() const { return mProperty.value( "expression" ); }
94 
98  QString getField() const { return mProperty.value( "field" ); }
99 
104  QString currentDefinition() const { return mCurrentDefinition; }
105 
110  const DataTypes& validDataTypes() const { return mDataTypes; }
111 
115  QString fullDescription() const { return mFullDescription; }
116 
120  QString usageInfo() const { return mUsageInfo; }
121 
125  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
126 
130  void registerEnabledWidgets( QList<QWidget*> wdgts );
131 
135  void registerEnabledWidget( QWidget* wdgt );
136 
142  QList<QWidget*> registeredEnabledWidgets();
143 
147  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
148 
152  void registerCheckedWidgets( QList<QWidget*> wdgts );
153 
157  void registerCheckedWidget( QWidget* wdgt );
158 
164  QList<QWidget*> registeredCheckedWidgets();
165 
169  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
170 
174  static QString trString();
175  static QString boolDesc();
176  static QString anyStringDesc();
177  static QString intDesc();
178  static QString intPosDesc();
179  static QString intPosOneDesc();
180  static QString doubleDesc();
181  static QString doublePosDesc();
182  static QString doubleXYDesc();
183  static QString double180RotDesc();
184  static QString intTranspDesc();
185  static QString unitsMmMuDesc();
186  static QString unitsMmMuPercentDesc();
187  static QString colorNoAlphaDesc();
188  static QString colorAlphaDesc();
189  static QString textHorzAlignDesc();
190  static QString textVertAlignDesc();
191  static QString penJoinStyleDesc();
192  static QString blendModesDesc();
193  static QString svgPathDesc();
194  static QString paperSizeDesc();
195  static QString paperOrientationDesc();
196 
197  public slots:
201  void setActive( bool active );
202 
206  void disableEnabledWidgets( bool disable );
207 
211  void checkCheckedWidgets( bool check );
212 
213  signals:
218  void dataDefinedChanged( const QString& definition );
219 
224  void dataDefinedActivated( bool active );
225 
226  protected:
227  void mouseReleaseEvent( QMouseEvent *event );
228 
232  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
233 
237  void setExpression( QString exp ) { mProperty.insert( "expression", exp ); }
238 
242  void setField( QString field ) { mProperty.insert( "field", field ); }
243 
244  private:
245  void showDescriptionDialog();
246  void showExpressionDialog();
247  void updateGui();
248 
249  const QgsVectorLayer* mVectorLayer;
250  QgsFields mFields;
251  QStringList mFieldNameList;
252  QStringList mFieldTypeList;
253  QMap< QString, QString > mProperty;
254  QList< QPointer<QWidget> > mEnabledWidgets;
255  QList< QPointer<QWidget> > mCheckedWidgets;
256 
257  QMenu* mDefineMenu;
258  QAction* mActionDataTypes;
259  QMenu* mFieldsMenu;
260 
261  QAction* mActionActive;
262  QAction* mActionDescription;
263  QAction* mActionExpDialog;
264  QAction* mActionExpression;
265  QAction* mActionPasteExpr;
266  QAction* mActionCopyExpr;
267  QAction* mActionClearExpr;
268 
269  DataTypes mDataTypes;
270  QString mDataTypesString;
271  QString mInputDescription;
272  QString mFullDescription;
273  QString mUsageInfo;
274  QString mCurrentDefinition;
275 
276  static QIcon mIconDataDefine;
277  static QIcon mIconDataDefineOn;
278  static QIcon mIconDataDefineError;
279  static QIcon mIconDataDefineExpression;
280  static QIcon mIconDataDefineExpressionOn;
281  static QIcon mIconDataDefineExpressionError;
282 
283  private slots:
284  void aboutToShowMenu();
285  void menuActionTriggered( QAction* action );
286 };
287 
288 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
289 
290 
291 #endif // QGSDATADEFINEDBUTTON_H
void clearEnabledWidgets()
Clears list of sibling widgets.
Definition: qgsdatadefinedbutton.h:147
void setExpression(QString exp)
Set the current defined expression.
Definition: qgsdatadefinedbutton.h:237
void setField(QString field)
Set the current defined field.
Definition: qgsdatadefinedbutton.h:242
bool isActive()
Whether the current data definition or expression is to be used.
Definition: qgsdatadefinedbutton.h:83
A container class for data source field mapping or expression.
Definition: qgsdatadefined.h:32
DataType
Definition: qgsdatadefinedbutton.h:40
void clearCheckedWidgets()
Clears list of checkable sibling widgets.
Definition: qgsdatadefinedbutton.h:169
Container of fields for a vector layer.
Definition: qgsfield.h:172
bool useExpression()
Whether the current expression is to be used instead of field mapping.
Definition: qgsdatadefinedbutton.h:88
QString fullDescription() const
The full definition description and current definition (internally generated on a contextual basis) ...
Definition: qgsdatadefinedbutton.h:115
QString getExpression() const
The current defined expression.
Definition: qgsdatadefinedbutton.h:93
A button for defining data source field mappings or expressions.
Definition: qgsdatadefinedbutton.h:34
QString getField() const
The current defined field.
Definition: qgsdatadefinedbutton.h:98
void setUseExpression(bool use)
Set whether the current expression is to be used instead of field mapping.
Definition: qgsdatadefinedbutton.h:232
QString usageInfo() const
The usage information about this data definition.
Definition: qgsdatadefinedbutton.h:120
const DataTypes & validDataTypes() const
The valid data types that will work for the definition (QVariant-coercible to expected type) Compared...
Definition: qgsdatadefinedbutton.h:110
void setUsageInfo(const QString &info)
Set the usage information about this data definition.
Definition: qgsdatadefinedbutton.h:125
QString currentDefinition() const
The current definition.
Definition: qgsdatadefinedbutton.h:104
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470