Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gui_saveable.cc @ 7875

Last change on this file since 7875 was 7661, checked in by bensch, 19 years ago

orxonox/trunk: merged the QT_GUI back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/qt_gui . -r7607:HEAD

absolutely no conflicts :)

File size: 3.1 KB
RevLine 
[4744]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[7140]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[7635]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
[1853]17
[7140]18#include "gui_saveable.h"
[7555]19#include "gui.h"
[7595]20#include "preferences.h"
[1853]21
[7447]22namespace OrxGui
23{
[1853]24
[7447]25  /**
26   * standard constructor
27  */
[7632]28  Saveable::Saveable (const std::string& optionName, SaveableGroup* group, const MultiType& defaultValue)
[7479]29  : BaseObject(optionName)
[7447]30  {
31    this->bSaveable = false;
[7632]32    this->_defaultValue = defaultValue;
[7479]33
[7595]34    assert(group != NULL);
[7555]35    this->group = group;
36    this->group->addSaveable(this);
37
[7447]38  }
[1856]39
[4320]40
[7447]41  /**
42   * standard deconstructor
43  */
[7480]44  Saveable::~Saveable ()
[7447]45  {
[7555]46    this->group->removeSaveable(this);
[7447]47    // delete what has to be deleted here
48  }
[1853]49
50
[7480]51  void Saveable::makeSaveable()
[7447]52  {
53    this->bSaveable = true;
[7143]54
[7447]55  }
[7143]56
57
[7598]58  void Saveable::load()
[7595]59  {
[7633]60    this->value() = Preferences::getInstance()->getMultiType(this->group->getName(), this->getName(), this->_defaultValue);
[7605]61    PRINTF(4)("Loaded to '%s' of group '%s' value '%s'\n", this->getName(), this->group->getName(), this->value().getCString());
[7595]62  }
63
[7598]64  void Saveable::save()
[7595]65  {
[7630]66    Preferences::getInstance()->setMultiType(this->group->getName(), this->getName(), this->value() );
[7605]67    PRINTF(4)("Saved to '%s' of group '%s' value '%s'\n", this->getName(), this->group->getName(), this->value().getCString());
[7595]68  }
69
70
71
72
[7549]73  SaveableGroup::SaveableGroup(const std::string& groupName, OrxGui::Gui* gui)
[7555]74      : BaseObject(groupName)
[7447]75  {
[7555]76    assert (gui != NULL);
77    this->gui = gui;
[7549]78
[7555]79    this->gui->addSaveableGroup(this);
80    //this->mainWidget = NULL;
[7447]81  }
[7143]82
83
84
[7480]85  SaveableGroup::~SaveableGroup()
[7447]86  {
[7555]87    this->gui->removeSaveableGroup(this);
88  }
[7447]89
[7555]90
91  /**
92   * @brief Adds a Saveable to the List.
93   * @param saveable the saveable to add.
94   */
95  void SaveableGroup::addSaveable(Saveable* saveable)
96  {
97    if (std::find(this->saveables.begin(), this->saveables.end(), saveable) == this->saveables.end())
98      this->saveables.push_back(saveable);
[7447]99  }
100
[7555]101  /**
102   * @brief Removes a Saveable from the List.
103   * @param saveable the saveable to remove.
104   */
105  void SaveableGroup::removeSaveable(Saveable* saveable)
106  {
107    std::vector<Saveable*>::iterator delSav = std::find(this->saveables.begin(), this->saveables.end(), saveable);
108    if (delSav != this->saveables.end())
109      this->saveables.erase(delSav);
110  }
111
112
113  /**
114   * @brief load the value onto the Group.
115   * @param value the Value to load.
116   */
[7598]117  void SaveableGroup::load()
[7595]118  {
[7598]119    std::vector<Saveable*>::iterator elem;
120    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
121      (*elem)->load();
[7595]122  }
[7493]123
[7555]124  /**
125   * @brief save the value from the Group
126   * @returns nothing.
127   */
[7598]128  void SaveableGroup::save()
[7600]129  {
130    std::vector<Saveable*>::iterator elem;
131    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
132      (*elem)->save();
133  }
[7493]134
135
136
[7447]137
[7143]138}
Note: See TracBrowser for help on using the repository browser.