diff options
Diffstat (limited to 'tests/auto/widgets/itemviews')
24 files changed, 752 insertions, 718 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 6cbf51efd9..89fb30557b 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -56,6 +51,7 @@ #include <qstyleditemdelegate.h> #include <qstringlistmodel.h> #include <qsortfilterproxymodel.h> +#include <qproxystyle.h> static inline void setFrameless(QWidget *w) { @@ -252,6 +248,7 @@ private slots: void sizeHintChangeTriggersLayout(); void shiftSelectionAfterChangingModelContents(); void QTBUG48968_reentrant_updateEditorGeometries(); + void QTBUG50102_SH_ItemView_ScrollMode(); void QTBUG50535_update_on_new_selection_model(); void testSelectionModelInSyncWithView(); }; @@ -875,7 +872,7 @@ class DnDTestModel : public QStandardItemModel public: DnDTestModel() : QStandardItemModel(20, 20), dropAction_result(Qt::IgnoreAction) { for (int i = 0; i < rowCount(); ++i) - setData(index(i, 0), QString("%1").arg(i)); + setData(index(i, 0), QString::number(i)); } Qt::DropAction dropAction() const { return dropAction_result; } }; @@ -1280,9 +1277,9 @@ void tst_QAbstractItemView::task250754_fontChange() QStandardItemModel *m = new QStandardItemModel(this); for (int i=0; i<20; ++i) { - QStandardItem *item = new QStandardItem(QString("Item number %1").arg(i)); + QStandardItem *item = new QStandardItem(QStringLiteral("Item number ") + QString::number(i)); for (int j=0; j<5; ++j) { - QStandardItem *child = new QStandardItem(QString("Child Item number %1").arg(j)); + QStandardItem *child = new QStandardItem(QStringLiteral("Child Item number ") + QString::number(j)); item->setChild(j, 0, child); } m->setItem(i, 0, item); @@ -1372,7 +1369,7 @@ void tst_QAbstractItemView::shiftArrowSelectionAfterScrolling() { QStandardItemModel model; for (int i=0; i<10; ++i) { - QStandardItem *item = new QStandardItem(QString("%1").arg(i)); + QStandardItem *item = new QStandardItem(QString::number(i)); model.setItem(i, 0, item); } @@ -1409,7 +1406,7 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection() { QStandardItemModel model; for (int i=0; i<3; ++i) { - QStandardItem *item = new QStandardItem(QString("%1").arg(i)); + QStandardItem *item = new QStandardItem(QString::number(i)); model.setItem(i, 0, item); } @@ -1486,7 +1483,7 @@ void tst_QAbstractItemView::ctrlRubberbandSelection() { QStandardItemModel model; for (int i=0; i<3; ++i) { - QStandardItem *item = new QStandardItem(QString("%1").arg(i)); + QStandardItem *item = new QStandardItem(QString::number(i)); model.setItem(i, 0, item); } @@ -1612,11 +1609,6 @@ void tst_QAbstractItemView::testDelegateDestroyEditor() void tst_QAbstractItemView::testClickedSignal() { -#if defined Q_OS_BLACKBERRY - QWidget rootWindow; - rootWindow.show(); - QTest::qWaitForWindowExposed(&rootWindow); -#endif QTableWidget view(5, 5); centerOnScreen(&view); @@ -2031,6 +2023,53 @@ void tst_QAbstractItemView::QTBUG48968_reentrant_updateEditorGeometries() // No crash, all fine. } +class ScrollModeProxyStyle: public QProxyStyle +{ +public: + ScrollModeProxyStyle(QAbstractItemView::ScrollMode sm, QStyle *style = 0) + : QProxyStyle(style) + , scrollMode(sm == QAbstractItemView::ScrollPerItem ? + QAbstractItemView::ScrollPerPixel : QAbstractItemView::ScrollPerItem) + { } + + int styleHint(QStyle::StyleHint hint, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *returnData) const override + { + if (hint == SH_ItemView_ScrollMode) + return scrollMode; + + return baseStyle()->styleHint(hint, opt, w, returnData); + } + + QAbstractItemView::ScrollMode scrollMode; +}; + +void tst_QAbstractItemView::QTBUG50102_SH_ItemView_ScrollMode() +{ + QListView view; + + // Default comes from the style + auto styleScrollMode = static_cast<QAbstractItemView::ScrollMode>(view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view, 0)); + QCOMPARE(view.verticalScrollMode(), styleScrollMode); + QCOMPARE(view.horizontalScrollMode(), styleScrollMode); + + // Change style, get new value + view.setStyle(new ScrollModeProxyStyle(styleScrollMode)); + auto proxyScrollMode = static_cast<QAbstractItemView::ScrollMode>(view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view, 0)); + QVERIFY(styleScrollMode != proxyScrollMode); + QCOMPARE(view.verticalScrollMode(), proxyScrollMode); + QCOMPARE(view.horizontalScrollMode(), proxyScrollMode); + + // Explicitly set vertical, same value + view.setVerticalScrollMode(proxyScrollMode); + QCOMPARE(view.verticalScrollMode(), proxyScrollMode); + QCOMPARE(view.horizontalScrollMode(), proxyScrollMode); + + // Change style, won't change value for vertical, will change for horizontal + view.setStyle(new ScrollModeProxyStyle(proxyScrollMode)); + QCOMPARE(view.verticalScrollMode(), proxyScrollMode); + QCOMPARE(view.horizontalScrollMode(), styleScrollMode); +} + void tst_QAbstractItemView::QTBUG50535_update_on_new_selection_model() { QStandardItemModel model; diff --git a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp index 6645da727c..d717278be9 100644 --- a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp +++ b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -51,14 +46,10 @@ class tst_QColumnView : public QObject { public: tst_QColumnView(); - virtual ~tst_QColumnView(); -public Q_SLOTS: +private slots: void initTestCase(); void init(); - void cleanup(); - -private slots: void rootIndex(); void grips(); void isIndexHidden(); @@ -112,12 +103,14 @@ public: for (int j = 0; j < 10; ++j) { QStandardItem *parentItem = invisibleRootItem(); for (int i = 0; i < 10; ++i) { - QStandardItem *item = new QStandardItem(QString("item %0").arg(i)); + const QString iS = QString::number(i); + const QString itemText = QLatin1String("item ") + iS; + QStandardItem *item = new QStandardItem(itemText); parentItem->appendRow(item); - QStandardItem *item2 = new QStandardItem(QString("item %0").arg(i)); + QStandardItem *item2 = new QStandardItem(itemText); parentItem->appendRow(item2); - item2->appendRow(new QStandardItem(QString("item %0").arg(i))); - parentItem->appendRow(new QStandardItem(QString("file %0").arg(i))); + item2->appendRow(new QStandardItem(itemText)); + parentItem->appendRow(new QStandardItem(QLatin1String("file ") + iS)); parentItem = item; } } @@ -181,10 +174,6 @@ tst_QColumnView::tst_QColumnView() m_fakeDirHomeIndex = m_fakeDirModel.indexFromItem(homeItem); } -tst_QColumnView::~tst_QColumnView() -{ -} - void tst_QColumnView::initTestCase() { QVERIFY(m_fakeDirHomeIndex.isValid()); @@ -199,10 +188,6 @@ void tst_QColumnView::init() #endif } -void tst_QColumnView::cleanup() -{ -} - void tst_QColumnView::rootIndex() { ColumnView view; diff --git a/tests/auto/widgets/itemviews/qdatawidgetmapper/qdatawidgetmapper.pro b/tests/auto/widgets/itemviews/qdatawidgetmapper/qdatawidgetmapper.pro index 3f4cb491f4..53b23b5ef2 100644 --- a/tests/auto/widgets/itemviews/qdatawidgetmapper/qdatawidgetmapper.pro +++ b/tests/auto/widgets/itemviews/qdatawidgetmapper/qdatawidgetmapper.pro @@ -1,5 +1,4 @@ CONFIG += testcase -CONFIG += parallel_test TARGET = tst_qdatawidgetmapper QT += widgets testlib SOURCES += tst_qdatawidgetmapper.cpp diff --git a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp index 8b80d52a5f..ea88020a56 100644 --- a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp +++ b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -66,8 +61,10 @@ static QStandardItemModel *testModel(QObject *parent = 0) QStandardItemModel *model = new QStandardItemModel(10, 10, parent); for (int row = 0; row < 10; ++row) { + const QString prefix = QLatin1String("item ") + QString::number(row) + + QLatin1Char(' '); for (int col = 0; col < 10; ++col) - model->setData(model->index(row, col), QString("item %1 %2").arg(row).arg(col)); + model->setData(model->index(row, col), prefix + QString::number(col)); } return model; diff --git a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp index f12876f745..e3a2d3cc99 100644 --- a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp +++ b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -416,14 +411,14 @@ void tst_QDirModel::rowsAboutToBeRemoved_data() bool tst_QDirModel::rowsAboutToBeRemoved_init(const QString &test_path, const QStringList &initial_files) { - QString path = QDir::currentPath() + "/" + test_path; + QString path = QDir::currentPath() + QLatin1Char('/') + test_path; if (!QDir::current().mkdir(test_path) && false) { // FIXME qDebug() << "failed to create dir" << path; return false; } for (int i = 0; i < initial_files.count(); ++i) { - QFile file(path + "/" + initial_files.at(i)); + QFile file(path + QLatin1Char('/') + initial_files.at(i)); if (!file.open(QIODevice::WriteOnly)) { qDebug() << "failed to open file" << initial_files.at(i); return false; @@ -443,7 +438,7 @@ bool tst_QDirModel::rowsAboutToBeRemoved_init(const QString &test_path, const QS bool tst_QDirModel::rowsAboutToBeRemoved_cleanup(const QString &test_path) { - QString path = QDir::currentPath() + "/" + test_path; + QString path = QDir::currentPath() + QLatin1Char('/') + test_path; QDir dir(path, "*", QDir::SortFlags(QDir::Name|QDir::IgnoreCase), QDir::Files); QStringList files = dir.entryList(); @@ -584,8 +579,8 @@ void tst_QDirModel::filePath() QString path = SRCDIR; #else QString path = QFileInfo(SRCDIR).absoluteFilePath(); - if (!path.endsWith("/")) - path += "/"; + if (!path.endsWith(QLatin1Char('/'))) + path += QLatin1Char('/'); #endif QCOMPARE(model.filePath(index), path + QString( "test.lnk")); model.setResolveSymlinks(true); diff --git a/tests/auto/widgets/itemviews/qfileiconprovider/qfileiconprovider.pro b/tests/auto/widgets/itemviews/qfileiconprovider/qfileiconprovider.pro index 0c3a780405..37173a175e 100644 --- a/tests/auto/widgets/itemviews/qfileiconprovider/qfileiconprovider.pro +++ b/tests/auto/widgets/itemviews/qfileiconprovider/qfileiconprovider.pro @@ -1,5 +1,4 @@ CONFIG += testcase -CONFIG += parallel_test TARGET = tst_qfileiconprovider QT += widgets testlib SOURCES += tst_qfileiconprovider.cpp diff --git a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp index fba83a24c7..6db1f78312 100644 --- a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp +++ b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -40,12 +35,6 @@ class tst_QFileIconProvider : public QObject { Q_OBJECT -public slots: - void initTestCase(); - void cleanupTestCase(); - void init(); - void cleanup(); - private slots: void qfileiconprovider_data(); void qfileiconprovider(); @@ -69,29 +58,6 @@ public: }; -// This will be called before the first test function is executed. -// It is only called once. -void tst_QFileIconProvider::initTestCase() -{ -} - -// This will be called after the last test function is executed. -// It is only called once. -void tst_QFileIconProvider::cleanupTestCase() -{ -} - -// This will be called before each test function is executed. -void tst_QFileIconProvider::init() -{ -} - -// This will be called after every test function. -void tst_QFileIconProvider::cleanup() -{ -} - - void tst_QFileIconProvider::qfileiconprovider_data() { } diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 55fcf04846..ca22eee514 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; @@ -106,15 +102,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(); @@ -238,6 +231,7 @@ private slots: void resizeToContentTest(); void testStreamWithHide(); void testStylePosition(); + void stretchAndRestoreLastSection(); void sizeHintCrash(); @@ -272,7 +266,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) @@ -382,10 +377,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 @@ -560,7 +551,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 @@ -1569,7 +1560,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(); } @@ -2242,13 +2233,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); @@ -2324,9 +2323,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); @@ -2494,7 +2491,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) + "};"; @@ -2572,7 +2569,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)); } @@ -2891,5 +2888,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" diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 25f27cb0c7..34713bdff9 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -189,15 +184,7 @@ class tst_QItemDelegate : public QObject { Q_OBJECT -public: - tst_QItemDelegate(); - virtual ~tst_QItemDelegate(); - private slots: - void initTestCase(); - void cleanupTestCase(); - void init(); - void cleanup(); void getSetCheck(); void textRectangle_data(); void textRectangle(); @@ -255,30 +242,6 @@ void tst_QItemDelegate::getSetCheck() QCOMPARE(obj1.hasClipping(), true); } -tst_QItemDelegate::tst_QItemDelegate() -{ -} - -tst_QItemDelegate::~tst_QItemDelegate() -{ -} - -void tst_QItemDelegate::initTestCase() -{ -} - -void tst_QItemDelegate::cleanupTestCase() -{ -} - -void tst_QItemDelegate::init() -{ -} - -void tst_QItemDelegate::cleanup() -{ -} - void tst_QItemDelegate::textRectangle_data() { QFont font; diff --git a/tests/auto/widgets/itemviews/qitemeditorfactory/qitemeditorfactory.pro b/tests/auto/widgets/itemviews/qitemeditorfactory/qitemeditorfactory.pro index 55df1d83f1..5ff7771585 100644 --- a/tests/auto/widgets/itemviews/qitemeditorfactory/qitemeditorfactory.pro +++ b/tests/auto/widgets/itemviews/qitemeditorfactory/qitemeditorfactory.pro @@ -1,5 +1,4 @@ CONFIG += testcase -CONFIG += parallel_test TARGET = tst_qitemeditorfactory QT += widgets testlib SOURCES += tst_qitemeditorfactory.cpp diff --git a/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp b/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp index 15fd19ede9..ae587279b2 100644 --- a/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp +++ b/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** diff --git a/tests/auto/widgets/itemviews/qitemview/qitemview.pro b/tests/auto/widgets/itemviews/qitemview/qitemview.pro index 6e1697f790..079953d60d 100644 --- a/tests/auto/widgets/itemviews/qitemview/qitemview.pro +++ b/tests/auto/widgets/itemviews/qitemview/qitemview.pro @@ -1,5 +1,4 @@ CONFIG += testcase -CONFIG += parallel_test TARGET = tst_qitemview QT += widgets testlib SOURCES += tst_qitemview.cpp diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp index 8fd86ea467..d3211eada8 100644 --- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp +++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -90,15 +85,10 @@ class tst_QItemView : public QObject { Q_OBJECT -public: - tst_QItemView() {}; - virtual ~tst_QItemView() {}; - -public slots: +private slots: void init(); void cleanup(); -private slots: void nonDestructiveBasicTest_data(); void nonDestructiveBasicTest(); @@ -288,14 +278,16 @@ void tst_QItemView::populate() const int baseInsert = 26; #endif for (int i = 0; i < 40; ++i) { + const QString iS = QString::number(i); parent = treeModel->index(0, 0, parent); treeModel->insertRows(0, baseInsert + i, parent); treeModel->insertColumns(0, baseInsert + i, parent); // Fill in some values to make it easier to debug for (int x = 0; x < treeModel->rowCount(); ++x) { + const QString xS = QString::number(x); for (int y = 0; y < treeModel->columnCount(); ++y) { QModelIndex index = treeModel->index(x, y, parent); - treeModel->setData(index, QString("%1_%2_%3").arg(x).arg(y).arg(i)); + treeModel->setData(index, xS + QLatin1Char('_') + QString::number(y) + QLatin1Char('_') + iS); treeModel->setData(index, QVariant(QColor(Qt::blue)), Qt::TextColorRole); } } diff --git a/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp b/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp index c108e9a122..f1da2f4fe7 100644 --- a/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp +++ b/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 3cf9f7fe0b..651172e79f 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -74,21 +69,22 @@ static inline void setFrameless(QWidget *w) w->setWindowFlags(flags); } +static QStringList generateList(const QString &prefix, int size) +{ + QStringList result; + result.reserve(size); + for (int i = 0; i < size; ++i) + result.append(prefix + QString::number(i)); + return result; +} + class tst_QListView : public QObject { Q_OBJECT -public: - tst_QListView(); - virtual ~tst_QListView(); - - -public slots: +private slots: void initTestCase(); - void cleanupTestCase(); - void init(); void cleanup(); -private slots: void getSetCheck(); void noDelegate(); void noModel(); @@ -152,6 +148,7 @@ private slots: void taskQTBUG_39902_mutualScrollBars_data(); void taskQTBUG_39902_mutualScrollBars(); void horizontalScrollingByVerticalWheelEvents(); + void taskQTBUG_7232_AllowUserToControlSingleStep(); void taskQTBUG_51086_skippingIndexesInSelectedIndexes(); }; @@ -256,7 +253,7 @@ public: wrongIndex = true; qWarning("got invalid modelIndex %d/%d", idx.row(), idx.column()); } - return QString("%1/%2").arg(idx.row()).arg(idx.column()); + return QString::number(idx.row()) + QLatin1Char('/') + QString::number(idx.column()); } void removeLastRow() @@ -283,24 +280,20 @@ public: mutable bool wrongIndex; }; -tst_QListView::tst_QListView() -{ -} - -tst_QListView::~tst_QListView() +class ScrollPerItemListView : public QListView { -} +public: + explicit ScrollPerItemListView(QWidget *parent = Q_NULLPTR) + : QListView(parent) + { + // Force per item scroll mode since it comes from the style by default + setVerticalScrollMode(QAbstractItemView::ScrollPerItem); + setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); + } +}; void tst_QListView::initTestCase() { -} - -void tst_QListView::cleanupTestCase() -{ -} - -void tst_QListView::init() -{ #ifdef Q_OS_WINCE //disable magic for WindowsCE qApp->setAutoMaximizeThreshold(-1); #endif @@ -311,7 +304,6 @@ void tst_QListView::cleanup() QVERIFY(QApplication::topLevelWidgets().isEmpty()); } - void tst_QListView::noDelegate() { QtTestModel model(0); @@ -365,10 +357,11 @@ void tst_QListView::cursorMove() view.setModel(&model); for (int j = 0; j < columns; ++j) { + const QString postfix = QLatin1Char(',') + QString::number(j) + QLatin1Char(']'); view.setModelColumn(j); for (int i = 0; i < rows; ++i) { QModelIndex index = model.index(i, j); - model.setData(index, QString("[%1,%2]").arg(i).arg(j)); + model.setData(index, QLatin1Char('[') + QString::number(i) + postfix); view.setCurrentIndex(index); QApplication::processEvents(); QCOMPARE(view.currentIndex(), index); @@ -469,7 +462,7 @@ void tst_QListView::hideRows() QStandardItemModel sim(0); QStandardItem *root = new QStandardItem("Root row"); for (int i=0;i<5;i++) - root->appendRow(new QStandardItem(QString("Row %1").arg(i))); + root->appendRow(new QStandardItem(QLatin1String("Row ") + QString::number(i))); sim.appendRow(root); view.setModel(&sim); view.setRootIndex(root->index()); @@ -703,9 +696,11 @@ void tst_QListView::singleSelectionRemoveColumn() int numCols = 3; int numRows = 3; QStandardItemModel model(numCols, numRows); - for (int r = 0; r < numRows; ++r) + for (int r = 0; r < numRows; ++r) { + const QString prefix = QString::number(r) + QLatin1Char(','); for (int c = 0; c < numCols; ++c) - model.setData(model.index(r, c), QString("%1,%2").arg(r).arg(c)); + model.setData(model.index(r, c), prefix + QString::number(c)); + } QListView view; view.setModel(&model); @@ -730,10 +725,11 @@ void tst_QListView::modelColumn() int numCols = 3; int numRows = 3; QStandardItemModel model(numCols, numRows); - for (int r = 0; r < numRows; ++r) + for (int r = 0; r < numRows; ++r) { + const QString prefix = QString::number(r) + QLatin1Char(','); for (int c = 0; c < numCols; ++c) - model.setData(model.index(r, c), QString("%1,%2").arg(r).arg(c)); - + model.setData(model.index(r, c), prefix + QString::number(c)); + } QListView view; view.setModel(&model); @@ -812,10 +808,7 @@ void tst_QListView::batchedMode() { const int rowCount = 3; - QStringList items; - for (int i = 0; i < rowCount; ++i) - items << QLatin1String("item ") + QString::number(i); - QStringListModel model(items); + QStringListModel model(generateList(QLatin1String("item "), rowCount)); QListView view; view.setWindowTitle(QTest::currentTestFunction()); @@ -841,13 +834,9 @@ void tst_QListView::batchedMode() void tst_QListView::setCurrentIndex() { - QStringList items; - int i; - for (i=0; i <20; ++i) - items << QString("item %1").arg(i); - QStringListModel model(items); + QStringListModel model(generateList(QLatin1String("item "), 20)); - QListView view; + ScrollPerItemListView view; view.setModel(&model); view.resize(220,182); @@ -867,7 +856,7 @@ void tst_QListView::setCurrentIndex() int offset = sb->value(); // first "scroll" down, verify that we scroll one step at a time - i = 0; + int i = 0; for (i = 0; i < 20; ++i) { QModelIndex idx = model.index(i,0); view.setCurrentIndex(idx); @@ -1177,7 +1166,7 @@ void tst_QListView::scrollTo() { QWidget topLevel; setFrameless(&topLevel); - QListView lv(&topLevel); + ScrollPerItemListView lv(&topLevel); QStringListModel model(&lv); QStringList list; list << "Short item 1"; @@ -1213,6 +1202,7 @@ void tst_QListView::scrollTo() model.setStringList(list); lv.setModel(&model); lv.setFixedSize(110, 200); + topLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); @@ -1286,15 +1276,16 @@ void tst_QListView::scrollBarRanges() const int rowHeight = 20; QWidget topLevel; - QListView lv(&topLevel); + ScrollPerItemListView lv(&topLevel); QStringListModel model(&lv); QStringList list; for (int i = 0; i < rowCount; ++i) - list << QString::fromLatin1("Item %1").arg(i); + list << QLatin1String("Item ") + QString::number(i); model.setStringList(list); lv.setModel(&model); lv.resize(250, 130); + TestDelegate *delegate = new TestDelegate(&lv); delegate->m_sizeHint = QSize(100, rowHeight); lv.setItemDelegate(delegate); @@ -1388,17 +1379,13 @@ void tst_QListView::scrollBarAsNeeded() QStringList list; int i; for (i = 0; i < rowCounts[r]; ++i) - list << QString::fromLatin1("Item %1").arg(i); + list << QLatin1String("Item ") + QString::number(i); model.setStringList(list); QApplication::processEvents(); QTest::qWait(50); - QStringList replacement; - for (i = 0; i < itemCount; ++i) { - replacement << QString::fromLatin1("Item %1").arg(i); - } - model.setStringList(replacement); + model.setStringList(generateList(QLatin1String("Item "), itemCount)); QApplication::processEvents(); @@ -1411,10 +1398,9 @@ void tst_QListView::moveItems() { QStandardItemModel model; for (int r = 0; r < 4; ++r) { - for (int c = 0; c < 4; ++c) { - QStandardItem* item = new QStandardItem(QString("standard item (%1,%2)").arg(r).arg(c)); - model.setItem(r, c, item); - } + const QString prefix = QLatin1String("standard item (") + QString::number(r) + QLatin1Char(','); + for (int c = 0; c < 4; ++c) + model.setItem(r, c, new QStandardItem(prefix + QString::number(c) + QLatin1Char(')'))); } PublicListView view; @@ -1456,15 +1442,6 @@ void tst_QListView::wordWrap() lv.setModel(&model); lv.setWordWrap(true); lv.setFixedSize(400, 150); - -#if defined Q_OS_BLACKBERRY - QFont font = lv.font(); - // On BB10 the root window is stretched over the whole screen - // This makes sure that the text will be long enough to produce - // a vertical scrollbar - font.setPixelSize(50); - lv.setFont(font); -#endif lv.showNormal(); QApplication::processEvents(); @@ -1526,9 +1503,10 @@ void tst_QListView::emptyItemSize() { QStandardItemModel model; for (int r = 0; r < 4; ++r) { - QStandardItem* item = new QStandardItem(QString("standard item (%1)").arg(r)); - model.setItem(r, 0, item); + const QString text = QLatin1String("standard item (") + QString::number(r) + QLatin1Char(')'); + model.setItem(r, new QStandardItem(text)); } + model.setItem(4, 0, new QStandardItem()); PublicListView view; @@ -1851,7 +1829,7 @@ void tst_QListView::taskQTBUG_2233_scrollHiddenItems() QWidget topLevel; setFrameless(&topLevel); - QListView view(&topLevel); + ScrollPerItemListView view(&topLevel); QStringListModel model(&view); QStringList list; for (int i = 0; i < rowCount; ++i) @@ -1995,12 +1973,7 @@ public: void tst_QListView::taskQTBUG_9455_wrongScrollbarRanges() { - QStringList list; - const int nrItems = 8; - for (int i = 0; i < nrItems; i++) - list << QString::asprintf("item %d", i); - - QStringListModel model(list); + QStringListModel model(generateList("item ", 8)); ListView_9455 w; setFrameless(&w); w.setModel(&model); @@ -2084,7 +2057,7 @@ void tst_QListView::taskQTBUG_12308_wrongFlowLayout() QListWidgetItem *item = new QListWidgetItem(); item->setText(QString("Item %L1").arg(i)); lw.addItem(item); - if (!item->text().contains(QString::fromLatin1("1"))) + if (!item->text().contains(QLatin1Char('1'))) item->setHidden(true); } lw.show(); @@ -2100,15 +2073,9 @@ void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems_data() void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems() { -#if defined Q_OS_BLACKBERRY - // On BB10 we need to create a root window which is automatically stretched - // over the whole screen - QWindow rootWindow; - rootWindow.show(); -#endif QFETCH(int, flow); - QListView lv; + ScrollPerItemListView lv; lv.setUniformItemSizes(true); lv.setFlow(static_cast<QListView::Flow>(flow)); @@ -2174,9 +2141,9 @@ void tst_QListView::draggablePaintPairs() view.scrollTo(expectedIndex); QItemViewPaintPairs pairs = privateClass->draggablePaintPairs(indexList, &rect); QCOMPARE(indexList.size(), pairs.size()); - foreach (const QItemViewPaintPair pair, pairs) { - QCOMPARE(rect, pair.first); - QCOMPARE(expectedIndex, pair.second); + foreach (const QItemViewPaintPair &pair, pairs) { + QCOMPARE(rect, pair.rect); + QCOMPARE(expectedIndex, pair.index); } } @@ -2203,7 +2170,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys() model.setStringList(list); // create listview - QListView lv; + ScrollPerItemListView lv; lv.setFlow(static_cast<QListView::Flow>(flow)); lv.setSpacing(spacing); lv.setModel(&model); @@ -2275,7 +2242,7 @@ void tst_QListView::spacing() model.setStringList(list); // create listview - QListView lv; + ScrollPerItemListView lv; lv.setFlow(static_cast<QListView::Flow>(flow)); lv.setModel(&model); lv.setSpacing(spacing); @@ -2298,12 +2265,6 @@ void tst_QListView::spacing() void tst_QListView::testScrollToWithHidden() { -#if defined Q_OS_BLACKBERRY - // On BB10 we need to create a root window which is automatically stretched - // over the whole screen - QWindow rootWindow; - rootWindow.show(); -#endif QListView lv; QStringListModel model; @@ -2494,6 +2455,44 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents() QVERIFY(lv.verticalScrollBar()->value() > vValue); } +void tst_QListView::taskQTBUG_7232_AllowUserToControlSingleStep() +{ + // When we set the scrollMode to ScrollPerPixel it will adjust the scrollbars singleStep automatically + // Setting a singlestep on a scrollbar should however imply that the user takes control. + // Setting a singlestep to -1 return to an automatic control of the singleStep. + QListView lv; + lv.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + lv.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + + QStandardItemModel model(1000, 100); + QString str = QString::fromLatin1("This is a long string made to ensure that we get some horizontal scroll (and we want scroll)"); + model.setData(model.index(0, 0), str); + lv.setModel(&model); + lv.setGeometry(150, 150, 150, 150); + lv.show(); + lv.setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + lv.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); + QVERIFY(QTest::qWaitForWindowExposed(&lv)); + + int vStep1 = lv.verticalScrollBar()->singleStep(); + int hStep1 = lv.horizontalScrollBar()->singleStep(); + QVERIFY(lv.verticalScrollBar()->singleStep() > 1); + QVERIFY(lv.horizontalScrollBar()->singleStep() > 1); + + lv.verticalScrollBar()->setSingleStep(1); + lv.setGeometry(200, 200, 200, 200); + QCOMPARE(lv.verticalScrollBar()->singleStep(), 1); + + lv.horizontalScrollBar()->setSingleStep(1); + lv.setGeometry(150, 150, 150, 150); + QCOMPARE(lv.horizontalScrollBar()->singleStep(), 1); + + lv.verticalScrollBar()->setSingleStep(-1); + lv.horizontalScrollBar()->setSingleStep(-1); + QCOMPARE(vStep1, lv.verticalScrollBar()->singleStep()); + QCOMPARE(hStep1, lv.horizontalScrollBar()->singleStep()); +} + void tst_QListView::taskQTBUG_51086_skippingIndexesInSelectedIndexes() { // simple way to get access to selectedIndexes() diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index ecf72613da..e8bd86bee5 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -46,7 +41,6 @@ class tst_QListWidget : public QObject public: tst_QListWidget(); - ~tst_QListWidget(); enum ModelChanged { RowsAboutToBeInserted, @@ -59,13 +53,10 @@ public: ColumnsRemoved }; -public slots: +private slots: void initTestCase(); void cleanupTestCase(); void init(); - void cleanup(); - -private slots: void addItem(); void addItem2(); void addItems(); @@ -124,6 +115,7 @@ private slots: void QTBUG8086_currentItemChangedOnClick(); void QTBUG14363_completerWithAnyKeyPressedEditTriggers(); void mimeData(); + void QTBUG50891_ensureSelectionModelSignalConnectionsAreSet(); protected slots: void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last) @@ -162,10 +154,6 @@ tst_QListWidget::tst_QListWidget(): testWidget(0), rcParent(8), rcFirst(8,0), rc { } -tst_QListWidget::~tst_QListWidget() -{ -} - void tst_QListWidget::initTestCase() { testWidget = new QListWidget(); @@ -210,10 +198,6 @@ void tst_QListWidget::checkDefaultValues() QCOMPARE(testWidget->count(), 0); } -void tst_QListWidget::cleanup() -{ -} - void tst_QListWidget::populate() { addItem(); @@ -230,7 +214,7 @@ void tst_QListWidget::populate() void tst_QListWidget::addItem() { int count = testWidget->count(); - QString label = QString("%1").arg(count); + const QString label = QString::number(count); testWidget->addItem(label); QCOMPARE(testWidget->count(), ++count); QCOMPARE(testWidget->item(testWidget->count()-1)->text(), label); @@ -244,7 +228,7 @@ void tst_QListWidget::addItem2() testWidget->addItem(0); QCOMPARE(testWidget->count(), count); - QListWidgetItem *item = new QListWidgetItem(QString("%1").arg(count)); + QListWidgetItem *item = new QListWidgetItem(QString::number(count)); item->setFlags(item->flags() | Qt::ItemIsEditable); testWidget->addItem(item); QCOMPARE(testWidget->count(), ++count); @@ -261,10 +245,10 @@ void tst_QListWidget::addItems() QCOMPARE(testWidget->count(), count); QStringList stringList; - QString label = QString("%1").arg(count); - stringList << QString("%1").arg(testWidget->count() + 1) - << QString("%1").arg(testWidget->count() + 2) - << QString("%1").arg(testWidget->count() + 3) + QString label = QString::number(count); + stringList << QString::number(testWidget->count() + 1) + << QString::number(testWidget->count() + 2) + << QString::number(testWidget->count() + 3) << label; testWidget->addItems(stringList); QCOMPARE(testWidget->count(), count + stringList.count()); @@ -276,7 +260,7 @@ void tst_QListWidget::openPersistentEditor() { // Boundary checking testWidget->openPersistentEditor(0); - QListWidgetItem *item = new QListWidgetItem(QString("%1").arg(testWidget->count())); + QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count())); testWidget->openPersistentEditor(item); int childCount = testWidget->viewport()->children().count(); @@ -290,7 +274,7 @@ void tst_QListWidget::closePersistentEditor() // Boundary checking int childCount = testWidget->viewport()->children().count(); testWidget->closePersistentEditor(0); - QListWidgetItem *item = new QListWidgetItem(QString("%1").arg(testWidget->count())); + QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count())); testWidget->closePersistentEditor(item); QCOMPARE(childCount, testWidget->viewport()->children().count()); @@ -316,7 +300,7 @@ void tst_QListWidget::setItemHidden() if (testWidget->isItemHidden(testWidget->item(i))) totalHidden++; - QListWidgetItem *item = new QListWidgetItem(QString("%1").arg(testWidget->count())); + QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count())); testWidget->addItem(item); // Check that nothing else changed @@ -362,7 +346,7 @@ void tst_QListWidget::setCurrentItem() { QFETCH(int, fill); for (int i = 0; i < fill; ++i) - testWidget->addItem(QString("%1").arg(i)); + testWidget->addItem(QString::number(i)); // Boundary checking testWidget->setCurrentItem((QListWidgetItem *)0); @@ -394,7 +378,7 @@ void tst_QListWidget::setCurrentRow() { QFETCH(int, fill); for (int i = 0; i < fill; ++i) - testWidget->addItem(QString("%1").arg(i)); + testWidget->addItem(QString::number(i)); // Boundary checking testWidget->setCurrentRow(-1); @@ -455,7 +439,7 @@ void tst_QListWidget::editItem() { // Boundary checking testWidget->editItem(0); - QListWidgetItem *item = new QListWidgetItem(QString("%1").arg(testWidget->count())); + QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count())); testWidget->editItem(item); QFETCH(bool, editable); @@ -650,7 +634,7 @@ void tst_QListWidget::item() QCOMPARE(item, static_cast<QListWidgetItem*>(0)); QCOMPARE(testWidget->count(), 3); } else { - QCOMPARE(item->text(), QString("item%1").arg(row)); + QCOMPARE(item->text(), QStringLiteral("item") + QString::number(row)); QCOMPARE(testWidget->count(), 3); } } @@ -683,7 +667,7 @@ void tst_QListWidget::takeItem() QCOMPARE(item, static_cast<QListWidgetItem*>(0)); QCOMPARE(testWidget->count(), 3); } else { - QCOMPARE(item->text(), QString("item%1").arg(row)); + QCOMPARE(item->text(), QStringLiteral("item") + QString::number(row)); QCOMPARE(testWidget->count(), 2); } @@ -746,7 +730,7 @@ void tst_QListWidget::selectedItems() //insert items for (int i=0; i<itemCount; ++i) - new QListWidgetItem(QString("Item%1").arg(i), testWidget); + new QListWidgetItem(QStringLiteral("Item") + QString::number(i), testWidget); //test the selection testWidget->setSelectionMode(QListWidget::SingleSelection); @@ -1245,8 +1229,8 @@ void tst_QListWidget::insertItemsWithSorting_data() QStringList ascendingItems; QStringList reverseItems; for (int i = 'a'; i <= 'z'; ++i) { - ascendingItems << QString("%0").arg(QLatin1Char(i)); - reverseItems << QString("%0").arg(QLatin1Char('z' - i + 'a')); + ascendingItems << QString(1, QLatin1Char(i)); + reverseItems << QString(1, QLatin1Char('z' - i + 'a')); ascendingRows << i - 'a'; reverseRows << 'z' - i + 'a'; } @@ -1490,7 +1474,7 @@ void tst_QListWidget::fastScroll() QWidget topLevel; MyListWidget widget(&topLevel); for (int i = 0; i < 50; ++i) - widget.addItem(QString("Item %1").arg(i)); + widget.addItem(QStringLiteral("Item ") + QString::number(i)); topLevel.resize(300, 300); // toplevel needs to be wide enough for the item topLevel.show(); @@ -1717,5 +1701,30 @@ void tst_QListWidget::mimeData() delete data2; } +void tst_QListWidget::QTBUG50891_ensureSelectionModelSignalConnectionsAreSet() +{ + qRegisterMetaType<QListWidgetItem*>("QListWidgetItem*"); + QListWidget list; + for (int i = 0 ; i < 4; ++i) + new QListWidgetItem(QString::number(i), &list); + + list.setSelectionModel(new QItemSelectionModel(list.model())); + list.show(); + + QSignalSpy currentItemChangedSpy(&list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*))); + QSignalSpy itemSelectionChangedSpy(&list, SIGNAL(itemSelectionChanged())); + + QVERIFY(QTest::qWaitForWindowExposed(&list)); + + QCOMPARE(currentItemChangedSpy.count(), 0); + QCOMPARE(itemSelectionChangedSpy.count(), 0); + + QTest::mouseClick(list.viewport(), Qt::LeftButton, 0, list.visualItemRect(list.item(2)).center()); + + QCOMPARE(currentItemChangedSpy.count(), 1); + QCOMPARE(itemSelectionChangedSpy.count(), 1); + +} + QTEST_MAIN(tst_QListWidget) #include "tst_qlistwidget.moc" diff --git a/tests/auto/widgets/itemviews/qtableview/qtableview.pro b/tests/auto/widgets/itemviews/qtableview/qtableview.pro index 0814af77fb..e02da95ab9 100644 --- a/tests/auto/widgets/itemviews/qtableview/qtableview.pro +++ b/tests/auto/widgets/itemviews/qtableview/qtableview.pro @@ -3,6 +3,4 @@ TARGET = tst_qtableview QT += widgets widgets-private testlib QT += core-private gui-private -TARGET.EPOCHEAPSIZE = 0x200000 0x800000 SOURCES += tst_qtableview.cpp -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index e5abd6bc46..f935d6eecf 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -65,17 +60,9 @@ class tst_QTableView : public QObject { Q_OBJECT -public: - tst_QTableView(); - virtual ~tst_QTableView(); - -public slots: +private slots: void initTestCase(); - void cleanupTestCase(); - void init(); - void cleanup(); -private slots: void getSetCheck(); void noDelegate(); @@ -214,6 +201,8 @@ private slots: void changeHeaderData(); void viewOptions(); + + void taskQTBUG_7232_AllowUserToControlSingleStep(); }; // Testing get/set functions @@ -325,8 +314,10 @@ public: return QVariant(); } - if (role == Qt::DisplayRole || role == Qt::EditRole) - return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(0); + if (role == Qt::DisplayRole || role == Qt::EditRole) { + return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',') + + QString::number(idx.column()) + QLatin1String(",0]"); + } return QVariant(); } @@ -415,7 +406,8 @@ public: void reset() { - QAbstractTableModel::reset(); + beginResetModel(); + endResetModel(); } int row_count; @@ -527,14 +519,6 @@ public: QSize hint; }; -tst_QTableView::tst_QTableView() -{ -} - -tst_QTableView::~tst_QTableView() -{ -} - void tst_QTableView::initTestCase() { #ifdef Q_OS_WINCE //disable magic for WindowsCE @@ -542,18 +526,6 @@ void tst_QTableView::initTestCase() #endif } -void tst_QTableView::cleanupTestCase() -{ -} - -void tst_QTableView::init() -{ -} - -void tst_QTableView::cleanup() -{ -} - void tst_QTableView::noDelegate() { QtTestTableModel model(3, 3); @@ -3606,7 +3578,11 @@ public: { return QVariant(); } - void res() { reset(); } + void res() + { + beginResetModel(); + endResetModel(); + } int rows; int columns; @@ -3797,7 +3773,7 @@ public: int role = Qt::DisplayRole) const { if (role == Qt::DisplayRole) - return QString("%1 - %2").arg(index.column()).arg(index.row()); + return QString::number(index.column()) + QLatin1String(" - ") + QString::number(index.row()); return QVariant(); } @@ -3919,12 +3895,12 @@ void tst_QTableView::task227953_setRootIndex() //setup the first table as a child of the first item for ( int row = 0; row < 40; ++row ) { - item1.appendRow(QList<QStandardItem*>() << new QStandardItem(QString("row %0").arg(row))); + item1.appendRow(QList<QStandardItem*>() << new QStandardItem(QLatin1String("row ") + QString::number(row))); } //setup the second table as a child of the second item for ( int row = 0; row < 10; ++row ) { - item2.appendRow(QList<QStandardItem*>() << new QStandardItem(QString("row %0").arg(row))); + item2.appendRow(QList<QStandardItem*>() << new QStandardItem(QLatin1String("row ") + QString::number(row))); } tableView.setModel(&model); @@ -4476,5 +4452,41 @@ void tst_QTableView::taskQTBUG_30653_doItemsLayout() QCOMPARE(scrollToBottomOffset, doItemsLayoutOffset); } +void tst_QTableView::taskQTBUG_7232_AllowUserToControlSingleStep() +{ + // When we set the scrollMode to ScrollPerPixel it will adjust the scrollbars singleStep automatically + // Setting a singlestep on a scrollbar should however imply that the user takes control (and it is not changed by geometry updates). + // Setting a singlestep to -1 return to an automatic control of the singleStep. + QTableView t; + t.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + t.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + QStandardItemModel model(200, 200); + t.setModel(&model); + t.show(); + QVERIFY(QTest::qWaitForWindowExposed(&t)); + t.setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + t.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); + + t.setGeometry(200, 200, 200, 200); + int vStep1 = t.verticalScrollBar()->singleStep(); + int hStep1 = t.horizontalScrollBar()->singleStep(); + QVERIFY(vStep1 > 1); + QVERIFY(hStep1 > 1); + + t.verticalScrollBar()->setSingleStep(1); + t.setGeometry(300, 300, 300, 300); + QCOMPARE(t.verticalScrollBar()->singleStep(), 1); + + t.horizontalScrollBar()->setSingleStep(1); + t.setGeometry(400, 400, 400, 400); + QCOMPARE(t.horizontalScrollBar()->singleStep(), 1); + + t.setGeometry(200, 200, 200, 200); + t.verticalScrollBar()->setSingleStep(-1); + t.horizontalScrollBar()->setSingleStep(-1); + QCOMPARE(vStep1, t.verticalScrollBar()->singleStep()); + QCOMPARE(hStep1, t.horizontalScrollBar()->singleStep()); +} + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" diff --git a/tests/auto/widgets/itemviews/qtablewidget/qtablewidget.pro b/tests/auto/widgets/itemviews/qtablewidget/qtablewidget.pro index d2c962b4de..114ce115eb 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/qtablewidget.pro +++ b/tests/auto/widgets/itemviews/qtablewidget/qtablewidget.pro @@ -1,5 +1,4 @@ CONFIG += testcase -CONFIG += parallel_test TARGET = tst_qtablewidget QT += widgets testlib SOURCES += tst_qtablewidget.cpp diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index ea31fd19dd..8f871b03f6 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -51,14 +46,11 @@ class tst_QTableWidget : public QObject public: tst_QTableWidget(); - ~tst_QTableWidget(); -public slots: +private slots: void initTestCase(); void cleanupTestCase(); void init(); - void cleanup(); -private slots: void getSetCheck(); void clear(); void clearContents(); @@ -161,10 +153,6 @@ tst_QTableWidget::tst_QTableWidget(): testWidget(0) { } -tst_QTableWidget::~tst_QTableWidget() -{ -} - void tst_QTableWidget::initTestCase() { testWidget = new QTableWidget(); @@ -188,11 +176,6 @@ void tst_QTableWidget::init() testWidget->showColumn(column); } -void tst_QTableWidget::cleanup() -{ - -} - void tst_QTableWidget::clearContents() { QTableWidgetItem *item = new QTableWidgetItem("test"); @@ -1473,7 +1456,7 @@ void tst_QTableWidget::task262056_sortDuplicate() for (int i = 0; i<8; i++ ) { QTableWidgetItem *twi = new QTableWidgetItem(items.at(i)); testWidget->setItem(i,0,twi); - testWidget->setItem(i,1,new QTableWidgetItem(QString("item %1").arg(i))); + testWidget->setItem(i,1,new QTableWidgetItem(QLatin1String("item ") + QString::number(i))); } testWidget->sortItems(0, Qt::AscendingOrder); QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged())); diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index ea85c8e057..938c8a47ac 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -119,20 +114,12 @@ class tst_QTreeView : public QObject { Q_OBJECT -public: - tst_QTreeView(); - virtual ~tst_QTreeView(); - - public slots: - void initTestCase(); - void cleanupTestCase(); - void init(); - void cleanup(); - void selectionOrderTest(); private slots: + void initTestCase(); + void getSetCheck(); // one test per QTreeView property @@ -256,6 +243,7 @@ private slots: void taskQTBUG_8176_emitOnExpandAll(); void taskQTBUG_37813_crash(); void taskQTBUG_45697_crash(); + void taskQTBUG_7232_AllowUserToControlSingleStep(); void testInitialFocus(); }; @@ -339,9 +327,12 @@ public: qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), idx.internalPointer()); } + QString result = QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',') + + QString::number(idx.column()) + QLatin1Char(',') + QString::number(level(idx)) + + QLatin1Char(']'); if (idx.row() & 1) - return QString("[%1,%2,%3] - this item is extra wide").arg(idx.row()).arg(idx.column()).arg(level(idx)); - return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(level(idx)); + result += QLatin1String(" - this item is extra wide"); + return result; } if (decorationsEnabled && role == Qt::DecorationRole) { QPixmap pm(16,16); @@ -399,14 +390,6 @@ public: mutable QMap<QModelIndex,QModelIndex> parentHash; }; -tst_QTreeView::tst_QTreeView() -{ -} - -tst_QTreeView::~tst_QTreeView() -{ -} - void tst_QTreeView::initTestCase() { #ifdef Q_OS_WINCE //disable magic for WindowsCE @@ -414,18 +397,6 @@ void tst_QTreeView::initTestCase() #endif } -void tst_QTreeView::cleanupTestCase() -{ -} - -void tst_QTreeView::init() -{ -} - -void tst_QTreeView::cleanup() -{ -} - // Testing get/set functions void tst_QTreeView::getSetCheck() { @@ -533,7 +504,7 @@ void tst_QTreeView::construction() QCOMPARE(view.sizeHintForRow(1), -1); QVERIFY(!view.tabKeyNavigation()); QCOMPARE(view.textElideMode(), Qt::ElideRight); - QCOMPARE(view.verticalScrollMode(), QAbstractItemView::ScrollPerItem); + QCOMPARE(static_cast<int>(view.verticalScrollMode()), view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view)); QCOMPARE(view.visualRect(QModelIndex()), QRect()); // QTreeView properties @@ -2085,13 +2056,14 @@ void tst_QTreeView::rowsAboutToBeRemoved() { QStandardItemModel model(3, 1); for (int i = 0; i < model.rowCount(); i++) { + const QString iS = QString::number(i); QModelIndex index = model.index(i, 0, QModelIndex()); - model.setData(index, QString("%1").arg(i)); + model.setData(index, iS); model.insertRows(0, 4, index); model.insertColumns(0,1,index); for (int i1 = 0; i1 < model.rowCount(index); i1++) { QModelIndex index2 = model.index(i1, 0, index); - model.setData(index2, QString("%1%2").arg(i).arg(i1)); + model.setData(index2, iS + QString::number(i1)); } } @@ -2229,14 +2201,16 @@ void tst_QTreeView::resizeColumnToContents() { QStandardItemModel model(50,2); for (int r = 0; r < model.rowCount(); ++r) { + const QString rS = QString::number(r); for (int c = 0; c < model.columnCount(); ++c) { QModelIndex idx = model.index(r, c); - model.setData(idx, QString::fromLatin1("%1,%2").arg(r).arg(c) ); + model.setData(idx, rS + QLatin1Char(',') + QString::number(c)); model.insertColumns(0, 2, idx); model.insertRows(0, 6, idx); for (int i = 0; i < 6; ++i) { + const QString iS = QString::number(i); for (int j = 0; j < 2 ; ++j) { - model.setData(model.index(i, j, idx), QString::fromLatin1("child%1%2").arg(i).arg(j)); + model.setData(model.index(i, j, idx), QLatin1String("child") + iS + QString::number(j)); } } } @@ -2391,7 +2365,7 @@ void tst_QTreeView::selectionWithHiddenItems() { QStandardItemModel model; for (int i = 0; i < model.rowCount(); ++i) - model.setData(model.index(i,0), QString("row %1").arg(i)); + model.setData(model.index(i,0), QLatin1String("row ") + QString::number(i)); QStandardItem item0("row 0"); QStandardItem item1("row 1"); @@ -2465,7 +2439,7 @@ void tst_QTreeView::selectAll() QCOMPARE(view2.selectedIndexes().count(), model.rowCount() * model.columnCount()); for (int i = 0; i < model.rowCount(); ++i) - model.setData(model.index(i,0), QString("row %1").arg(i)); + model.setData(model.index(i,0), QLatin1String("row ") + QString::number(i)); PublicView view; view.setModel(&model); int selectedCount = view.selectedIndexes().count(); @@ -2817,8 +2791,9 @@ public: if (parentNode->isDead) qFatal("%s: grandparentNode is dead!", Q_FUNC_INFO); } - return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()) - .arg(parentNode->isDead ? "dead" : "alive"); + return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',') + + QString::number(idx.column()) + QLatin1Char(',') + + QLatin1String(parentNode->isDead ? "dead" : "alive") + QLatin1Char(']'); } return QVariant(); } @@ -3021,7 +2996,7 @@ void tst_QTreeView::filterProxyModelCrash() QStandardItemModel model; QList<QStandardItem *> items; for (int i = 0; i < 100; i++) - items << new QStandardItem(QString::fromLatin1("item %1").arg(i)); + items << new QStandardItem(QLatin1String("item ") + QString::number(i)); model.appendColumn(items); QSortFilterProxyModel proxy; @@ -3387,11 +3362,11 @@ void tst_QTreeView::task203696_hidingColumnsAndRowsn() { QTreeView view; QStandardItemModel *model = new QStandardItemModel(0, 3, &view); - for (int i = 0; i < 3; ++i) - { + for (int i = 0; i < 3; ++i) { + const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col "); model->insertRow(model->rowCount()); for (int j = 0; j < model->columnCount(); ++j) - model->setData(model->index(i, j), QString("row %1 col %2").arg(i).arg(j)); + model->setData(model->index(i, j), prefix + QString::number(j)); } view.setModel(model); view.show(); @@ -3413,8 +3388,9 @@ void tst_QTreeView::addRowsWhileSectionsAreHidden() for (i = 0; i < 3; ++i) { model->insertRow(model->rowCount()); + const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col "); for (int j = 0; j < model->columnCount(); ++j) { - model->setData(model->index(i, j), QString("row %1 col %2").arg(i).arg(j)); + model->setData(model->index(i, j), prefix + QString::number(j)); } } int col; @@ -3423,8 +3399,9 @@ void tst_QTreeView::addRowsWhileSectionsAreHidden() for (i = 3; i < 6; ++i) { model->insertRow(model->rowCount()); + const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col "); for (int j = 0; j < model->columnCount(); ++j) { - model->setData(model->index(i, j), QString("row %1 col %2").arg(i).arg(j)); + model->setData(model->index(i, j), prefix + QString::number(j)); } } for (col = 0; col < pass; ++col) @@ -3478,8 +3455,10 @@ void tst_QTreeView::task220298_selectColumns() virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const { - if(role == Qt::DisplayRole) - return QVariant(QString("%1-%2").arg(index.column()).arg(index.row())); + if (role == Qt::DisplayRole) { + return QVariant(QString::number(index.column()) + QLatin1Char('-') + + QString::number(index.row())); + } return QVariant(); } @@ -3517,7 +3496,7 @@ void tst_QTreeView::task224091_appendColumns() QList<QStandardItem *> projlist; for (int k = 0; k < 10; ++k) - projlist.append(new QStandardItem(QString("Top Level %0").arg(k))); + projlist.append(new QStandardItem(QLatin1String("Top Level ") + QString::number(k))); model->appendColumn(projlist); model->invisibleRootItem()->appendRow(new QStandardItem("end")); @@ -3744,7 +3723,7 @@ void tst_QTreeView::task246536_scrollbarsNotWorking() QVERIFY(QTest::qWaitForWindowExposed(&tree)); QList<QStandardItem *> items; for(int i=0; i<100; ++i){ - items << new QStandardItem(QString::fromLatin1("item %1").arg(i)); + items << new QStandardItem(QLatin1String("item ") + QString::number(i)); } model.invisibleRootItem()->appendColumn(items); QTest::qWait(100); @@ -3932,7 +3911,8 @@ void tst_QTreeView::taskQTBUG_6450_selectAllWith1stColumnHidden() QList<QTreeWidgetItem *> items; const int nrRows = 10; for (int i = 0; i < nrRows; ++i) { - items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)))); + const QString text = QLatin1String("item: ") + QString::number(i); + items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(text))); items.last()->setText(1, QString("is an item")); } tree.insertTopLevelItems(0, items); @@ -3963,9 +3943,11 @@ public: void tst_QTreeView::taskQTBUG_9216_setSizeAndUniformRowHeightsWrongRepaint() { QStandardItemModel model(10, 10, this); - for (int row = 0; row < 10; row++) + for (int row = 0; row < 10; row++) { + const QString prefix = QLatin1String("row ") + QString::number(row) + QLatin1String(", col "); for (int col = 0; col < 10; col++) - model.setItem(row, col, new QStandardItem(QString("row %0, col %1").arg(row).arg(col))); + model.setItem(row, col, new QStandardItem(prefix + QString::number(col))); + } TreeViewQTBUG_9216 view; view.setUniformRowHeights(true); view.setModel(&model); @@ -4284,7 +4266,7 @@ void tst_QTreeView::testInitialFocus() { QTreeWidget treeWidget; treeWidget.setColumnCount(5); - new QTreeWidgetItem(&treeWidget, QStringList(QString("1;2;3;4;5").split(";"))); + new QTreeWidgetItem(&treeWidget, QStringList(QString("1;2;3;4;5").split(QLatin1Char(';')))); treeWidget.setTreePosition(2); treeWidget.header()->hideSection(0); // make sure we skip hidden section(s) treeWidget.header()->swapSections(1, 2); // make sure that we look for first visual index (and not first logical) @@ -4338,9 +4320,10 @@ void tst_QTreeView::taskQTBUG_37813_crash() treeWidget.setColumnCount(2); QList<QTreeWidgetItem *> items; for (int r = 0; r < 2; ++r) { + const QString prefix = QLatin1String("Row ") + QString::number(r) + QLatin1String(" Column "); QTreeWidgetItem *item = new QTreeWidgetItem(); for (int c = 0; c < treeWidget.columnCount(); ++c) - item->setText(c, QString::fromLatin1("Row %1 Column %2").arg(r).arg(c)); + item->setText(c, prefix + QString::number(c)); items.append(item); } treeWidget.addTopLevelItems(items); @@ -4431,5 +4414,47 @@ void tst_QTreeView::taskQTBUG_45697_crash() QTRY_VERIFY(testWidget.timerTick() >= 2); } +void tst_QTreeView::taskQTBUG_7232_AllowUserToControlSingleStep() +{ + // When we set the scrollMode to ScrollPerPixel it will adjust the scrollbars singleStep automatically + // Setting a singlestep on a scrollbar should however imply that the user takes control. + // Setting a singlestep to -1 return to an automatic control of the singleStep. + QTreeWidget t; + t.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + t.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + t.setColumnCount(2); + QTreeWidgetItem *mainItem = new QTreeWidgetItem(&t, QStringList() << "Root"); + for (int i = 0; i < 200; ++i) { + QTreeWidgetItem *item = new QTreeWidgetItem(mainItem, QStringList(QString("Item"))); + new QTreeWidgetItem(item, QStringList() << "Child" << "1"); + new QTreeWidgetItem(item, QStringList() << "Child" << "2"); + new QTreeWidgetItem(item, QStringList() << "Child" << "3"); + } + t.expandAll(); + + t.setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + t.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); + + t.setGeometry(200, 200, 200, 200); + int vStep1 = t.verticalScrollBar()->singleStep(); + int hStep1 = t.horizontalScrollBar()->singleStep(); + QVERIFY(vStep1 > 1); + QVERIFY(hStep1 > 1); + + t.verticalScrollBar()->setSingleStep(1); + t.setGeometry(300, 300, 300, 300); + QCOMPARE(t.verticalScrollBar()->singleStep(), 1); + + t.horizontalScrollBar()->setSingleStep(1); + t.setGeometry(400, 400, 400, 400); + QCOMPARE(t.horizontalScrollBar()->singleStep(), 1); + + t.setGeometry(200, 200, 200, 200); + t.verticalScrollBar()->setSingleStep(-1); + t.horizontalScrollBar()->setSingleStep(-1); + QCOMPARE(vStep1, t.verticalScrollBar()->singleStep()); + QCOMPARE(hStep1, t.horizontalScrollBar()->singleStep()); +} + QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 117c53a2bb..f1e8c7c814 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -320,7 +315,7 @@ void tst_QTreeWidget::addTopLevelItem() for (int i = 0; i < 100; i += count) { tops.clear(); for (int j = 0; j < count; ++j) - tops << new TreeItem(QStringList() << QString("%0").arg(j)); + tops << new TreeItem(QStringList(QString::number(j))); tree.addTopLevelItems(tops); QCOMPARE(tree.topLevelItemCount(), count + i); for (int j = 0; j < count; ++j) @@ -511,10 +506,10 @@ void tst_QTreeWidget::takeItem() for (int i=0; i<3; ++i) { QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); - top->setText(0, QString("top%1").arg(i)); + top->setText(0, QStringLiteral("top") + QString::number(i)); for (int j=0; j<3; ++j) { QTreeWidgetItem *child = new QTreeWidgetItem(top); - child->setText(0, QString("child%1").arg(j)); + child->setText(0, QStringLiteral("child") + QString::number(j)); } } @@ -528,7 +523,7 @@ void tst_QTreeWidget::takeItem() QCOMPARE(item, (QTreeWidgetItem *)0); QCOMPARE(count, testWidget->topLevelItemCount()); } else { - QCOMPARE(item->text(0), QString("top%1").arg(index)); + QCOMPARE(item->text(0), QStringLiteral("top") + QString::number(index)); QCOMPARE(count-1, testWidget->topLevelItemCount()); delete item; } @@ -539,7 +534,7 @@ void tst_QTreeWidget::takeItem() QCOMPARE(item, (QTreeWidgetItem *)0); QCOMPARE(count, testWidget->topLevelItem(0)->childCount()); } else { - QCOMPARE(item->text(0), QString("child%1").arg(index)); + QCOMPARE(item->text(0), QStringLiteral("child") + QString::number(index)); QCOMPARE(count-1, testWidget->topLevelItem(0)->childCount()); delete item; } @@ -794,10 +789,11 @@ void tst_QTreeWidget::selectedItems() // create items for (int t=0; t<topLevel; ++t) { QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); - top->setText(0, QString("top%1").arg(t)); + const QString topS = QLatin1String("top") + QString::number(t); + top->setText(0, topS); for (int c=0; c<children; ++c) { QTreeWidgetItem *child = new QTreeWidgetItem(top); - child->setText(0, QString("top%1child%2").arg(t).arg(c)); + child->setText(0, topS + QLatin1String("child") + QString::number(c)); } } @@ -1442,11 +1438,10 @@ static void fillTreeWidget(QTreeWidgetItem *parent, int rows) { const int columns = parent->treeWidget()->columnCount(); for (int r = 0; r < rows; ++r) { + const QString prefix = QLatin1String("[r:") + QString::number(r) + QLatin1String(",c:"); QTreeWidgetItem *w = new QTreeWidgetItem(parent); - for ( int c = 0; c < columns; ++c ) { - QString s = QString("[r:%1,c:%2]").arg(r).arg(c); - w->setText(c, s); - } + for (int c = 0; c < columns; ++c) + w->setText(c, prefix + QString::number(c) + QLatin1Char(']')); fillTreeWidget(w, rows - r - 1); } } @@ -1455,10 +1450,9 @@ static void fillTreeWidget(QTreeWidget *tree, int rows) { for (int r = 0; r < rows; ++r) { QTreeWidgetItem *w = new QTreeWidgetItem(); - for ( int c = 0; c < tree->columnCount(); ++c ) { - QString s = QString("[r:%1,c:%2]").arg(r).arg(c); - w->setText(c, s); - } + const QString prefix = QLatin1String("[r:") + QString::number(r) + QLatin1String(",c:"); + for (int c = 0; c < tree->columnCount(); ++c) + w->setText(c, prefix + QString::number(c) + QLatin1Char(']')); tree->insertTopLevelItem(r, w); fillTreeWidget(w, rows - r - 1); } @@ -1555,7 +1549,7 @@ void tst_QTreeWidget::keyboardNavigation() } QTreeWidgetItem *current = testWidget->currentItem(); - QCOMPARE(current->text(0), QString("[r:%1,c:0]").arg(row)); + QCOMPARE(current->text(0), QLatin1String("[r:") + QString::number(row) + QLatin1String(",c:0]")); if (current->parent()) QCOMPARE(current->parent()->indexOfChild(current), row); else @@ -1696,7 +1690,7 @@ void tst_QTreeWidget::addChild() for (int i = 0; i < 100; i += count) { QList<QTreeWidgetItem*> list; for (int j = 0; j < count; ++j) - list << new QTreeWidgetItem(QStringList() << QString("%0").arg(j)); + list << new QTreeWidgetItem(QStringList(QString::number(j))); item->addChildren(list); QCOMPARE(item->childCount(), count + i); for (int j = 0; j < count; ++j) { @@ -1743,7 +1737,8 @@ void tst_QTreeWidget::setData() for (int i = 1; i <= 2; ++i) { for (int j = 0; j < 5; ++j) { QVariantList args; - QString text = QString("text %0").arg(i); + const QString iS = QString::number(i); + const QString text = QLatin1String("text ") + iS; item->setText(j, text); QCOMPARE(item->text(j), text); QCOMPARE(itemChangedSpy.count(), 1); @@ -1765,7 +1760,7 @@ void tst_QTreeWidget::setData() item->setIcon(j, icon); QCOMPARE(itemChangedSpy.count(), 0); - QString toolTip = QString("toolTip %0").arg(i); + const QString toolTip = QLatin1String("toolTip ") + iS; item->setToolTip(j, toolTip); QCOMPARE(item->toolTip(j), toolTip); QCOMPARE(itemChangedSpy.count(), 1); @@ -1775,7 +1770,7 @@ void tst_QTreeWidget::setData() item->setToolTip(j, toolTip); QCOMPARE(itemChangedSpy.count(), 0); - QString statusTip = QString("statusTip %0").arg(i); + const QString statusTip = QLatin1String("statusTip ") + iS; item->setStatusTip(j, statusTip); QCOMPARE(item->statusTip(j), statusTip); QCOMPARE(itemChangedSpy.count(), 1); @@ -1785,7 +1780,7 @@ void tst_QTreeWidget::setData() item->setStatusTip(j, statusTip); QCOMPARE(itemChangedSpy.count(), 0); - QString whatsThis = QString("whatsThis %0").arg(i); + const QString whatsThis = QLatin1String("whatsThis ") + iS; item->setWhatsThis(j, whatsThis); QCOMPARE(item->whatsThis(j), whatsThis); QCOMPARE(itemChangedSpy.count(), 1); @@ -2007,7 +2002,7 @@ void tst_QTreeWidget::columnCount() void tst_QTreeWidget::setHeaderLabels() { - QStringList list = QString("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z").split(","); + QStringList list = QString("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z").split(QLatin1Char(',')); testWidget->setHeaderLabels(list); QCOMPARE(testWidget->header()->count(), list.count()); } @@ -2147,8 +2142,8 @@ void tst_QTreeWidget::insertItemsWithSorting_data() QStringList ascendingItems; QStringList reverseItems; for (int i = 'a'; i <= 'z'; ++i) { - ascendingItems << QString("%0").arg(QLatin1Char(i)); - reverseItems << QString("%0").arg(QLatin1Char('z' - i + 'a')); + ascendingItems << QString(1, QLatin1Char(i)); + reverseItems << QString(1, QLatin1Char('z' - i + 'a')); ascendingRows << i - 'a'; reverseRows << 'z' - i + 'a'; } @@ -2671,9 +2666,9 @@ void tst_QTreeWidget::expandAndCallapse() QTreeWidgetItem *top = new QTreeWidgetItem(&tw, QStringList() << "top"); QTreeWidgetItem *p; for (int i = 0; i < 10; ++i) { - p = new QTreeWidgetItem(top, QStringList() << QString("%1").arg(i)); + p = new QTreeWidgetItem(top, QStringList(QString::number(i))); for (int j = 0; j < 10; ++j) - new QTreeWidgetItem(p, QStringList() << QString("%1").arg(j)); + new QTreeWidgetItem(p, QStringList(QString::number(j))); } QSignalSpy spy0(&tw, SIGNAL(itemExpanded(QTreeWidgetItem*))); QSignalSpy spy1(&tw, SIGNAL(itemCollapsed(QTreeWidgetItem*))); @@ -3133,7 +3128,7 @@ void tst_QTreeWidget::selectionOrder() testWidget->setColumnCount(1); QList<QTreeWidgetItem *> items; for (int i = 0; i < 10; ++i) - items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)))); + items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QLatin1String("item: ") + QString::number(i)))); testWidget->insertTopLevelItems(0, items); QModelIndex idx = testWidget->indexFromItem(items[0]); diff --git a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/qtreewidgetitemiterator.pro b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/qtreewidgetitemiterator.pro index 5fa6762617..42a00618a2 100644 --- a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/qtreewidgetitemiterator.pro +++ b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/qtreewidgetitemiterator.pro @@ -1,5 +1,4 @@ CONFIG += testcase -CONFIG += parallel_test TARGET = tst_qtreewidgetitemiterator QT += widgets testlib SOURCES += tst_qtreewidgetitemiterator.cpp diff --git a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp index c52198fa2c..f08e57c84b 100644 --- a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp +++ b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ ** @@ -46,15 +41,11 @@ class tst_QTreeWidgetItemIterator : public QObject public: tst_QTreeWidgetItemIterator(); - ~tst_QTreeWidgetItemIterator(); -public slots: +private slots: void initTestCase(); void cleanupTestCase(); - void init(); - void cleanup(); -private slots: void postincrement(); void preincrement(); void postdecrement(); @@ -81,10 +72,6 @@ tst_QTreeWidgetItemIterator::tst_QTreeWidgetItemIterator(): testWidget(0) { } -tst_QTreeWidgetItemIterator::~tst_QTreeWidgetItemIterator() -{ -} - void tst_QTreeWidgetItemIterator::initTestCase() { testWidget = new QTreeWidget(); @@ -105,7 +92,8 @@ void tst_QTreeWidgetItemIterator::initTestCase() */ for (int i=0; i <= 16; ++i) { QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); - top->setText(0, QString("top%1").arg(i)); + const QString topS = QLatin1String("top") + QString::number(i); + top->setText(0, topS); switch (i) { case 0: testWidget->setItemHidden(top, true);break; case 1: testWidget->setItemHidden(top, false);break; @@ -136,7 +124,7 @@ void tst_QTreeWidgetItemIterator::initTestCase() } for (int j=0; j <= 16; ++j) { QTreeWidgetItem *child = new QTreeWidgetItem(top); - child->setText(0, QString("top%1,child%2").arg(i).arg(j)); + child->setText(0, topS + QLatin1String(",child") + QString::number(j)); switch (j) { case 0: testWidget->setItemHidden(child, true);break; case 1: testWidget->setItemHidden(child, false);break; @@ -174,14 +162,6 @@ void tst_QTreeWidgetItemIterator::cleanupTestCase() delete testWidget; } -void tst_QTreeWidgetItemIterator::init() -{ -} - -void tst_QTreeWidgetItemIterator::cleanup() -{ -} - void tst_QTreeWidgetItemIterator::iteratorflags_data() { /* @@ -1074,6 +1054,24 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget_data() << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All << 1 << 3 << QString("top0,child1") << QString("top0,child1") << 0; } +static void populate3Levels(QTreeWidget &tw, int topLevelItems, int childItems, int grandChildItems) +{ + for (int i1 = 0; i1 < topLevelItems; ++i1) { + QTreeWidgetItem *top = new QTreeWidgetItem(&tw); + const QString top1S = QLatin1String("top") + QString::number(i1); + top->setText(0, top1S); + for (int i2 = 0; i2 < childItems; ++i2) { + QTreeWidgetItem *child = new QTreeWidgetItem(top); + const QString childS = top1S + QLatin1String(",child") + QString::number(i2); + child->setText(0, childS); + for (int i3 = 0; i3 < grandChildItems; ++i3) { + QTreeWidgetItem *grandChild = new QTreeWidgetItem(child); + grandChild->setText(0, childS + QLatin1String(",grandchild") + QString::number(i3)); + } + } + } +} + void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget() { QFETCH(int, topLevelItems); @@ -1089,18 +1087,7 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget() QTreeWidget tw; tw.clear(); tw.setColumnCount(2); - for (int i1=0; i1 < topLevelItems; ++i1) { - QTreeWidgetItem *top = new QTreeWidgetItem(&tw); - top->setText(0, QString("top%1").arg(i1)); - for (int i2=0; i2 < childItems; ++i2) { - QTreeWidgetItem *child = new QTreeWidgetItem(top); - child->setText(0, QString("top%1,child%2").arg(i1).arg(i2)); - for (int i3=0; i3 < grandChildItems; ++i3) { - QTreeWidgetItem *grandChild = new QTreeWidgetItem(child); - grandChild->setText(0, QString("top%1,child%2,grandchild%3").arg(i1).arg(i2).arg(i3)); - } - } - } + populate3Levels(tw, topLevelItems, childItems, grandChildItems); QTreeWidgetItemIterator it(&tw, QTreeWidgetItemIterator::IteratorFlags(iteratorflags)); it+=expecteditemindex; @@ -1161,18 +1148,7 @@ void tst_QTreeWidgetItemIterator::updateIteratorAfterDeletedItem_and_ContinueIte QTreeWidget tw; tw.clear(); tw.setColumnCount(2); - for (int i1=0; i1 < topLevelItems; ++i1) { - QTreeWidgetItem *top = new QTreeWidgetItem(&tw); - top->setText(0, QString("top%1").arg(i1)); - for (int i2=0; i2 < childItems; ++i2) { - QTreeWidgetItem *child = new QTreeWidgetItem(top); - child->setText(0, QString("top%1,child%2").arg(i1).arg(i2)); - for (int i3=0; i3 < grandChildItems; ++i3) { - QTreeWidgetItem *grandChild = new QTreeWidgetItem(child); - grandChild->setText(0, QString("top%1,child%2,grandchild%3").arg(i1).arg(i2).arg(i3)); - } - } - } + populate3Levels(tw, topLevelItems, childItems, grandChildItems); QTreeWidgetItemIterator it(&tw, QTreeWidgetItemIterator::All); it += iterator_initial_index; |