VPTissue Reference Manual
HasUnsavedChanges.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "HasUnsavedChanges.h"
21 
22 using namespace std;
23 
24 namespace SimShell {
25 namespace Gui {
26 
27 HasUnsavedChanges::HasUnsavedChanges(string&& title)
28  : m_title(move(title))
29 {
30 }
31 
33 {
34 }
35 
36 HasUnsavedChanges::ChildrenType::iterator HasUnsavedChanges::begin()
37 {
38  return m_children.begin();
39 }
40 
41 HasUnsavedChanges::ChildrenType::const_iterator HasUnsavedChanges::begin() const
42 {
43  return m_children.begin();
44 }
45 
46 HasUnsavedChanges::ChildrenType::iterator HasUnsavedChanges::end()
47 {
48  return m_children.end();
49 }
50 
51 HasUnsavedChanges::ChildrenType::const_iterator HasUnsavedChanges::end() const
52 {
53  return m_children.end();
54 }
55 
57 {
58  if (IsOpened()) {
60  // Force close children first
61  for (auto child : m_children) {
62  child->ForceClose();
63  }
65  }
66 }
67 
69 {
70  return m_title;
71 }
72 
74 {
75  if (!InternalIsClean()) {
76  return false;
77  }
78  for (auto child : m_children) {
79  if (!child->IsClean())
80  return false;
81  }
82  return true;
83 }
84 
86 {
87  // Save children first
88  for (auto child : m_children) {
89  if (!child->Save())
90  return false;
91  }
92  if (IsOpened()) {
93  return InternalSave();
94  } else {
95  return true;
96  }
97 }
98 
100 {
101  if (Save()) {
102  ForceClose();
103  return true;
104  } else {
105  return false;
106  }
107 }
108 
109 void HasUnsavedChanges::AddChild(HasUnsavedChanges::ChildrenType::value_type&& v)
110 {
111  m_children.push_back(move(v));
112 }
113 
114 void HasUnsavedChanges::SetChildren(HasUnsavedChanges::ChildrenType&& c)
115 {
116  m_children = move(c);
117 }
118 
119 } // namespace Gui
120 } // namespace SimShell
STL namespace.
virtual bool InternalIsClean() const =0
The result should be true only if THIS widget is in clean state.
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.
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.
Interface for HasUnsavedChanges.
void AddChild(ChildrenType::value_type &&v)
Add child.
void SetChildren(ChildrenType &&c)
Set children.
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.
virtual bool InternalSave()=0
Implementation should only save THIS widget.