QGIS API Documentation  2.3.0-Master
 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 <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 
38  public:
39  enum DataType
40  {
41  AnyType = 0,
42  String = 1,
43  Int = 2,
44  Double = 4
45  };
46  Q_DECLARE_FLAGS( DataTypes, DataType )
47 
48 
57  QgsDataDefinedButton( QWidget* parent = 0,
58  const QgsVectorLayer* vl = 0,
59  const QgsDataDefined* datadefined = 0,
60  DataTypes datatypes = AnyType,
61  QString description = QString( "" ) );
63 
72  void init( const QgsVectorLayer* vl,
73  const QgsDataDefined* datadefined = 0,
74  DataTypes datatypes = AnyType,
75  QString description = QString( "" ) );
76 
77  QMap< QString, QString > definedProperty() const { return mProperty; }
78 
82  bool isActive() { return mProperty.value( "active" ).toInt(); }
83 
87  bool useExpression() { return mProperty.value( "useexpr" ).toInt(); }
88 
92  QString getExpression() const { return mProperty.value( "expression" ); }
93 
97  QString getField() const { return mProperty.value( "field" ); }
98 
103  QString currentDefinition() const { return mCurrentDefinition; }
104 
109  const DataTypes& validDataTypes() const { return mDataTypes; }
110 
114  QString fullDescription() const { return mFullDescription; }
115 
119  QString usageInfo() const { return mUsageInfo; }
120 
124  void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); }
125 
129  void registerEnabledWidgets( QList<QWidget*> wdgts );
130 
134  void registerEnabledWidget( QWidget* wdgt );
135 
141  QList<QWidget*> registeredEnabledWidgets();
142 
146  void clearEnabledWidgets() { mEnabledWidgets.clear(); }
147 
151  void registerCheckedWidgets( QList<QWidget*> wdgts );
152 
156  void registerCheckedWidget( QWidget* wdgt );
157 
163  QList<QWidget*> registeredCheckedWidgets();
164 
168  void clearCheckedWidgets() { mCheckedWidgets.clear(); }
169 
173  static QString trString();
174  static QString boolDesc();
175  static QString anyStringDesc();
176  static QString intDesc();
177  static QString intPosDesc();
178  static QString intPosOneDesc();
179  static QString doubleDesc();
180  static QString doublePosDesc();
181  static QString doubleXYDesc();
182  static QString double180RotDesc();
183  static QString intTranspDesc();
184  static QString unitsMmMuDesc();
185  static QString unitsMmMuPercentDesc();
186  static QString colorNoAlphaDesc();
187  static QString colorAlphaDesc();
188  static QString textHorzAlignDesc();
189  static QString textVertAlignDesc();
190  static QString penJoinStyleDesc();
191  static QString blendModesDesc();
192  static QString svgPathDesc();
193 
194  public slots:
198  void setActive( bool active );
199 
203  void disableEnabledWidgets( bool disable );
204 
208  void checkCheckedWidgets( bool check );
209 
210  signals:
215  void dataDefinedChanged( const QString& definition );
216 
221  void dataDefinedActivated( bool active );
222 
223  protected:
224  void mouseReleaseEvent( QMouseEvent *event );
225 
229  void setUseExpression( bool use ) { mProperty.insert( "useexpr", use ? "1" : "0" ); }
230 
234  void setExpression( QString exp ) { mProperty.insert( "expression", exp ); }
235 
239  void setField( QString field ) { mProperty.insert( "field", field ); }
240 
241  private:
242  void showDescriptionDialog();
243  void showExpressionDialog();
244  void updateGui();
245 
248  QStringList mFieldNameList;
249  QStringList mFieldTypeList;
250  QMap< QString, QString > mProperty;
251  QList< QPointer<QWidget> > mEnabledWidgets;
252  QList< QPointer<QWidget> > mCheckedWidgets;
253 
254  QMenu* mDefineMenu;
256  QMenu* mFieldsMenu;
257 
258  QAction* mActionActive;
263  QAction* mActionCopyExpr;
265 
266  DataTypes mDataTypes;
270  QString mUsageInfo;
272 
273  static QIcon mIconDataDefine;
274  static QIcon mIconDataDefineOn;
275  static QIcon mIconDataDefineError;
279 
280  private slots:
281  void aboutToShowMenu();
282  void menuActionTriggered( QAction* action );
283 };
284 
285 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButton::DataTypes )
286 
287 
288 #endif // QGSDATADEFINEDBUTTON_H
static QIcon mIconDataDefineExpressionError
void clearEnabledWidgets()
Clears list of sibling widgets.
void setExpression(QString exp)
Set the current defined expression.
void setField(QString field)
Set the current defined field.
bool isActive()
Whether the current data definition or expression is to be used.
A container class for data source field mapping or expression.
void clearCheckedWidgets()
Clears list of checkable sibling widgets.
Container of fields for a vector layer.
Definition: qgsfield.h:164
bool useExpression()
Whether the current expression is to be used instead of field mapping.
QString fullDescription() const
The full definition description and current definition (internally generated on a contextual basis) ...
static QIcon mIconDataDefineExpression
QList< QPointer< QWidget > > mCheckedWidgets
QString getExpression() const
The current defined expression.
A button for defining data source field mappings or expressions.
static QIcon mIconDataDefineExpressionOn
const QgsVectorLayer * mVectorLayer
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...
void setUsageInfo(const QString &info)
Set the usage information about this data definition.
QList< QPointer< QWidget > > mEnabledWidgets
QString currentDefinition() const
The current definition.
Represents a vector layer which manages a vector based data sets.
QMap< QString, QString > mProperty