QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgseditorconfigwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgseditorconfigwidget.cpp
3  --------------------------------------
4  Date : 24.4.2013
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias at opengis dot ch
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 
16 #include "qgseditorconfigwidget.h"
18 
19 QgsEditorConfigWidget::QgsEditorConfigWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent )
20  : QWidget( parent )
21  , mLayer( vl )
22  , mField( fieldIdx )
23 
24 {
25 }
26 
28 {
29  return mField;
30 }
31 
33 {
34  return mLayer;
35 }
36 
38 {
40 }
41 
43 {
44  button->blockSignals( true );
46  connect( button, &QgsPropertyOverrideButton::changed, this, &QgsEditorConfigWidget::updateProperty );
47  button->registerExpressionContextGenerator( this );
48  button->blockSignals( false );
49 }
50 
52 {
53  Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
54  {
55  updateDataDefinedButton( button );
56  }
57 }
58 
60 {
61  if ( !button )
62  return;
63 
64  if ( button->propertyKey() < 0 )
65  return;
66 
67  QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
68  whileBlocking( button )->setToProperty( mPropertyCollection.property( key ) );
69 }
70 
71 void QgsEditorConfigWidget::updateProperty()
72 {
73  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
74  QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
75  mPropertyCollection.setProperty( key, button->toProperty() );
76  emit changed();
77 }
78 
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the editor widget property definitions.
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
int field()
Returns the field for which this configuration widget applies.
int propertyKey() const
Returns the property key linked to the button.
QgsPropertyCollection mPropertyCollection
Temporary property collection for config widgets.
QgsEditorConfigWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent)
Create a new configuration widget.
A button for controlling property overrides which may apply to a widget.
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void updateDataDefinedButtons()
Updates all property override buttons to reflect the widgets&#39;s current properties.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer&#39;s project and layer.
void changed()
Emitted when the configuration of the widget is changed.
void changed()
Emitted when property definition changes.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:225
void updateDataDefinedButton(QgsPropertyOverrideButton *button)
Updates a specific property override button to reflect the widgets&#39;s current properties.
Property
Data defined properties for different editor widgets.
void initializeDataDefinedButton(QgsPropertyOverrideButton *button, QgsWidgetWrapper::Property key)
Registers a property override button, setting up its initial value, connections and description...
Represents a vector layer which manages a vector based data sets.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
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)...
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.