Skip to content

Commit ad23240

Browse files
committed
Port symbology and composer to properties framework
1 parent 43bbf68 commit ad23240

165 files changed

Lines changed: 2262 additions & 2927 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎python/core/composer/qgscomposerobject.sip‎

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,24 @@ class QgsComposerObject : QObject, QgsExpressionContextGenerator
8484
*/
8585
virtual bool readXml( const QDomElement& itemElem, const QDomDocument& doc );
8686

87-
/** Returns a reference to the data defined settings for one of the item's data defined properties.
88-
* @param property data defined property to return
89-
* @note this method was added in version 2.5
87+
/** Returns a reference to the object's property collection, used for data defined overrides.
88+
* @note added in QGIS 3.0
89+
* @see setDataDefinedProperties()
9090
*/
91-
QgsDataDefined* dataDefinedProperty( const DataDefinedProperty property ) const;
91+
QgsPropertyCollection& dataDefinedProperties();
9292

93-
/** Sets parameters for a data defined property for the item
94-
* @param property data defined property to set
95-
* @param active true if data defined property is active, false if it is disabled
96-
* @param useExpression true if the expression should be used
97-
* @param expression expression for data defined property
98-
* @param field field name if the data defined property should take its value from a field
99-
* @note this method was added in version 2.5
93+
/** Returns a reference to the object's property collection, used for data defined overrides.
94+
* @note added in QGIS 3.0
95+
* @see setDataDefinedProperties()
96+
*/
97+
//const QgsPropertyCollection& dataDefinedProperties() const;
98+
99+
/** Sets the objects's property collection, used for data defined overrides.
100+
* @param collection property collection. Existing properties will be replaced.
101+
* @note added in QGIS 3.0
102+
* @see dataDefinedProperties()
100103
*/
101-
void setDataDefinedProperty( const DataDefinedProperty property, const bool active, const bool useExpression, const QString &expression, const QString &field );
104+
void setDataDefinedProperties( const QgsPropertyCollection& collection );
102105

103106
/** Set a custom property for the object.
104107
* @param key property key. If a property with the same key already exists it will be overwritten.
@@ -159,18 +162,6 @@ class QgsComposerObject : QObject, QgsExpressionContextGenerator
159162
*/
160163
virtual void refreshDataDefinedProperty( const DataDefinedProperty property = AllProperties, const QgsExpressionContext* context = 0 );
161164

162-
protected:
163-
164-
/** Evaluate a data defined property and return the calculated value
165-
* @returns true if data defined property could be successfully evaluated
166-
* @param property data defined property to evaluate
167-
* @param expressionValue QVariant for storing the evaluated value
168-
* @param context expression context for evaluating expressions. Must have feature and fields set to current
169-
* atlas feature and coverage layer fields prior to calling this method.
170-
* @note this method was added in version 2.5
171-
*/
172-
bool dataDefinedEvaluate( const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue, const QgsExpressionContext& context = QgsExpressionContext() ) const;
173-
174165
signals:
175166
/** Emitted when the item changes. Signifies that the item widgets must update the
176167
* gui elements.

‎python/core/composer/qgscomposerutils.sip‎

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -102,40 +102,19 @@ class QgsComposerUtils
102102
*/
103103
static bool decodePresetPaperSize( const QString& presetString, double &width, double &height );
104104

105-
/** Reads all data defined properties from xml
106-
* @param itemElem dom element containing data defined properties
107-
* @param dataDefinedNames map of data defined property to name used within xml
108-
* @param dataDefinedProperties map of data defined properties to QgsDataDefined in which to store properties from xml
109-
* @note this method was added in version 2.5
105+
/** Reads all pre 3.0 data defined properties from an XML element.
106+
* @note this method was added in version 3.0
110107
* @see readDataDefinedProperty
111108
* @see writeDataDefinedPropertyMap
112109
*/
113-
static void readDataDefinedPropertyMap( const QDomElement &itemElem,
114-
QMap< QgsComposerObject::DataDefinedProperty, QString >* dataDefinedNames,
115-
QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties
116-
);
110+
static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
111+
QgsPropertyCollection& dataDefinedProperties );
117112

