Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

better saveability

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 '%s'\n", this->getName(), this->group->getName(), this->value().getCString());
61  }
62
63  void Saveable::save()
64  {
65    Preferences::getInstance()->setMultiType(this->group->getName(), this->getName(), this->value(), true);
66    PRINTF(4)("Saved to '%s' of group '%s' value '%s'\n", this->getName(), this->group->getName(), this->value().getCString());
67  }
68
69
70
71
72  SaveableGroup::SaveableGroup(const std::string& groupName, OrxGui::Gui* gui)
73      : BaseObject(groupName)
74  {
75    assert (gui != NULL);
76    this->gui = gui;
77
78    this->gui->addSaveableGroup(this);
79    //this->mainWidget = NULL;
80  }
81
82
83
84  SaveableGroup::~SaveableGroup()
85  {
86    this->gui->removeSaveableGroup(this);
87  }
88
89
90  /**
91   * @brief Adds a Saveable to the List.
92   * @param saveable the saveable to add.
93   */
94  void SaveableGroup::addSaveable(Saveable* saveable)
95  {
96    if (std::find(this->saveables.begin(), this->saveables.end(), saveable) == this->saveables.end())
97      this->saveables.push_back(saveable);
98  }
99
100  /**
101   * @brief Removes a Saveable from the List.
102   * @param saveable the saveable to remove.
103   */
104  void SaveableGroup::removeSaveable(Saveable* saveable)
105  {
106    std::vector<Saveable*>::iterator delSav = std::find(this->saveables.begin(), this->saveables.end(), saveable);
107    if (delSav != this->saveables.end())
108      this->saveables.erase(delSav);
109  }
110
111
112  /**
113   * @brief load the value onto the Group.
114   * @param value the Value to load.
115   */
116  void SaveableGroup::load()
117  {
118    std::vector<Saveable*>::iterator elem;
119    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
120      (*elem)->load();
121  }
122
123  /**
124   * @brief save the value from the Group
125   * @returns nothing.
126   */
127  void SaveableGroup::save()
128  {
129    std::vector<Saveable*>::iterator elem;
130    for (elem = this->saveables.begin(); elem != this->saveables.end(); ++elem)
131      (*elem)->save();
132  }
133
134
135
136
137}
Note: See TracBrowser for help on using the repository browser.