summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorThorbjørn Martsum <tmartsum@gmail.com>2013-04-11 07:32:43 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-13 16:32:40 +0200
commit70410467f0f99ce6d16fe0ac2b2a93a0c053fa05 (patch)
treec50279cd1578c001a0c9f298a110cc8fdbc71fe5 /src/widgets/itemviews
parent64a2e00e376888d5cb29afc461ac2ad69862f074 (diff)
resizeToContents - QTableView to consider cells outside visible area
This makes sizeHintForColumn and sizeHintForRow considering indexes that are outside the visual area - which is what most people want. It is a bit weird that scrolling gives '...' That will make the behavior a bit more like QTreeView, that considers indexes outside the visual area. Furthermore it is important since the user cannot just resize a column when QHeaderView::ResizeToContens is used. Task-number: QTBUG-4206 Change-Id: Icb209a19ce9e62cd30ca7159a4ad2aa9aadc1b6a Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qtableview.cpp81
1 files changed, 79 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp
index 45844173d3..d72e19114d 100644
--- a/src/widgets/itemviews/qtableview.cpp
+++ b/src/widgets/itemviews/qtableview.cpp
@@ -2230,7 +2230,8 @@ int QTableView::sizeHintForRow(int row) const
int hint = 0;
QModelIndex index;
int columnsProcessed = 0;
- for (int column = left; column <= right; ++column) {
+ int column = left;
+ for (; column <= right; ++column) {
int logicalColumn = d->horizontalHeader->logicalIndex(column);
if (d->horizontalHeader->isSectionHidden(logicalColumn))
continue;
@@ -2248,6 +2249,47 @@ int QTableView::sizeHintForRow(int row) const
break;
}
+ int actualRight = d->model->columnCount(d->root) - 1;
+ int idxLeft = left;
+ int idxRight = column - 1;
+
+ while (columnsProcessed != maximumProcessCols && (idxLeft > 0 || idxRight < actualRight)) {
+ int logicalIdx = -1;
+
+ if ((columnsProcessed % 2 && idxLeft > 0) || idxRight == actualRight) {
+ while (idxLeft > 0) {
+ --idxLeft;
+ int logcol = d->horizontalHeader->logicalIndex(idxLeft);
+ if (d->horizontalHeader->isSectionHidden(logcol))
+ continue;
+ logicalIdx = logcol;
+ break;
+ }
+ } else {
+ while (idxRight < actualRight) {
+ ++idxRight;
+ int logcol = d->horizontalHeader->logicalIndex(idxRight);
+ if (d->horizontalHeader->isSectionHidden(logcol))
+ continue;
+ logicalIdx = logcol;
+ break;
+ }
+ }
+ if (logicalIdx < 0)
+ continue;
+
+ index = d->model->index(row, logicalIdx, d->root);
+
+ if (d->wrapItemText) {// for wrapping boundaries
+ option.rect.setY(rowViewportPosition(index.row()));
+ option.rect.setHeight(rowHeight(index.row()));
+ option.rect.setX(columnViewportPosition(index.column()));
+ option.rect.setWidth(columnWidth(index.column()));
+ }
+ hint = d->heightHintForIndex(index, hint, option);
+ ++columnsProcessed;
+ }
+
return d->showGrid ? hint + 1 : hint;
}
@@ -2286,7 +2328,8 @@ int QTableView::sizeHintForColumn(int column) const
int hint = 0;
int rowsProcessed = 0;
QModelIndex index;
- for (int row = top; row <= bottom; ++row) {
+ int row = top;
+ for (; row <= bottom; ++row) {
int logicalRow = d->verticalHeader->logicalIndex(row);
if (d->verticalHeader->isSectionHidden(logicalRow))
continue;
@@ -2298,6 +2341,40 @@ int QTableView::sizeHintForColumn(int column) const
break;
}
+ int actualBottom = d->model->rowCount(d->root) - 1;
+ int idxTop = top;
+ int idxBottom = row - 1;
+
+ while (rowsProcessed != maximumProcessRows && (idxTop > 0 || idxBottom < actualBottom)) {
+ int logicalIdx = -1;
+
+ if ((rowsProcessed % 2 && idxTop > 0) || idxBottom == actualBottom) {
+ while (idxTop > 0) {
+ --idxTop;
+ int logrow = d->verticalHeader->logicalIndex(idxTop);
+ if (d->verticalHeader->isSectionHidden(logrow))
+ continue;
+ logicalIdx = logrow;
+ break;
+ }
+ } else {
+ while (idxBottom < actualBottom) {
+ ++idxBottom;
+ int logrow = d->verticalHeader->logicalIndex(idxBottom);
+ if (d->verticalHeader->isSectionHidden(logrow))
+ continue;
+ logicalIdx = logrow;
+ break;
+ }
+ }
+ if (logicalIdx < 0)
+ continue;
+
+ index = d->model->index(logicalIdx, column, d->root);
+ hint = d->widthHintForIndex(index, hint, option);
+ ++rowsProcessed;
+ }
+
return d->showGrid ? hint + 1 : hint;
}