QGIS API Documentation  3.6.0-Noosa (5873452)
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  Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
55  {
56  updateDataDefinedButton( button );
57  }
58 }
59 
61 {
62  if ( !button )
63  return;
64 
65  if ( button->propertyKey() < 0 )
66  return;
67 
68  QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
69  whileBlocking( button )->setToProperty( mPropertyCollection.property( key ) );
70 }
71 
72 void QgsEditorConfigWidget::updateProperty()
73 {
74  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
75  QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
76  mPropertyCollection.setProperty( key, button->toProperty() );
77  emit changed();
78 }
79 
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.
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.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the 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.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:212
int propertyKey() const
Returns the property key linked to the button.
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.