VPTissue Reference Manual
PTreeModel.h
Go to the documentation of this file.
1 #ifndef PTREEMODEL_H_INCLUDED
2 #define PTREEMODEL_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include <boost/property_tree/ptree_fwd.hpp>
23 #include <QAbstractItemModel>
24 #include <vector>
25 
26 class QUndoStack;
27 
28 namespace SimShell {
29 namespace Gui {
30 
38 {
39  Q_OBJECT
40 public:
42  PTreeModel(boost::property_tree::ptree const& tree, QObject* parent = 0);
43 
45  PTreeModel(PTreeModel const&) =delete;
46 
48  PTreeModel & operator=(PTreeModel const&);
49 
51  virtual ~PTreeModel();
52 
58  bool IsOnlyEditData() const;
59 
68  bool MoveRow(int old_row, QModelIndex const& old_parent, int new_row, QModelIndex const& new_parent);
69 
79  bool MoveRows(int old_row, QModelIndex const& old_parent, int new_row, QModelIndex const& new_parent, int count);
80 
85  void SetOnlyEditData(bool);
86 
93  void SetUndoStack(QUndoStack*);
94 
95  // Notice: Load() method is gone. If you want to load a different ptree,
96  // simply construct a new model!
97 
101  boost::property_tree::ptree Store() const;
102 
103  // Implementation of QAbstractItemModel, see QAbstractItemModel documentation for details.
104  virtual int columnCount(QModelIndex const& parent = QModelIndex()) const;
105  virtual QVariant data(QModelIndex const& index, int role = Qt::DisplayRole) const;
106  virtual Qt::ItemFlags flags(QModelIndex const& index) const;
107  virtual QVariant headerData(int section, Qt::Orientation, int role) const;
108  virtual QModelIndex index(int row, int column, QModelIndex const& parent = QModelIndex()) const;
109  virtual bool insertRow(int row, QModelIndex const& parent = QModelIndex());
110  virtual bool insertRows(int row, int count, QModelIndex const& parent = QModelIndex());
111  virtual bool removeRow(int row, QModelIndex const& parent = QModelIndex());
112  virtual bool removeRows(int row, int count, QModelIndex const& parent = QModelIndex());
113  virtual QModelIndex parent(QModelIndex const& index) const;
114  virtual int rowCount(QModelIndex const& parent = QModelIndex()) const;
115  virtual bool setData(QModelIndex const& index, QVariant const& value, int role = Qt::EditRole);
116  virtual Qt::DropActions supportedDragActions() const;
117  virtual Qt::DropActions supportedDropActions() const;
118  virtual QStringList mimeTypes() const;
119  virtual QMimeData* mimeData(QModelIndexList const& indexes) const;
120  virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, QModelIndex const& parent);
121 
122 private:
126  struct Item
127  {
128  public:
129  Item(Item* parent = 0, QVariant const& key = QVariant(), int row = 0);
130  Item(Item const&);
131  Item& operator=(Item const&);
132  ~Item();
133 
135  Item* GetParent();
136 
138  Item* GetChild(unsigned int i);
139 
141  Item const* GetChild(unsigned int i) const;
142 
144  int GetChildrenCount() const;
145 
147  Item const* GetParent() const;
148 
150  void InsertChild(unsigned int row, Item*);
151 
156  void Load(boost::property_tree::ptree const& t);
157 
159  void RemoveChild(unsigned int row);
160 
165  boost::property_tree::ptree Store() const;
166 
167  QVariant key;
168  QVariant data;
169  QVariant background;
170  int row;
171 
172  private:
173  Item* parent; // read-only
174  std::vector<Item*> children; // use public methods!
175  };
176 
177  QUndoStack* undo_stack;
178  Item* root;
179  bool only_edit_data;
180 
181  class EditKeyCommand;
182  class EditDataCommand;
183  class InsertRowsCommand;
184  class RemoveRowsCommand;
185  class MoveRowsCommand;
186 };
187 
188 } // namespace
189 } // namespace
190 
191 #endif // end_of_inclde_guard
bool MoveRows(int old_row, QModelIndex const &old_parent, int new_row, QModelIndex const &new_parent, int count)
Moves a block of contagious rows from one place to another.
Definition: PTreeModel.cpp:250
see the online Qt documentation
Undo command that represents a single edit operation for a data value of PTreeModel.
boost::property_tree::ptree Store() const
Creates a new property tree from the current model state.
Definition: PTreeModel.cpp:399
PTreeModel(boost::property_tree::ptree const &tree, QObject *parent=0)
Constructs an empty PTreeModel.
bool MoveRow(int old_row, QModelIndex const &old_parent, int new_row, QModelIndex const &new_parent)
Moves a single row from one place to another.
Definition: PTreeModel.cpp:245
Undo command that represents a single move operation of rows inside a PTreeModel. ...
virtual ~PTreeModel()
Virtual destructor.
Definition: PTreeModel.cpp:55
Qt model reflecting hierarchical structure of a ptree.
Definition: PTreeModel.h:37
bool IsOnlyEditData() const
Test whether the "only edit data" option set.
Definition: PTreeModel.cpp:221
Undo command that represents a single insertion operation of rows into a PTreeModel.
void SetOnlyEditData(bool)
Set the "only edit values" option.
Definition: PTreeModel.cpp:389
Undo command that represents a single edit operation for a key value of PTreeModel.
see the online Qt documentation
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
Undo command that represents a single removal operation of rows from a PTreeModel.
void SetUndoStack(QUndoStack *)
Set this model to use a given undo stack.
Definition: PTreeModel.cpp:394