22 #include <boost/property_tree/ptree.hpp>
27 using boost::property_tree::ptree;
30 QVariant
const & ov, QVariant
const & nv)
31 : model(m), item(it), index(in), old_value(ov), new_value(nv)
36 PTreeModel::EditKeyCommand::~EditKeyCommand()
42 item->key = old_value;
43 emit model->dataChanged(index, index);
48 item->key = new_value;
49 emit model->dataChanged(index, index);
53 QVariant
const & ov, QVariant
const & nv)
54 : model(m), item(it), index(in), old_value(ov), new_value(nv)
59 PTreeModel::EditDataCommand::~EditDataCommand()
65 item->data = old_value;
66 emit model->dataChanged(index, index);
71 item->data = new_value;
72 emit model->dataChanged(index, index);
76 : model(m), parent(p), parent_index(pi), row(r), count(c), undone(false)
78 items =
new Item*[count];
79 for (
int i = 0; i < count; i++) {
80 items[i] =
new Item(parent,
"(empty)", i + row);
87 QModelIndex
const &
pi,
int r, ptree
const & tree)
88 : model(m), parent(p), parent_index(pi), row(r), count(tree.size()), undone(false)
90 items =
new Item*[count];
92 for (ptree::const_iterator it = tree.begin(); it != tree.end(); it++) {
93 items[i] =
new Item(parent, it->first.c_str(), i + row);
94 items[i]->Load(it->second);
100 PTreeModel::InsertRowsCommand::~InsertRowsCommand()
104 for (
int i = 0; i < count; i++) {
113 model->beginRemoveRows(parent_index, row, row + count - 1);
114 for (
int i = 0; i < count; i++) {
115 parent->RemoveChild(row);
118 model->endRemoveRows();
124 model->beginInsertRows(parent_index, row, row + count - 1);
125 for (
int i = 0; i < count; i++) {
126 parent->InsertChild(row + i, items[i]);
128 model->endInsertRows();
132 : model(m), parent(p), parent_index(pi), row(r), count(c), undone(false)
134 items =
new Item*[count];
135 for (
int i = 0; i < count; i++) {
136 items[i] = parent->GetChild(i + row);
141 PTreeModel::RemoveRowsCommand::~RemoveRowsCommand()
145 for (
int i = 0; i < count; i++) {
155 model->beginInsertRows(parent_index, row, row + count - 1);
156 for (
int i = 0; i < count; i++) {
157 parent->InsertChild(row + i, items[i]);
159 model->endInsertRows();
164 model->beginRemoveRows(parent_index, row, row + count - 1);
165 for (
int i = 0; i < count; i++) {
166 parent->RemoveChild(row);
169 model->endRemoveRows();
173 int r, Item* np, QModelIndex
const & npi,
int nr,
int c)
174 : model(m), old_parent(op), new_parent(np), old_parent_index(opi), new_parent_index(npi),
175 old_row(r), new_row(nr), count(c)
177 items =
new Item*[count];
178 for (
int i = 0; i < count; i++) {
179 items[i] = old_parent->GetChild(old_row + i);
184 PTreeModel::MoveRowsCommand::~MoveRowsCommand()
192 model->beginRemoveRows(new_parent_index, new_row, new_row + count - 1);
193 for (
int i = 0; i < count; i++) {
194 new_parent->RemoveChild(new_row + i);
196 model->endRemoveRows();
198 model->beginInsertRows(old_parent_index, old_row, old_row + count - 1);
199 for (
int i = 0; i < count; i++) {
200 items[i]->row = old_row + i;
201 old_parent->InsertChild(old_row + i, items[i]);
203 model->endInsertRows();
210 model->beginRemoveRows(old_parent_index, old_row, old_row + count - 1);
211 for (
int i = 0; i < count; i++) {
212 old_parent->RemoveChild(old_row + i);
214 model->endRemoveRows();
216 model->beginInsertRows(new_parent_index, new_row, new_row + count - 1);
217 for (
int i = 0; i < count; i++) {
218 items[i]->row = new_row + i;
219 new_parent->InsertChild(new_row + i, items[i]);
221 model->endInsertRows();
InsertRowsCommand(PTreeModel *m, Item *parent, QModelIndex const &parent_index, int row, int count)
Interface for PTree undo commands.
RemoveRowsCommand(PTreeModel *m, Item *parent, QModelIndex const &parent_index, int row, int count)
virtual void undo()
See QUndoCommand documentation for details.
EditKeyCommand(PTreeModel *m, Item *i, QModelIndex const &x, QVariant const &old_value, QVariant const &new_value)
virtual void redo()
See QUndoCommand documentation for details.
Qt model reflecting hierarchical structure of a ptree.
virtual void undo()
See QUndoCommand documentation for details.
virtual void redo()
See QUndoCommand documentation for details.
virtual void redo()
See QUndoCommand documentation for details.
virtual void undo()
See QUndoCommand documentation for details.
virtual void redo()
See QUndoCommand documentation for details.
virtual void undo()
See QUndoCommand documentation for details.
MoveRowsCommand(PTreeModel *m, Item *old_parent, QModelIndex const &old_parent_index, int old_row, Item *new_parent, QModelIndex const &new_parent_index, int new_row, int count)
EditDataCommand(PTreeModel *m, Item *i, QModelIndex const &x, QVariant const &old_value, QVariant const &new_value)
virtual void undo()
See QUndoCommand documentation for details.
Namespace for generic graphical shell for simulators.
virtual void redo()
See QUndoCommand documentation for details.
constexpr double pi()
Math constant pi.