FreeDebks  1.0.3
 All Classes Files Functions Variables Friends Pages
FdModelJournal.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 FDMODELJOURNAL_HPP
21 #define FDMODELJOURNAL_HPP
22 
23 #include <QAbstractTableModel>
24 #include <QUndoStack>
25 #include <QtXml>
26 
27 #include "dataDefinitions.hpp"
28 
30 
37 class FdModelJournal : public QAbstractTableModel
38 {
39 Q_OBJECT
40 
41 friend class FdJournalSetData;
42 friend class FdJournalRemove;
43 
44 protected:
45  QUndoStack* mStack;
46 
47 private:
49  QList<FdItemJournal_p> mEntries;
50  void init();
51 
52 public:
53  explicit FdModelJournal(FdSubWindow* parent);
54  FdModelJournal(FdSubWindow* parent, QDomElement& journal);
55  QVariant data(const FdItemJournal_p entry, JournalColumn column) const;
56  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
57  void setData(FdItemJournal_p entry, JournalColumn column, const QVariant &value);
58  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
59  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
60  Qt::ItemFlags flags(const QModelIndex &index) const;
61  bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
62  int rowCount(const QModelIndex &parent = QModelIndex()) const;
63  int columnCount(const QModelIndex &parent = QModelIndex()) const;
64  void insertEntry(FdItemJournal_p entry, int row);
65  void insertEntries(QList<FdItemJournal_p> entries, int row);
66  void removeEntries(QList<FdItemJournal_p> entries);
67  QModelIndex itemIndex(FdItemJournal_p entry);
68  QAction* redo();
69  QAction* undo();
70  QStringList labels() const;
71  FdItemJournal_p lastEntryByLabel(QString label) const;
72  FdItemJournal_p lastEntryByLabel(QString label, int row) const;
73  QModelIndexList entryByPartialText(QString text) const;
74  FdItemCoa_p selectedAccount(const QModelIndex& index) const;
75  QList<FdItemJournal_p> accountEntries(FdItemCoa_p account) const;
76  QDate getMinDate();
77  QDate getMaxDate();
78  bool isUsed(FdItemCoa_p account) const;
79  QDomElement toXml(QDomDocument& document) const;
80 
81 signals:
82  void error(const QModelIndex& index);
83 
84 public slots:
85  QModelIndex addEntry(const QModelIndex& selected = QModelIndex());
86  void removeSelected(const QList<int>& rows);
87  void orderByDate();
88  void copyFromPreviousLine(const QModelIndex& selected);
89  bool recomputeAccounts();
90 
91 };
92 
93 #endif // FDMODELJOURNAL_HPP