25 #include <QCloseEvent>
26 #include <QHeaderView>
28 #include <QMessageBox>
36 using boost::property_tree::ptree;
38 int const PTreeEditorWindow::g_column_width = 200;
45 m_treeview->SetOnlyEditData(m_only_edit_data);
46 setCentralWidget(m_treeview);
47 connect(m_treeview, SIGNAL(Edited()),
this, SLOT(Apply()));
48 connect(m_treeview, SIGNAL(StatusChanged(QString
const&)),
this, SIGNAL(StatusChanged(QString
const&)));
51 m_action_show_toolbar_main =
new QAction(
"Main Toolbar",
this);
54 QAction* action_find = m_treeview->GetFindDialogAction();
55 QAction* action_clear_highlight = m_treeview->GetClearHighlightAction();
56 QAction* action_undo = m_treeview->GetUndoAction();
57 QAction* action_redo = m_treeview->GetRedoAction();
58 QAction* action_cut = m_treeview->GetCutAction();
59 QAction* action_copy = m_treeview->GetCopyAction();
60 QAction* action_paste = m_treeview->GetPasteAction();
61 QAction* action_expand_all = m_treeview->GetExpandAllAction();
62 QAction* action_expand_none = m_treeview->GetExpandNoneAction();
64 m_action_show_toolbar_main->setCheckable(
true);
65 m_action_show_toolbar_main->setChecked(
true);
68 m_toolbar_main =
new QToolBar(
this);
69 m_toolbar_main->setToolButtonStyle(Qt::ToolButtonIconOnly);
70 m_toolbar_main->setMovable(
false);
71 m_toolbar_main->setWindowTitle(
"Main toolbar");
72 m_toolbar_main->toggleViewAction()->setEnabled(
false);
73 m_toolbar_main->setIconSize(QSize(16,16));
75 m_toolbar_main->addAction(action_undo);
76 m_toolbar_main->addAction(action_redo);
77 m_toolbar_main->addSeparator();
78 m_toolbar_main->addAction(action_cut);
79 m_toolbar_main->addAction(action_copy);
80 m_toolbar_main->addAction(action_paste);
81 m_toolbar_main->addSeparator();
82 m_toolbar_main->addAction(action_expand_all);
83 m_toolbar_main->addAction(action_expand_none);
84 m_toolbar_main->addSeparator();
85 m_toolbar_main->addAction(action_find);
86 m_toolbar_main->addAction(action_clear_highlight);
87 addToolBar(m_toolbar_main);
89 connect(m_action_show_toolbar_main, SIGNAL(toggled(
bool)), m_toolbar_main, SLOT(setVisible(
bool)));
94 if (m_edit_path.empty())
95 m_pt = m_model->
Store();
97 m_pt.put_child(m_edit_path, m_model->
Store());
110 result.put(
"edit_path", m_edit_path);
140 return m_only_edit_data;
153 if (edit_path.toStdString() == m_edit_path)
157 int result = QMessageBox::warning(
this, windowTitle(),
"Apply changes before opening different subtree?\n",
158 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No);
159 if (result == QMessageBox::Yes)
161 else if (result == QMessageBox::Cancel)
165 m_edit_path = edit_path.toStdString();
168 m_model =
new PTreeModel(m_pt.get_child(m_edit_path),
this);
171 m_treeview->header()->resizeSection(0, g_column_width);
181 m_edit_path = edit_path.toStdString();
182 m_model =
new PTreeModel(m_pt.get_child(m_edit_path),
this);
185 m_treeview->header()->resizeSection(0, g_column_width);
192 m_treeview->GetRedoAction()->trigger();
197 m_only_edit_data = b;
199 m_treeview->SetOnlyEditData(m_only_edit_data);
207 auto edit_path = state.get_optional<
string>(
"edit_path");
209 OpenPath(QString::fromStdString(edit_path.get()));
212 auto treeview = state.get_child_optional(
"treeview");
220 return QSize(320, 600);
225 m_treeview->GetUndoAction()->trigger();
std::string GetEditPath() const
Get the current edit path.
bool OpenPTree(const boost::property_tree::ptree &, QString const &edit_path="")
Set ptree to show in editor.
virtual bool InternalIsClean() const
boost::property_tree::ptree Store() const
Creates a new property tree from the current model state.
PTreeEditorWindow(QWidget *parent=nullptr)
void SetOnlyEditData(bool)
Set the "only edit values" option.
virtual boost::property_tree::ptree GetPTreeState() const
bool OpenPath(const QString &edit_path)
Set subtree to show in editor.
bool IsClean() const
Test whether the view's internal undo stack is in a clean state.
virtual void setModel(QAbstractItemModel *model)
Reimplemented from QTreeView, also enables/disables certain actions.
Qt model reflecting hierarchical structure of a ptree.
void Undo()
Undo last manipulation by the user.
void Redo()
Redo last manipulation by the user.
virtual bool IsOpened() const
void SetClean()
Set the view's internal undo stack's current state to be the clean state.
TreeView widget that presents an editable ptree to the user.
virtual QSize sizeHint() const
Reimplemented from QWidget.
bool IsOnlyEditData() const
Test whether the "only edit data" option is set.
see the online Qt documentation
Interface for PTreeEditorWindow.
virtual void InternalForceClose()
Abstract class that represents the ability be in closed or opened state, and, if the latter...
virtual void SetPTreeState(const boost::property_tree::ptree &)
void SetOnlyEditData(bool)
Set the "only edit values" option.
see the online Qt documentation
Interface for PTreeModel.
void ApplyTriggered(const boost::property_tree::ptree &pt)
Emitted when changes are applied to ptree.
bool SaveAndClose()
Try to save this object (and its children) and, if successful, close them all.
virtual void SetPTreeState(const boost::property_tree::ptree &)
Namespace for generic graphical shell for simulators.
virtual bool InternalSave()
void Apply()
Write changes to ptree object. Clean state is achieved as a side effect.
virtual boost::property_tree::ptree GetPTreeState() const