118-
/** Reads a single data defined property from xml DOM element
119-
* @param property data defined property to read
120-
* @param ddElem dom element containing settings for data defined property
121-
* @param dataDefinedProperties map of data defined properties to QgsDataDefined in which to store properties from xml
122-
* @note this method was added in version 2.5
113+
/** Reads a pre 3.0 data defined property from an XML DOM element.
114+
* @note this method was added in version 3.0
123115
* @see readDataDefinedPropertyMap
124116
*/
125-
static void readDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem,
126-
QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties );
127-
128-
/** Writes data defined properties to xml
129-
* @param itemElem DOM element in which to store data defined properties
130-
* @param doc DOM document
131-
* @param dataDefinedNames map of data defined property to name used within xml
132-
* @param dataDefinedProperties map of data defined properties to QgsDataDefined for storing in xml
133-
* @note this method was added in version 2.5
134-
* @see readDataDefinedPropertyMap
135-
*/
136-
static void writeDataDefinedPropertyMap( QDomElement &itemElem, QDomDocument &doc,
137-
const QMap< QgsComposerObject::DataDefinedProperty, QString >* dataDefinedNames,
138-
const QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties );
117+
static QgsAbstractProperty* readOldDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem ) /Factory/;
139118

140119
/** Returns a font where size is set in pixels and the size has been upscaled with FONT_WORKAROUND_SCALE
141120
* to workaround QT font rendering bugs

‎python/core/composer/qgscomposition.sip‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -660,22 +660,6 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
660660
*/
661661
QList< QgsPaperItem* > pages();
662662

663-
/** Returns a reference to the data defined settings for one of the composition's data defined properties.
664-
* @param property data defined property to return
665-
* @note this method was added in version 2.5
666-
*/
667-
QgsDataDefined* dataDefinedProperty( const QgsComposerObject::DataDefinedProperty property );
668-
669-
/** Sets parameters for a data defined property for the composition
670-
* @param property data defined property to set
671-
* @param active true if data defined property is active, false if it is disabled
672-
* @param useExpression true if the expression should be used
673-
* @param expression expression for data defined property
674-
* @param field field name if the data defined property should take its value from a field
675-
* @note this method was added in version 2.5
676-
*/
677-
void setDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, bool active, bool useExpression, const QString &expression, const QString &field );
678-
679663
/** Returns the items model attached to the composition
680664
* @returns QgsComposerModel for composition
681665
* @note this method was added in version 2.5
@@ -775,6 +759,25 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
775759
*/
776760
QgsExpressionContext createExpressionContext() const;
777761

762+
/** Returns a reference to the composition's property collection, used for data defined overrides.
763+
* @note added in QGIS 3.0
764+
* @see setDataDefinedProperties()
765+
*/
766+
QgsPropertyCollection& dataDefinedProperties();
767+
768+
/** Returns a reference to the composition's property collection, used for data defined overrides.
769+
* @note added in QGIS 3.0
770+
* @see setDataDefinedProperties()
771+
*/
772+
//const QgsPropertyCollection& dataDefinedProperties() const;
773+
774+
/** Sets the composition's property collection, used for data defined overrides.
775+
* @param collection property collection. Existing properties will be replaced.
776+
* @note added in QGIS 3.0
777+
* @see dataDefinedProperties()
778+
*/
779+
void setDataDefinedProperties( const QgsPropertyCollection& collection );
780+
778781
protected:
779782
void init();
780783

‎python/core/qgsproperty.sip‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class QgsAbstractProperty
5656

