From 072485048fc8360b822e35b4cc43b0728e04cc1b Mon Sep 17 00:00:00 2001 From: Vyacheslav Grigoryev Date: Mon, 4 Apr 2016 01:03:20 +0300 Subject: QHeaderView: fixing selection of reordered rows and columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old code incorrectly calculated visual region for a selection (specified by QItemSelection object) in case of reordered / swapped rows or columns. It used the leftmost and rightmost (upmost and downmost for vertical mode) logical indexes directly. However some middle logical index (in case of reorder) may be the leftmost or rightmost visual index. In such cases the repainting didn't work properly. This fix first checks whether reordering / swapping is in use. If it isn't (ie visual=logical) we use code similar to the old code. Otherwise the new code scans all selected logical indexes, translates them into visual ones and gets the correct leftmost and rightmost indexes. [ChangeLog][QtWidgets][QHeaderView] Fixed a repainting issue when items had been reordered. Task-number: QTBUG-50171 Change-Id: If6afabebf445cf32a8e0afe262b6ee149e7c4b2b Reviewed-by: Thorbjørn Lund Martsum --- .../itemviews/qheaderview/tst_qheaderview.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 55fcf04846..4736aa5c12 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -77,6 +77,7 @@ public: void testEvent(); void testhorizontalOffset(); void testverticalOffset(); + void testVisualRegionForSelection(); friend class tst_QHeaderView; }; @@ -211,6 +212,7 @@ private slots: void QTBUG8650_crashOnInsertSections(); void QTBUG12268_hiddenMovedSectionSorting(); void QTBUG14242_hideSectionAutoSize(); + void QTBUG50171_visualRegionForSwappedItems(); void ensureNoIndexAtLength(); void offsetConsistent(); @@ -2282,6 +2284,24 @@ void tst_QHeaderView::QTBUG14242_hideSectionAutoSize() QCOMPARE(calced_length, afterlength); } +void tst_QHeaderView::QTBUG50171_visualRegionForSwappedItems() +{ + protected_QHeaderView headerView(Qt::Horizontal); + QtTestModel model; + model.rows = 2; + model.cols = 3; + headerView.setModel(&model); + headerView.swapSections(1, 2); + headerView.hideSection(0); + headerView.testVisualRegionForSelection(); +} + +void protected_QHeaderView::testVisualRegionForSelection() +{ + QRegion r = visualRegionForSelection(QItemSelection(model()->index(1, 0), model()->index(1, 2))); + QCOMPARE(r.boundingRect().contains(QRect(1, 1, length() - 2, 1)), true); +} + void tst_QHeaderView::ensureNoIndexAtLength() { QTableView qtv; -- cgit v1.2.3 From ccfe33dc670a1491d9e1daa2ae17f5fe30484276 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 21 Apr 2016 11:22:32 +0200 Subject: QWidget::grab(): Use device pixel ratio. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return pixmaps with device pixel ratio similar to QScreen::grabWindow(), cf c0963486ce689e778d59dafd26d36d8ef9e3ee74. Adapt kernel tests accordingly. Task-number: QTBUG-52137 Change-Id: I9ce276d5e2d87ae0d39c8639267d1ac283fed854 Reviewed-by: Morten Johan Sørvig --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 1c2a74109f..b9fe40e64c 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -3035,8 +3035,23 @@ protected: QSize sizeHint() const { return QSize(500, 500); } }; +// Scale to remove devicePixelRatio should scaling be active. +static QPixmap grabFromWidget(QWidget *w, const QRect &rect) +{ + QPixmap pixmap = w->grab(rect); + const qreal devicePixelRatio = pixmap.devicePixelRatioF(); + if (!qFuzzyCompare(devicePixelRatio, qreal(1))) { + pixmap = pixmap.scaled((QSizeF(pixmap.size()) / devicePixelRatio).toSize(), + Qt::KeepAspectRatio, Qt::SmoothTransformation); + pixmap.setDevicePixelRatio(1); + } + return pixmap; +} + void tst_QWidget::testContentsPropagation() { + if (!qFuzzyCompare(qApp->devicePixelRatio(), qreal(1))) + QSKIP("This test does not work with scaling."); ContentsPropagationWidget widget; widget.setFixedSize(500, 500); widget.setContentsPropagation(false); @@ -9208,7 +9223,7 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() QPixmap correct(main.size()); correct.fill(Qt::green); - const QPixmap mainPixmap = main.grab(QRect(QPoint(0, 0), QSize(-1, -1))); + const QPixmap mainPixmap = grabFromWidget(&main, QRect(QPoint(0, 0), QSize(-1, -1))); QTRY_COMPARE(mainPixmap.toImage().convertToFormat(QImage::Format_RGB32), correct.toImage().convertToFormat(QImage::Format_RGB32)); @@ -9672,10 +9687,10 @@ void tst_QWidget::grab() p.drawTiledPixmap(0, 0, 128, 128, pal.brush(QPalette::Window).texture(), 0, 0); p.end(); - QPixmap actual = widget.grab(QRect(64, 64, 64, 64)); + QPixmap actual = grabFromWidget(&widget, QRect(64, 64, 64, 64)); QVERIFY(lenientCompare(actual, expected)); - actual = widget.grab(QRect(64, 64, -1, -1)); + actual = grabFromWidget(&widget, QRect(64, 64, -1, -1)); QVERIFY(lenientCompare(actual, expected)); // Make sure a widget that is not yet shown is grabbed correctly. -- cgit v1.2.3 From e27fae353ca9a2d4d5054d32bb3a2622ccf9d889 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 14 Apr 2016 18:57:14 +0300 Subject: QFileSystemModel: fix updating QFileInfo for a node after a file rename Use the correct parent path for the renamed file when creating QFileInfo. It must be a path to the parent directory, not to the root directory of the model. Modify tst_QFileSystemModel::setData() to test renames in subdirs of the root directory of the model. Change-Id: I69d9e3a937616857a81617791ed118af3f6eea05 Task-number: QTBUG-52561 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- .../qfilesystemmodel/tst_qfilesystemmodel.cpp | 34 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index d370a647b4..19b1d0e7c8 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -697,6 +697,7 @@ void tst_QFileSystemModel::nameFilters() } void tst_QFileSystemModel::setData_data() { + QTest::addColumn("subdirName"); QTest::addColumn("files"); QTest::addColumn("oldFileName"); QTest::addColumn("newFileName"); @@ -706,7 +707,15 @@ void tst_QFileSystemModel::setData_data() << QDir::temp().absolutePath() + '/' + "a" << false; */ - QTest::newRow("in current dir") << (QStringList() << "a" << "b" << "c") + QTest::newRow("in current dir") + << QString() + << (QStringList() << "a" << "b" << "c") + << "a" + << "d" + << true; + QTest::newRow("in subdir") + << "s" + << (QStringList() << "a" << "b" << "c") << "a" << "d" << true; @@ -715,15 +724,25 @@ void tst_QFileSystemModel::setData_data() void tst_QFileSystemModel::setData() { QSignalSpy spy(model, SIGNAL(fileRenamed(QString,QString,QString))); - QString tmp = flatDirTestPath; + QFETCH(QString, subdirName); QFETCH(QStringList, files); QFETCH(QString, oldFileName); QFETCH(QString, newFileName); QFETCH(bool, success); + QString tmp = flatDirTestPath; + if (!subdirName.isEmpty()) { + QDir dir(tmp); + QVERIFY(dir.mkdir(subdirName)); + tmp.append('/' + subdirName); + } QVERIFY(createFiles(tmp, files)); - QModelIndex root = model->setRootPath(tmp); - QTRY_COMPARE(model->rowCount(root), files.count()); + QModelIndex tmpIdx = model->setRootPath(flatDirTestPath); + if (!subdirName.isEmpty()) { + tmpIdx = model->index(tmp); + model->fetchMore(tmpIdx); + } + QTRY_COMPARE(model->rowCount(tmpIdx), files.count()); QModelIndex idx = model->index(tmp + '/' + oldFileName); QCOMPARE(idx.isValid(), true); @@ -731,16 +750,21 @@ void tst_QFileSystemModel::setData() model->setReadOnly(false); QCOMPARE(model->setData(idx, newFileName), success); + model->setReadOnly(true); if (success) { QCOMPARE(spy.count(), 1); QList arguments = spy.takeFirst(); QCOMPARE(model->data(idx, QFileSystemModel::FileNameRole).toString(), newFileName); + QCOMPARE(model->fileInfo(idx).filePath(), tmp + '/' + newFileName); QCOMPARE(model->index(arguments.at(0).toString()), model->index(tmp)); QCOMPARE(arguments.at(1).toString(), oldFileName); QCOMPARE(arguments.at(2).toString(), newFileName); QCOMPARE(QFile::rename(tmp + '/' + newFileName, tmp + '/' + oldFileName), true); } - QTRY_COMPARE(model->rowCount(root), files.count()); + QTRY_COMPARE(model->rowCount(tmpIdx), files.count()); + // cleanup + if (!subdirName.isEmpty()) + QVERIFY(QDir(tmp).removeRecursively()); } void tst_QFileSystemModel::sortPersistentIndex() -- cgit v1.2.3