Data series mapper using QtScript to return a mapped value for each value in the series.
#include <DataAnalysis/DataStructures/scripteddataseriesmapper.h>
◆ ScriptedDataSeriesMapper() [1/2]
◆ ScriptedDataSeriesMapper() [2/2]
◆ ~ScriptedDataSeriesMapper()
◆ clone()
- Returns
- A clone of this object.
- Note
- Subclasses would normally return their own type rather than the Clonable type. The C++ language rules allow a more derived type to be returned from a virtual function and the compiler will still treat it as a valid override.
Implements DataSeriesMapper.
◆ createMementoData()
- Parameters
-
dataSeries | The model that will be used for mapping nodes to values. |
- Returns
- A memento object which client code cannot do anything useful with except pass it around. The memento is ultimately only useful to the getValue() function. It holds internal data the mapper will use to perform the required mapping.
Implements DataSeriesMapper.
◆ getFunctionName()
const QString & getFunctionName |
( |
| ) |
const |
- Returns
- The name of the function that will be called to map each item of the data series to a new value.
The default function name is an empty string, however the convention is to use mapToValue
as the function name. The default is empty because it allows the script contents to be as trivial as possible. See setFunctionName() for more details on this issue.
- See also
- setFunctionName()
◆ getGlobals()
const QVector< QVariant > & getGlobals |
( |
| ) |
const |
- Returns
- The array of global values provided to the scripting engine.
- See also
- setGlobals()
◆ getScript()
const QString & getScript |
( |
| ) |
const |
- Returns
- The script being used by the mapper.
- See also
- setScript()
◆ getValue()
- Parameters
-
index | The index of the item being mapped. |
srcValue | The value of the source data series at the specified index. |
destValue | The mapped value should be assigned to this before returning. |
mementoData | Must be the same object supplied by a previous call to createMementoData(). |
- Returns
- True if the srcValue could be mapped. If there was some kind of error, false should be returned and the caller should not attempt to continue mapping values.
Implements DataSeriesMapper.
◆ operator=()
◆ setFunctionName()
void setFunctionName |
( |
const QString & |
functionName | ) |
|
- Parameters
-
functionName | The name of the function to call to map each item of the data series to a new value. |
The functionName should refer to a valid function defined in the script provided to the mapper. If it does not, an error will occur and the mapper will fail (and therefore return 0 for all values). The one exception to this is if functionName is empty. In this case, the contents of the script are assumed to be just the body of a function and the mapper should wrap it in its own function. This is not as clear, since the script still needs to have return statements but the script itself won't show what is being returned from. Still, some users may find this "feature" useful if their script contents are more or less trivial. In this case, the script will be provided with function parameters named index
and srcValue
which can be treated like local variables.
- See also
- getFunctionName()
◆ setGlobals()
void setGlobals |
( |
const QVector< QVariant > & |
globals | ) |
|
- Parameters
-
globals | An array of values to be stored in the script engine under the array name args . Elements of this array can be accessed in the usual way (eg args [2]) from any point in the script. |
- See also
- getGlobals()
◆ setScript()
void setScript |
( |
const QString & |
script | ) |
|
- Parameters
-
script | The script to use for the mapper. |
- See also
- getScript()