5757
/** Returns a clone of the property.
5858
*/
59-
virtual QgsAbstractProperty* clone() = 0 /Factory/;
59+
virtual QgsAbstractProperty* clone() const = 0 /Factory/;
6060

6161
/** Returns whether the property is currently active.
6262
* @see setActive()
@@ -69,6 +69,12 @@ class QgsAbstractProperty
6969
*/
7070
void setActive( bool active );
7171

72+
/**
73+
* Returns an expression string representing the state of the property, or an empty
74+
* string if the property could not be converted to an expression
75+
*/
76+
virtual QString asExpression() const = 0;
77+
7278
/**
7379
* Prepares the property against a specified expression context. Calling prepare before evaluating the
7480
* property multiple times allows precalculation of expensive setup tasks such as parsing expressions.
@@ -93,6 +99,18 @@ class QgsAbstractProperty
9399
*/
94100
QVariant value( const QgsExpressionContext& context, const QVariant& defaultValue = QVariant() ) const;
95101

102+
/**
103+
* Calculates the current value of the property and interprets it as a string.
104+
* @param context QgsExpressionContext to evaluate the property for.
105+
* @param defaultString default string to return if the property cannot be calculated as a string
106+
* @param ok if specified, will be set to true if conversion was successful
107+
* @returns value parsed to string
108+
* @see value()
109+
* @see valueAsDouble()
110+
* @see valueAsInt()
111+
*/
112+
QString valueAsString( const QgsExpressionContext& context, const QString& defaultString = QString(), bool* ok /Out/ = nullptr ) const;
113+
96114
/** Calculates the current value of the property and interprets it as a color.
97115
* @param context QgsExpressionContext to evaluate the property for.
98116
* @param defaultColor default color to return if the property cannot be calculated as a color
@@ -101,7 +119,7 @@ class QgsAbstractProperty
101119
* @see valueAsDouble()
102120
* @see valueAsInt()
103121
*/
104-
QColor valueAsColor( const QgsExpressionContext& context, const QColor& defaultColor = QColor() ) const;
122+
QColor valueAsColor( const QgsExpressionContext& context, const QColor& defaultColor = QColor(), bool* ok /Out/ = nullptr ) const;
105123

106124
/** Calculates the current value of the property and interprets it as a double.
107125
* @param context QgsExpressionContext to evaluate the property for.
@@ -111,7 +129,7 @@ class QgsAbstractProperty
111129
* @see valueAsInt()
112130
* @see valueAsColor()
113131
*/
114-
double valueAsDouble( const QgsExpressionContext& context, double defaultValue = 0.0 ) const;
132+
double valueAsDouble( const QgsExpressionContext& context, double defaultValue = 0.0, bool* ok /Out/ = nullptr ) const;
115133

116134
/** Calculates the current value of the property and interprets it as an integer.
117135
* @param context QgsExpressionContext to evaluate the property for.
@@ -121,7 +139,7 @@ class QgsAbstractProperty
121139
* @see valueAsDouble()
122140
* @see valueAsColor()
123141
*/
124-
int valueAsInt( const QgsExpressionContext& context, int defaultValue = 0 ) const;
142+
int valueAsInt( const QgsExpressionContext& context, int defaultValue = 0, bool* ok /Out/ = nullptr ) const;
125143

126144
/**
127145
* Calculates the current value of the property and interprets it as an boolean.
@@ -132,7 +150,7 @@ class QgsAbstractProperty
132150
* @see valueAsDouble()
133151
* @see valueAsColor()
134152
*/
135-
bool valueAsBool( const QgsExpressionContext& context, bool defaultValue = false ) const;
153+
bool valueAsBool( const QgsExpressionContext& context, bool defaultValue = false, bool* ok /Out/ = nullptr ) const;
136154

