File indexing completed on 2024-10-06 03:46:05

0001 /***************************************************************************
0002                           cvariable.cpp  -  one variable
0003                           ------------------------------
0004     begin                : Po sep 8 2003
0005     copyright            : (C) 2003 by Tomas Mecir
0006     email                : kmuddy@kmuddy.com
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "cvariable.h"
0019 #include "cvalue.h"
0020 
0021 #include <kconfig.h>
0022 #include <kconfiggroup.h>
0023 
0024 cVariable::cVariable ()
0025 {
0026   _name = QString();
0027   val = nullptr;
0028 }
0029 
0030 cVariable::~cVariable ()
0031 {
0032   delete val;
0033 }
0034 
0035 cSaveableField *cVariable::newInstance ()
0036 {
0037   return new cVariable;
0038 }
0039 
0040 void cVariable::load (KConfig *config, const QString &group)
0041 {
0042   KConfigGroup g = config->group (group);
0043   setName (g.readEntry ("Name", QString()));
0044   setValue (cValue::load (&g));
0045 }
0046 
0047 QString cVariable::value ()
0048 {
0049   if (val) return val->asString ();
0050   return QString();
0051 }
0052 
0053 void cVariable::setValue (const QString &newvalue)
0054 {
0055   cValue *oldv = val;
0056   val = new cValue (newvalue);
0057   delete oldv;
0058 }
0059 
0060 void cVariable::setValue (const cValue *v)
0061 {
0062   cValue *oldv = val;
0063   val = new cValue (*v);
0064   delete oldv;
0065 }
0066 
0067