summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp188
1 files changed, 152 insertions, 36 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 4736aa5c12..47ec93ce16 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -1,32 +1,27 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com
-** Contact: http://www.qt.io/licensing/
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -47,6 +42,7 @@
#include <qitemdelegate.h>
#include <qtreewidget.h>
#include <qdebug.h>
+#include <qscreen.h>
typedef QList<int> IntList;
@@ -107,15 +103,12 @@ class tst_QHeaderView : public QObject
public:
tst_QHeaderView();
- virtual ~tst_QHeaderView();
-public slots:
+private slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
-
-private slots:
void getSetCheck();
void visualIndex();
@@ -240,6 +233,7 @@ private slots:
void resizeToContentTest();
void testStreamWithHide();
void testStylePosition();
+ void stretchAndRestoreLastSection();
void sizeHintCrash();
@@ -274,7 +268,8 @@ public:
wrongIndex = true;
qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), idx.internalPointer());
}
- return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(0);//idx.data());
+ return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',')
+ + QString::number(idx.column()) + QLatin1String(",0]");
}
void insertOneColumn(int col)
@@ -384,10 +379,6 @@ tst_QHeaderView::tst_QHeaderView()
qRegisterMetaType<int>("Qt::SortOrder");
}
-tst_QHeaderView::~tst_QHeaderView()
-{
-}
-
void tst_QHeaderView::initTestCase()
{
#ifdef Q_OS_WINCE //disable magic for WindowsCE
@@ -562,7 +553,7 @@ void tst_QHeaderView::hidden()
void tst_QHeaderView::stretch()
{
- // Show before resize and setStrechLastSection
+ // Show before resize and setStretchLastSection
#if defined(Q_OS_WINCE)
QSize viewSize(200,300);
#else
@@ -1571,7 +1562,7 @@ public:
return QVariant();
}
if (role == Qt::DisplayRole) {
- return QString::fromLatin1("%1,%2").arg(index.row()).arg(index.column());
+ return QString::number(index.row()) + QLatin1Char(',') + QString::number(index.column());
}
return QVariant();
}
@@ -2244,13 +2235,21 @@ void tst_QHeaderView::QTBUG8650_crashOnInsertSections()
model.insertColumn(0, items);
}
+static void setModelTexts(QStandardItemModel *model)
+{
+ const int columnCount = model->columnCount();
+ for (int i = 0, rowCount = model->rowCount(); i < rowCount; ++i) {
+ const QString prefix = QLatin1String("item [") + QString::number(i) + QLatin1Char(',');
+ for (int j = 0; j < columnCount; ++j)
+ model->setData(model->index(i, j), prefix + QString::number(j) + QLatin1Char(']'));
+ }
+}
+
void tst_QHeaderView::QTBUG12268_hiddenMovedSectionSorting()
{
QTableView view; // ### this test fails on QTableView &view = *m_tableview; !? + shadowing view member
QStandardItemModel *model = new QStandardItemModel(4,3, &view);
- for (int i = 0; i< model->rowCount(); ++i)
- for (int j = 0; j< model->columnCount(); ++j)
- model->setData(model->index(i,j), QString("item [%1,%2]").arg(i).arg(j));
+ setModelTexts(model);
view.setModel(model);
view.horizontalHeader()->setSectionsMovable(true);
view.setSortingEnabled(true);
@@ -2344,9 +2343,7 @@ void tst_QHeaderView::initialSortOrderRole()
{
QTableView view; // ### Shadowing member view (of type QHeaderView)
QStandardItemModel *model = new QStandardItemModel(4, 3, &view);
- for (int i = 0; i< model->rowCount(); ++i)
- for (int j = 0; j< model->columnCount(); ++j)
- model->setData(model->index(i,j), QString("item [%1,%2]").arg(i).arg(j));
+ setModelTexts(model);
QStandardItem *ascendingItem = new QStandardItem();
QStandardItem *descendingItem = new QStandardItem();
ascendingItem->setData(Qt::AscendingOrder, Qt::InitialSortOrderRole);
@@ -2514,7 +2511,7 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
QString msg = "semantic problem at " + QString(__FILE__) + " (" + sline + ")";
msg += "\nThe *expected* result was : {" + istr(x[0]) + istr(x[1]) + istr(x[2]) + istr(x[3])
- + istr(x[4]) + istr(x[5]) + istr(x[6], false) + "}";
+ + istr(x[4]) + istr(x[5]) + istr(x[6], false) + QLatin1Char('}');
msg += "\nThe calculated result was : {";
msg += istr(chk_visual) + istr(chk_logical) + istr(chk_sizes) + istr(chk_hidden_size)
+ istr(chk_lookup_visual) + istr(chk_lookup_logical) + istr(header_lenght, false) + "};";
@@ -2592,7 +2589,7 @@ void tst_QHeaderView::additionalInit()
for (int i = 0; i < model->rowCount(); ++i) {
model->setData(model->index(i, 0), QVariant(i));
s.setNum(i);
- s += ".";
+ s += QLatin1Char('.');
s += 'a' + (i % 25);
model->setData(model->index(i, 1), QVariant(s));
}
@@ -2911,5 +2908,124 @@ void tst_QHeaderView::sizeHintCrash()
treeView.header()->sizeHintForRow(0);
}
+void tst_QHeaderView::stretchAndRestoreLastSection()
+{
+ QStandardItemModel m(10, 10);
+ QTableView tv;
+ tv.setModel(&m);
+ tv.showMaximized();
+
+ const int defaultSectionSize = 30;
+ const int someOtherSectionSize = 40;
+ const int biggerSizeThanAnySection = 50;
+
+ QVERIFY(QTest::qWaitForWindowExposed(&tv));
+
+ QHeaderView &header = *tv.horizontalHeader();
+ header.setDefaultSectionSize(defaultSectionSize);
+ header.resizeSection(9, someOtherSectionSize);
+ header.setStretchLastSection(true);
+
+ // Default last section is larger
+ QCOMPARE(header.sectionSize(8), defaultSectionSize);
+ QVERIFY(header.sectionSize(9) >= biggerSizeThanAnySection);
+
+ // Moving last section away (restore old last section 9 - and make 8 larger)
+ header.swapSections(9, 8);
+ QCOMPARE(header.sectionSize(9), someOtherSectionSize);
+ QVERIFY(header.sectionSize(8) >= biggerSizeThanAnySection);
+
+ // Make section 9 the large one again
+ header.hideSection(8);
+ QVERIFY(header.sectionSize(9) >= biggerSizeThanAnySection);
+
+ // Show section 8 again - and make that one the last one.
+ header.showSection(8);
+ QVERIFY(header.sectionSize(8) > biggerSizeThanAnySection);
+ QCOMPARE(header.sectionSize(9), someOtherSectionSize);
+
+ // Swap the sections so the logical indexes are equal to visible indexes again.
+ header.moveSection(9, 8);
+ QCOMPARE(header.sectionSize(8), defaultSectionSize);
+ QVERIFY(header.sectionSize(9) >= biggerSizeThanAnySection);
+
+ // Append sections
+ m.setColumnCount(15);
+ QCOMPARE(header.sectionSize(9), someOtherSectionSize);
+ QVERIFY(header.sectionSize(14) >= biggerSizeThanAnySection);
+
+ // Truncate sections (remove sections with the last section)
+ m.setColumnCount(10);
+ QVERIFY(header.sectionSize(9) >= biggerSizeThanAnySection);
+ for (int u = 0; u < 9; ++u)
+ QCOMPARE(header.sectionSize(u), defaultSectionSize);
+
+ // Insert sections
+ m.insertColumns(2, 2);
+ QCOMPARE(header.sectionSize(9), defaultSectionSize);
+ QCOMPARE(header.sectionSize(10), defaultSectionSize);
+ QVERIFY(header.sectionSize(11) >= biggerSizeThanAnySection);
+
+ // Append an extra section and check restore
+ m.setColumnCount(m.columnCount() + 1);
+ QCOMPARE(header.sectionSize(11), someOtherSectionSize);
+ QVERIFY(header.sectionSize(12) >= biggerSizeThanAnySection);
+
+ // Remove some sections but not the last one.
+ m.removeColumns(2, 2);
+ QCOMPARE(header.sectionSize(9), someOtherSectionSize);
+ QVERIFY(header.sectionSize(10) >= biggerSizeThanAnySection);
+ for (int u = 0; u < 9; ++u)
+ QCOMPARE(header.sectionSize(u), defaultSectionSize);
+
+ // Empty the header and start over with some more tests
+ m.setColumnCount(0);
+ m.setColumnCount(10);
+ QVERIFY(header.sectionSize(9) >= biggerSizeThanAnySection);
+
+ // Check resize of the last section
+ header.resizeSection(9, someOtherSectionSize);
+ QVERIFY(header.sectionSize(9) >= biggerSizeThanAnySection); // It should still be stretched
+ header.swapSections(9, 8);
+ QCOMPARE(header.sectionSize(9), someOtherSectionSize);
+
+ // Restore the order
+ header.swapSections(9, 8);
+ QVERIFY(header.sectionSize(9) >= biggerSizeThanAnySection);
+
+ // Hide the last 3 sections and test stretch last section on swap/move
+ // when hidden sections with a larger visual index exists.
+ header.hideSection(7);
+ header.hideSection(8);
+ header.hideSection(9);
+ QVERIFY(header.sectionSize(6) >= biggerSizeThanAnySection);
+ header.moveSection(2, 7);
+ QVERIFY(header.sectionSize(2) >= biggerSizeThanAnySection);
+ header.swapSections(1, 8);
+ QCOMPARE(header.sectionSize(2), defaultSectionSize);
+ QVERIFY(header.sectionSize(1) >= biggerSizeThanAnySection);
+
+ // Inserting sections 2
+ m.setColumnCount(0);
+ m.setColumnCount(10);
+ header.resizeSection(1, someOtherSectionSize);
+ header.swapSections(1, 9);
+ m.insertColumns(9, 2);
+ header.swapSections(1, 11);
+ QCOMPARE(header.sectionSize(1), someOtherSectionSize);
+
+ // Test import/export of the original (not stretched) sectionSize.
+ m.setColumnCount(0);
+ m.setColumnCount(10);
+ header.resizeSection(9, someOtherSectionSize);
+ QVERIFY(header.sectionSize(9) >= biggerSizeThanAnySection);
+ QByteArray b = header.saveState();
+ m.setColumnCount(0);
+ m.setColumnCount(10);
+ header.restoreState(b);
+ header.setStretchLastSection(false);
+ QCOMPARE(header.sectionSize(9), someOtherSectionSize);
+}
+
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"