VPTissue Reference Manual
HasUnsavedChanges.h
Go to the documentation of this file.
1 #ifndef GUI_HASUNSAVEDCHANGES_H_INCLUDED
2 #define GUI_HASUNSAVEDCHANGES_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include <string>
23 #include <vector>
24 
25 namespace SimShell {
26 namespace Gui {
27 
40 {
41 public:
42  typedef std::vector<HasUnsavedChanges*> ChildrenType;
43 
45  HasUnsavedChanges(std::string&& title);
46 
48  virtual ~HasUnsavedChanges();
49 
51  ChildrenType::iterator begin();
52 
54  ChildrenType::const_iterator begin() const;
55 
57  ChildrenType::iterator end();
58 
60  ChildrenType::const_iterator end() const;
61 
63  void ForceClose();
64 
66  const std::string& GetTitle();
67 
69  bool IsClean() const;
70 
72  virtual bool IsOpened() const = 0;
73 
76  bool Save();
77 
79  bool SaveAndClose();
80 
81 protected:
83  void AddChild(ChildrenType::value_type&& v);
84 
86  void SetChildren(ChildrenType&& c);
87 
89  virtual void InternalForceClose() = 0;
90 
92  virtual bool InternalIsClean() const = 0;
93 
95  virtual void InternalPreForceClose() {}
96 
99  virtual bool InternalSave() = 0;
100 
101 private:
102  std::string m_title;
103  ChildrenType m_children;
104 };
105 
110 {
111 public:
112  HasUnsavedChangesDummy() : HasUnsavedChanges("Dummy"), m_opened(true) {}
113 
114  void SetChildren(ChildrenType&& c) { HasUnsavedChanges::SetChildren(move(c)); }
115 
116  virtual bool IsOpened() const { return m_opened; }
117 
118 protected:
119  virtual void InternalForceClose() { m_opened = false; }
120  virtual bool InternalIsClean() const { return true; }
121  virtual bool InternalSave() { return true; }
122 
123 private:
124  bool m_opened;
125 };
126 
127 } // namespace
128 } // namespace
129 
130 #endif // end_of_inclde_guard
virtual void InternalForceClose()
Implementation should only close THIS widget, not its children.
virtual bool InternalIsClean() const =0
The result should be true only if THIS widget is in clean state.
virtual bool InternalSave()
Implementation should only save THIS widget.
virtual void InternalForceClose()=0
Implementation should only close THIS widget, not its children.
bool Save()
Try to save this widget's (and its children's) changes.
ChildrenType::iterator end()
Get iterator to one position after last child.
Dummy UnsavedChanges class.
ChildrenType::iterator begin()
Get iterator to first child.
virtual bool IsOpened() const =0
void ForceClose()
Force this object and its children to go back to unopened state so it can be safely deleted...
const std::string & GetTitle()
Get title of this object.
void AddChild(ChildrenType::value_type &&v)
Add child.
Abstract class that represents the ability be in closed or opened state, and, if the latter...
void SetChildren(ChildrenType &&c)
Set children.
virtual bool InternalIsClean() const
The result should be true only if THIS widget is in clean state.
bool SaveAndClose()
Try to save this object (and its children) and, if successful, close them all.
virtual ~HasUnsavedChanges()
Virtual destructor.
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
virtual void InternalPreForceClose()
Additional things to do before closing children of this widget.
HasUnsavedChanges(std::string &&title)
virtual bool InternalSave()=0
Implementation should only save THIS widget.