Back to index

scribus-ng  1.3.4.dfsg+svn20071115
prefscontext.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Copyright (C) 2004 by Riku Leino                                      *
00009  *   tsoots@gmail.com                                                      *
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019  *   GNU General Public License for more details.                          *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU General Public License     *
00022  *   along with this program; if not, write to the                         *
00023  *   Free Software Foundation, Inc.,                                       *
00024  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025  ***************************************************************************/
00026 
00027 #include "prefscontext.h"
00028 
00029 PrefsContext::PrefsContext()
00030 {
00031        name = "";
00032        ispersistent = false;
00033        isplugin = false;
00034 }
00035 
00036 PrefsContext::PrefsContext(QString contextName, bool persistent, bool plugin)
00037 {
00038        name = contextName;
00039        ispersistent = persistent;
00040        isplugin = plugin;
00041 }
00042 
00043 QString PrefsContext::getName()
00044 {
00045        return name;
00046 }
00047 
00048 bool PrefsContext::isPersistent()
00049 {
00050        return ispersistent;
00051 }
00052 
00053 bool PrefsContext::isPlugin()
00054 {
00055        return isplugin;
00056 }
00057 
00058 bool PrefsContext::isEmpty()
00059 {
00060        return (values.size() == 0 && tables.size() == 0);
00061 }
00062 
00063 bool PrefsContext::contains(const QString& key)
00064 {
00065        return values.contains(key);
00066 }
00067 
00068 bool PrefsContext::containsTable(const QString& key)
00069 {
00070        return tables.contains(key);
00071 }
00072 
00073 QString PrefsContext::get(const QString& key, const QString& defValue)
00074 {
00075        if (!values.contains(key))
00076               values[key] = defValue;
00077 
00078        return values[key];
00079 }
00080 
00081 void PrefsContext::set(const QString& key, const char* value)
00082 {
00083        set(key, QString(value));
00084 }
00085 
00086 void PrefsContext::set(const QString& key, const std::string& value)
00087 {
00088        set(key, QString(value.c_str()));
00089 }
00090 
00091 void PrefsContext::set(const QString& key, const QString& value)
00092 {
00093        values[key] = value;
00094 }
00095 
00096 int PrefsContext::getInt(const QString& key, int defValue)
00097 {
00098        if (!values.contains(key))
00099               set(key, defValue);
00100        QString stringValue = values[key];
00101        bool ok = false;
00102        int ivalue = stringValue.toInt(&ok);
00103        if (!ok)
00104               ivalue = defValue;
00105        return ivalue;
00106 }
00107 
00108 uint PrefsContext::getUInt(const QString& key, uint defValue)
00109 {
00110        if (!values.contains(key))
00111               set(key, QString("%1").arg(defValue));
00112        QString stringValue = values[key];
00113        bool ok = false;
00114        int uivalue = stringValue.toUInt(&ok);
00115        if (!ok)
00116               uivalue = defValue;
00117        return uivalue;
00118 }
00119 
00120 void PrefsContext::set(const QString& key, int value)
00121 {
00122        set(key, QString("%1").arg(value));
00123 }
00124 
00125 void PrefsContext::set(const QString& key, uint value)
00126 {
00127        set(key, QString("%1").arg(value));
00128 }
00129 
00130 double PrefsContext::getDouble(const QString& key, double defValue)
00131 {
00132        if (!values.contains(key))
00133               set(key, defValue);
00134        QString stringValue = values[key];
00135        bool ok = false;
00136        double dvalue = stringValue.toDouble(&ok);
00137        if (!ok)
00138               dvalue = defValue;
00139        return dvalue;
00140 }
00141 
00142 void PrefsContext::set(const QString& key, double value)
00143 {
00144        set(key, QString("%1").arg(value));
00145 }
00146 
00147 bool PrefsContext::getBool(const QString& key, bool defValue)
00148 {
00149        if (!values.contains(key))
00150               set(key, defValue);
00151        QString stringValue = values[key];
00152        bool ok = false;
00153        int ivalue = stringValue.toInt(&ok);
00154        if (!ok)
00155               ivalue = defValue;
00156        return ivalue;
00157 }
00158 
00159 void PrefsContext::set(const QString& key, bool value)
00160 {
00161        set(key, QString("%1").arg(value));
00162 }
00163 
00164 PrefsTable* PrefsContext::getTable(const QString& name)
00165 {
00166        if (!tables.contains(name))
00167               tables[name] = new PrefsTable(name);
00168        return tables[name];
00169 }
00170 
00171 void PrefsContext::removeTable(const QString& name)
00172 {
00173        tables.remove(name);
00174 }
00175 
00176 PrefsContext::~PrefsContext()
00177 {
00178        TableMap::Iterator it;
00179        for (it = tables.begin(); it != tables.end(); ++it)
00180               delete it.data();
00181 }