QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
49 class 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:
56 
62  QgsPropertyOverrideButton( QWidget *parent SIP_TRANSFERTHIS = nullptr,
63  const QgsVectorLayer *layer = nullptr );
64 
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 
207  void updateFieldLists();
208 
214  void setSymbol( std::shared_ptr< QgsSymbol > symbol ) { mSymbol = symbol; } SIP_SKIP
215 
216  public slots:
217 
221  void setActive( bool active );
222 
223  signals:
224 
226  void changed();
227 
229  void activated( bool isActive );
230 
232  void createAuxiliaryField();
233 
234  protected:
235  void mouseReleaseEvent( QMouseEvent *event ) override;
236 
237  private:
238 
239  void showDescriptionDialog();
240  void showExpressionDialog();
241  void showAssistant();
242  void updateGui();
243 
248  void setActivePrivate( bool active );
249 
250 
251  int mPropertyKey = -1;
252 
253  const QgsVectorLayer *mVectorLayer = nullptr;
254 
255  QStringList mFieldNameList;
256  QStringList mFieldTypeList;
257 
258  QString mExpressionString;
259  QString mFieldName;
260 
261  QMenu *mDefineMenu = nullptr;
262  QAction *mActionDataTypes = nullptr;
263  QMenu *mFieldsMenu = nullptr;
264  QMenu *mVariablesMenu = nullptr;
265  QAction *mActionVariables = nullptr;
266 
267  QAction *mActionActive = nullptr;
268  QAction *mActionDescription = nullptr;
269  QAction *mActionExpDialog = nullptr;
270  QAction *mActionExpression = nullptr;
271  QAction *mActionPasteExpr = nullptr;
272  QAction *mActionCopyExpr = nullptr;
273  QAction *mActionClearExpr = nullptr;
274  QAction *mActionAssistant = nullptr;
275  QAction *mActionCreateAuxiliaryField = nullptr;
276 
277  QgsPropertyDefinition mDefinition;
278 
280  QString mDataTypesString;
281  QString mInputDescription;
282  QString mFullDescription;
283  QString mUsageInfo;
284 
285  QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
286 
287  enum SiblingType
288  {
289  SiblingCheckState,
290  SiblingEnableState,
291  SiblingVisibility,
292  SiblingExpressionText,
293  };
294  struct SiblingWidget
295  {
296  SiblingWidget( const QPointer<QWidget> &widgetPointer, SiblingType siblingType, bool natural = true )
297  : mWidgetPointer( widgetPointer )
298  , mSiblingType( siblingType )
299  , mNatural( natural )
300  {}
301  QPointer<QWidget> mWidgetPointer;
302  SiblingType mSiblingType;
303  bool mNatural;
304  };
305  QList< SiblingWidget > mSiblingWidgets;
306 
308  QgsProperty mProperty;
309 
310  bool mAuxiliaryStorageEnabled = false;
311 
312  std::shared_ptr< QgsSymbol > mSymbol;
313 
314  private slots:
315  void aboutToShowMenu();
316  void menuActionTriggered( QAction *action );
317  void showHelp();
318  void updateSiblingWidgets( bool state );
319 };
320 
321 
322 #endif // QGSPROPERTYOVERRIDEBUTTON_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
QString fullDescription() const
Returns the full definition description and current definition (internally generated on a contextual ...
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...
bool isActive() const
Returns true if the button has an active property.
void setUsageInfo(const QString &info)
Set the usage information for the property.
QgsPropertyDefinition::DataType validDataType() const
Returns the data type which the widget will accept.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
QString usageInfo() const
Returns usage information for the property.
A button for controlling property overrides which may apply to a widget.
#define SIP_SKIP
Definition: qgis_sip.h:119
Abstract base class for QgsPropertyCollection like objects.
A store for object properties.
Definition: qgsproperty.h:229
Definition for a property.
Definition: qgsproperty.h:46
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Abstract interface for generating an expression context.
DataType
Valid data types required by property.
Definition: qgsproperty.h:83
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the button.
Property requires a string value.
Definition: qgsproperty.h:91
Represents a vector layer which manages a vector based data sets.