FreeDebks  1.0.3
 All Classes Files Functions Variables Friends Pages
FdModelCoa.hpp
Go to the documentation of this file.
1 // --------------------------------------------------------------------
2 // Copyright © 2011-2013 Mathieu Schopfer
3 //
4 // This file is part of FreeDebks.
5 //
6 // FreeDebks is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // FreeDebks is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with FreeDebks. If not, see <http://www.gnu.org/licenses/>.
18 // --------------------------------------------------------------------
19 
20 #ifndef FDMODELCOA_HPP
21 #define FDMODELCOA_HPP
22 
23 #include <QAbstractItemModel>
24 #include <QUndoStack>
25 #include <QMimeData>
26 #include <QTextStream>
27 #include <QtXml>
28 
29 #include "dataDefinitions.hpp"
30 
32 
41 class FdModelCoa : public QAbstractItemModel
42 {
43 Q_OBJECT
44 
45 friend class FdCoaAddItem;
46 friend class FdCoaDragDrop;
47 friend class FdCoaSetData;
48 friend class FdCoaRemove;
49 
50 private:
57  FdItemCoa_p mRootItem;
62  QMap<qint32, FdItemCoa_p> mIndexes;
63  void init();
64 
65 protected:
66  QUndoStack* mStack;
67 
68 public:
69  explicit FdModelCoa(FdSubWindow* parent);
70  FdModelCoa(FdSubWindow* parent, QDomElement& coa);
71  FdModelCoa(FdSubWindow* parent, const FdModelCoa* model);
72  FdItemCoa_p getRootItem() const;
73  QVariant data(FdItemCoa_p item, CoaColumn column) const;
74  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
75  void setData(FdItemCoa_p, CoaColumn column, const QVariant &value);
76  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
77  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
78  Qt::ItemFlags flags(const QModelIndex &index) const;
79  Qt::DropActions supportedDragActions() const;
80  Qt::DropActions supportedDropActions() const;
81  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
82  QModelIndex index(FdItemCoa_p item) const;
83  QModelIndex index(FdItemCoa_p item, CoaColumn column) const;
84  QModelIndex parent(const QModelIndex &index) const;
85  QStringList mimeTypes() const;
86  QMimeData* mimeData(const QModelIndexList &indexes) const;
87  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
88  int rowCount(const QModelIndex &parent = QModelIndex()) const;
89  int columnCount(const QModelIndex &parent = QModelIndex()) const;
90  bool insertItem(FdItemCoa_p item, int row, FdItemCoa_p parent);
91  bool insertItems(QList<FdItemCoa_p> items, int row, FdItemCoa_p parent);
92  bool removeItem(FdItemCoa_p item, FdItemCoa_p parent);
93  void moveItem(FdItemCoa_p item, FdItemCoa_p parent, int row);
94  void orderItems(FdItemCoa_p parent = FdItemCoa_p(0));
95  FdItemCoa_p item(const QModelIndex &index) const;
96  QAction* redo();
97  QAction* undo();
98  bool idExists(QString id) const;
99  bool labelExists(QString label) const;
100  bool isAccountId(QString id) const;
101  bool isAccountLabel(QString label) const;
102  bool isRemovable(FdItemCoa_p item) const;
103  bool isRemovable(const QModelIndex& index) const;
104  QStringList accountsIds() const;
105  QStringList accountsLabels() const;
106  QList<FdItemCoa_p> accounts() const;
107  FdItemCoa_p itemById(QString id) const;
108  FdItemCoa_p itemByLabel(QString label) const;
109  QModelIndexList itemByPartialText(QString text) const;
110  QDomElement toXml(QDomDocument& document) const;
111 
112 public slots:
113  QModelIndex addItem(const QModelIndex& selected);
114  void removeSelected(QModelIndexList selected);
115  void recomputeBalances();
116 };
117 
118 #endif // FDMODELCOA_HPP