This object allows you to evaluate an ArcadeExpression under a given ArcadeProfile. More...
Header: | #include <ArcadeEvaluator> |
Since: | Esri::ArcGISRuntime 100.14 |
Inherits: | Esri::ArcGISRuntime::Object and Esri::ArcGISRuntime::Loadable |
This class was introduced in Esri::ArcGISRuntime 100.14.
Public Functions
ArcadeEvaluator(Esri::ArcGISRuntime::ArcadeExpression *expression, Esri::ArcGISRuntime::ArcadeProfile profile, QObject *parent = nullptr) | |
virtual | ~ArcadeEvaluator() override |
Esri::ArcGISRuntime::TaskWatcher | attributes(const QString &variableName, Esri::ArcGISRuntime::FeatureTable *attributeNameSource) |
Esri::ArcGISRuntime::TaskWatcher | attributes(const QString &variableName, Esri::ArcGISRuntime::GeoElement *attributeNameSource) |
Esri::ArcGISRuntime::TaskWatcher | evaluate(const QVariantMap &profileVariables) |
Esri::ArcGISRuntime::ArcadeExpression * | expression() const |
bool | isStable() const |
Esri::ArcGISRuntime::ArcadeProfile | profile() const |
QStringList | profileVariablesUsed() const |
Reimplemented Public Functions
virtual void | cancelLoad() override |
virtual void | load() override |
virtual Esri::ArcGISRuntime::Error | loadError() const override |
virtual Esri::ArcGISRuntime::LoadStatus | loadStatus() const override |
virtual void | retryLoad() override |
Signals
void | attributesCompleted(QUuid taskId, const QStringList &stringResult) |
void | doneLoading(Esri::ArcGISRuntime::Error loadError) |
void | evaluateCompleted(QUuid taskId, Esri::ArcGISRuntime::ArcadeEvaluationResult *arcadeEvaluationResult) |
void | loadStatusChanged(Esri::ArcGISRuntime::LoadStatus loadStatus) |
Detailed Description
This Object allows you to set up, execute, and query information about an Arcade script. For more general information on Arcade and its usages, see the Arcade online documentation.
To construct the ArcadeEvaluator object you need to supply an ArcadeExpression along with an ArcadeProfile. ArcadeExpression is an object that contains the Arcade script plus some additional metadata while ArcadeProfile specifies availability of profile variables and limits what functions are available.
The basic workflow is:
- Construct an ArcadeEvaluator object using ArcadeExpression and ArcadeProfile.
- Query information about a script.
- Insert the required profile values into a dictionary.
- Call evaluate.
- Use the returned ArcadeEvaluationResult.
From an ArcadeEvaluator object you can query information to determine
- Which profile variables are accessed by the script.
- Which attributes are used by a particular profile variable.
- Whether the script is considered stable.
Not all scripts use all the profiles variables. profileVariablesUsed returns an array of the names of the profile variables used in the current script. Possible uses include:
- Informing dependency analysis to determine which scripts need to run when a value of a profile variable changes.
- Minimizing expensive calculation of unneeded profile variables.
attributes(QString, FeatureTable) lets you dig deeper to determine which attributes are required on a specific profile variable. If you are querying a subset of attributes when querying a feature, use this information to ensure the profile variable will have the attributes it requires.
isStable property indicates if the given script will return the same value for an identical set of profile variables. For this to be true
a script must avoid using unstable built-in functions such as now() or random().
isStable can be combined with the knowledge of the used profile variables to construct caches of results. This lets you avoid running scripts when repeated calls with the same profiles variables will not alter the evaluation result.
Member Function Documentation
ArcadeEvaluator::ArcadeEvaluator (Esri::ArcGISRuntime::ArcadeExpression *expression, Esri::ArcGISRuntime::ArcadeProfile profile, QObject *parent = nullptr)
Creates an ArcadeEvaluator object
- expression - Arcade expression you want to evaluate
- profile - The ArcadeProfile context the expression should be evaluated under
- parent - The optional parent QObject
[signal]
void ArcadeEvaluator::attributesCompleted (QUuid taskId , const QStringList &stringResult )
Signal emitted when either the attributes(QString, FeatureTable), or attributes(QString, GeoElement) operations complete.
- taskId - The task ID of the asynchronous operation
- stringResult - The result of the asynchronous operation
[signal]
void ArcadeEvaluator::doneLoading (Esri::ArcGISRuntime::Error loadError )
Signal emitted when this object is done loading.
- loadError - Details about any error that may have occurred
Note: If there is a load error, it will also be emitted on the errorOccurred
signal.
[signal]
void ArcadeEvaluator::evaluateCompleted (QUuid taskId , Esri::ArcGISRuntime::ArcadeEvaluationResult *arcadeEvaluationResult )
Signal emitted when the evaluate operation completes.
- taskId - The task ID of the asynchronous operation.
- arcadeEvaluationResult - the result of the asynchronous operation.
See also Returned QObjects Parenting.
[signal]
void ArcadeEvaluator::loadStatusChanged (Esri::ArcGISRuntime::LoadStatus loadStatus )
Signal emitted when the load status changes for this object.
- loadStatus - The LoadStatus
See also Loadable.
[override virtual]
ArcadeEvaluator::~ArcadeEvaluator ()
Destructor.
Esri::ArcGISRuntime::TaskWatcher ArcadeEvaluator::attributes(const QString &variableName , Esri::ArcGISRuntime::FeatureTable *attributeNameSource )
For a given profile variable, asynchronously gets a list of attributes used in the script.
- variableName - The name of the profile variable whose used attributes are returned.
- attributeNameSource - A FeatureTable from which we can get a list of all attribute names for the profile variable of interest.
To fully support the wildcard expansion in the expects statement, calculation of used attributes on a profile variable requires an object that can supply a full set of attribute names.
This method returns a TaskWatcher for the asynchronous operation.
Esri::ArcGISRuntime::TaskWatcher ArcadeEvaluator::attributes(const QString &variableName , Esri::ArcGISRuntime::GeoElement *attributeNameSource )
For a given profile variable, asynchronously gets a list of attributes used in the script.
- variableName - The name of the profile variable whose used attributes are required.
- attributeNameSource - A GeoElement from which we can get a list of all attributes names for the profile variable of interest.
To fully support the wildcard expansion in the expects statement, calculation of used attributes on a profile variable requires an object that can supply a full set of attribute names.
This method returns a TaskWatcher for the asynchronous operation.
[override virtual]
void ArcadeEvaluator::cancelLoad ()
Reimplements: Loadable::cancelLoad().
Cancels loading metadata for the object.
Cancels loading the metadata if the object is loading and calls doneLoading.
Esri::ArcGISRuntime::TaskWatcher ArcadeEvaluator::evaluate(const QVariantMap &profileVariables )
Asynchronously evaluates the script using the supplied profileVariables.
- profileVariables - The profile variables for the script as key/value pairs. Required for evaluation.
Each entry of the profileVariables map is placed into the interpreter as a value accessible throughout the script. The name and type of these should comply with the profile the Arcade evaluator has been constructed with. Values are not persisted across evaluations, meaning all required profile variables must be supplied with each evaluation.
Each value of a key/value pair in the map is converted to a type understood by the interpreter. The result is then placed into the interpreter as a profile variable using the key as its name.
Values in the map can be any of the following types:
- QString
- Integers and floating points of various sizes. Arcade uses doubles for all internal calculations.
- Boolean.
- QDateTime
- Geometry
- GeoElement (or anything derived from it such as Feature, EncFeature)
- FeatureTable, see FeatureTableType
- Geodatabase
- GeoModel (or anything derived from it such as Map or Scene)
- ServiceGeodatabase
- Location
- QVariantMap. The keys of the map will always be strings and the values could be of any type in this list. This can be recursive.
The following list describes how ArcGIS Runtime types are converted to Arcade types.
- GeoElement types are converted to an Arcade Feature type.
- Location is converted to an Arcade Feature type.
- FeatureTable types are converted to an Arcade FeatureSet type.
- Geodatabase is converted to an Arcade FeatureSetCollection type.
- ServiceGeodatabase is converted to an Arcade FeatureSetCollection type.
- GeoModel is converted to an Arcade FeatureSetCollection type.
This method returns a TaskWatcher for the asynchronous operation.
Esri::ArcGISRuntime::ArcadeExpression *ArcadeEvaluator::expression() const
Returns the Arcade expression of the Arcade evaluator.
bool ArcadeEvaluator::isStable () const
Returns whether a script is considered stable.
A script is considered stable if the script will return the same result given the same inputs. There are certain functions listed below that will return different values on each evaluation. Using these functions means the script is not considered stable.
Arcade functions that stop a script from being considered stable:
- Now
- Today
- TimeStamp
- Tandom
- Guid
- NextSequence
[override virtual]
void ArcadeEvaluator::load()
Reimplements: Loadable::load().
Loads the metadata for the object asynchronously.
Loads the metadata if the object is not loaded and calls doneLoading.
[override virtual]
Esri::ArcGISRuntime::Error ArcadeEvaluator::loadError () const
Reimplements: Loadable::loadError() const.
Returns the load error.
See also Error.
[override virtual]
Esri::ArcGISRuntime::LoadStatus ArcadeEvaluator::loadStatus () const
Reimplements: Loadable::loadStatus() const.
Returns the load status.
See also LoadStatus.
Esri::ArcGISRuntime::ArcadeProfile ArcadeEvaluator::profile() const
Returns the Arcade profile under which the script should evaluate.
QStringList ArcadeEvaluator::profileVariablesUsed () const
Returns a string list of the names of all profile variable used in the script.
A collection of names of the profile variables used in the script. Each variable name should have a dictionary of profile values passed to the evaluate function.
[override virtual]
void ArcadeEvaluator::retryLoad ()
Reimplements: Loadable::retryLoad().
Loads or retries loading metadata for the object asynchronously.
Retries loading the metadata if the object fails to load. Loads the object if it is not loaded. Will not retry to load the object if the object is loaded. Calls done loading.