|
| 1 | +/*************************************************************************** |
| 2 | + qgsdatadefinedbuttonv2.h |
| 3 | + ------------------------ |
| 4 | + Date : March 2016 |
| 5 | + Copyright : (C) 2016 by Nyall Dawson |
| 6 | + Email : nyall dot dawson at gmail 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 QGSDATADEFINEDBUTTONV2_H |
| 16 | +#define QGSDATADEFINEDBUTTONV2_H |
| 17 | + |
| 18 | +#include "qgis_gui.h" |
| 19 | +#include <QDialog> |
| 20 | +#include <QFlags> |
| 21 | +#include <QMap> |
| 22 | +#include <QPointer> |
| 23 | +#include <QToolButton> |
| 24 | +#include <QScopedPointer> |
| 25 | +#include "qgsproperty.h" |
| 26 | +#include "qgsexpressioncontext.h" |
| 27 | +#include "qgsexpressioncontextgenerator.h" |
| 28 | + |
| 29 | +class QgsVectorLayer; |
| 30 | +class QgsDataDefined; |
| 31 | +class QgsMapCanvas; |
| 32 | + |
| 33 | +/** \ingroup gui |
| 34 | + * \class QgsDataDefinedButtonV2 |
| 35 | + * A button for defining data source field mappings or expressions. |
| 36 | + */ |
| 37 | + |
| 38 | +class GUI_EXPORT QgsDataDefinedButtonV2: public QToolButton |
| 39 | +{ |
| 40 | + Q_OBJECT |
| 41 | + Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo ) |
| 42 | + |
| 43 | + public: |
| 44 | + |
| 45 | + //! Valid data types accepted by property |
| 46 | + enum DataType |
| 47 | + { |
| 48 | + String = 1, |
| 49 | + Int = 1 << 1, |
| 50 | + Double = 1 << 2, |
| 51 | + AnyType = String | Int | Double |
| 52 | + }; |
| 53 | + Q_DECLARE_FLAGS( DataTypes, DataType ) |
| 54 | + |
| 55 | + /** |
| 56 | + * Constructor for QgsDataDefinedButtonV2. |
| 57 | + * @param parent parent widget |
| 58 | + * @param layer associated vector layer |
| 59 | + * @param propertyCollection associated property collection |
| 60 | + * @param propertyKey key for corresponding property |
| 61 | + * @param dataTypes expected data type for property values |
| 62 | + * @param description string description of expected input data |
| 63 | + */ |
| 64 | + QgsDataDefinedButtonV2( QWidget* parent = nullptr, |
| 65 | + const QgsVectorLayer* layer = nullptr, |
| 66 | + const QgsAbstractProperty* property = nullptr, |
| 67 | + const QgsDataDefinedButtonV2::DataTypes& dataTypes = AnyType, |
| 68 | + const QString& description = QString() ); |
| 69 | + |
| 70 | + /** |
| 71 | + * Initialize a newly constructed data defined button (useful if button was included in a form layout). |
| 72 | + * @param layer associated vector layer |
| 73 | + * @param propertyCollection associated property collection |
| 74 | + * @param propertyKey key for corresponding property |
| 75 | + * @param dataTypes expected data type for property values |
| 76 | + * @param description string description of expected input data |
| 77 | + */ |
| 78 | + void init( const QgsVectorLayer* layer, |
| 79 | + const QgsAbstractProperty* property = nullptr, |
| 80 | + const QgsDataDefinedButtonV2::DataTypes& dataTypes = AnyType, |
| 81 | + const QString& description = QString() ); |
| 82 | + |
| 83 | + QgsAbstractProperty* toProperty(); |
| 84 | + |
| 85 | + /** |
| 86 | + * The valid data types that will work for the definition (QVariant-coercible to expected type) |
| 87 | + * Compared against the variant type of the QgsField from data source and expression result |
| 88 | + */ |
| 89 | + const DataTypes& validDataTypes() const { return mDataTypes; } |
| 90 | + |
| 91 | + /** |
| 92 | + * The full definition description and current definition (internally generated on a contextual basis) |
| 93 | + */ |
| 94 | + QString fullDescription() const { return mFullDescription; } |
| 95 | + |
| 96 | + /** |
| 97 | + * The usage information about this data definition |
| 98 | + */ |
| 99 | + QString usageInfo() const { return mUsageInfo; } |
| 100 | + |
| 101 | + /** |
| 102 | + * Set the usage information about this data definition |
| 103 | + */ |
| 104 | + void setUsageInfo( const QString& info ) { mUsageInfo = info; updateGui(); } |
| 105 | + |
| 106 | + //! Callback function for retrieving the expression context for the button |
| 107 | + typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context ); |
| 108 | + |
| 109 | + /** |
| 110 | + * Register an expression context generator class that will be used to retrieve |
| 111 | + * an expression context for the button. |
| 112 | + * @param generator A QgsExpressionContextGenerator class that will be used to |
| 113 | + * create an expression context when required. |
| 114 | + */ |
| 115 | + void registerExpressionContextGenerator( QgsExpressionContextGenerator* generator ); |
| 116 | + |
| 117 | + /** |
| 118 | + * Common descriptions for expected input values |
| 119 | + */ |
| 120 | + static QString trString(); |
| 121 | + static QString charDesc(); |
| 122 | + static QString boolDesc(); |
| 123 | + static QString anyStringDesc(); |
| 124 | + static QString intDesc(); |
| 125 | + static QString intPosDesc(); |
| 126 | + static QString intPosOneDesc(); |
| 127 | + static QString doubleDesc(); |
| 128 | + static QString doublePosDesc(); |
| 129 | + static QString double0to1Desc(); |
| 130 | + static QString doubleXYDesc(); |
| 131 | + static QString double180RotDesc(); |
| 132 | + static QString intTranspDesc(); |
| 133 | + static QString unitsMmMuDesc(); |
| 134 | + static QString unitsMmMuPercentDesc(); |
| 135 | + static QString colorNoAlphaDesc(); |
| 136 | + static QString colorAlphaDesc(); |
| 137 | + static QString textHorzAlignDesc(); |
| 138 | + static QString textVertAlignDesc(); |
| 139 | + static QString penJoinStyleDesc(); |
| 140 | + static QString blendModesDesc(); |
| 141 | + static QString svgPathDesc(); |
| 142 | + static QString filePathDesc(); |
| 143 | + static QString paperSizeDesc(); |
| 144 | + static QString paperOrientationDesc(); |
| 145 | + static QString horizontalAnchorDesc(); |
| 146 | + static QString verticalAnchorDesc(); |
| 147 | + static QString gradientTypeDesc(); |
| 148 | + static QString gradientCoordModeDesc(); |
| 149 | + static QString gradientSpreadDesc(); |
| 150 | + static QString lineStyleDesc(); |
| 151 | + static QString capStyleDesc(); |
| 152 | + static QString fillStyleDesc(); |
| 153 | + static QString markerStyleDesc(); |
| 154 | + static QString customDashDesc(); |
| 155 | + |
| 156 | + public slots: |
| 157 | + |
| 158 | + /** |
| 159 | + * Set whether the current data definition or expression is to be used |
| 160 | + */ |
| 161 | + void setActive( bool active ); |
| 162 | + |
| 163 | + signals: |
| 164 | + |
| 165 | + //! Emitted when property definition changes |
| 166 | + void changed(); |
| 167 | + |
| 168 | + protected: |
| 169 | + void mouseReleaseEvent( QMouseEvent *event ) override; |
| 170 | + |
| 171 | + private: |
| 172 | + |
| 173 | + void updateFieldLists(); |
| 174 | + void setToProperty( const QgsAbstractProperty* property ); |
| 175 | + void showDescriptionDialog(); |
| 176 | + void showExpressionDialog(); |
| 177 | + void updateGui(); |
| 178 | + |
| 179 | + const QgsVectorLayer* mVectorLayer; |
| 180 | + |
| 181 | + QStringList mFieldNameList; |
| 182 | + QStringList mFieldTypeList; |
| 183 | + |
| 184 | + bool mActive; |
| 185 | + bool mUseExpression; |
| 186 | + QString mExpressionString; |
| 187 | + QString mFieldName; |
| 188 | + |
| 189 | + QMenu* mDefineMenu; |
| 190 | + QAction* mActionDataTypes; |
| 191 | + QMenu* mFieldsMenu; |
| 192 | + QMenu* mVariablesMenu; |
| 193 | + QAction* mActionVariables; |
| 194 | + |
| 195 | + QAction* mActionActive; |
| 196 | + QAction* mActionDescription; |
| 197 | + QAction* mActionExpDialog; |
| 198 | + QAction* mActionExpression; |
| 199 | + QAction* mActionPasteExpr; |
| 200 | + QAction* mActionCopyExpr; |
| 201 | + QAction* mActionClearExpr; |
| 202 | + QAction* mActionAssistant; |
| 203 | + |
| 204 | + DataTypes mDataTypes; |
| 205 | + QString mDataTypesString; |
| 206 | + QString mInputDescription; |
| 207 | + QString mFullDescription; |
| 208 | + QString mUsageInfo; |
| 209 | + |
| 210 | + QgsExpressionContextGenerator* mExpressionContextGenerator; |
| 211 | + |
| 212 | + private slots: |
| 213 | + void aboutToShowMenu(); |
| 214 | + void menuActionTriggered( QAction* action ); |
| 215 | +}; |
| 216 | + |
| 217 | +Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataDefinedButtonV2::DataTypes ) |
| 218 | + |
| 219 | + |
| 220 | +#endif // QGSDATADEFINEDBUTTONV2_H |
0 commit comments