Updraft  1.0
Open source glider flight visualisation tool.
Updraft::Core::SettingsModel Class Reference

Model that stores all settings. More...

#include <settingsmodel.h>

Collaboration diagram for Updraft::Core::SettingsModel:

List of all members.

Signals

void itemChanged (SettingsItem *item)
 Signals that an item's data changed.

Public Member Functions

 SettingsModel ()
 ~SettingsModel ()
void loadSettings (QString filename)
 Loads settings from a xml settings file.
void saveSettings (QString filename)
 Saves the settings to a settings file.
int columnCount (const QModelIndex &index) const
 Returns the number of columns under the given index.
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Gets the data for the given index and data role.
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Gets the index for the desired SettingsItem.
QModelIndex indexFromItem (SettingsItem *item) const
 Looks up the model index for a given SettingsItem.
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 Inserts a row into the model under the given parent item.
SettingsItemitemFromIndex (const QModelIndex &index) const
 Converts the model index to the item at that index.
QModelIndex parent (const QModelIndex &index) const
 Returns a parent model index for the given index.
int rowCount (const QModelIndex &parent=QModelIndex()) const
 Returns the number of rows under the given index.
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
 Sets the item data.
QModelIndex sibling (int row, int column, const QModelIndex &index) const
 Gets the index of a sibling item to the given item.

Private Member Functions

QString dataRoleToString (int role) const
 Gets a textual representation of the given data role.
void insertRowInternal (int row, SettingsItem *item)
 Internal helper function for adding rows.
void reinitializeData ()
 Reinitializes the internal data structures, effectively erasing the whole data model.

Private Attributes

QDomDocument domDoc
 The representation of the XML document where the settings are stored.
SettingsItemrootItem
 The root item of the SettingsItem hieararchy.

Detailed Description

Model that stores all settings.

The setting values are internally stored in a QDomDocument and a hierarchy of SettingsItem instances is kept that points to the QDomDocument.


Constructor & Destructor Documentation


Member Function Documentation

int Updraft::Core::SettingsModel::columnCount ( const QModelIndex &  index) const [inline]

Returns the number of columns under the given index.

This is always equal to 1 in the SettingsModel.

Parameters:
indexThe index whose number of columns should be retrieved
Returns:
Number of columns for the given index.
QVariant Updraft::Core::SettingsModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const

Gets the data for the given index and data role.

Parameters:
indexThe model index denoting the desired setting or settings group.
roleThe data role for the data to be retrieved.
Returns:
The desired data.
QString Updraft::Core::SettingsModel::dataRoleToString ( int  role) const [private]

Gets a textual representation of the given data role.

This representation is used when saving into the settings file.

Parameters:
roleThe data role whose textual representation we want.
Returns:
The textual representation of the given data role.
QModelIndex Updraft::Core::SettingsModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const

Gets the index for the desired SettingsItem.

Parameters:
rowThe row index of the desired item.
columnThe column index of the desired item.
parentThe parent of the desired item.
Returns:
The child of the given parent index at the position [row, column]

Looks up the model index for a given SettingsItem.

Parameters:
itemThe item whose QModelIndex should be returned.
Returns:
The model index for the given item.
bool Updraft::Core::SettingsModel::insertRow ( int  row,
const QModelIndex &  parent = QModelIndex() 
)

Inserts a row into the model under the given parent item.

Parameters:
rowThe row index of the row to be inserted.
parentThe model index of the parent item.
Returns:
A boolean value indicating success or failure.
void Updraft::Core::SettingsModel::insertRowInternal ( int  row,
SettingsItem item 
) [private]

Internal helper function for adding rows.

Parameters:
rowThe row index of the new row.
itemThe SettingsItem under which we want the row to be added.

Signals that an item's data changed.

Parameters:
itemThe item whose data was changed
SettingsItem * Updraft::Core::SettingsModel::itemFromIndex ( const QModelIndex &  index) const

Converts the model index to the item at that index.

Parameters:
indexThe model index of the item to be retrieved.
Returns:
Pointer to the SettingsItem at the given index.
void Updraft::Core::SettingsModel::loadSettings ( QString  filename)

Loads settings from a xml settings file.

If the file does not exist, the application attempts to create it.

Parameters:
filenamePath to the settings file.
QModelIndex Updraft::Core::SettingsModel::parent ( const QModelIndex &  index) const

Returns a parent model index for the given index.

Parameters:
indexThe model index whose parent we want.
Returns:
The parent index for the given model index.

Reinitializes the internal data structures, effectively erasing the whole data model.

int Updraft::Core::SettingsModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

Returns the number of rows under the given index.

Parameters:
parentThe index whose number of rows we want.
Returns:
Number of rows for the given index.
void Updraft::Core::SettingsModel::saveSettings ( QString  filename)

Saves the settings to a settings file.

Parameters:
filenamePath to the settings file.
bool Updraft::Core::SettingsModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::DisplayRole 
)

Sets the item data.

Parameters:
indexThe index of the item whose data we want to set.
valueThe value to be set.
roleThe desired data role of the data being set.
Returns:
A boolean value indicating success or failure.
QModelIndex Updraft::Core::SettingsModel::sibling ( int  row,
int  column,
const QModelIndex &  index 
) const

Gets the index of a sibling item to the given item.

Parameters:
rowRow index of the sibling.
columnColumn index of the sibling.
indexThe model index of the item whose sibling we want.
Returns:
The desired sibling item's index.

Member Data Documentation

QDomDocument Updraft::Core::SettingsModel::domDoc [private]

The representation of the XML document where the settings are stored.

The root item of the SettingsItem hieararchy.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines