QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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"
19 
20 QgsEditorConfigWidget::QgsEditorConfigWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent )
21  : QWidget( parent )
22  , mLayer( vl )
23  , mField( fieldIdx )
24 
25 {
26 }
27 
29 {
30  return mField;
31 }
32 
34 {
35  return mLayer;
36 }
37 
39 {
41 }
42 
44 {
45  button->blockSignals( true );
47  connect( button, &QgsPropertyOverrideButton::changed, this, &QgsEditorConfigWidget::updateProperty );
48  button->registerExpressionContextGenerator( this );
49  button->blockSignals( false );
50 }
51 
53 {
54  const auto propertyOverrideButtons { findChildren< QgsPropertyOverrideButton * >() };
55  for ( QgsPropertyOverrideButton *button : propertyOverrideButtons )
56  {
57  updateDataDefinedButton( button );
58  }
59 }
60 
62 {
63  if ( !button )
64  return;
65 
66  if ( button->propertyKey() < 0 )
67  return;
68 
69  QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
70  whileBlocking( button )->setToProperty( mPropertyCollection.property( key ) );
71 }
72 
73 void QgsEditorConfigWidget::updateProperty()
74 {
75  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
76  QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
77  mPropertyCollection.setProperty( key, button->toProperty() );
78  emit changed();
79 }
80 
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
qgsexpressioncontextutils.h
QgsPropertyOverrideButton::changed
void changed()
Emitted when property definition changes.
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:306
QgsPropertyOverrideButton::propertyKey
int propertyKey() const
Returns the property key linked to the button.
Definition: qgspropertyoverridebutton.h:123
QgsEditorConfigWidget::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgseditorconfigwidget.cpp:38
QgsEditorConfigWidget::QgsEditorConfigWidget
QgsEditorConfigWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent)
Create a new configuration widget.
Definition: qgseditorconfigwidget.cpp:20
qgseditorconfigwidget.h
QgsPropertyCollection::property
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
Definition: qgspropertycollection.cpp:204
QgsPropertyOverrideButton
Definition: qgspropertyoverridebutton.h:50
QgsWidgetWrapper::Property
Property
Data defined properties for different editor widgets.
Definition: qgswidgetwrapper.h:76
QgsEditorConfigWidget::field
int field()
Returns the field for which this configuration widget applies.
Definition: qgseditorconfigwidget.cpp:28
QgsEditorConfigWidget::layer
QgsVectorLayer * layer()
Returns the layer for which this configuration widget applies.
Definition: qgseditorconfigwidget.cpp:33
whileBlocking
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:262
QgsEditorConfigWidget::initializeDataDefinedButton
void initializeDataDefinedButton(QgsPropertyOverrideButton *button, QgsWidgetWrapper::Property key)
Registers a property override button, setting up its initial value, connections and description.
Definition: qgseditorconfigwidget.cpp:43
QgsPropertyOverrideButton::toProperty
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
Definition: qgspropertyoverridebutton.cpp:210
QgsPropertyOverrideButton::init
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).
Definition: qgspropertyoverridebutton.cpp:96
QgsWidgetWrapper::propertyDefinitions
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the editor widget property definitions.
Definition: qgswidgetwrapper.cpp:22
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsPropertyOverrideButton::registerExpressionContextGenerator
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
Definition: qgspropertyoverridebutton.cpp:954
QgsEditorConfigWidget::mPropertyCollection
QgsPropertyCollection mPropertyCollection
Temporary property collection for config widgets.
Definition: qgseditorconfigwidget.h:110
QgsEditorConfigWidget::updateDataDefinedButton
void updateDataDefinedButton(QgsPropertyOverrideButton *button)
Updates a specific property override button to reflect the widgets's current properties.
Definition: qgseditorconfigwidget.cpp:61
QgsEditorConfigWidget::changed
void changed()
Emitted when the configuration of the widget is changed.
QgsPropertyCollection::setProperty
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Definition: qgspropertycollection.cpp:177
QgsEditorConfigWidget::updateDataDefinedButtons
void updateDataDefinedButtons()
Updates all property override buttons to reflect the widgets's current properties.
Definition: qgseditorconfigwidget.cpp:52
qgspropertyoverridebutton.h