Skip to content

Class ValueHandler#

ClassList > ValueHandler

Handles the value of a configuration option (abstract class). More...

  • #include <valuehandler.h>

Inherited by the following classes: Bool, BoundedInt, ButtonList, Color, ExistingDir, FilenamePattern, KeySequence, LowerBoundedInt, Region, SaveFileExtension, String, UserColors

Public Functions#

Type Name
virtual bool check (const QVariant & val) = 0
Check the value semantically.
virtual QString expected ()
The expected value (descriptive). Used when reporting configuration errors.
virtual QVariant fallback ()
Fallback value (default value).
virtual QVariant representation (const QVariant & val)
Return the representation of the value in the config file.
QVariant value (const QVariant & val)
Adapt the value for proper use.

Protected Functions#

Type Name
virtual QVariant process (const QVariant & val)
Process a value, presuming it is a valid QVariant .

Detailed Description#

Each configuration option is represented as a QVariant. If the option was not specified in a config file, the QVariant will be invalid.

Each option will usually be handled in three different ways: * have its value checked for semantic errors (type, format, etc).

See also: ValueHandler::check

  • have its value (that was taken from the config file) adapted for proper use.

See also: ValueHandler::value

  • provided a fallback value in case: the config does not explicitly specify it, or the config contains an error and is globally falling back to defaults.

See also: ValueHandler::fallback.

  • some options may want to be stored in the config file in a different way than the default one provided by QVariant.

See also: ValueHandler::representation

Note:

Please see the documentation of the functions to learn when you should override each.

Public Functions Documentation#

function check#

Check the value semantically.

virtual bool ValueHandler::check (
    const QVariant & val
) = 0

Parameters:

  • val The value that was read from the config file

Returns:

Whether the value is correct

Note:

The function should presume that val.isValid() is true.

function expected#

virtual QString ValueHandler::expected () 

function fallback#

virtual QVariant ValueHandler::fallback () 

function representation#

Return the representation of the value in the config file.

virtual QVariant ValueHandler::representation (
    const QVariant & val
) 

Override this if you want to write the value in a different format than the one provided by QVariant.

function value#

Adapt the value for proper use.

QVariant ValueHandler::value (
    const QVariant & val
) 

Parameters:

  • val The value that was read from the config file

Returns:

The modified value

If the value is invalid (unspecified in the config) or does not pass check, the fallback will be returned. Otherwise the value is processed by process and then returned.

Note:

Cannot be overridden

See also: fallback, process

Protected Functions Documentation#

function process#

Process a value, presuming it is a valid QVariant .

virtual QVariant ValueHandler::process (
    const QVariant & val
) 

Parameters:

  • val The value that was read from the config file

Returns:

The processed value

Note:

You will usually want to override this. In rare cases, you may want to override value.