20 #include "FdViewJournal.hpp"
21 #include "../../data/FdModelJournal.hpp"
22 #include "../../data/FdModelCoa.hpp"
23 #include "../FdMainWindow.hpp"
24 #include "../FdSubWindow.hpp"
25 #include "../../data/FdItemCoa.hpp"
29 mModel = mSubwindow->journal();
32 connect(mModel, SIGNAL(error(QModelIndex)),
this, SLOT(setCurrentIndex(QModelIndex)));
34 setSelectionBehavior(QAbstractItemView::SelectRows);
35 setSelectionMode(QAbstractItemView::ExtendedSelection);
36 QHeaderView* header = verticalHeader();
37 header->setDefaultSectionSize(16);
38 setVerticalHeader(header);
39 setEditTriggers(DoubleClicked | EditKeyPressed);
41 setAlternatingRowColors(
true);
44 settings.beginGroup(
"ViewJournal");
45 setColumnWidth(JournalDate, settings.value(
"date", 70).toInt());
46 setColumnWidth(JournalObject, settings.value(
"object", 50).toInt());
47 setColumnWidth(JournalLabel, settings.value(
"label", 300).toInt());
48 setColumnWidth(JournalDebitId, settings.value(
"debitId", 50).toInt());
49 setColumnWidth(JournalCreditId, settings.value(
"debitLabel", 225).toInt());
50 setColumnWidth(JournalDebitLabel, settings.value(
"creditId", 50).toInt());
51 setColumnWidth(JournalCreditLabel, settings.value(
"creditLabel", 225).toInt());
53 horizontalHeader()->setResizeMode(JournalAmount, QHeaderView::Stretch);
56 setItemDelegate(mDelegate);
58 setContextMenuPolicy(Qt::CustomContextMenu);
59 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint&)),
this, SLOT(contextMenu(
const QPoint&)));
61 mSearchTimer =
new QTimer();
62 mSearchTimer->setInterval(qApp->keyboardInputInterval());
63 mSearchTimer->setSingleShot(
true);
64 connect(mSearchTimer, SIGNAL(timeout()),
this, SLOT(searchTimeout()));
74 if(event->button() == Qt::LeftButton && !(indexAt(event->pos()).isValid()))
85 if(cursorAction == QAbstractItemView::MoveNext)
87 if(state() == QAbstractItemView::EditingState)
90 QModelIndex index = currentIndex();
91 int col = index.column();
92 if(col == JournalLabel || col == JournalDebitId || col == JournalDebitLabel || col == JournalCreditId)
93 return mModel->index(index.row(), col+2);
94 if(index.column() == JournalColumnCount-1 && index.row() == model()->rowCount()-1)
97 else if(cursorAction == QAbstractItemView::MoveHome && modifiers == Qt::ControlModifier)
99 else if(cursorAction == QAbstractItemView::MoveEnd && modifiers == Qt::ControlModifier)
115 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));
120 if(currentIndex().isValid() && state() != QAbstractItemView::EditingState)
121 edit(currentIndex());
126 const int rows = model()->rowCount();
131 dateHeader.
width = 0.075*area.width();
132 dateHeader.text = tr(
"Date",
"Journal printed pages column header.");
133 dateHeader.alignement = Qt::AlignLeft;
134 dateHeader.color = Qt::black;
137 objectHeader.
width = 0.025*area.width();
138 objectHeader.text =
"";
139 objectHeader.alignement = Qt::AlignLeft;
140 objectHeader.color = Qt::black;
143 labelHeader.
width = 0.31*area.width();
144 labelHeader.text = tr(
"Label",
"Journal printed pages column header.");
145 labelHeader.alignement = Qt::AlignLeft;
146 labelHeader.color = Qt::black;
149 debitHeader.
width = 0.26*area.width();
150 debitHeader.text = tr(
"Debit account",
"Journal printed pages column header.");
151 debitHeader.alignement = Qt::AlignLeft;
152 debitHeader.color = Qt::black;
155 creditHeader.
width = 0.26*area.width();
156 creditHeader.text = tr(
"Credit account",
"Journal printed pages column header.");
157 creditHeader.alignement = Qt::AlignLeft;
158 creditHeader.color = Qt::black;
161 amountHeader.
width = 0.07*area.width();
162 amountHeader.text = tr(
"Amount",
"Journal printed pages column header.");
163 amountHeader.alignement = Qt::AlignRight;
164 amountHeader.color = Qt::black;
166 QList<tableElement*> header;
167 header << &dateHeader << &objectHeader << &labelHeader << &debitHeader << &creditHeader << &amountHeader;
175 QList<tableElement*> row;
176 row << &date << &
object << &label << &debit << &credit << &amount;
182 for(
int i = 0; i < rows; ++i)
184 if(remainingArea.height() == 0)
186 remainingArea = area;
201 index = model()->index(i, JournalDate);
204 index = model()->index(i, JournalObject);
205 object.text = model()->data(index).toString();
207 index = model()->index(i, JournalLabel);
208 label.
text = model()->data(index).toString();
210 index = model()->index(i, JournalDebitId);
211 text = model()->data(index).toString();
212 index = model()->index(i, JournalDebitLabel);
213 debit.
text = text+
" "+model()->data(index).toString();
215 index = model()->index(i, JournalCreditId);
216 text = model()->data(index).toString();
217 index = model()->index(i, JournalCreditLabel);
218 credit.
text = text+
" "+model()->data(index).toString();
220 index = model()->index(i, JournalAmount);
232 QModelIndexList indexes = selectedIndexes();
234 for(
int i = 0; i < indexes.size(); ++i)
236 if(indexes[i].column() == 0)
237 rows << indexes[i].row();
248 else if(rows.size() == 1)
265 for(
int i = 0; i < rows.size(); ++i)
269 text = tr(
"Sum : %1",
"Text displayed in the dock widget when the user selects two rows or more in the journal. The argument is the sum of all entries amounts.").arg(
mDelegate->
displayText(sum));
277 settings.beginGroup(
"ViewJournal");
278 settings.setValue(
"date", columnWidth(JournalDate));
279 settings.setValue(
"object", columnWidth(JournalObject));
280 settings.setValue(
"label", columnWidth(JournalLabel));
281 settings.setValue(
"debitId", columnWidth(JournalDebitId));
282 settings.setValue(
"debitLabel", columnWidth(JournalCreditId));
283 settings.setValue(
"creditId", columnWidth(JournalDebitLabel));
284 settings.setValue(
"creditLabel", columnWidth(JournalCreditLabel));
306 mainWindow->enableRemoveAction(current.isValid());
308 int col = current.column();
309 if(col == JournalDebitId || col == JournalDebitLabel || col == JournalCreditId || col == JournalCreditLabel)
334 QModelIndex index = currentIndex();
335 QMenu* menu =
new QMenu();
339 menu->addActions(
mainWindow->getContextMenuActionsEdit());
340 menu->addSeparator();
342 menu->addActions(
mainWindow->getContextMenuActionsJournal());
343 menu->exec(mapToGlobal(position));
359 mainWindow->setDockText(tr(
"Sorry, no matches found.",
"No matches found when searching item by text."));
380 mainWindow->setDockText(tr(
"Sorry, no matches found.",
"No matches found when searching item by text."));
384 QStyledItemDelegate(0), mModel(model), mSubwindow(subwindow), mView(view)
398 if(value.type() == QVariant::Date)
399 return value.toDate().toString(Qt::SystemLocaleShortDate);
400 else if(value.type() == QVariant::Double)
401 return QLocale::system().toString(value.toDouble(),
'f', 2);
411 void FdDelegateJournal::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
414 if(!
mModel->
data(index, ValidityRole).toBool())
416 QStyleOptionViewItem viewOption(option);
417 viewOption.palette.setColor(QPalette::Highlight, Qt::red);
430 int column = index.column();
432 if(column == JournalDate || column == JournalObject || column == JournalAmount)
437 if(column == JournalLabel)
439 else if(column == JournalDebitId || column == JournalCreditId)
441 else if(column == JournalDebitLabel || column == JournalCreditLabel)
445 connect(line, SIGNAL(destroyed()),
mView, SLOT(lineEditDestroyed()));
446 QCompleter* completer =
new QCompleter(list, line);
447 completer->setCaseSensitivity(Qt::CaseInsensitive);
448 line->setCompleter(completer);