mkRPG
Public Member Functions | Static Public Member Functions
Options Struct Reference

The Options class provides session-independant options and preferences. More...

#include <options.h>

Public Member Functions

template<class T >
load (QString group, QString opt)
template<class T >
void save (QString group, QString opt, T val)
template<class T >
void setDefault (QString group, QString opt, T val)
bool isAdjustable (QString group, QString opt, bool adjust=true)
void setAdjustable (QString group, QString opt, bool adjust)
void reinitialise (QString group="")

Static Public Member Functions

static Optionsoptions ()

Detailed Description

The Options class provides session-independant options and preferences.

## Features

The Options class aims at storing global options, that are available at any place in the entire application. The preferences are permanantly stored and remain bewteen the separate sessions and windows.

Two sorts of options exist :

The sort of option can be set with the setAdjustable function.

## Design

The Options class is designed following the __Singleton design pattern__. The constructor is thus private, and the only Options instance is created at the first call of options.

QSetting is used internaly, see Qt's documentation for details about the storing mechanisms.

## Reading and writting existing options

To read or write options, the Options instance must be retreived, using the options function, then the load and save functions can be called.

## Adding options

To add a new option, it is only needed to add a default hard coded value, uisng the Default and DefaultF macros in the Options constructor.

It is strongly advice to use macro to define new options group (see WIN, for an example).

Note:
To use Options with custom types (other than ```C++``` standard), the defining header of the type must be included at the top of the options.h file, in order to be used in the default value declaration.
Warning:
Pointer objects are not supported, and the result of the use of the Options class with such values is undefined.
See also:
options.h

Member Function Documentation

bool Options::isAdjustable ( QString  group,
QString  opt,
bool  adjust = true 
)

Returns ```true``` if the option defined by its group and name is adjustable, ```false``` elsewhere.

See also:
setAdjustable
template<class T >
T Options::load ( QString  group,
QString  opt 
) [inline]

Reads an option defined by its group and name.

Note:
The template argument must be precised since it can't be deduced from arguments' types.
Warning:
If the option type and the reading type mismatch, an default null value is returned.
See also:
save
Options & Options::options ( ) [static]

Returns the unique Options instance.

void Options::reinitialise ( QString  group = "")

Clear all options from the group. If ```group == ""```, all entries are deleted.

template<class T >
void Options::save ( QString  group,
QString  opt,
val 
) [inline]

Writes the new value of the options defined by its group and name, if the option is adjustable. See Options for details about options types.

Note:
The template argument can be omitted since it would be deduced from the value argument.
See also:
setDefault, load
void Options::setAdjustable ( QString  group,
QString  opt,
bool  adjust 
)

Sets if the option defined by its group and name is adjustable.

See also:
isAdjustable
template<class T >
void Options::setDefault ( QString  group,
QString  opt,
val 
) [inline]

Writes the new value of the options defined by its group and name, whatever the option type is. See Options for details about options types.

Note:
The template argument can be omitted since it would be deduced from the value argument.
See also:
save, load

The documentation for this struct was generated from the following files:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Defines