QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
qgspropertyoverridebutton.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspropertyoverridebutton.h
3 ---------------------------
4 Date : January 2017
5 Copyright : (C) 2017 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 QGSPROPERTYOVERRIDEBUTTON_H
16#define QGSPROPERTYOVERRIDEBUTTON_H
17
18#include "qgis_gui.h"
19#include "qgis_sip.h"
21#include "qgsproperty.h"
23
24#include <QDialog>
25#include <QFlags>
26#include <QMap>
27#include <QPointer>
28#include <QToolButton>
29
30class QgsVectorLayer;
31class QgsMapCanvas;
32class QgsSymbol;
33
48
49class GUI_EXPORT QgsPropertyOverrideButton : public QToolButton
50{
51 Q_OBJECT
52 Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
53 Q_PROPERTY( bool active READ isActive WRITE setActive )
54
55 public:
61 QgsPropertyOverrideButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QgsVectorLayer *layer = nullptr );
62
71 void init( int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer = nullptr, bool auxiliaryStorageEnabled = false );
72
81 void init( int propertyKey, const QgsProperty &property, const QgsPropertyDefinition &definition, const QgsVectorLayer *layer = nullptr, bool auxiliaryStorageEnabled = false );
82
91 void init( int propertyKey, const QgsAbstractPropertyCollection &collection, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer = nullptr, bool auxiliaryStorageEnabled = false );
92
98 QgsProperty toProperty() const;
99
103 void setToProperty( const QgsProperty &property );
104
108 int propertyKey() const { return mPropertyKey; }
109
113 bool isActive() const { return mProperty && mProperty.isActive(); }
114
120 QgsPropertyDefinition::DataType validDataType() const { return mDataTypes; }
121
126 QString fullDescription() const { return mFullDescription; }
127
132 QString usageInfo() const { return mUsageInfo; }
133
138 void setUsageInfo( const QString &info )
139 {
140 mUsageInfo = info;
141 updateGui();
142 }
143
149 void setVectorLayer( const QgsVectorLayer *layer );
150
156 const QgsVectorLayer *vectorLayer() const { return mVectorLayer; }
157
163 void registerCheckedWidget( QWidget *widget, bool natural = true );
164
170 void registerEnabledWidget( QWidget *widget, bool natural = true );
171
177 void registerVisibleWidget( QWidget *widget, bool natural = true );
178
183 void registerExpressionWidget( QWidget *widget );
184
189 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
190
200 void registerLinkedWidget( QWidget *widget );
201
206 void updateFieldLists();
207
213 void setSymbol( std::shared_ptr<QgsSymbol> symbol ) SIP_SKIP { mSymbol = std::move( symbol ); }
214
215 public slots:
216
220 void setActive( bool active );
221
222
224
225 // exposed to Python for testing only
226 void aboutToShowMenu();
227 void menuActionTriggered( QAction *action );
228
230
231 signals:
232
234 void changed();
235
237 void activated( bool isActive );
238
241
242 protected:
243 void mouseReleaseEvent( QMouseEvent *event ) override;
244
245 private:
246 void showDescriptionDialog();
247 void showExpressionDialog();
248 void showAssistant();
249 void updateGui();
250
255 void setActivePrivate( bool active );
256
257 // Returns color name if current expression is a reference to a color
258 QString getColor() const;
259
260 int mPropertyKey = -1;
261
262 const QgsVectorLayer *mVectorLayer = nullptr;
263
264 QStringList mFieldNameList;
265 QStringList mFieldDisplayNameList;
266 QList<QIcon> mFieldIcons;
267
268 QString mExpressionString;
269 QString mFieldName;
270
271 QMenu *mDefineMenu = nullptr;
272 QAction *mActionDataTypes = nullptr;
273 QMenu *mFieldsMenu = nullptr;
274 QMenu *mVariablesMenu = nullptr;
275 QAction *mActionVariables = nullptr;
276 QMenu *mColorsMenu = nullptr;
277 QAction *mActionColors = nullptr;
278
279 QAction *mActionActive = nullptr;
280 QAction *mActionDescription = nullptr;
281 QAction *mActionExpDialog = nullptr;
282 QAction *mActionExpression = nullptr;
283 QAction *mActionPasteExpr = nullptr;
284 QAction *mActionCopyExpr = nullptr;
285 QAction *mActionClearExpr = nullptr;
286 QAction *mActionAssistant = nullptr;
287 QAction *mActionCreateAuxiliaryField = nullptr;
288
289 QgsPropertyDefinition mDefinition;
290
292 QString mDataTypesString;
293 QString mInputDescription;
294 QString mFullDescription;
295 QString mUsageInfo;
296
297 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
298
299 enum SiblingType
300 {
301 SiblingCheckState,
302 SiblingEnableState,
303 SiblingVisibility,
304 SiblingExpressionText,
305 SiblingLinkedWidget,
306 };
307 struct SiblingWidget
308 {
309 SiblingWidget( const QPointer<QWidget> &widgetPointer, SiblingType siblingType, bool natural = true )
310 : mWidgetPointer( widgetPointer )
311 , mSiblingType( siblingType )
312 , mNatural( natural )
313 {}
314 QPointer<QWidget> mWidgetPointer;
315 SiblingType mSiblingType;
316 bool mNatural;
317 };
318 QList<SiblingWidget> mSiblingWidgets;
319
321 QgsProperty mProperty;
322
323 bool mAuxiliaryStorageEnabled = false;
324
325 std::shared_ptr<QgsSymbol> mSymbol;
326
327 private slots:
328
329 void showHelp();
330 void updateSiblingWidgets( bool state );
331};
332
333#endif // QGSPROPERTYOVERRIDEBUTTON_H
Abstract base class for QgsPropertyCollection like objects.
Abstract interface for generating an expression context.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition for a property.
Definition qgsproperty.h:47
DataType
Valid data types required by property.
Definition qgsproperty.h:84
@ DataTypeString
Property requires a string value.
Definition qgsproperty.h:91
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the button.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
void setUsageInfo(const QString &info)
Set the usage information for the property.
bool isActive() const
Returns true if the button has an active property.
void changed()
Emitted when property definition changes.
void activated(bool isActive)
Emitted when the activated status of the widget changes.
void init(int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer=nullptr, bool auxiliaryStorageEnabled=false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
void setSymbol(std::shared_ptr< QgsSymbol > symbol)
Sets a symbol which can be used for previews inside the widget or in any dialog created by the widget...
int propertyKey() const
Returns the property key linked to the button.
void setActive(bool active)
Set whether the current property override definition is to be used.
void setToProperty(const QgsProperty &property)
Sets the widget to reflect the current state of a QgsProperty.
QgsPropertyDefinition::DataType validDataType() const
Returns the data type which the widget will accept.
void createAuxiliaryField()
Emitted when creating a new auxiliary field.
QgsPropertyOverrideButton(QWidget *parent=nullptr, const QgsVectorLayer *layer=nullptr)
Constructor for QgsPropertyOverrideButton.
void mouseReleaseEvent(QMouseEvent *event) override
QString fullDescription() const
Returns the full definition description and current definition (internally generated on a contextual ...
QString usageInfo() const
Returns usage information for the property.
A store for object properties.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_SKIP
Definition qgis_sip.h:133
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.