VPTissue Reference Manual
PTreeContainerPreferencesObserver.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  */
21 #include <QMessageBox>
22 
23 namespace SimShell {
24 namespace Gui {
25 
26 PTreeContainerPreferencesObserver::PTreeContainerPreferencesObserver(QString const & title, QWidget* parent)
27  : PTreeContainer(title, parent) {}
28 
30 {
31 }
32 
34 {
35  if (!IsClean()) {
36  // TODO: (extremely low priority since this case will never occur) Make it possible for the user to save his unsaved changes elsewhere.
37  if (QMessageBox::warning(this, "Preferences updated",
38  "Another entity has updated the preferences contained in this window to "
39  "a newer version. You have unsaved changes. Do you want to discard them "
40  "and use the most recent version, or keep your changes and ignore the"
41  "newer version?",
42  QMessageBox::Discard | QMessageBox::Ignore, QMessageBox::Discard)
43  == QMessageBox::Ignore)
44  {
45  return;
46  }
47  }
48 
49  auto state = GetPTreeState();
50  ForceClose();
51  Open(e.GetPreferences());
52  SetPTreeState(state);
53 }
54 
55 } // namespace Gui
56 } // namespace SimShell
57 
Event used to inform some observer that preferences have changed.
const boost::property_tree::ptree & GetPreferences() const
Get preferences.
Interface for PTreeContainerPreferencesObserver.
bool Open(boost::property_tree::ptree const &pt, QString const &edit_path="")
Open ptree with given edit path.
void Update(const Ws::Event::PreferencesChanged &)
Call this method to update the maintained ptree.
void ForceClose()
Force this object and its children to go back to unopened state so it can be safely deleted...
see the online Qt documentation
virtual boost::property_tree::ptree GetPTreeState() const
virtual void SetPTreeState(const boost::property_tree::ptree &)
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32