Workspace 6.21.5
Public Member Functions | List of all members
ScriptedDataSeriesMapper Class Reference

Data series mapper using QtScript to return a mapped value for each value in the series.

#include <DataAnalysis/DataStructures/scripteddataseriesmapper.h>

Inheritance diagram for ScriptedDataSeriesMapper:
[legend]

Public Member Functions

 ScriptedDataSeriesMapper ()
 
 ScriptedDataSeriesMapper (const ScriptedDataSeriesMapper &mapper)
 
 ~ScriptedDataSeriesMapper () override
 
ScriptedDataSeriesMapperclone () const override
 
Application::Memento::DatacreateMementoData (const DataSeries &dataSeries) const override
 
const QString & getFunctionName () const
 
const QVector< QVariant > & getGlobals () const
 
const QString & getScript () const
 
bool getValue (int index, double srcValue, double &destValue, Application::Memento::Data &mementoData) const override
 
ScriptedDataSeriesMapperoperator= (const ScriptedDataSeriesMapper &mapper)
 
void setFunctionName (const QString &functionName)
 
void setGlobals (const QVector< QVariant > &globals)
 
void setScript (const QString &script)
 
- Public Member Functions inherited from DataSeriesMapper
DataSeriesMapperclone () const override=0
 
virtual Application::Memento::DatacreateMementoData (const DataSeries &dataSeries) const =0
 
virtual bool getValue (int index, double srcValue, double &destValue, Application::Memento::Data &mementoData) const =0
 
void logText (const QString &msg) const
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()=default
 
virtual Clonableclone () const =0
 

Constructor & Destructor Documentation

◆ ScriptedDataSeriesMapper() [1/2]

◆ ScriptedDataSeriesMapper() [2/2]

◆ ~ScriptedDataSeriesMapper()

~ScriptedDataSeriesMapper ( )
override

Member Function Documentation

◆ clone()

ScriptedDataSeriesMapper * clone ( ) const
overridevirtual
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()

Application::Memento::Data * createMementoData ( const DataSeries dataSeries) const
overridevirtual
Parameters
dataSeriesThe 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()

bool getValue ( int  index,
double  srcValue,
double &  destValue,
Application::Memento::Data mementoData 
) const
overridevirtual
Parameters
indexThe index of the item being mapped.
srcValueThe value of the source data series at the specified index.
destValueThe mapped value should be assigned to this before returning.
mementoDataMust 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=()

ScriptedDataSeriesMapper & operator= ( const ScriptedDataSeriesMapper mapper)

◆ setFunctionName()

void setFunctionName ( const QString &  functionName)
Parameters
functionNameThe 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
globalsAn 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
scriptThe script to use for the mapper.
See also
getScript()