bbob_settings.cpp

Go to the documentation of this file.
00001 #include "bbob_settings.h"
00002 
00003 /*! \file bbob_settings.cpp
00004     \brief Provides an interface for storing/retrieving data in configuration files.
00005 
00006     Provides convience functions for QSettings, handling system specific directories.  Currently all files are
00007     stored in INI format, which is easy to read and edit.  Eventually this will be XML files for an offline
00008     editor using DTDs for data verification.
00009 */
00010 
00011 /// This will use INI format, so settings can be edited easily.
00012 BBoB_Settings::BBoB_Settings(QString program)
00013 {
00014     settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "BBoB", program);
00015 
00016     Program = program;
00017 }
00018 
00019 BBoB_Settings::~BBoB_Settings()
00020 {
00021     Sync();
00022 }
00023 
00024 void BBoB_Settings::Sync()
00025 {
00026     settings->sync();
00027 }
00028 
00029 
00030 QVariant BBoB_Settings::getValue(QString name, QVariant default_string)
00031 {
00032     return settings->value(name, default_string);
00033 }
00034 
00035 QVariant BBoB_Settings::getValue(QString group, QString name, QVariant default_value)
00036 {
00037     settings->beginGroup(group);
00038     QVariant retval = settings->value(name, default_value);
00039     settings->endGroup();
00040     return retval;
00041 }
00042 
00043 QStringList BBoB_Settings::getGroups(QString group)
00044 {
00045     if (group.isEmpty())
00046         settings->endGroup();
00047     else
00048         settings->beginGroup(group);
00049 
00050     QStringList retval = settings->childGroups();
00051     settings->endGroup();
00052     return retval;
00053 }
00054 
00055 QStringList BBoB_Settings::getValues(QString group)
00056 {
00057     QString g;
00058     if (! groupName.isEmpty())
00059         g = group + "/" + groupName;
00060     else
00061         g = group;
00062 
00063     settings->beginGroup(g);
00064     QStringList retval = settings->allKeys();
00065     settings->endGroup();
00066     return retval;
00067 }
00068 
00069 void BBoB_Settings::setValue( QString key, QVariant value )
00070 {
00071     settings->setValue(key, value );
00072 }
00073 
00074 void BBoB_Settings::setValue( QString group, QString key, QVariant value )
00075 {
00076     settings->beginGroup(group);
00077     settings->setValue(key, value );
00078     settings->endGroup();
00079 }
00080 
00081 QStringList BBoB_Settings::getList(QString group)
00082 {
00083     QString g;
00084     if (! groupName.isEmpty())
00085         g = group + "/" + groupName;
00086     else
00087         g = group;
00088 
00089     settings->beginGroup(g);
00090     QStringList list = settings->childKeys();
00091     settings->endGroup();
00092     return list;
00093 }
00094 
00095 QVariant BBoB_Settings::getListValue(QString group, QString name, QVariant default_value)
00096 {
00097     QString g;
00098     if (! groupName.isEmpty())
00099         g = group + "/" + groupName;
00100     else
00101         g = group;
00102 
00103     settings->beginGroup(g);
00104     QVariant retval = settings->value(name, default_value);
00105     settings->endGroup();
00106     return retval;
00107 }
00108 
00109 void BBoB_Settings::setList(QString name)
00110 {
00111     groupName = name;
00112 }
00113 
00114 void BBoB_Settings::writeList(QString group, QString key, QVariant value)
00115 {
00116     settings->beginGroup(group + "/" + groupName);
00117     settings->setValue(key, value );
00118     settings->endGroup();
00119 }
00120 
00121 void BBoB_Settings::removeValues(QString group, QString key)
00122 {
00123     QString g;
00124     if (! groupName.isEmpty())
00125         g = group + "/" + groupName;
00126     else
00127         g = group;
00128 
00129     settings->beginGroup(g);
00130     settings->remove(key);
00131     settings->endGroup();
00132 }
00133 
00134 

Generated on Sun Oct 28 22:51:26 2007 for BBoB by  doxygen 1.5.3