20 #include "FdModelJournal.hpp"
21 #include "FdItemJournal.hpp"
22 #include "FdCommandsJournal.hpp"
23 #include "FdModelCoa.hpp"
24 #include "FdItemCoa.hpp"
25 #include "../gui/FdSubWindow.hpp"
31 QAbstractTableModel(0), mSubwindow(parent)
40 QAbstractTableModel(0), mSubwindow(parent)
42 mEntries = QList<FdItemJournal_p>();
43 QDomElement entry = journal.firstChildElement();
44 while(!entry.isNull())
47 entry = entry.nextSiblingElement();
56 connect(
mStack, SIGNAL(cleanChanged(
bool)),
mSubwindow, SLOT(cleanStateChanged(
bool)));
63 case JournalDate:
return entry->date();
64 case JournalObject:
return entry->object();
65 case JournalLabel:
return entry->label();
67 if(!entry->debit().isNull())
68 return entry->debit()->id();
70 case JournalDebitLabel:
71 if(!entry->debit().isNull())
72 return entry->debit()->label();
75 if(!entry->credit().isNull())
76 return entry->credit()->id();
78 case JournalCreditLabel:
79 if(!entry->credit().isNull())
80 return entry->credit()->label();
82 case JournalAmount:
return entry->amount();
92 if(role == ValidityRole)
93 return mEntries[index.row()]->isValid();
94 if(role == Qt::TextAlignmentRole && index.column() == JournalAmount)
95 return Qt::AlignRight;
96 if (role != Qt::DisplayRole && role != Qt::EditRole)
99 return data(
mEntries[index.row()], JournalColumn(index.column()));
106 int columnEnd = column;
110 entry->setDate(value.toDate());
113 entry->setObject(value.toString());
116 entry->setLabel(value.toString());
120 columnEnd = JournalDebitLabel;
122 case JournalDebitLabel:
124 column = JournalDebitId;
126 case JournalCreditId:
128 columnEnd = JournalCreditLabel;
130 case JournalCreditLabel:
132 column = JournalCreditId;
135 entry->setAmount(value.toDouble());
139 emit(dataChanged(index(row, column), index(row, columnEnd)));
153 if(!index.isValid() || role != Qt::EditRole)
156 if(value ==
data(index, Qt::DisplayRole))
159 int column = index.column();
167 case JournalCreditId:
171 case JournalDebitLabel:
174 column = JournalDebitId;
177 case JournalCreditLabel:
180 column = JournalCreditId;
188 FdItemJournal_p entry =
mEntries.at(index.row());
190 if(column == JournalLabel)
192 FdItemJournal_p lastEntry =
lastEntryByLabel(value.toString(), index.row()-1);
193 if(!lastEntry.isNull())
195 QUndoCommand* copyEntry =
new QUndoCommand();
196 copyEntry->setText(QObject::tr(
"copy entry",
"Will appear like this : Undo/Redo copy entry."));
197 new FdJournalSetData(
this, entry, JournalDebitId, lastEntry->debit()->id(), copyEntry);
198 new FdJournalSetData(
this, entry, JournalCreditId, lastEntry->credit()->id(), copyEntry);
211 if(role == Qt::DisplayRole)
213 if (orientation == Qt::Horizontal)
217 case JournalDate:
return tr(
"Date",
"Journal column header.");
218 case JournalObject:
return tr(
"Object",
"Journal column header.");
219 case JournalLabel:
return tr(
"Label",
"Journal column header.");
220 case JournalDebitId:
return tr(
"Debit",
"Journal column header.");
221 case JournalDebitLabel:
return tr(
"Debit account",
"Journal column header.");
222 case JournalCreditId:
return tr(
"Credit",
"Journal column header.");
223 case JournalCreditLabel:
return tr(
"Credit account",
"Journal column header.");
224 case JournalAmount:
return tr(
"Amount",
"Journal column header.");
237 return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
244 beginRemoveRows(parent, row, row+count-1);
245 for(
int i = 0; i < count; ++i)
260 return JournalColumnCount;
270 int count = entries.size();
271 beginInsertRows(QModelIndex(), row, row+count-1);
273 for(
int i = 0; i < count; ++i)
275 account = entries[i]->debit();
277 entries[i]->setDebit(FdItemCoa_p(0));
279 account = entries[i]->credit();
281 entries[i]->setCredit(FdItemCoa_p(0));
290 for(
int i = 0; i < entries.size(); ++i)
291 removeRow(
mEntries.indexOf(entries[i]));
299 for(
int i = 0; i <
mEntries.size(); ++i)
305 return QModelIndex();
313 return mStack->createRedoAction(
this);
321 return mStack->createUndoAction(
this);
334 QString label =
mEntries[i]->label();
335 if(!labels.contains(label))
354 for(
int i = row; i >= 0; --i)
360 return FdItemJournal_p(0);
368 QModelIndexList results;
371 if(
mEntries[i]->label().contains(text, Qt::CaseInsensitive) ||
mEntries[i]->amount() == text.toDouble())
372 results << index(i, 0);
382 FdItemJournal_p entry =
mEntries[index.row()];
383 if(index.column() == JournalDebitId || index.column() == JournalDebitLabel)
384 return entry->debit();
385 else if (index.column() == JournalCreditId || index.column() == JournalCreditLabel)
386 return entry->credit();
388 return FdItemCoa_p(0);
396 QList<FdItemJournal_p> entries;
397 for(
int i = 0; i <
mEntries.size(); ++i)
433 for(
int i = 0; i <
mEntries.size(); ++i)
444 QDomElement journal = document.createElement(
"Journal");
445 for(
int i = 0; i <
mEntries.size(); ++i)
449 QDomElement entry =
mEntries[i]->toXml(document);
450 journal.appendChild(entry);
467 if(selected.isValid())
468 row = selected.row()+1;
478 FdItemJournal_p item = FdItemJournal_p(
new FdItemJournal(date));
480 return index(row, JournalDate);
488 QList<FdItemJournal_p> entries;
489 QList<FdItemJournal_p> toDelete;
490 for(
int i = 0; i < rows.size(); ++i)
518 for(
int i = 0; i <
rowCount()-1; ++i)
537 int row = selected.row();
538 if(selected.row() != 0)
547 for(
int i = 0; i <
mEntries.size(); ++i)
551 emit(
error(index(i,0)));