3 #include "TableViewHeader.h" 7 #include <QAbstractItemModel> 8 #include <QFontMetrics> 10 #include <QLinearGradient> 12 #include <QMessageBox> 13 #include <QMouseEvent> 18 #include <QVBoxLayout> 20 #include "AbstractTableModel.h" 21 #include "AbstractTreeModel.h" 22 #include "TableColumn.h" 23 #include "TableColumnList.h" 24 #include "TableView.h" 36 m_horizontalOffset = 0;
38 m_filterProgressMin = 0;
39 m_filterProgressMax = 0;
40 m_rebuildProgress = 0;
41 m_rebuildProgressMin = 0;
42 m_rebuildProgressMax = 0;
44 m_sortProgressMin = 0;
45 m_sortProgressMax = 0;
49 m_clickedColumnEdge = -1;
52 setMouseTracking(
true);
85 return QSize(0, QFontMetrics(font()).height() + 6);
110 disconnect(m_model, SIGNAL(filterProgressChanged(
int)),
112 disconnect(m_model, SIGNAL(rebuildProgressChanged(
int)),
114 disconnect(m_model, SIGNAL(sortProgressChanged(
int)),
116 disconnect(m_model, SIGNAL(filterProgressRangeChanged(
int,
int)),
118 disconnect(m_model, SIGNAL(rebuildProgressRangeChanged(
int,
int)),
120 disconnect(m_model, SIGNAL(sortProgressRangeChanged(
int,
int)),
122 disconnect(m_model, SIGNAL(filterCountsChanged(
int,
int)),
124 disconnect(
this, SIGNAL(requestedGlobalSelection(
bool)),
125 m_model, SLOT(setGlobalSelection(
bool)));
126 disconnect(m_model, SIGNAL(m_modelModified()),
127 this, SLOT(update()));
132 connect(m_model, SIGNAL(filterProgressChanged(
int)),
134 connect(m_model, SIGNAL(rebuildProgressChanged(
int)),
136 connect(m_model, SIGNAL(sortProgressChanged(
int)),
138 connect(m_model, SIGNAL(filterProgressRangeChanged(
int,
int)),
140 connect(m_model, SIGNAL(rebuildProgressRangeChanged(
int,
int)),
142 connect(m_model, SIGNAL(sortProgressRangeChanged(
int,
int)),
144 connect(m_model, SIGNAL(filterCountsChanged(
int,
int)),
146 connect(
this, SIGNAL(requestedGlobalSelection(
bool)),
147 m_model, SLOT(setGlobalSelection(
bool)));
148 connect(m_model, SIGNAL(modelModified()),
this, SLOT(update()));
152 for (
int i = 0; i < m_columns->size(); i++) {
153 disconnect((*m_columns)[i], SIGNAL(visibilityChanged()),
154 this, SLOT(update()));
158 m_columns = m_model->getColumns();
160 for (
int i = 0; i < m_columns->size(); i++)
161 connect((*m_columns)[i], SIGNAL(visibilityChanged()),
this, SLOT(update()));
172 int visibleTopLevelItemCount,
int topLevelItemCount) {
173 m_visibleCount = visibleTopLevelItemCount;
174 m_totalCount = topLevelItemCount;
176 if (m_visibleCount >= 0) {
178 for (
int i = 0; i < visibleCols.size(); i++) {
181 if (col->getTitle().isEmpty())
182 col->setWidth(QFontMetrics(font()).width(
183 QString::number(m_visibleCount)) + 22);
198 m_horizontalOffset = newOffset;
209 QPoint mousePos =
event->pos();
217 if (event->buttons() == Qt::LeftButton) {
219 if (m_clickedColumnEdge == -1 && m_clickedColumn != -1) {
221 if (m_columns->getVisibleColumns()[m_clickedColumn]->getTitle().isEmpty()) {
222 emit requestedGlobalSelection(
true);
242 QPoint mousePos =
event->pos();
244 if (m_clickedColumnEdge >= 0) {
246 QRect columnToResizeRect(
getColumnRect(m_clickedColumnEdge));
247 columnToResizeRect.setRight(mousePos.x());
249 TableColumn *col = m_columns->getVisibleColumns()[m_clickedColumnEdge];
252 if (columnToResizeRect.width() > 1) {
253 newWidth = columnToResizeRect.width();
254 if (m_columns->getSortingOrder()[0] == col)
255 newWidth = qMax(newWidth, ARROW_WIDTH + SORT_ARROW_MARGIN * 2);
258 m_columns->getVisibleColumns()[m_clickedColumnEdge]->setWidth(newWidth);
262 setCursor(Qt::SizeHorCursor);
265 setCursor(Qt::ArrowCursor);
279 m_clickedColumnEdge >= m_columns->getVisibleColumns().size() - 2;
280 if (m_clickedColumnEdge != -1) {
281 emit columnResized(wasLastCol);
285 TableColumn *col = m_columns->getVisibleColumns()[m_clickedColumn];
288 m_columns->getVisibleColumns().getSortingOrder()[0];
291 col->setSortAscending(!col->sortAscending());
293 m_columns->raiseToTop(col);
295 if (!m_model->sortingOn()) {
296 QMessageBox::information(
this, tr(
"Sorting Disabled"),
297 tr(
"Sorting is currently disabled for this table. Please configure your sorting " 298 "options before trying to sort by [<font color='red'>%1</font>].")
299 .arg(col->getTitle()),
305 m_clickedColumnEdge = -1;
306 m_clickedColumn = -1;
318 QPainter painter(
this);
319 painter.setRenderHints(QPainter::Antialiasing |
320 QPainter::TextAntialiasing);
322 ARROW_HEIGHT = qMax(height() / 5, 3);
323 ASSERT(height() > 8);
324 ARROW_WIDTH = ARROW_HEIGHT * 2 - 1;
353 if (column < visibleCols.size() && column >= 0) {
356 for (
int i = 0; i < column; i++)
357 indent += visibleCols[i]->getWidth() - 1;
359 colRect = QRect(indent - m_horizontalOffset, 0,
360 visibleCols[column]->getWidth(), height());
375 int mousedColumn = -1;
378 i < m_columns->getVisibleColumns().size() && mousedColumn < 0;
381 if (columnRect.contains(mousePos))
406 if (mousePos.x() - columnRect.left() < TableColumn::EDGE_WIDTH)
407 edge = mousedColumn - 1;
428 bool isAtColumnEdge =
false;
430 if (!columnRect.isNull()) {
432 mousePos.x() - columnRect.left() < TableColumn::EDGE_WIDTH;
434 columnRect.right() - mousePos.x() < TableColumn::EDGE_WIDTH;
435 bool isResizable =
false;
438 if (isOnLeft && columnNum > 0)
439 isResizable = visCols[columnNum - 1]->getTitle().size();
441 isResizable = visCols[columnNum]->getTitle().size();
443 isAtColumnEdge = (isOnLeft || isOnRight) && isResizable;
446 return isAtColumnEdge;
457 int visibleColWidth = -m_horizontalOffset;
460 for (
int i = 0; i < visibleCols.size(); i++)
461 visibleColWidth += visibleCols[i]->getWidth() - 1;
463 QRect rect(0, 0, qMin(width(), visibleColWidth), rowHeight);
465 int x = rect.center().x();
466 QLinearGradient gradient(x, rect.top(), x, rect.bottom());
469 bool selected =
false;
470 QColor color = selected ? palette().highlight().color() :
471 palette().button().color();
474 int adjustment = 110;
475 gradient.setColorAt(0, color.lighter(adjustment));
476 gradient.setColorAt(1, color.darker(adjustment));
477 painter->fillRect(rect, gradient);
481 QBrush brush = painter->brush();
482 QPainter::CompositionMode compMode = painter->compositionMode();
483 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
486 painter->setBrush(QBrush(QColor(0, 70, 100, 30)));
487 paintProgress(painter, rect, m_filterProgressMin, m_filterProgressMax,
488 m_filterProgress,
false);
491 painter->setBrush(QBrush(QColor(100, 70, 0, 30)));
492 paintProgress(painter, rect, m_rebuildProgressMin, m_rebuildProgressMax,
493 m_rebuildProgress,
false);
496 painter->setBrush(QBrush(QColor(0, 100, 0, 30)));
497 paintProgress(painter, rect, m_sortProgressMin, m_sortProgressMax,
498 m_sortProgress,
true);
502 painter->setBrush(brush);
503 painter->setCompositionMode(compMode);
505 for (
int i = 0; i < visibleCols.size(); i++) {
508 QString columnText = visibleCol->getTitle();
509 QRect columnRect(
getColumnRect(visibleCols.indexOf(visibleCol)));
510 QPen pen(palette().dark().color().darker(150));
511 pen.setCapStyle(Qt::RoundCap);
512 painter->setPen(pen);
513 painter->drawLine(columnRect.topLeft() + QPoint(0, 1),
514 columnRect.bottomLeft() + QPoint(0, 1));
516 painter->drawLine(columnRect.topLeft() + QPoint(1, 0),
517 columnRect.topRight() - QPoint(0, 0));
519 painter->drawLine(columnRect.topLeft() + QPoint(1, 1),
520 columnRect.topRight() + QPoint(0, 1));
522 painter->drawLine(columnRect.bottomLeft() + QPoint(1, 1),
523 columnRect.bottomRight() + QPoint(0, 1));
525 painter->drawLine(columnRect.bottomLeft() + QPoint(1, 1),
526 columnRect.bottomRight() + QPoint(0, 1));
528 painter->drawLine(columnRect.topRight() + QPoint(0, 1),
529 columnRect.bottomRight() - QPoint(0, 0));
531 painter->setPen(selected ? palette().highlightedText().color() :
532 palette().buttonText().color());
534 QRect textRect(columnRect.x(),
536 columnRect.width() - (SORT_ARROW_MARGIN * 2 + ARROW_WIDTH),
537 columnRect.height());
538 painter->drawText(textRect , Qt::AlignCenter | Qt::TextSingleLine,
541 if (visibleCol == visibleCols.getSortingOrder()[0] &&
542 visibleCol->getWidth() >= SORT_ARROW_MARGIN * 2 + ARROW_WIDTH) {
543 ASSERT(SORT_ARROW_MARGIN > 0);
545 QRect arrowRect(textRect.right() + 1,
547 SORT_ARROW_MARGIN * 2 + ARROW_WIDTH,
550 ASSERT(arrowRect.width() + textRect.width() == columnRect.width());
551 ASSERT(arrowRect.right() == columnRect.right());
555 QPoint left(arrowRect.left() + SORT_ARROW_MARGIN,
556 arrowRect.center().y() - ((ARROW_HEIGHT - 1) / 2));
558 int yOffSet = ((ARROW_HEIGHT - 1) / 2);
559 if (ARROW_HEIGHT % 2 == 0)
561 QPoint center(left.x() + ((ARROW_WIDTH - 1) / 2),
562 arrowRect.center().y() + yOffSet);
564 QPoint right(center.x() + ((ARROW_WIDTH - 1) / 2),
565 arrowRect.center().y() - ((ARROW_HEIGHT - 1) / 2));
567 ASSERT(right.x() == arrowRect.right() - SORT_ARROW_MARGIN);
568 ASSERT(right.x() - center.x() == center.x() - left.x());
570 if (!visibleCol->sortAscending()) {
572 left.setY(center.y());
573 center.setY(right.y());
574 right.setY(left.y());
577 if (m_model->sortingOn()) {
578 painter->drawLine(left, center);
579 painter->drawLine(center, right);
584 columnRect.moveLeft(columnRect.right());
600 const QRect &rect,
int min,
int max,
int value,
bool over100) {
601 double progressPercent = 1.0;
602 int progressRange = max - min;
604 if (progressRange > 0)
605 progressPercent = ((double)(value - min)) / progressRange;
606 else if (progressRange == 0)
609 if (progressPercent < 1.0 || over100) {
610 QRect progressRect(rect);
611 progressRect.setWidth((
int)(progressRect.width() * progressPercent));
612 painter->fillRect(progressRect, painter->brush());
623 m_filterProgress = newProgress;
635 m_filterProgressMin = min;
636 m_filterProgressMax = max;
647 m_rebuildProgress = newProgress;
659 m_rebuildProgressMin = min;
660 m_rebuildProgressMax = max;
671 m_sortProgress = newProgress;
683 m_sortProgressMin = min;
684 m_sortProgressMax = max;
Translates the tree model into a table model.
Namespace for ISIS/Bullet specific routines.