137155
/** Writes the current state of the property into an XML element
138156
* @param propertyElem destination element for the property's state
@@ -197,7 +215,8 @@ class QgsStaticProperty : QgsAbstractProperty
197215

198216
virtual Type propertyType() const;
199217

200-
virtual QgsStaticProperty* clone() /Factory/;
218+
virtual QgsStaticProperty* clone() const /Factory/;
219+
virtual QString asExpression() const;
201220

202221
/** Sets the static value for the property.
203222
* @param value property value
@@ -238,11 +257,12 @@ class QgsFieldBasedProperty : QgsAbstractProperty
238257
* @param field field name
239258
* @param isActive whether the property is intially active
240259
*/
241-
QgsFieldBasedProperty( const QString& field = QString(), bool isActive = false );
260+
QgsFieldBasedProperty( const QString& field = QString(), bool isActive = true );
242261

243262
virtual Type propertyType() const;
244263

245-
virtual QgsFieldBasedProperty* clone() /Factory/;
264+
virtual QgsFieldBasedProperty* clone() const /Factory/;
265+
virtual QString asExpression() const;
246266

247267
/** Sets the field name the property references.
248268
* @param field field name
@@ -285,11 +305,12 @@ class QgsExpressionBasedProperty : QgsAbstractProperty
285305
* @param expression expression string
286306
* @param isActive whether the property is intially active
287307
*/
288-
QgsExpressionBasedProperty( const QString& expression = QString(), bool isActive = false );
308+
QgsExpressionBasedProperty( const QString& expression = QString(), bool isActive = true );
289309

290310
virtual Type propertyType() const;
291311

292-
virtual QgsExpressionBasedProperty* clone() /Factory/;
312+
virtual QgsExpressionBasedProperty* clone() const /Factory/;
313+
virtual QString asExpression() const;
293314

294315
/** Sets the expression to use for the property value.
295316
* @param expression expression string

‎python/core/qgspropertycollection.sip‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ class QgsAbstractPropertyCollection
8888
*/
8989
virtual QVariant value( int key, const QgsExpressionContext& context, const QVariant& defaultValue = QVariant() ) const = 0;
9090

91+
/**
92+
* Calculates the current value of the property with the specified key and interprets it as a string.
93+
* @param key integer key for property to return. The intended use case is that a context specific enum is cast to
94+
* int and used for the key value.
95+
* @param context QgsExpressionContext to evaluate the property for.
96+
* @param defaultValue default string to return if the property cannot be calculated as a string
97+
* @param ok if specified, will be set to true if conversion was successful
98+
* @returns value parsed to string
99+
* @see value()
100+
* @see valueAsInteger()
101+
* @see valueAsColor()
102+
*/
103+
QString valueAsString( int key, const QgsExpressionContext& context, const QString& defaultString = QString(), bool* ok /Out/ = nullptr ) const;
104+
91105

92106
/**
93107
* Calculates the current value of the property with the specified key and interprets it as a color.
@@ -100,7 +114,7 @@ class QgsAbstractPropertyCollection
100114
* @see valueAsDouble()
101115
* @see valueAsInteger()
102116
*/
103-
QColor valueAsColor( int key, const QgsExpressionContext& context, const QColor& defaultColor = QColor() ) const;
117+
QColor valueAsColor( int key, const QgsExpressionContext& context, const QColor& defaultColor = QColor(), bool* ok /Out/ = nullptr ) const;
104118

105119
/**
106120
* Calculates the current value of the property with the specified key and interprets it as a double.
@@ -113,7 +127,7 @@ class QgsAbstractPropertyCollection
113127
* @see valueAsInteger()
114128
* @see valueAsColor()
115129
*/
116-
double valueAsDouble( int key, const QgsExpressionContext& context, double defaultValue = 0.0 ) const;
130+
double valueAsDouble( int key, const QgsExpressionContext& context, double defaultValue = 0.0, bool* ok /Out/ = nullptr ) const;
117131

