lib/Setting.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  * 
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
00019  *  USA.
00020  */
00021 
00022 #include "Setting.h"
00023 #include <qobject.h>
00024 
00025 Setting::Setting ()
00026 {
00027   dict.setAutoDelete(TRUE);
00028 }
00029 
00030 Setting::~Setting ()
00031 {
00032 }
00033 
00034 void Setting::getData (QString &k, QString &d)
00035 {
00036   d.truncate(0);
00037   QString *s = dict[k];
00038   if (s)
00039     d = s->left(s->length());
00040 }
00041 
00042 double Setting::getDouble (QString &k)
00043 {
00044   QString *s = dict[k];
00045   if (s)
00046     return s->toDouble();
00047   else
00048     return 0;
00049 }
00050 
00051 int Setting::getInt (QString &k)
00052 {
00053   QString *s = dict[k];
00054   if (s)
00055     return s->toInt();
00056   else
00057     return 0;
00058 }
00059 
00060 void Setting::setData (QString &k, QString &d)
00061 {
00062   dict.replace(k, new QString(d));
00063 }
00064 
00065 void Setting::getKeyList (QStringList &l)
00066 {
00067   l.clear();
00068   QDictIterator<QString> it(dict);
00069   for (; it.current(); ++it)
00070     l.append(it.currentKey());
00071 }
00072 
00073 void Setting::remove (QString &k)
00074 {
00075   dict.remove(k);
00076 }
00077 
00078 void Setting::getString (QString &s)
00079 {
00080   s.truncate(0);
00081   QStringList l;
00082   QDictIterator<QString> it(dict);
00083   for (; it.current(); ++it)
00084   {
00085     QString *s = it.current();
00086     l.append(it.currentKey() + "=" + s->left(s->length()));
00087   }
00088   s = l.join("|");
00089 }
00090 
00091 void Setting::parse (QString &d)
00092 {
00093   dict.clear();
00094 
00095   QStringList l = QStringList::split("|", d, FALSE);
00096 
00097   int loop;
00098   for (loop = 0; loop < (int) l.count(); loop++)
00099   {
00100     QStringList l2 = QStringList::split("=", l[loop], FALSE);
00101     dict.replace(l2[0], new QString(l2[1]));
00102   }
00103 }
00104 
00105 void Setting::clear ()
00106 {
00107   dict.clear();
00108 }
00109 
00110 int Setting::count ()
00111 {
00112   return (int) dict.count();
00113 }
00114 
00115 void Setting::copy (Setting *r)
00116 {
00117   QString k, d;
00118   QDictIterator<QString> it(dict);
00119   for (; it.current(); ++it)
00120   {
00121     QString *s = it.current();
00122     k = it.currentKey();
00123     d = s->left(s->length());
00124     r->setData(k, d);
00125   }
00126 }
00127