Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8018 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
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
17
18#include "gui_saveable.h"
19#include "gui.h"
20#include "preferences.h"
21
22namespace OrxGui
23{
24
25  /**
26   * standard constructor
27  */
28  Saveable::Saveable (const std::string& optionName, SaveableGroup* group, const MultiType& defaultValue)
29  : BaseObject(optionName)
30  {
31    this->bSaveable = false;
32    this->_defaultValue = defaultValue;
33
34    assert(group != NULL);
35    this->group = group;
36    this->group->addSaveable(this);
37
38  }
39
40
41  /**
42   * standard deconstructor
43  */
44  Saveable::~Saveable ()
45  {
46    this->group->removeSaveable(this);
47    // delete what has to be deleted here
48  }
49
50
51  void Saveable::makeSaveable()
52  {
53    this->bSaveable = true;
54
55  }
56
57
58  void Saveable::load()
59  {
60    this->value() = Preferences::getInstance()->getMultiType(this->group->getName(), this->getName(), this->_defaultValue);
61    PRINTF(4)("Loaded to '%s' of group '%s' value '%s'\n", this->getName(), this->group->getName(), this->value().getCString());
62  }
63
64  void Saveable::save()
65  {
66    Preferences::getInstance()->setMultiType(this->group->getName(), this->getName(), this->value() );
67    PRINTF(4)("Saved to '%s' of group '%s' value '%s'\n", this->getName(), this->group->getName(), this->value().getCString());
68  }
69
70
71
72
73  SaveableGroup::SaveableGroup(const std::string& groupName, OrxGui::Gui* gui)
74      : BaseObject(groupName)
75  {
76    assert (gui != NULL);
77    this->gui = gui;
78
79    this->gui->addSaveableGroup(this);
80    //this->mainWidget = NULL;
81  }
82
83
84
85  SaveableGroup::~SaveableGroup()
86  {
87    this->gui->removeSaveableGroup(this);
88  }
89
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);
99  }
100
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   */
117  void SaveableGroup::load()
118  {
119    std::vector<Saveable*>::iterator elem;
120    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
121      (*elem)->load();
122  }
123
124  /**
125   * @brief save the value from the Group
126   * @returns nothing.
127   */
128  void SaveableGroup::save()
129  {
130    std::vector<Saveable*>::iterator elem;
131    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
132      (*elem)->save();
133  }
134
135
136
137
138}
Note: See TracBrowser for help on using the repository browser.