118132
/**
119133
* Calculates the current value of the property with the specified key and interprets it as an integer.
@@ -126,7 +140,7 @@ class QgsAbstractPropertyCollection
126140
* @see valueAsDouble()
127141
* @see valueAsColor()
128142
*/
129-
int valueAsInt( int key, const QgsExpressionContext& context, int defaultValue = 0 ) const;
143+
int valueAsInt( int key, const QgsExpressionContext& context, int defaultValue = 0, bool* ok /Out/ = nullptr ) const;
130144

131145
/**
132146
* Calculates the current value of the property with the specified key and interprets it as an boolean.
@@ -139,7 +153,7 @@ class QgsAbstractPropertyCollection
139153
* @see valueAsDouble()
140154
* @see valueAsColor()
141155
*/
142-
bool valueAsBool( int key, const QgsExpressionContext& context, bool defaultValue = false ) const;
156+
bool valueAsBool( int key, const QgsExpressionContext& context, bool defaultValue = false, bool* ok /Out/ = nullptr ) const;
143157

144158

145159
/**
@@ -164,14 +178,14 @@ class QgsAbstractPropertyCollection
164178

165179
/**
166180
* Returns true if the collection has any active properties, or false if all properties
167-
* within the collection are deactived.
181+
* within the collection are deactivated.
168182
* @see hasActiveDynamicProperties()
169183
*/
170184
virtual bool hasActiveProperties() const = 0;
171185

172186
/**
173187
* Returns true if the collection has any active, non-static properties, or false if either all non-static properties
174-
* within the collection are deactived or if the collection only contains static properties.
188+
* within the collection are deactivated or if the collection only contains static properties.
175189
* @see hasActiveProperties()
176190
*/
177191
virtual bool hasActiveDynamicProperties() const = 0;
@@ -323,14 +337,14 @@ class QgsPropertyCollectionStack : QgsAbstractPropertyCollection
323337
QgsPropertyCollection* collection( const QString& name );
324338

325339
/** Returns true if the collection has any active properties, or false if all properties
326-
* within the collection are deactived.
340+
* within the collection are deactivated.
327341
* @see hasActiveProperty()
328342
* @see hasActiveDynamicProperties()
329343
*/
330344
bool hasActiveProperties() const;
331345

332346
/** Returns true if the collection has any active, non-static properties, or false if either all non-static properties
333-
* within the collection are deactived or if the collection only contains static properties.
347+
* within the collection are deactivated or if the collection only contains static properties.
334348
* @see hasActiveProperties()
335349
*/
336350
bool hasActiveDynamicProperties() const;

‎python/core/symbology-ng/qgs25drenderer.sip‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Qgs25DRenderer : QgsFeatureRenderer
3333
void startRender( QgsRenderContext& context, const QgsFields& fields );
3434
void stopRender( QgsRenderContext& context );
3535

36-
QSet<QString> usedAttributes() const;
36+
QSet<QString> usedAttributes( const QgsRenderContext& context ) const;
3737
QgsFeatureRenderer* clone() const;
3838

3939
virtual QgsSymbol* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );

‎python/core/symbology-ng/qgsarrowsymbollayer.sip‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QgsArrowSymbolLayer : public QgsLineSymbolLayer
3232
virtual bool setSubSymbol( QgsSymbol* symbol /Transfer/ );
3333

3434
/** Return a list of attributes required to render this feature */
35-
virtual QSet<QString> usedAttributes() const;
35+
virtual QSet<QString> usedAttributes( const QgsRenderContext& context ) const;
3636

3737
/** Get current arrow width */
3838
double arrowWidth() const;

‎python/core/symbology-ng/qgscategorizedsymbolrenderer.sip‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer
5959

6060
virtual void stopRender( QgsRenderContext& context );
6161

62-
virtual QSet<QString> usedAttributes() const;
62+
virtual QSet<QString> usedAttributes( const QgsRenderContext& context ) const;
6363

6464
virtual QString dump() const;
6565

0 commit comments

Comments
 (0)