summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-01-24 10:33:37 +0100
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-01-25 20:06:06 +0100
commit318b58562ae89453fb98e8145cd0440e14ba60b0 (patch)
tree622bc032cf076b4569621032f3a3315d95c3ae88 /tests/auto/widgets/itemviews
parentc28fde3fdac19fd5a5f614bb7983080031c924b3 (diff)
parent79352528a1726b4551ea4d9285dd2394dd0d43da (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts: .qmake.conf mkspecs/common/msvc-desktop.conf mkspecs/common/msvc-version.conf mkspecs/common/winrt_winphone/qmake.conf mkspecs/features/mac/default_post.prf mkspecs/features/mac/sdk.prf mkspecs/features/qt.prf mkspecs/features/uikit/default_post.prf mkspecs/features/winrt/default_pre.prf mkspecs/winphone-arm-msvc2013/qmake.conf mkspecs/winphone-x86-msvc2013/qmake.conf mkspecs/winrt-arm-msvc2013/qmake.conf mkspecs/winrt-x64-msvc2013/qmake.conf mkspecs/winrt-x86-msvc2013/qmake.conf qmake/generators/win32/msvc_vcproj.cpp src/gui/kernel/qwindowsysteminterface.cpp src/network/kernel/qhostaddress.cpp src/plugins/platforms/mirclient/qmirclientplugin.cpp src/plugins/platforms/mirclient/qmirclientplugin.h src/widgets/util/qsystemtrayicon.cpp tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp tools/configure/Makefile.mingw tools/configure/Makefile.win32 Done-with: Jake Petroules <jake.petroules@qt.io> Done-with: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Change-Id: I4be3262d3994e11929d3b1ded2c3379783797dbe
Diffstat (limited to 'tests/auto/widgets/itemviews')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp82
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp14
2 files changed, 86 insertions, 10 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 32a324b888..1078dcc2e9 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -169,6 +169,9 @@ private slots:
void moveSectionAndReset();
void moveSectionAndRemove();
void saveRestore();
+ void restoreQt4State();
+ void restoreToMoreColumns();
+ void restoreBeforeSetModel();
void defaultSectionSizeTest();
void defaultSectionSizeTestStyles();
@@ -1523,11 +1526,11 @@ public:
{
return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
}
- int rowCount(const QModelIndex & /* parent */) const
+ int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const
{
return 8;
}
- int columnCount(const QModelIndex &/*parent= QModelIndex()*/) const
+ int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const
{
return m_col_count;
}
@@ -1588,41 +1591,56 @@ void tst_QHeaderView::moveSectionAndRemove()
QCOMPARE(v.count(), 0);
}
-void tst_QHeaderView::saveRestore()
+static QByteArray savedState()
{
- SimpleModel m;
+ QStandardItemModel m(4, 4);
QHeaderView h1(Qt::Horizontal);
h1.setModel(&m);
h1.swapSections(0, 2);
h1.resizeSection(1, 10);
h1.setSortIndicatorShown(true);
- h1.setSortIndicator(1,Qt::DescendingOrder);
- QByteArray s1 = h1.saveState();
+ h1.setSortIndicator(2, Qt::DescendingOrder);
+ h1.setSectionHidden(3, true);
+ return h1.saveState();
+}
+
+void tst_QHeaderView::saveRestore()
+{
+ QStandardItemModel m(4, 4);
+ const QByteArray s1 = savedState();
QHeaderView h2(Qt::Vertical);
QSignalSpy spy(&h2, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)));
h2.setModel(&m);
- h2.restoreState(s1);
+ QVERIFY(h2.restoreState(s1));
QCOMPARE(spy.count(), 1);
- QCOMPARE(spy.at(0).at(0).toInt(), 1);
+ QCOMPARE(spy.at(0).at(0).toInt(), 2);
QCOMPARE(h2.logicalIndex(0), 2);
QCOMPARE(h2.logicalIndex(2), 0);
QCOMPARE(h2.sectionSize(1), 10);
- QCOMPARE(h2.sortIndicatorSection(), 1);
+ QCOMPARE(h2.sortIndicatorSection(), 2);
QCOMPARE(h2.sortIndicatorOrder(), Qt::DescendingOrder);
QCOMPARE(h2.isSortIndicatorShown(), true);
+ QVERIFY(!h2.isSectionHidden(2));
+ QVERIFY(h2.isSectionHidden(3));
+ QCOMPARE(h2.hiddenSectionCount(), 1);
QByteArray s2 = h2.saveState();
-
QCOMPARE(s1, s2);
+
QVERIFY(!h2.restoreState(QByteArrayLiteral("Garbage")));
+}
+void tst_QHeaderView::restoreQt4State()
+{
// QTBUG-40462
// Setting from Qt4, where information about multiple sections were grouped together in one
// sectionItem object
+ QStandardItemModel m(4, 10);
+ QHeaderView h2(Qt::Vertical);
QByteArray settings_qt4 =
QByteArray::fromHex("000000ff00000000000000010000000100000000010000000000000000000000000000"
"0000000003e80000000a0101000100000000000000000000000064ffffffff00000081"
@@ -1652,6 +1670,50 @@ void tst_QHeaderView::saveRestore()
QCOMPARE(h2.saveState(), old_state);
}
+void tst_QHeaderView::restoreToMoreColumns()
+{
+ // Restore state onto a model with more columns
+ const QByteArray s1 = savedState();
+ QHeaderView h4(Qt::Horizontal);
+ QStandardItemModel fiveColumnsModel(1, 5);
+ h4.setModel(&fiveColumnsModel);
+ QCOMPARE(fiveColumnsModel.columnCount(), 5);
+ QCOMPARE(h4.count(), 5);
+ QVERIFY(h4.restoreState(s1));
+ QCOMPARE(fiveColumnsModel.columnCount(), 5);
+ QCOMPARE(h4.count(), 5);
+ QCOMPARE(h4.sectionSize(1), 10);
+ for (int i = 0; i < h4.count(); ++i)
+ QVERIFY(h4.sectionSize(i) > 0 || h4.isSectionHidden(i));
+ QVERIFY(!h4.isSectionHidden(2));
+ QVERIFY(h4.isSectionHidden(3));
+ QCOMPARE(h4.hiddenSectionCount(), 1);
+ QCOMPARE(h4.sortIndicatorSection(), 2);
+ QCOMPARE(h4.sortIndicatorOrder(), Qt::DescendingOrder);
+}
+
+void tst_QHeaderView::restoreBeforeSetModel()
+{
+ QHeaderView h2(Qt::Horizontal);
+ const QByteArray s1 = savedState();
+ // First restore
+ QVERIFY(h2.restoreState(s1));
+ // Then setModel
+ QStandardItemModel model(4, 4);
+ h2.setModel(&model);
+
+ // Check the result
+ QCOMPARE(h2.logicalIndex(0), 2);
+ QCOMPARE(h2.logicalIndex(2), 0);
+ QCOMPARE(h2.sectionSize(1), 10);
+ QCOMPARE(h2.sortIndicatorSection(), 2);
+ QCOMPARE(h2.sortIndicatorOrder(), Qt::DescendingOrder);
+ QCOMPARE(h2.isSortIndicatorShown(), true);
+ QVERIFY(!h2.isSectionHidden(2));
+ QVERIFY(h2.isSectionHidden(3));
+ QCOMPARE(h2.hiddenSectionCount(), 1);
+}
+
void tst_QHeaderView::defaultSectionSizeTest()
{
// Setup
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index e5e9b87df4..8c7c5f1050 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -151,6 +151,7 @@ private slots:
void taskQTBUG_7232_AllowUserToControlSingleStep();
void taskQTBUG_51086_skippingIndexesInSelectedIndexes();
void expandingListItems();
+ void taskQTBUG_47694_indexOutOfBoundBatchLayout();
};
// Testing get/set functions
@@ -2510,5 +2511,18 @@ void tst_QListView::expandingListItems()
QVERIFY(w.visualRect(item1->index()).width() < w.visualRect(item2->index()).width());
}
+void tst_QListView::taskQTBUG_47694_indexOutOfBoundBatchLayout()
+{
+ QListView view;
+ view.setLayoutMode(QListView::Batched);
+ int batchSize = view.batchSize();
+
+ QStandardItemModel model(batchSize + 1, 1);
+
+ view.setModel(&model);
+
+ view.scrollTo(model.index(batchSize - 1, 0));
+}
+
QTEST_MAIN(tst_QListView)
#include "tst_qlistview.moc"