QGIS API Documentation 3.41.0-Master (af5edcb665c)
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"
20#include <QDialog>
21#include <QFlags>
22#include <QMap>
23#include <QPointer>
24#include <QToolButton>
25#include "qgsproperty.h"
28
29class QgsVectorLayer;
30class QgsMapCanvas;
31class QgsSymbol;
32
48class GUI_EXPORT QgsPropertyOverrideButton : public QToolButton
49{
50 Q_OBJECT
51 Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
52 Q_PROPERTY( bool active READ isActive WRITE setActive )
53
54 public:
60 QgsPropertyOverrideButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QgsVectorLayer *layer = nullptr );
61
70 void init( int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer = nullptr, bool auxiliaryStorageEnabled = false );
71
80 void init( int propertyKey, const QgsProperty &property, const QgsPropertyDefinition &definition, const QgsVectorLayer *layer = nullptr, bool auxiliaryStorageEnabled = false );
81
90 void init( int propertyKey, const QgsAbstractPropertyCollection &collection, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer = nullptr, bool auxiliaryStorageEnabled = false );
91
97 QgsProperty toProperty() const;
98
102 void setToProperty( const QgsProperty &property );
103
107 int propertyKey() const { return mPropertyKey; }
108
112 bool isActive() const { return mProperty && mProperty.isActive(); }
113
119 QgsPropertyDefinition::DataType validDataType() const { return mDataTypes; }
120
125 QString fullDescription() const { return mFullDescription; }
126
131 QString usageInfo() const { return mUsageInfo; }
132
137 void setUsageInfo( const QString &info )
138 {
139 mUsageInfo = info;
140 updateGui();
141 }
142
148 void setVectorLayer( const QgsVectorLayer *layer );
149
155 const QgsVectorLayer *vectorLayer() const { return mVectorLayer; }
156
162 void registerCheckedWidget( QWidget *widget, bool natural = true );
163
169 void registerEnabledWidget( QWidget *widget, bool natural = true );
170
176 void registerVisibleWidget( QWidget *widget, bool natural = true );
177
182 void registerExpressionWidget( QWidget *widget );
183
188 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
189
199 void registerLinkedWidget( QWidget *widget );
200
205 void updateFieldLists();
206
212 void setSymbol( std::shared_ptr<QgsSymbol> symbol ) SIP_SKIP
213 {
214 mSymbol = symbol;
215 }
216
217 public slots:
218
222 void setActive( bool active );
223
224
226
227 // exposed to Python for testing only
228 void aboutToShowMenu();
229 void menuActionTriggered( QAction *action );
230
232
233 signals:
234
236 void changed();
237
239 void activated( bool isActive );
240
243
244 protected:
245 void mouseReleaseEvent( QMouseEvent *event ) override;
246
247 private:
248 void showDescriptionDialog();
249 void showExpressionDialog();
250 void showAssistant();
251 void updateGui();
252
257 void setActivePrivate( bool active );
258
259 // Returns color name if current expression is a reference to a color
260 QString getColor() const;
261
262 int mPropertyKey = -1;
263
264 const QgsVectorLayer *mVectorLayer = nullptr;
265
266 QStringList mFieldNameList;
267 QStringList mFieldDisplayNameList;
268 QList<QIcon> mFieldIcons;
269
270 QString mExpressionString;
271 QString mFieldName;
272
273 QMenu *mDefineMenu = nullptr;
274 QAction *mActionDataTypes = nullptr;
275 QMenu *mFieldsMenu = nullptr;
276 QMenu *mVariablesMenu = nullptr;
277 QAction *mActionVariables = nullptr;
278 QMenu *mColorsMenu = nullptr;
279 QAction *mActionColors = nullptr;
280
281 QAction *mActionActive = nullptr;
282 QAction *mActionDescription = nullptr;
283 QAction *mActionExpDialog = nullptr;
284 QAction *mActionExpression = nullptr;
285 QAction *mActionPasteExpr = nullptr;
286 QAction *mActionCopyExpr = nullptr;
287 QAction *mActionClearExpr = nullptr;
288 QAction *mActionAssistant = nullptr;
289 QAction *mActionCreateAuxiliaryField = nullptr;
290
291 QgsPropertyDefinition mDefinition;
292
294 QString mDataTypesString;
295 QString mInputDescription;
296 QString mFullDescription;
297 QString mUsageInfo;
298
299 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
300
301 enum SiblingType
302 {
303 SiblingCheckState,
304 SiblingEnableState,
305 SiblingVisibility,
306 SiblingExpressionText,
307 SiblingLinkedWidget,
308 };
309 struct SiblingWidget
310 {
311 SiblingWidget( const QPointer<QWidget> &widgetPointer, SiblingType siblingType, bool natural = true )
312 : mWidgetPointer( widgetPointer )
313 , mSiblingType( siblingType )
314 , mNatural( natural )
315 {}
316 QPointer<QWidget> mWidgetPointer;
317 SiblingType mSiblingType;
318 bool mNatural;
319 };
320 QList<SiblingWidget> mSiblingWidgets;
321
323 QgsProperty mProperty;
324
325 bool mAuxiliaryStorageEnabled = false;
326
327 std::shared_ptr<QgsSymbol> mSymbol;
328
329 private slots:
330
331 void showHelp();
332 void updateSiblingWidgets( bool state );
333};
334
335#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
A button for controlling property overrides which may apply to a widget.
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the button.
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 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...
QgsPropertyDefinition::DataType validDataType() const
Returns the data type which the widget will accept.
void createAuxiliaryField()
Emitted when creating a new auxiliary field.
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 data sets.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.