20 #include "FdViewResults.hpp"
21 #include "../../data/FdModelResults.hpp"
22 #include "../../data/FdItemResults.hpp"
23 #include "../FdSubWindow.hpp"
24 #include "../FdMainWindow.hpp"
27 QTableView(0), mSubwindow(parent)
29 mModel = mSubwindow->results();
32 setSelectionBehavior(QAbstractItemView::SelectRows);
33 setSelectionMode(QAbstractItemView::ExtendedSelection);
34 setDragDropMode(QAbstractItemView::InternalMove);
37 setDropIndicatorShown(
true);
38 setEditTriggers(DoubleClicked | EditKeyPressed);
39 QHeaderView* header = verticalHeader();
40 header->setDefaultSectionSize(16);
41 setVerticalHeader(header);
43 setAlternatingRowColors(
true);
46 settings.beginGroup(
"ViewResults");
47 setColumnWidth(ResultsId, settings.value(
"id", 50).toInt());
48 setColumnWidth(ResultsLabel, settings.value(
"label", 300).toInt());
49 setColumnWidth(ResultsCalculation, settings.value(
"calculation", 500).toInt());
51 horizontalHeader()->setResizeMode(ResultsResult, QHeaderView::Stretch);
54 setItemDelegate(mDelegate);
56 setContextMenuPolicy(Qt::CustomContextMenu);
57 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint&)),
this, SLOT(contextMenu(
const QPoint&)));
59 mSearchTimer =
new QTimer();
60 mSearchTimer->setInterval(qApp->keyboardInputInterval());
61 mSearchTimer->setSingleShot(
true);
62 connect(mSearchTimer, SIGNAL(timeout()),
this, SLOT(searchTimeout()));
70 if(event->button() == Qt::LeftButton && !(indexAt(event->pos()).isValid()))
78 else if(rows.size() == 1)
95 if(cursorAction == QAbstractItemView::MoveNext)
97 QModelIndex index = currentIndex();
98 if(index.column() == ResultsCalculation)
100 if(index.row() == model()->rowCount()-1)
103 return mModel->index(index.row()+1, ResultsId);
106 else if(cursorAction == QAbstractItemView::MovePrevious)
108 QModelIndex index = currentIndex();
109 if(index.column() == ResultsId)
112 return mModel->index(index.row()-1, ResultsCalculation);
118 else if(cursorAction == QAbstractItemView::MoveHome && modifiers == Qt::ControlModifier)
123 else if(cursorAction == QAbstractItemView::MoveEnd && modifiers == Qt::ControlModifier)
142 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));
147 const int rows = model()->rowCount();
150 bool titlePrinted =
false;
151 bool headerPrinted =
false;
154 labelHeader.
width = 0.6*area.width();
155 labelHeader.text = tr(
"Label",
"Results printed pages column header.");
156 labelHeader.alignement = Qt::AlignLeft;
157 labelHeader.color = Qt::black;
160 previousHeader.
width = 0.2*area.width();
161 previousHeader.text = tr(
"Previous year",
"Results printed pages column header.");
162 previousHeader.alignement = Qt::AlignRight;
163 previousHeader.color = Qt::black;
166 resultHeader.
width = 0.2*area.width();
167 resultHeader.text = tr(
"Result",
"Results printed pages column header.");
168 resultHeader.alignement = Qt::AlignRight;
169 resultHeader.color = Qt::black;
171 QList<tableElement*> header;
172 header << &labelHeader << &previousHeader << &resultHeader;
178 QList<tableElement*> row;
179 row << &label << &previous << &result;
181 FdItemResults_p item;
183 int neededHeight = 1200 + rows*185;
185 if(neededHeight > remainingArea.height() && neededHeight < 0.75*area.height())
186 remainingArea.setHeight(0);
188 for(
int i = 0; i < rows; ++i)
192 if(remainingArea.height() == 0)
196 remainingArea = area;
197 subwindow->
printHeaderFooter(printer, painter, tr(
"Results"), pageNumber+startPage);
198 headerPrinted =
false;
209 headerPrinted =
true;
214 label.
text = item->id()+
" "+item->label();
217 if(result.text.toDouble() < 0)
218 result.color = Qt::red;
220 result.color = Qt::black;
228 QModelIndexList indexes = selectedIndexes();
230 for(
int i = 0; i < indexes.size(); ++i)
232 if(indexes[i].column() == 0)
233 rows << indexes[i].row();
241 settings.beginGroup(
"ViewResults");
242 settings.setValue(
"id", columnWidth(ResultsId));
243 settings.setValue(
"label", columnWidth(ResultsLabel));
244 settings.setValue(
"calculation", columnWidth(ResultsCalculation));
265 mainWindow->enableRemoveAction(current.isValid());
272 QModelIndex index = currentIndex();
273 QMenu* menu =
new QMenu();
277 menu->addActions(
mainWindow->getContextMenuActionsEdit());
278 menu->addSeparator();
280 menu->addActions(
mainWindow->getContextMenuActionsResults());
281 menu->exec(mapToGlobal(position));
297 mainWindow->setDockText(tr(
"Sorry, no matches found.",
"No matches found when searching item by text."));
318 mainWindow->setDockText(tr(
"Sorry, no matches found.",
"No matches found when searching item by text."));
322 QStyledItemDelegate(0), mModel(model)
336 if(value.type() == QVariant::Double)
337 return QLocale::system().toString(value.toDouble(),
'f', 2);
342 void FdDelegateResults::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const
344 FdItemResults_p item =
mModel->
item(index.row());
345 QStyleOptionViewItem viewOption(option);
347 if(!
mModel->
data(index, ValidityRole).toBool())
348 viewOption.palette.setColor(QPalette::Highlight, Qt::red);
350 if(index.column() == ResultsResult && item->result() < 0)
351 viewOption.palette.setColor(QPalette::Text, Qt::red);