casa
$Rev:20696$
|
Implementation of DisplayParameter to store choice parameters. More...
#include <DParameterChoice.h>
Public Member Functions | |
DParameterChoice (const String name, const String description, const String help, const Vector< String > &options, const String defaultvalue, const String value, const String context="", const Bool editable=False) | |
Constructor taking the name of the parameter, a short description, some help text, a list of allowed options, a default value, an initial value, the context of the parameter, and a flag indicating whether the parameter is editable. | |
DParameterChoice (const String name, const String description, const String help, const ColormapDefinition::colormapnamemap &options, const String defaultvalue, const String value, const String context="", const Bool editable=False) | |
DParameterChoice (const DParameterChoice &other) | |
(Required) copy constructor. | |
virtual | ~DParameterChoice () |
Destructor. | |
DParameterChoice & | operator= (const DParameterChoice &other) |
(Required) copy assignment. | |
virtual Bool | fromRecord (const RecordInterface &record) |
Parse record , and update this parameter if a field exists whose name matches that of this parameter. | |
virtual void | toRecord (RecordInterface &record, const Bool fullrecord=True, const Bool overwrite=False) |
Place a record describing this parameter in a sub-field of record with name matching that of this parameter. | |
Vector< String > | options () const |
Return the list of allowed options for this parameter. | |
String | defaultValue () |
Return the default for this parameter. | |
String | value () |
Return the current value of this parameter. | |
void | setEditable (const Bool editable) |
Set or change if this parameter is editable (determines wether choice or userchoice is returned in the record. | |
void | setOptions (const Vector< String > &options) |
Set or change the list of allowed options for this parameter. | |
void | setDefaultValue (const String defaultvalue) |
Set or change the default value for this parameter. | |
void | setValue (const String value) |
Set or change the current value. | |
const String & | operator= (const String &value) |
Convenient syntax to set (only) the value. | |
Bool | existsOption (const String value) |
Determine whether this value exists in the list of options. | |
Protected Member Functions | |
DParameterChoice () | |
(Required) default constructor. | |
Private Attributes | |
Bool | itsEditable |
Store for whether this parameter is editable. | |
Vector< String > | itsOptions |
Store for the allowed options for this parameter. | |
String | itsDefaultValue |
Store for the default of this parameter. | |
String | itsValue |
Store for the value of this parameter. |
Implementation of DisplayParameter to store choice parameters.
Public interface
DParameterChoice is an implementation of a DisplayParameter providing a choice parameter type.
This class is derived from DisplayParameter and provides a choice-type parameter. Choice parameters simply have a vector of possible String selections, and a default selection. They cannot be unset.
A DParameterChoice can easily be used to store and update any parameter which can be expressed as a selection from two or more options. In the following example, a DParameterChoice is constructed to provide the name of the font to use in axis labelling:
Vector<String> fonts(4); fonts(0) = "roman"; // ..\. DParameterChoice pchoice("font", "Label font", "Select the font to use for axis labelling", fonts, fonts(0), fonts(0)); // ..\. // update the parameter from some Record pchoice.fromRecord(rec); // examine the value of the parameter if (pchoice.value() == "italic") { // ..\. }
Many parameters are naturally choices, or can be expressed as choices, hence this class.
Definition at line 104 of file DParameterChoice.h.
casa::DParameterChoice::DParameterChoice | ( | const String | name, |
const String | description, | ||
const String | help, | ||
const Vector< String > & | options, | ||
const String | defaultvalue, | ||
const String | value, | ||
const String | context = "" , |
||
const Bool | editable = False |
||
) |
Constructor taking the name of the parameter, a short description, some help text, a list of allowed options, a default value, an initial value, the context of the parameter, and a flag indicating whether the parameter is editable.
Obviously the defaultvalue
and value
parameters must exist in the list of allowed options, otherwise an exception is thrown.
casa::DParameterChoice::DParameterChoice | ( | const String | name, |
const String | description, | ||
const String | help, | ||
const ColormapDefinition::colormapnamemap & | options, | ||
const String | defaultvalue, | ||
const String | value, | ||
const String | context = "" , |
||
const Bool | editable = False |
||
) |
casa::DParameterChoice::DParameterChoice | ( | const DParameterChoice & | other | ) |
(Required) copy constructor.
virtual casa::DParameterChoice::~DParameterChoice | ( | ) | [virtual] |
Destructor.
casa::DParameterChoice::DParameterChoice | ( | ) | [protected] |
(Required) default constructor.
String casa::DParameterChoice::defaultValue | ( | ) | [inline] |
Return the default for this parameter.
Definition at line 154 of file DParameterChoice.h.
References itsDefaultValue.
Bool casa::DParameterChoice::existsOption | ( | const String | value | ) |
Determine whether this value exists in the list of options.
virtual Bool casa::DParameterChoice::fromRecord | ( | const RecordInterface & | record | ) | [virtual] |
Parse record
, and update this parameter if a field exists whose name matches that of this parameter.
Return True
if the parameter is changed, otherwise return False
.
Implements casa::DisplayParameter.
DParameterChoice& casa::DParameterChoice::operator= | ( | const DParameterChoice & | other | ) |
(Required) copy assignment.
Convenient syntax to set (only) the value.
Definition at line 179 of file DParameterChoice.h.
Vector<String> casa::DParameterChoice::options | ( | ) | const [inline] |
Return the list of allowed options for this parameter.
Definition at line 150 of file DParameterChoice.h.
References itsOptions.
Referenced by setOptions().
void casa::DParameterChoice::setDefaultValue | ( | const String | defaultvalue | ) | [inline] |
Set or change the default value for this parameter.
Definition at line 171 of file DParameterChoice.h.
References itsDefaultValue.
void casa::DParameterChoice::setEditable | ( | const Bool | editable | ) | [inline] |
Set or change if this parameter is editable (determines wether choice or userchoice is returned in the record.
Reimplemented from casa::DisplayParameter.
Definition at line 163 of file DParameterChoice.h.
References casa::DisplayParameter::editable(), and itsEditable.
void casa::DParameterChoice::setOptions | ( | const Vector< String > & | options | ) | [inline] |
Set or change the list of allowed options for this parameter.
Reimplemented in casa::DParameterMapKeyChoice.
Definition at line 167 of file DParameterChoice.h.
References itsOptions, and options().
void casa::DParameterChoice::setValue | ( | const String | value | ) | [inline] |
Set or change the current value.
Definition at line 175 of file DParameterChoice.h.
virtual void casa::DParameterChoice::toRecord | ( | RecordInterface & | record, |
const Bool | fullrecord = True , |
||
const Bool | overwrite = False |
||
) | [virtual] |
Place a record describing this parameter in a sub-field of record
with name matching that of this parameter.
If overwrite
is True
, then any existing field with matching name will be overwritten. If fullrecord
is True
, then a complete description of the parameter is given, otherwise just its current value is stored in record
. Presently fullrecord
is ignored.
Implements casa::DisplayParameter.
String casa::DParameterChoice::value | ( | ) | [inline] |
Return the current value of this parameter.
Definition at line 158 of file DParameterChoice.h.
References itsValue.
Referenced by casa::SkyCatOverlayDD::charColor(), casa::SkyCatOverlayDD::charFont(), casa::SkyCatOverlayDD::mapColumn(), casa::SkyCatOverlayDD::markerColor(), casa::SkyCatOverlayDD::nameColumn(), operator=(), casa::Profile2dDD::profileColor(), setValue(), casa::WorldAxesDD::spectralUnit(), casa::WorldAxesDD::velocityType(), and casa::QtDisplayData::wouldDisplayColorBar().
Store for the default of this parameter.
Definition at line 197 of file DParameterChoice.h.
Referenced by defaultValue(), and setDefaultValue().
Bool casa::DParameterChoice::itsEditable [private] |
Store for whether this parameter is editable.
Reimplemented from casa::DisplayParameter.
Definition at line 192 of file DParameterChoice.h.
Referenced by setEditable().
Vector<String> casa::DParameterChoice::itsOptions [private] |
Store for the allowed options for this parameter.
Definition at line 194 of file DParameterChoice.h.
Referenced by options(), and setOptions().
String casa::DParameterChoice::itsValue [private] |
Store for the value of this parameter.
Definition at line 200 of file DParameterChoice.h.
Referenced by operator=(), setValue(), and value().