QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
214 {
215 mSymbol = std::move( symbol );
216 }
217
218 public slots:
219
223 void setActive( bool active );
224
225
227
228 // exposed to Python for testing only
229 void aboutToShowMenu();
230 void menuActionTriggered( QAction *action );
231
233
234 signals:
235
237 void changed();
238
240 void activated( bool isActive );
241
244
245 protected:
246 void mouseReleaseEvent( QMouseEvent *event ) override;
247
248 private:
249 void showDescriptionDialog();
250 void showExpressionDialog();
251 void showAssistant();
252 void updateGui();
253
258 void setActivePrivate( bool active );
259
260 // Returns color name if current expression is a reference to a color
261 QString getColor() const;
262
263 int mPropertyKey = -1;
264
265 const QgsVectorLayer *mVectorLayer = nullptr;
266
267 QStringList mFieldNameList;
268 QStringList mFieldDisplayNameList;
269 QList<QIcon> mFieldIcons;
270
271 QString mExpressionString;
272 QString mFieldName;
273
274 QMenu *mDefineMenu = nullptr;
275 QAction *mActionDataTypes = nullptr;
276 QMenu *mFieldsMenu = nullptr;
277 QMenu *mVariablesMenu = nullptr;
278 QAction *mActionVariables = nullptr;
279 QMenu *mColorsMenu = nullptr;
280 QAction *mActionColors = nullptr;
281
282 QAction *mActionActive = nullptr;
283 QAction *mActionDescription = nullptr;
284 QAction *mActionExpDialog = nullptr;
285 QAction *mActionExpression = nullptr;
286 QAction *mActionPasteExpr = nullptr;
287 QAction *mActionCopyExpr = nullptr;
288 QAction *mActionClearExpr = nullptr;
289 QAction *mActionAssistant = nullptr;
290 QAction *mActionCreateAuxiliaryField = nullptr;
291
292 QgsPropertyDefinition mDefinition;
293
295 QString mDataTypesString;
296 QString mInputDescription;
297 QString mFullDescription;
298 QString mUsageInfo;
299
300 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
301
302 enum SiblingType
303 {
304 SiblingCheckState,
305 SiblingEnableState,
306 SiblingVisibility,
307 SiblingExpressionText,
308 SiblingLinkedWidget,
309 };
310 struct SiblingWidget
311 {
312 SiblingWidget( const QPointer<QWidget> &widgetPointer, SiblingType siblingType, bool natural = true )
313 : mWidgetPointer( widgetPointer )
314 , mSiblingType( siblingType )
315 , mNatural( natural )
316 {}
317 QPointer<QWidget> mWidgetPointer;
318 SiblingType mSiblingType;
319 bool mNatural;
320 };
321 QList<SiblingWidget> mSiblingWidgets;
322
324 QgsProperty mProperty;
325
326 bool mAuxiliaryStorageEnabled = false;
327
328 std::shared_ptr<QgsSymbol> mSymbol;
329
330 private slots:
331
332 void showHelp();
333 void updateSiblingWidgets( bool state );
334};
335
336#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:45
DataType
Valid data types required by property.
Definition qgsproperty.h:83
@ DataTypeString
Property requires a string value.
Definition qgsproperty.h:90
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:231
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.