VPTissue Reference Manual
PTreeContainer.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 "PTreeContainer.h"
21 
22 #include "MyDockWidget.h"
23 #include "PTreeEditorWindow.h"
24 #include "PTreeMenu.h"
25 
26 using namespace std;
27 using namespace boost::property_tree;
28 
29 namespace SimShell {
30 namespace Gui {
31 
32 PTreeContainer::PTreeContainer(QString const & title, QWidget* parent)
33  : QWidget(parent), HasUnsavedChanges(title.toStdString()), m_opened(false), m_title(title)
34 {
35  m_window = new PTreeEditorWindow();
36  m_window->setWindowTitle(m_title);
37  m_dock = new MyDockWidget(nullptr);
38  m_dock->setWindowTitle(m_title);
39  m_dock->setWidget(m_window);
40  m_menu = new PTreeMenu(m_title, QString(), nullptr);
41 
42  connect(m_menu, SIGNAL(ItemTriggered(QString const &)), this, SLOT(OpenPath(QString const &)));
43  connect(m_window, SIGNAL(ApplyTriggered(boost::property_tree::ptree const &)), this, SLOT(RefreshMenu(boost::property_tree::ptree const &)));
44  connect(m_window, SIGNAL(ApplyTriggered(boost::property_tree::ptree const &)), this, SIGNAL(Applied(boost::property_tree::ptree const &)));
45  connect(m_window, SIGNAL(StatusChanged(QString const &)), this, SIGNAL(StatusChanged(QString const &)));
46 
47  SetChildren({
48  m_window,
49  m_menu
50  });
51 }
52 
53 PTreeContainer::~PTreeContainer()
54 {
55  delete m_window;
56  delete m_dock;
57  delete m_menu;
58 }
59 
60 QDockWidget* PTreeContainer::GetDock() const
61 {
62  return m_dock;
63 }
64 
65 std::string PTreeContainer::GetEditPath() const
66 {
67  return m_window->GetEditPath();
68 }
69 
70 
71 PTreeMenu* PTreeContainer::GetMenu() const {
72  return m_menu;
73 }
74 
75 ptree PTreeContainer::GetPTreeState() const
76 {
77  ptree result;
78  result.put_child("editor_window", m_window->GetPTreeState());
79  result.put_child("dock", m_dock->GetPTreeState());
80  return result;
81 }
82 
83 void PTreeContainer::InternalForceClose()
84 {
85  m_opened = false;
86  m_dock->setWindowTitle(m_title);
87 }
88 
89 bool PTreeContainer::InternalIsClean() const
90 {
91  return true;
92 }
93 
94 bool PTreeContainer::InternalSave()
95 {
96  return true;
97 }
98 
99 bool PTreeContainer::IsOpened() const
100 {
101  return m_opened;
102 }
103 
104 bool PTreeContainer::Open(boost::property_tree::ptree const & pt, QString const & edit_path)
105 {
106  if (m_window->OpenPTree(pt, edit_path))
107  {
108  m_menu->OpenPTree(pt);
109  m_dock->setWindowTitle(m_title + ": " + edit_path);
110  m_opened = true;
111  return true;
112  }
113  return false;
114 }
115 
116 void PTreeContainer::OpenPath(QString const & path)
117 {
118  m_window->OpenPath(path);
119  m_dock->show();
120  m_dock->setWindowTitle(m_title + ": " + path);
121 }
122 
123 void PTreeContainer::Redo() {
124  m_window->Redo();
125 }
126 
127 void PTreeContainer::RefreshMenu(boost::property_tree::ptree const & pt)
128 {
129  m_menu->OpenPTree(pt);
130 }
131 
132 void PTreeContainer::SetPTreeState(const ptree& state)
133 {
134  auto editor_window_state = state.get_child_optional("editor_window");
135  if (editor_window_state)
136  m_window->SetPTreeState(editor_window_state.get());
137 
138  auto dock_state = state.get_child_optional("dock");
139  if (dock_state) {
140  m_dock->SetPTreeState(dock_state.get());
141  }
142 }
143 
144 void PTreeContainer::SetOnlyEditData(bool b)
145 {
146  m_window->SetOnlyEditData(b);
147 }
148 
149 void PTreeContainer::Undo() {
150  m_window->Undo();
151 }
152 
153 } // namespace Gui
154 } // namespace SimShell
STL namespace.
Interface for PTreeMenu.
see the online Qt documentation
Interface for PTreeEditorWindow.
A menu reflecting the structure of a ptree.
Definition: PTreeMenu.h:39
see the online Qt documentation
bool OpenPTree(boost::property_tree::ptree const &pt, int depth=-1)
Open a ptree.
Definition: PTreeMenu.cpp:82
Header for MyDockWidget.
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
Interface for PTreeContainer.