26 #include <QDialogButtonBox>
27 #include <QHeaderView>
29 #include <QPushButton>
31 #include <QVBoxLayout>
40 SaveChangesDialog::SaveChangesDialog(
const ptree& pt,
QWidget* parent)
43 auto layout =
new QVBoxLayout;
44 auto label =
new QLabel(
"The following windows contain unsaved changes:");
46 layout->addWidget(label);
48 m_model =
new CheckableTreeModel(pt, treeview);
49 treeview->setModel(m_model);
50 treeview->header()->hide();
51 layout->addWidget(treeview);
53 auto box =
new QDialogButtonBox(Qt::Horizontal,
this);
54 m_save_button = box->addButton(QDialogButtonBox::Save);
55 m_cancel_button = box->addButton(QDialogButtonBox::Cancel);
56 m_discard_button = box->addButton(QDialogButtonBox::Discard);
57 layout->addWidget(box);
59 connect(box, SIGNAL(clicked(QAbstractButton*)),
this, SLOT(SLOT_Clicked(QAbstractButton*)));
62 setWindowTitle(
"Save changes?");
65 void SaveChangesDialog::SLOT_Clicked(QAbstractButton* button)
67 if (button == m_save_button) {
69 }
else if (button == m_cancel_button) {
71 }
else if (button == m_discard_button) {
79 dummy.SetChildren({widget});
81 function<ptree(HasUnsavedChanges*)> work_recursive;
84 for (
auto child : *widget) {
85 if (child->IsOpened() && !child->IsClean()) {
87 child_pt.put(
"checked",
true);
88 child_pt.put_child(
"children", work_recursive(child));
89 result.put_child(child->GetTitle(), child_pt);
95 if (unsaved_tree.size())
100 switch (dialog.exec()) {
103 function<bool(const ptree&, HasUnsavedChanges*)> work_recursive;
105 auto pt_it = pt.begin();
106 auto i_it = i->
begin();
108 while (pt_it != pt.end())
110 auto& child_pt = pt_it->second;
111 auto checked = child_pt.get<
bool>(
"checked");
113 if (!(*i_it)->Save())
117 auto children_optional = child_pt.get_child_optional(
"children");
118 if (children_optional) {
119 if (!work_recursive(children_optional.get(), *i_it))
127 })(dialog.m_model->
ToPTree(), &dummy)) {
Dialog window that displays a tree of objects containing unsaved changes.
Dummy UnsavedChanges class.
ChildrenType::iterator begin()
Get iterator to first child.
void ForceClose()
Force this object and its children to go back to unopened state so it can be safely deleted...
CheckableTreeModel header.
Interface for HasUnsavedChanges.
Abstract class that represents the ability be in closed or opened state, and, if the latter...
boost::property_tree::ptree ToPTree()
Get checked/unchecked state of items, represented by a ptree of the form discussed in the constructor...
see the online Qt documentation
see the online Qt documentation
Namespace for generic graphical shell for simulators.
see the online Qt documentation
Interface for SaveChangesDialog.