mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Allow setting a QgsFeedback object in QgsExpressionContext
This can be checked by expression functions which are costly to evaluate (e.g. those which fetch features from a layer) and which would benefit from early exits when the results of the expression evaluation are no longer needed (e.g. due to canceling a layer rendering, etc)
This commit is contained in:
parent
e416d77270
commit
8869c9cbe4
@ -783,6 +783,29 @@ Clears all cached values from the context.
|
||||
.. seealso:: :py:func:`cachedValue`
|
||||
|
||||
.. versionadded:: 2.16
|
||||
%End
|
||||
|
||||
void setFeedback( QgsFeedback *feedback );
|
||||
%Docstring
|
||||
Attach a ``feedback`` object that can be queried regularly by the expression engine to check
|
||||
if expression evaluation should be canceled.
|
||||
|
||||
Ownership of ``feedback`` is NOT transferred, and the caller must take care that it exists
|
||||
for the lifetime of the expression context.
|
||||
|
||||
.. seealso:: :py:func:`feedback`
|
||||
|
||||
.. versionadded:: 3.20
|
||||
%End
|
||||
|
||||
QgsFeedback *feedback() const;
|
||||
%Docstring
|
||||
Returns the feedback object that can be queried regularly by the expression to check
|
||||
if evaluation should be canceled, if set.
|
||||
|
||||
.. seealso:: :py:func:`setFeedback`
|
||||
|
||||
.. versionadded:: 3.20
|
||||
%End
|
||||
|
||||
static const QString EXPR_FIELDS;
|
||||
|
@ -592,3 +592,13 @@ void QgsExpressionContext::clearCachedValues() const
|
||||
{
|
||||
mCachedValues.clear();
|
||||
}
|
||||
|
||||
void QgsExpressionContext::setFeedback( QgsFeedback *feedback )
|
||||
{
|
||||
mFeedback = feedback;
|
||||
}
|
||||
|
||||
QgsFeedback *QgsExpressionContext::feedback() const
|
||||
{
|
||||
return mFeedback;
|
||||
}
|
||||
|
@ -715,6 +715,29 @@ class CORE_EXPORT QgsExpressionContext
|
||||
*/
|
||||
void clearCachedValues() const;
|
||||
|
||||
/**
|
||||
* Attach a \a feedback object that can be queried regularly by the expression engine to check
|
||||
* if expression evaluation should be canceled.
|
||||
*
|
||||
* Ownership of \a feedback is NOT transferred, and the caller must take care that it exists
|
||||
* for the lifetime of the expression context.
|
||||
*
|
||||
* \see feedback()
|
||||
*
|
||||
* \since QGIS 3.20
|
||||
*/
|
||||
void setFeedback( QgsFeedback *feedback );
|
||||
|
||||
/**
|
||||
* Returns the feedback object that can be queried regularly by the expression to check
|
||||
* if evaluation should be canceled, if set.
|
||||
*
|
||||
* \see setFeedback()
|
||||
*
|
||||
* \since QGIS 3.20
|
||||
*/
|
||||
QgsFeedback *feedback() const;
|
||||
|
||||
//! Inbuilt variable name for fields storage
|
||||
static const QString EXPR_FIELDS;
|
||||
//! Inbuilt variable name for value original value variable
|
||||
@ -748,6 +771,8 @@ class CORE_EXPORT QgsExpressionContext
|
||||
QStringList mHighlightedVariables;
|
||||
QStringList mHighlightedFunctions;
|
||||
|
||||
QgsFeedback *mFeedback = nullptr;
|
||||
|
||||
// Cache is mutable because we want to be able to add cached values to const contexts
|
||||
mutable QMap< QString, QVariant > mCachedValues;
|
||||
|
||||
|
@ -340,7 +340,7 @@ void QgsFeatureRequest::setFeedback( QgsFeedback *feedback )
|
||||
mFeedback = feedback;
|
||||
}
|
||||
|
||||
QgsFeedback *QgsFeatureRequest::feedback()
|
||||
QgsFeedback *QgsFeatureRequest::feedback() const
|
||||
{
|
||||
return mFeedback;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user