wiki:TutorialAddingNewParameter

Version 3 (modified by Marek Kurdej, 11 years ago) ( diff )

Added: formatters #!

Adding new parameter

Let us suppose that we want to add two new parameters to our component. First parameter, named "integer-value" of type int will be obligatory (required). Second one, named "floating-point-value" of type double will be optional/defaulted (we will provide a default value and the user will not be obliged to set it.

  1. Add member fields to your component which will contain parameter values.

For instance, your class can look like:

class MyComponent
    : public QObject
    , public ComponentBase
{
public:
    // ...

private:
    int mInteger;
    double mDouble;
};
  1. Invoke addParameters() in your component constructor.

This function returns an object that allows you to add parameters. Then, after (), add parameters:

For a required parameter: add a line like ("parameter-name", value<!ParameterType>(&variableToSetWithParameterValue)->required(), "parameter description".

For a optional/defaulted parameter: add a line like ("parameter-name", value<!ParameterType>(&variableToSetWithParameterValue)->default_value(kDefaultParameterValue), "parameter description".

addParameters()
("integer-value", value<int>(&mInteger)->required(), "integer value for test")
("floating-point-value", value<double>(&mDouble)->default_value(kDefaultMemoryName), "floating-point value for test")
;
  1. Modify your XML file

In the <components section, modify your component by adding the required and, optionally, the defaulted arguments.

Before the modification:

<component name="mycomp" type="MyComponent" />

After the modification:

<component name="mycomp" type="MyComponent" integer-value="12345" />

or

<component name="mycomp" type="MyComponent" integer-value="12345" floating-point-value="543.21" />
Note: See TracWiki for help on using the wiki.