Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/qt_gui/src/lib/gui/gui_saveable.cc @ 7604

Last change on this file since 7604 was 7604, checked in by bensch, 18 years ago

orxonox/trunk: Prefs reader will rule

File size: 3.0 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_
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)
29  : BaseObject(optionName)
30  {
31    this->bSaveable = false;
32
33    assert(group != NULL);
34    this->group = group;
35    this->group->addSaveable(this);
36
37  }
38
39
40  /**
41   * standard deconstructor
42  */
43  Saveable::~Saveable ()
44  {
45    this->group->removeSaveable(this);
46    // delete what has to be deleted here
47  }
48
49
50  void Saveable::makeSaveable()
51  {
52    this->bSaveable = true;
53
54  }
55
56
57  void Saveable::load()
58  {
59    this->value() = Preferences::getInstance()->getMultiType(this->group->getName(), this->getName(), this->_value);
60    PRINTF(4)("Loaded to '%s' of group '%s' value ", this->getName(), this->group->getName());
61    this->value().debug();
62
63  }
64
65  void Saveable::save()
66  {
67    Preferences::getInstance()->setMultiType(this->group->getName(), this->getName(), this->value(), true);
68    PRINTF(4)("Saved to '%s' of group '%s' value ", this->getName(), this->group->getName());
69    this->value().debug();
70  }
71
72
73
74
75  SaveableGroup::SaveableGroup(const std::string& groupName, OrxGui::Gui* gui)
76      : BaseObject(groupName)
77  {
78    assert (gui != NULL);
79    this->gui = gui;
80
81    this->gui->addSaveableGroup(this);
82    //this->mainWidget = NULL;
83  }
84
85
86
87  SaveableGroup::~SaveableGroup()
88  {
89    this->gui->removeSaveableGroup(this);
90  }
91
92
93  /**
94   * @brief Adds a Saveable to the List.
95   * @param saveable the saveable to add.
96   */
97  void SaveableGroup::addSaveable(Saveable* saveable)
98  {
99    if (std::find(this->saveables.begin(), this->saveables.end(), saveable) == this->saveables.end())
100      this->saveables.push_back(saveable);
101  }
102
103  /**
104   * @brief Removes a Saveable from the List.
105   * @param saveable the saveable to remove.
106   */
107  void SaveableGroup::removeSaveable(Saveable* saveable)
108  {
109    std::vector<Saveable*>::iterator delSav = std::find(this->saveables.begin(), this->saveables.end(), saveable);
110    if (delSav != this->saveables.end())
111      this->saveables.erase(delSav);
112  }
113
114
115  /**
116   * @brief load the value onto the Group.
117   * @param value the Value to load.
118   */
119  void SaveableGroup::load()
120  {
121    std::vector<Saveable*>::iterator elem;
122    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
123      (*elem)->load();
124  }
125
126  /**
127   * @brief save the value from the Group
128   * @returns nothing.
129   */
130  void SaveableGroup::save()
131  {
132    std::vector<Saveable*>::iterator elem;
133    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
134      (*elem)->save();
135  }
136
137
138
139
140}
Note: See TracBrowser for help on using the repository browser.