@@ -93,6 +93,13 @@ class CORE_EXPORT QgsAbstractProperty
9393 */
9494 void setActive ( bool active ) { mActive = active; }
9595
96+ /* *
97+ * Prepares the property against a specified expression context. Calling prepare before evaluating the
98+ * property multiple times allows precalculation of expensive setup tasks such as parsing expressions.
99+ * Returns true if preparation was successful.
100+ */
101+ virtual bool prepare ( const QgsExpressionContext& context = QgsExpressionContext() ) const { Q_UNUSED ( context ); return true ; }
102+
96103 /* *
97104 * Returns the set of any fields referenced by the property.
98105 * @param context expression context the property will be evaluated against.
@@ -262,6 +269,13 @@ class CORE_EXPORT QgsFieldBasedProperty : public QgsAbstractProperty
262269 */
263270 QgsFieldBasedProperty ( const QString& field = QString(), bool isActive = false );
264271
272+ /* *
273+ * Copy constructor
274+ */
275+ QgsFieldBasedProperty ( const QgsFieldBasedProperty& other );
276+
277+ QgsFieldBasedProperty& operator =( const QgsFieldBasedProperty& other );
278+
265279 virtual Type propertyType () const override { return FieldBasedProperty; }
266280
267281 virtual QgsFieldBasedProperty* clone () override ;
@@ -279,6 +293,7 @@ class CORE_EXPORT QgsFieldBasedProperty : public QgsAbstractProperty
279293 */
280294 QString field () const { return mField ; }
281295
296+ bool prepare ( const QgsExpressionContext& context = QgsExpressionContext() ) const override ;
282297 virtual QSet< QString > referencedFields ( const QgsExpressionContext& context = QgsExpressionContext() ) const override ;
283298 bool writeXml ( QDomElement& propertyElem, QDomDocument& doc ) const override ;
284299 bool readXml ( const QDomElement& propertyElem, const QDomDocument& doc ) override ;
@@ -290,6 +305,7 @@ class CORE_EXPORT QgsFieldBasedProperty : public QgsAbstractProperty
290305 private:
291306
292307 QString mField ;
308+ mutable int mCachedFieldIdx = -1 ;
293309
294310};
295311
@@ -328,6 +344,7 @@ class CORE_EXPORT QgsExpressionBasedProperty : public QgsAbstractProperty
328344 */
329345 QString expressionString () const { return mExpressionString ; }
330346
347+ bool prepare ( const QgsExpressionContext& context = QgsExpressionContext() ) const override ;
331348 virtual QSet< QString > referencedFields ( const QgsExpressionContext& context = QgsExpressionContext() ) const override ;
332349 bool writeXml ( QDomElement& propertyElem, QDomDocument& doc ) const override ;
333350 bool readXml ( const QDomElement& propertyElem, const QDomDocument& doc ) override ;
@@ -339,13 +356,11 @@ class CORE_EXPORT QgsExpressionBasedProperty : public QgsAbstractProperty
339356 private:
340357
341358 QString mExpressionString ;
342- mutable bool mPrepared ;
359+ mutable bool mPrepared = false ;
343360 mutable QgsExpression mExpression ;
344361 // ! Cached set of referenced columns
345362 mutable QSet< QString > mReferencedCols ;
346363
347- bool prepare ( const QgsExpressionContext& context ) const ;
348-
349364};
350365
351366/* *
0 commit comments