20 #include "FdViewCoa.hpp"
21 #include "../FdMainWindow.hpp"
22 #include "../FdSubWindow.hpp"
23 #include "../../data/FdModelCoa.hpp"
24 #include "../../data/FdItemCoa.hpp"
27 QTreeView(0), mSubwindow(parent)
29 mModel = mSubwindow->coa();
32 setSelectionBehavior(QAbstractItemView::SelectRows);
33 setSelectionMode(QAbstractItemView::ExtendedSelection);
34 setDragDropMode(QAbstractItemView::InternalMove);
37 setDropIndicatorShown(
true);
38 setAlternatingRowColors(
true);
41 settings.beginGroup(
"ViewCoa");
42 setColumnWidth(CoaId, settings.value(
"id", 100).toInt());
43 setColumnWidth(CoaLabel, settings.value(
"label", 500).toInt());
44 setColumnWidth(CoaBalanceSheet, settings.value(
"balanceSheet", 110).toInt());
45 setColumnWidth(CoaSigns, settings.value(
"signs", 40).toInt());
46 setColumnWidth(CoaInitial, settings.value(
"initial", 90).toInt());
48 header()->setResizeMode(CoaBalance, QHeaderView::Stretch);
49 header()->setDefaultAlignment(Qt::AlignCenter);
52 setItemDelegate(mDelegate);
54 setContextMenuPolicy(Qt::CustomContextMenu);
55 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint&)),
this, SLOT(contextMenu(
const QPoint&)));
57 mSearchTimer =
new QTimer();
58 mSearchTimer->setInterval(qApp->keyboardInputInterval());
59 mSearchTimer->setSingleShot(
true);
60 connect(mSearchTimer, SIGNAL(timeout()),
this, SLOT(searchTimeout()));
68 if (event->button() == Qt::LeftButton && !(indexAt(event->pos()).isValid()))
79 QModelIndex index = currentIndex();
83 if(cursorAction == QAbstractItemView::MoveNext)
87 if(index.column() == CoaLabel && item->type() == AccountType)
88 return model()->index(index.row(), index.column()+2, index.parent());
89 else if(index.column() == CoaLabel && item->type() == CategoryType) {}
90 else if(index.column() != CoaInitial)
91 return model()->index(index.row(), index.column()+1, index.parent());
93 return model()->index(index.row(), CoaId, index.parent());
95 else if(cursorAction == QAbstractItemView::MovePrevious)
99 if(index.column() == CoaSigns)
100 return model()->index(index.row(), index.column()-2, index.parent());
101 else if(index.column() != CoaId)
102 return model()->index(index.row(), index.column()-1, index.parent());
104 if(item->type() == AccountType)
105 return model()->index(index.row(), CoaInitial, index.parent());
106 else if(item->type() == CategoryType)
107 return model()->index(index.row(), CoaLabel, index.parent());
109 else if(cursorAction == QAbstractItemView::MovePageUp)
112 if(item->parent()->type() != RootType)
117 else if(cursorAction == QAbstractItemView::MovePageDown)
120 if(item->childrenCount())
139 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));
142 int FdViewCoa::print(QPrinter &printer, QPainter &painter,
const QRect &area, QRect& remainingArea)
144 QFont font = painter.font();
146 font.setPointSize(12);
149 int pageNumber =
print(printer,
161 remainingArea.setRect(area.x(), remainingArea.y()+2*rowHeight, area.width(), remainingArea.height()-2*rowHeight);
165 int FdViewCoa::print(QPrinter &printer, QPainter &painter,
const QRect &area, QRect &remainingArea, QFont font,
int rowHeight,
int tabulation,
int widthLabel,
int widthAmount, FdItemCoa_p parent,
int pageNumber,
int level)
173 for(
int i = 0; i < parent->childrenCount(); ++i)
175 item = parent->child(i);
176 rows = item->childrenCount();
179 if((pageNumber || level) && rows*rowHeight > remainingArea.height() && rows*rowHeight < area.height())
180 remainingArea.setHeight(0);
182 if(remainingArea.height() < rowHeight)
184 remainingArea = area;
189 FdSubWindow::printTitle(painter, remainingArea, tr(
"Chart of accounts",
"Chart of accounts printed page title."));
196 x += remainingArea.x()+widthLabel;
197 rect.setRect(x, remainingArea.y(), widthAmount, rowHeight);
198 painter.drawText(rect, Qt::AlignRight, tr(
"Previous year",
"Chart of accounts printed pages column header."));
200 rect.setRect(x, remainingArea.y(), widthAmount, rowHeight);
201 painter.drawText(rect, Qt::AlignRight, tr(
"Current year",
"Chart of accounts printed pages column header."));
203 remainingArea.setRect(remainingArea.x(), remainingArea.y()+rowHeight, remainingArea.width(), remainingArea.height()-rowHeight);
206 if(item->type() == CategoryType)
208 remainingArea.setRect(remainingArea.x(), remainingArea.y()+rowHeight, remainingArea.width(), remainingArea.height()-rowHeight);
214 painter.setFont(font);
216 x = remainingArea.x()+level*tabulation;
217 rect.setRect(x, remainingArea.y(), widthLabel, rowHeight);
218 text = item->displayLabel();
219 painter.drawText(rect, Qt::AlignLeft, text);
221 x -= level*tabulation;
223 rect.setRect(x, remainingArea.y(), widthAmount, rowHeight);
224 if(item->onBalanceSheet())
226 if(item->initialBalance() < 0)
227 painter.setPen(Qt::red);
230 painter.drawText(rect, Qt::AlignRight, text);
232 else if(item->previousBalance())
234 if(item->previousBalance() < 0)
235 painter.setPen(Qt::red);
238 painter.drawText(rect, Qt::AlignRight, text);
240 painter.setPen(Qt::black);
243 rect.setRect(x, remainingArea.y(), widthAmount, rowHeight);
244 if(item->balance() < 0)
245 painter.setPen(Qt::red);
247 painter.drawText(rect, Qt::AlignRight, text);
248 painter.setPen(Qt::black);
250 remainingArea.setRect(remainingArea.x(), remainingArea.y()+rowHeight, remainingArea.width(), remainingArea.height()-rowHeight);
252 if(item->children().size())
253 pageNumber =
print(printer,
274 QModelIndexList selected = selectedIndexes();
275 QModelIndexList indexes;
276 for(
int i = 0; i < selected.size(); ++i)
278 if(selected[i].column() == 0)
279 indexes << selected[i];
282 for(
int i = 0; i < indexes.size(); ++i)
284 QModelIndex index = indexes[i];
285 while(index.parent() != QModelIndex())
287 if(indexes.contains(index.parent()))
293 index = index.parent();
303 settings.beginGroup(
"ViewCoa");
304 settings.setValue(
"id", columnWidth(CoaId));
305 settings.setValue(
"label", columnWidth(CoaLabel));
306 settings.setValue(
"balanceSheet", columnWidth(CoaBalanceSheet));
307 settings.setValue(
"signs", columnWidth(CoaSigns));
308 settings.setValue(
"initial", columnWidth(CoaInitial));
338 if(
mModel->
item(current)->type() == AccountType)
348 QModelIndex index = currentIndex();
349 QMenu* menu =
new QMenu();
353 menu->addActions(
mainWindow->getContextMenuActionsEdit());
354 menu->addSeparator();
356 menu->addActions(
mainWindow->getContextMenuActionsCoa());
357 menu->exec(mapToGlobal(position));
373 mainWindow->setDockText(tr(
"Sorry, no matches found.",
"No matches found when searching item by text."));
394 mainWindow->setDockText(tr(
"Sorry, no matches found.",
"No matches found when searching item by text."));
411 if(value.type() == QVariant::Double)
412 return QLocale::system().toString(value.toDouble(),
'f', 2);
429 void FdDelegateCoa::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
431 QStyleOptionViewItem viewOption(option);
434 if(item->type() == CategoryType)
435 viewOption.font.setBold(
true);
437 if((index.column() == CoaInitial && item->initialBalance() < 0) || (index.column() == CoaBalance && item->balance() < 0))
438 viewOption.palette.setColor(QPalette::Text, Qt::red);
448 if(index.column() == CoaSigns)
450 QComboBox* box =
new QComboBox(parent);
451 box->addItem(
"+-", PlusMinus);
452 box->addItem(
"-+", MinusPlus);
453 QVariant value =
mModel->
item(index)->signature();
454 box->setCurrentIndex(box->findData(value));
466 if(index.column() == CoaSigns)
468 QComboBox* box =
static_cast<QComboBox*
>(editor);
469 QVariant value = box->itemData(box->currentIndex());
470 model->setData(index, value, Qt::EditRole);