QGIS API Documentation  3.13.0-Master (788156190c)
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"
26 #include "qgspropertycollection.h"
27 #include "qgsexpressioncontext.h"
29 
30 class QgsVectorLayer;
31 class QgsMapCanvas;
32 class QgsSymbol;
33 
50 class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton
51 {
52  Q_OBJECT
53  Q_PROPERTY( QString usageInfo READ usageInfo WRITE setUsageInfo )
54  Q_PROPERTY( bool active READ isActive WRITE setActive )
55 
56  public:
57 
63  QgsPropertyOverrideButton( QWidget *parent SIP_TRANSFERTHIS = nullptr,
64  const QgsVectorLayer *layer = nullptr );
65 
74  void init( int propertyKey,
75  const QgsProperty &property,
76  const QgsPropertiesDefinition &definitions,
77  const QgsVectorLayer *layer = nullptr,
78  bool auxiliaryStorageEnabled = false );
79 
88  void init( int propertyKey,
89  const QgsProperty &property,
90  const QgsPropertyDefinition &definition,
91  const QgsVectorLayer *layer = nullptr,
92  bool auxiliaryStorageEnabled = false );
93 
102  void init( int propertyKey,
103  const QgsAbstractPropertyCollection &collection,
104  const QgsPropertiesDefinition &definitions,
105  const QgsVectorLayer *layer = nullptr,
106  bool auxiliaryStorageEnabled = false );
107 
113  QgsProperty toProperty() const;
114 
118  void setToProperty( const QgsProperty &property );
119 
123  int propertyKey() const { return mPropertyKey; }
124 
128  bool isActive() const { return mProperty && mProperty.isActive(); }
129 
135  QgsPropertyDefinition::DataType validDataType() const { return mDataTypes; }
136 
141  QString fullDescription() const { return mFullDescription; }
142 
147  QString usageInfo() const { return mUsageInfo; }
148 
153  void setUsageInfo( const QString &info ) { mUsageInfo = info; updateGui(); }
154 
160  void setVectorLayer( const QgsVectorLayer *layer );
161 
167  const QgsVectorLayer *vectorLayer() const { return mVectorLayer; }
168 
174  void registerCheckedWidget( QWidget *widget, bool natural = true );
175 
181  void registerEnabledWidget( QWidget *widget, bool natural = true );
182 
188  void registerVisibleWidget( QWidget *widget, bool natural = true );
189 
194  void registerExpressionWidget( QWidget *widget );
195 
200  void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
201 
211  void registerLinkedWidget( QWidget *widget );
212 
218  void updateFieldLists();
219 
225  void setSymbol( std::shared_ptr< QgsSymbol > symbol ) { mSymbol = symbol; } SIP_SKIP
226 
227  public slots:
228 
232  void setActive( bool active );
233 
234 
236 
237  // exposed to Python for testing only
238  void aboutToShowMenu();
239  void menuActionTriggered( QAction *action );
240 
242 
243  signals:
244 
246  void changed();
247 
249  void activated( bool isActive );
250 
252  void createAuxiliaryField();
253 
254  protected:
255  void mouseReleaseEvent( QMouseEvent *event ) override;
256 
257  private:
258 
259  void showDescriptionDialog();
260  void showExpressionDialog();
261  void showAssistant();
262  void updateGui();
263 
268  void setActivePrivate( bool active );
269 
270 
271  int mPropertyKey = -1;
272 
273  const QgsVectorLayer *mVectorLayer = nullptr;
274 
275  QStringList mFieldNameList;
276  QStringList mFieldTypeList;
277 
278  QString mExpressionString;
279  QString mFieldName;
280 
281  QMenu *mDefineMenu = nullptr;
282  QAction *mActionDataTypes = nullptr;
283  QMenu *mFieldsMenu = nullptr;
284  QMenu *mVariablesMenu = nullptr;
285  QAction *mActionVariables = nullptr;
286  QMenu *mColorsMenu = nullptr;
287  QAction *mActionColors = nullptr;
288 
289  QAction *mActionActive = nullptr;
290  QAction *mActionDescription = nullptr;
291  QAction *mActionExpDialog = nullptr;
292  QAction *mActionExpression = nullptr;
293  QAction *mActionPasteExpr = nullptr;
294  QAction *mActionCopyExpr = nullptr;
295  QAction *mActionClearExpr = nullptr;
296  QAction *mActionAssistant = nullptr;
297  QAction *mActionCreateAuxiliaryField = nullptr;
298 
299  QgsPropertyDefinition mDefinition;
300 
302  QString mDataTypesString;
303  QString mInputDescription;
304  QString mFullDescription;
305  QString mUsageInfo;
306 
307  QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
308 
309  enum SiblingType
310  {
311  SiblingCheckState,
312  SiblingEnableState,
313  SiblingVisibility,
314  SiblingExpressionText,
315  SiblingLinkedWidget,
316  };
317  struct SiblingWidget
318  {
319  SiblingWidget( const QPointer<QWidget> &widgetPointer, SiblingType siblingType, bool natural = true )
320  : mWidgetPointer( widgetPointer )
321  , mSiblingType( siblingType )
322  , mNatural( natural )
323  {}
324  QPointer<QWidget> mWidgetPointer;
325  SiblingType mSiblingType;
326  bool mNatural;
327  };
328  QList< SiblingWidget > mSiblingWidgets;
329 
331  QgsProperty mProperty;
332 
333  bool mAuxiliaryStorageEnabled = false;
334 
335  std::shared_ptr< QgsSymbol > mSymbol;
336 
337  private slots:
338 
339  void showHelp();
340  void updateSiblingWidgets( bool state );
341 };
342 
343 #endif // QGSPROPERTYOVERRIDEBUTTON_H
QgsPropertyOverrideButton::validDataType
QgsPropertyDefinition::DataType validDataType() const
Returns the data type which the widget will accept.
Definition: qgspropertyoverridebutton.h:135
QgsProperty
A store for object properties.
Definition: qgsproperty.h:229
QgsPropertyDefinition::DataTypeString
@ DataTypeString
Property requires a string value.
Definition: qgsproperty.h:91
QgsPropertyOverrideButton::setUsageInfo
void setUsageInfo(const QString &info)
Set the usage information for the property.
Definition: qgspropertyoverridebutton.h:153
QgsMapCanvas
Definition: qgsmapcanvas.h:78
QgsPropertyOverrideButton::fullDescription
QString fullDescription() const
Returns the full definition description and current definition (internally generated on a contextual ...
Definition: qgspropertyoverridebutton.h:141
QgsAbstractPropertyCollection
Abstract base class for QgsPropertyCollection like objects.
Definition: qgspropertycollection.h:39
QgsSymbol
Definition: qgssymbol.h:62
QgsPropertyOverrideButton
Definition: qgspropertyoverridebutton.h:50
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:27
QgsPropertyDefinition::DataType
DataType
Valid data types required by property.
Definition: qgsproperty.h:83
qgsexpressioncontext.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgis_sip.h
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:46
qgsexpressioncontextgenerator.h
QgsPropertyOverrideButton::isActive
bool isActive() const
Returns true if the button has an active property.
Definition: qgspropertyoverridebutton.h:128
QgsVectorLayer
Definition: qgsvectorlayer.h:386
QgsPropertyOverrideButton::vectorLayer
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the button.
Definition: qgspropertyoverridebutton.h:167
qgsproperty.h
qgspropertycollection.h
QgsPropertyOverrideButton::usageInfo
QString usageInfo() const
Returns usage information for the property.
Definition: qgspropertyoverridebutton.h:147
QgsPropertyOverrideButton::setSymbol
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...
Definition: qgspropertyoverridebutton.h:225
QgsExpressionContextGenerator
Definition: qgsexpressioncontextgenerator.h:36
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53