@@ -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
0 commit comments