#include <uasettings.h>

Collaboration diagram for UaSettings:

List of all members.

Public Types

enum  Scope { UserScope = 0, SystemScope = 1 }
 

Scope enumeration.

More...

Public Member Functions

 UaSettings (const UaUniString &sOrganization, const UaUniString &sApplication, Scope scope=UserScope)
 UaSettings (const UaUniString &sPath)
 ~UaSettings ()
UaUniString organizationName () const
UaUniString applicationName () const
Scope scope () const
void beginGroup (const UaUniString &sGroup)
void removeKey (const UaUniString &sKey)
void setValue (const UaUniString &sKey, const UaVariant &value)
UaUniString endGroup ()
UaUniString group ()
UaUniStringList childGroups () const
UaUniStringList childKeys () const
UaVariant value (const UaUniString &sKey, const UaVariant &defaultValue=UaVariant())
bool contains (const UaUniString &sKey)

Detailed Description

The UaSettings class provides persistent platform-independent application settings. Users normally expect an application to remember its settings (window sizes and positions, options, etc.) across sessions. This information is often stored in the system registry on Windows. On Unix systems, many applications (including the KDE applications) use INI text files. UaSettings is an abstraction around these technologies, enabling you to save and restore application settings in a portable manner. UaSettings's API is based on UaVariant, allowing you to save most value-based types, such as UaString with the minimum of effort.


Member Enumeration Documentation

Scope enumeration.

Enumerator:
UserScope 

Store settings in a location specific to the current user (e.g., in the user's home directory).

SystemScope 

Store settings in a global location, so that all users on the same machine access the same set of settings.


Constructor & Destructor Documentation

UaSettings::UaSettings ( const UaUniString sOrganization,
const UaUniString sApplication,
Scope  scope = UserScope 
)

construction Get the needed variables to create the path to the ini file.

Parameters:
sOrganizationthe name of the organisation.
sApplicationthe name of the application.
scopethe scope of the user or of the system.
UaSettings::UaSettings ( const UaUniString sPath )

construction Get the path to the already created ini file and call method to read it out.

Parameters:
sPaththe path to the existing ini file.
UaSettings::~UaSettings (  )

destruction calls the private method writeIniFile() to write all values out of the map into the ini file.


Member Function Documentation

UaUniString UaSettings::applicationName (  ) const [inline]

Get the name of the application.

Returns:
the name of the application.
void UaSettings::beginGroup ( const UaUniString sGroup )

Appends a prefix to the current group. The current group is automatically prepended to all keys specified to UaSettings. Groups are useful to avoid typing in the same setting paths over and over. For example:

      settings.beginGroup("Test");
      settings.setValue("size", 10);
      settings.setValue("size2", FullScreen());
      settings.endGroup();

      settings.beginGroup("Test2");
      settings.setValue("visible", Visible());
      settings.endGroup();
Parameters:
sGroupthe group you want to have.
UaUniStringList UaSettings::childGroups (  ) const

Returns a list of all key top-level groups that contain keys that can be read using the UaSettings object.

Returns:
a list of all child groups.
UaUniStringList UaSettings::childKeys (  ) const

Returns a list of all top-level keys that can be read using the UaSettings object.

Returns:
a list of all child keys.
bool UaSettings::contains ( const UaUniString sKey )

Checks if the given sKey exists in the current group.

Parameters:
sKeythe key to search for.
Returns:
True if the key exists, false otherwise.
UaUniString UaSettings::endGroup (  )

Resets the group to what it was before the corresponding beginGroup() call. For example:

     settings.beginGroup("alpha");
     settings.beginGroup("beta");
     UaUniString ret = settings.endGroup();  // ret = beta 
     ret = settings.endGroup();              // ret = alpha
See also:
beginGroup()
UaUniString UaSettings::group (  )

Returns the current group.

See also:
beginGroup(), endGroup()
Returns:
the current group.
UaUniString UaSettings::organizationName (  ) const [inline]

Get the name of the organisation.

Returns:
the name of the organisation.
void UaSettings::removeKey ( const UaUniString sKey )

Removes the setting sKey.

Parameters:
sKeythe key to remove from the ini file..
Scope UaSettings::scope (  ) const [inline]

Get the actual used scope.

Returns:
the actual used scope.
void UaSettings::setValue ( const UaUniString sKey,
const UaVariant value 
)

Sets the value of setting sKey to value. If the key already exists, the previous value is overwritten. For example:

      UaSettings settings;
      settings.setValue("interval", 30);
      settings.value("interval").toInt();     // returns 30

      settings.setValue("interval", 6.55);
      settings.value("interval").toDouble();  // returns 6.55
Parameters:
sKeythe key you want to write into the ini file.
valuethe value for the key to write into the ini file.
UaVariant UaSettings::value ( const UaUniString sKey,
const UaVariant defaultValue = UaVariant() 
)

Returns the value for setting sKey. If the setting doesn't exist, returns defaultValue. If no default value is specified, a default UaVariant is returned. For example:

      UaSettings settings;
      settings.setValue("animal/snake", 58);
      settings.value("animal/snake", 1024).toInt();   // returns 58
      settings.value("animal/zebra", 1024).toInt();   // returns 1024
      settings.value("animal/zebra").toInt();         // returns 0
Parameters:
sKeythe key you want to read out of the ini file.
defaultValuethe value for the key to read out the ini file.
Returns:
the value you read out of the ini file.

The documentation for this class was generated from the following files:
  • /home/buildbot/work/uasdkcpp/src/uabase/uabasecpp/uasettings.h
  • /home/buildbot/work/uasdkcpp/src/uabase/uabasecpp/uasettings.cpp