20 #include "FdViewAccountSummary.hpp"
21 #include "../../data/FdModelJournal.hpp"
22 #include "../../data/FdItemCoa.hpp"
23 #include "../../data/FdItemJournal.hpp"
24 #include "../FdMainWindow.hpp"
25 #include "../FdSubWindow.hpp"
28 QTableView(0), mSubwindow(parent), mAccount(account)
30 setProperty(
"TabRole", TabRole(AccountRole));
32 connect(
this, SIGNAL(refresh()), mModel, SLOT(refresh()));
34 setSelectionBehavior(QAbstractItemView::SelectRows);
35 QHeaderView* header = verticalHeader();
36 header->setDefaultSectionSize(16);
37 setVerticalHeader(header);
38 setEditTriggers(NoEditTriggers);
40 setAlternatingRowColors(
true);
43 settings.beginGroup(
"ViewAccountSummary");
44 setColumnWidth(AccountDate, settings.value(
"date", 70).toInt());
45 setColumnWidth(AccountLabel, settings.value(
"label", 70).toInt());
46 setColumnWidth(AccountCounterpart, settings.value(
"counterpart", 70).toInt());
47 setColumnWidth(AccountDebit, settings.value(
"debit", 70).toInt());
48 setColumnWidth(AccountCredit, settings.value(
"credit", 70).toInt());
50 horizontalHeader()->setResizeMode(AccountBalance, QHeaderView::Stretch);
53 setItemDelegate(mDelegate);
55 setContextMenuPolicy(Qt::CustomContextMenu);
56 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint&)),
this, SLOT(contextMenu(
const QPoint&)));
58 mSearchTimer =
new QTimer();
59 mSearchTimer->setInterval(qApp->keyboardInputInterval());
60 mSearchTimer->setSingleShot(
true);
61 connect(mSearchTimer, SIGNAL(timeout()),
this, SLOT(searchTimeout()));
69 if(event->button() == Qt::LeftButton && !(indexAt(event->pos()).isValid()))
70 setCurrentIndex(QModelIndex());
83 mainWindow->setDockText(tr(
"Searched string : %1",
"Text displayed in the dock widget while keyboardsearching in views. The argument is the user input string to search.").arg(
mSearchText));
89 const int rows = model()->rowCount();
90 bool subtitlePrinted =
false;
91 bool headerPrinted =
false;
94 dateHeader.
width = 0.08*area.width();
95 dateHeader.text = tr(
"Date",
"Accounts summaries column header on printed pages.");
96 dateHeader.alignement = Qt::AlignLeft;
97 dateHeader.color = Qt::black;
100 labelHeader.
width = 0.36*area.width();
101 labelHeader.text = tr(
"Label",
"Accounts summaries column header on printed pages.");
102 labelHeader.alignement = Qt::AlignLeft;
103 labelHeader.color = Qt::black;
106 counterpartHeader.
width = 0.3*area.width();
107 counterpartHeader.text = tr(
"Counterpart",
"Accounts summaries column header on printed pages.");
108 counterpartHeader.alignement = Qt::AlignLeft;
109 counterpartHeader.color = Qt::black;
112 debitHeader.
width = 0.08*area.width();
113 debitHeader.text = tr(
"Debit",
"Accounts summaries column header on printed pages.");
114 debitHeader.alignement = Qt::AlignRight;
115 debitHeader.color = Qt::black;
118 creditHeader.
width = 0.08*area.width();
119 creditHeader.text = tr(
"Credit",
"Accounts summaries column header on printed pages.");
120 creditHeader.alignement = Qt::AlignRight;
121 creditHeader.color = Qt::black;
124 balanceHeader.
width = 0.1*area.width();
125 balanceHeader.text = tr(
"Balance",
"Accounts summaries column header on printed pages.");
126 balanceHeader.alignement = Qt::AlignRight;
127 balanceHeader.color = Qt::black;
129 QList<tableElement*> header;
130 header << &dateHeader << &labelHeader << &counterpartHeader << &debitHeader << &creditHeader << &balanceHeader;
138 QList<tableElement*> row;
139 row << &date << &label << &counterpart << &debit << &credit << &balance;
143 QString subtitle =
mAccount->displayLabel();
147 int neededHeight = 350 + (rows+1)*185;
149 if(pageNumber && neededHeight > remainingArea.height() && neededHeight < area.height())
150 remainingArea.setHeight(0);
152 else if(pageNumber && neededHeight > remainingArea.height() && remainingArea.height() < 720)
153 remainingArea.setHeight(0);
155 for(
int i = 0; i < rows; ++i)
158 if(!remainingArea.height() || !pageNumber)
160 if(!remainingArea.height())
161 remainingArea = area;
170 subwindow->
printHeaderFooter(printer, painter, tr(
"Accounts summaries",
"Text displayed on accounts summaries printed pages footer.")+
" - "+subtitle, pageNumber);
171 headerPrinted =
false;
177 subtitlePrinted =
true;
183 headerPrinted =
true;
186 index = model()->index(i, AccountDate);
189 index = model()->index(i, AccountLabel);
190 label.
text = model()->data(index).toString();
192 index = model()->index(i, AccountCounterpart);
193 counterpart.
text = model()->data(index).toString();
195 index = model()->index(i, AccountDebit);
198 index = model()->index(i, AccountCredit);
201 index = model()->index(i, AccountBalance);
203 if(balance.text.toDouble() < 0)
204 balance.color = Qt::red;
206 balance.color = Qt::black;
212 if(remainingArea.height())
213 remainingArea.setRect(area.x(), remainingArea.y()+300, area.width(), remainingArea.height()-300);
237 QModelIndexList indexes = selectedIndexes();
239 for(
int i = 0; i < indexes.size(); ++i)
241 if(indexes[i].column() == 0)
242 rows << indexes[i].row();
250 if(!account.isNull())
262 settings.beginGroup(
"ViewAccountSummary");
263 settings.setValue(
"date", columnWidth(AccountDate));
264 settings.setValue(
"label", columnWidth(AccountLabel));
265 settings.setValue(
"counterpart", columnWidth(AccountCounterpart));
266 settings.setValue(
"debit", columnWidth(AccountDebit));
267 settings.setValue(
"credit", columnWidth(AccountCredit));
278 if(current.isValid() && current.row())
300 QModelIndex index = currentIndex();
304 QMenu* menu =
new QMenu();
305 menu->addActions(
mainWindow->getContextMenuActionsAccount());
306 menu->exec(mapToGlobal(position));
323 mainWindow->setDockText(tr(
"Sorry, no matches found.",
"No matches found when searching item by text."));
344 mainWindow->setDockText(tr(
"Sorry, no matches found.",
"No matches found when searching item by text."));
353 QAbstractTableModel(0), mSubwindow(subwindow), mAccount(account)
361 if(role == Qt::TextAlignmentRole && (index.column() == AccountDebit || index.column() == AccountCredit || index.column() == AccountBalance))
362 return Qt::AlignRight;
363 if (role != Qt::DisplayRole && role != Qt::EditRole)
366 int column = index.column();
367 FdItemJournal_p entry =
mEntries[index.row()];
373 case AccountLabel:
return tr(
"Initial balance",
"Initial balance of an account, entry label for accounts summaries first row.");
375 if(
mAccount->signature() == PlusMinus)
380 if(
mAccount->signature() == MinusPlus)
394 case AccountDate:
return entry->date();
395 case AccountLabel:
return entry->label();
396 case AccountCounterpart:
398 return entry->credit()->displayLabel();
400 return entry->debit()->displayLabel();
403 return entry->amount();
408 return entry->amount();
412 double balance =
data(this->index(index.row()-1, index.column())).toDouble();
414 return balance + entry->amount()*
mAccount->signature();
416 return balance - entry->amount()*
mAccount->signature();
425 if(role == Qt::DisplayRole)
427 if (orientation == Qt::Horizontal)
431 case AccountDate:
return tr(
"Date",
"Accounts summaries view column header.");
432 case AccountLabel:
return tr(
"Label",
"Accounts summaries view column header.");
433 case AccountCounterpart:
return tr(
"Counterpart",
"Accounts summaries view column header.");
434 case AccountDebit:
return tr(
"Debit",
"Accounts summaries view column header.");
435 case AccountCredit:
return tr(
"Credit",
"Accounts summaries view column header.");
436 case AccountBalance:
return tr(
"Balance",
"Accounts summaries view column header.");
453 return AccountColumnCount;
461 QModelIndexList results;
464 if(
mEntries[i]->label().contains(text, Qt::CaseInsensitive) ||
mEntries[i]->amount() == text.toDouble())
465 results << index(i, 0);
474 beginRemoveRows(QModelIndex(), 0,
rowCount()-1);
480 entries.prepend(FdItemJournal_p(0));
481 beginInsertRows(QModelIndex(), 0, entries.size()-1);
492 if(!
mAccount.isNull() && index.row())
494 FdItemJournal_p entry = mEntries[index.row()];
496 return entry->credit();
498 return entry->debit();
501 return FdItemCoa_p(0);
511 return mEntries[index.row()];
514 return FdItemJournal_p(0);
518 QStyledItemDelegate(0), mModel(model), mSubwindow(subwindow)
532 if(value.type() == QVariant::Date)
533 return value.toDate().toString(Qt::SystemLocaleShortDate);
534 else if(value.type() == QVariant::Double)
535 return QLocale::system().toString(value.toDouble(),
'f', 2);
545 QStyleOptionViewItem viewOption(option);
547 if(index.column() == AccountBalance &&
mModel->
data(index).toDouble() < 0)
548 viewOption.palette.setColor(QPalette::Text, Qt::red);