-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrymodel.cpp
197 lines (181 loc) · 4.63 KB
/
entrymodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* Copyright (c) 2013 Georg Lippitsch
*
* This file is part of Aussackler.
*
* Aussackler is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Aussackler is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Aussackler. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
#include <QFont>
#include "entrymodel.h"
#include "entry.h"
#include "invest.h"
EntryModel::EntryModel(ASTransactionList * transactions, QObject * parent) :
QAbstractTableModel(parent),
ASTransactionSorter(transactions)
{
}
void EntryModel::transactionsChanged()
{
int rowsBefore = rows();
int n = sortoutTransactions();
if (n)
{
QModelIndex index;
beginInsertRows(index, rowsBefore, rowsBefore + n - 1);
endInsertRows();
}
}
int EntryModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid())
return 0;
return rows();
}
int EntryModel::columnCount(const QModelIndex& parent) const
{
if (parent.isValid())
return 0;
return 11;
}
QVariant EntryModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::FontRole)
{
if (index.row() >= 0)
{
ASAccountEntry * e = getSubsetList()[index.row()];
if (e->getOverwrittenBy() != NULL)
{
QFont f = QApplication::font();
f.setStrikeOut(true);
return f;
}
}
}
if (role != Qt::DisplayRole)
return QVariant();
ASAccountEntry * e = getSubsetList()[index.row()];
switch(index.column())
{
case 0:
return e->getDescription();
case 1:
return e->getDate();
case 2:
return e->getAmount();
case 3:
return e->getVatAmount();
case 4:
return e->getAmount() + e->getVatAmount();
case 5:
return QString::number(e->getChargePercentage()) + " %";
case 6:
if (e->getAccount())
return e->getAccount()->getDescription();
else
return "";
case 7:
if (e->getCategory())
{
return e->getCategory()->getDescription();
}
else
{
if (dynamic_cast<ASInvestEntry*>(e))
{
return tr("(Investition)");
}
else
{
return "";
}
}
case 8:
if (e->getVatCategories().count() > 0 &&
e->getVatCategories()[0])
{
return e->getVatCategories()[0]->getDescription();
}
else
{
return "-";
}
case 9:
if (e->getDocument())
return e->getDocument()->getLatest()->getDescription();
else
return "";
case 10:
if (e->getDocument())
{
const ASDocument * d =
dynamic_cast<const ASDocument*>(e->getDocument()->getLatest());
if (d)
{
return d->getDocumentDate().toString(tr("dd.MM.yyyy"));
}
}
return "";
}
return QVariant();
}
QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole || section < 0)
return QVariant();
if (orientation == Qt::Horizontal) {
switch(section)
{
case 0:
return tr("Beschreibung");
case 1:
return tr("Buchungsdatum");
case 2:
return tr("Betrag Netto");
case 3:
return tr("Ust. Betrag");
case 4:
return tr("Betrag Brutto");
case 5:
return tr("Betr. Anteil");
case 6:
return tr("Konto");
case 7:
return tr("Kategorie");
case 8:
return tr("Ust. Kategorie");
case 9:
return tr("Beleg");
case 10:
return tr("Belegdatum");
default:
return QVariant();
}
}
else if (orientation == Qt::Vertical)
{
return section + 1;
}
else
{
return QVariant();
}
}
ASAccountEntry * EntryModel::getEntry(const QModelIndex& index)
{
return getTransactionByRow(index.row());
}