diff options
author | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2010-03-04 16:00:46 (GMT) |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2010-03-05 08:58:49 (GMT) |
commit | 0f89d7ef7b5e961cfc6ee7960ad6bf07eff71691 (patch) | |
tree | 0b1c69cbac099845ad7a01101212b3a1381edde9 | |
parent | 46d5f85a03bd87708152baba2674f2e5f36afe22 (diff) | |
download | Qt-0f89d7ef7b5e961cfc6ee7960ad6bf07eff71691.zip Qt-0f89d7ef7b5e961cfc6ee7960ad6bf07eff71691.tar.gz Qt-0f89d7ef7b5e961cfc6ee7960ad6bf07eff71691.tar.bz2 |
Wrong dirty region after row selection in right-to-left mode in QTableView
When computing the region from the selection range, we didn't take
care of the actual position of the cells, which is reverted when in
RtoL mode. Also gets fixed a 2-pixel error introduced in commit
718905c097a7f3bbf9805a2561cd855a0b2d8f59, and that was responsible for
(potentialy) painting more cells than needed.
Auto-test included.
Reviewed-by: Olivier
Task-number: QTBUG-7774
-rw-r--r-- | src/gui/itemviews/qtableview.cpp | 14 | ||||
-rw-r--r-- | tests/auto/qtableview/tst_qtableview.cpp | 26 |
2 files changed, 37 insertions, 3 deletions
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index 3111896..cf1b542 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -1908,6 +1908,7 @@ QRegion QTableView::visualRegionForSelection(const QItemSelection &selection) co width, rowHeight(r))); } } else { // nothing moved + const int gridAdjust = showGrid() ? 1 : 0; for (int i = 0; i < selection.count(); ++i) { QItemSelectionRange range = selection.at(i); if (range.parent() != d->root || !range.isValid()) @@ -1916,9 +1917,16 @@ QRegion QTableView::visualRegionForSelection(const QItemSelection &selection) co const int rtop = rowViewportPosition(range.top()); const int rbottom = rowViewportPosition(range.bottom()) + rowHeight(range.bottom()); - const int rleft = columnViewportPosition(range.left()); - const int rright = columnViewportPosition(range.right()) + columnWidth(range.right()); - selectionRegion += QRect(QPoint(rleft, rtop), QPoint(rright, rbottom)); + int rleft; + int rright; + if (isLeftToRight()) { + rleft = columnViewportPosition(range.left()); + rright = columnViewportPosition(range.right()) + columnWidth(range.right()); + } else { + rleft = columnViewportPosition(range.right()); + rright = columnViewportPosition(range.left()) + columnWidth(range.left()); + } + selectionRegion += QRect(QPoint(rleft, rtop), QPoint(rright - 1 - gridAdjust, rbottom - 1 - gridAdjust)); if (d->hasSpans()) { foreach (QSpanCollection::Span *s, d->spans.spansInRect(range.left(), range.top(), range.width(), range.height())) { diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index a5cbbd4..35fba52 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -200,6 +200,7 @@ private slots: void taskQTBUG_4516_clickOnRichTextLabel(); void taskQTBUG_5237_wheelEventOnHeader(); void taskQTBUG_8585_crashForNoGoodReason(); + void taskQTBUG_7774_RtoLVisualRegionForSelection(); void mouseWheel_data(); void mouseWheel(); @@ -3994,5 +3995,30 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason() } +class TableView7774 : public QTableView +{ +public: + QRegion visualRegionForSelection(const QItemSelection &selection) const + { + return QTableView::visualRegionForSelection(selection); + } +}; + +void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection() +{ + TableView7774 view; + QStandardItemModel model(5,5); + view.setModel(&model); + view.setLayoutDirection(Qt::RightToLeft); + view.show(); + QTest::qWaitForWindowShown(&view); + + QItemSelectionRange range(model.index(2, 0), model.index(2, model.columnCount() - 1)); + QItemSelection selection; + selection << range; + QRegion region = view.visualRegionForSelection(selection); + QCOMPARE(region.rects().at(0), view.visualRect(range.topLeft()) | view.visualRect(range.bottomRight())); +} + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" |