diff options
Diffstat (limited to 'tests/auto/widgets/itemviews')
17 files changed, 472 insertions, 214 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index ff910ba359..79f51d27c7 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -530,11 +530,16 @@ void tst_QAbstractItemView::basic_tests(TestView *view) // setIconSize view->setIconSize(QSize(16, 16)); QCOMPARE(view->iconSize(), QSize(16, 16)); + QSignalSpy spy(view, &QAbstractItemView::iconSizeChanged); + QVERIFY(spy.isValid()); view->setIconSize(QSize(32, 32)); QCOMPARE(view->iconSize(), QSize(32, 32)); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.at(0).at(0).value<QSize>(), QSize(32, 32)); // Should this happen? view->setIconSize(QSize(-1, -1)); QCOMPARE(view->iconSize(), QSize(-1, -1)); + QCOMPARE(spy.count(), 2); QCOMPARE(view->currentIndex(), QModelIndex()); QCOMPARE(view->rootIndex(), QModelIndex()); @@ -1112,7 +1117,7 @@ void tst_QAbstractItemView::setItemDelegate() centerOnScreen(&v); moveCursorAway(&v); v.show(); -#ifdef Q_WS_X11 +#ifdef Q_DEAD_CODE_FROM_QT4_X11 QCursor::setPos(v.geometry().center()); #endif QApplication::setActiveWindow(&v); @@ -1822,7 +1827,6 @@ void tst_QAbstractItemView::testFocusPolicy() QVERIFY(!qApp->focusWidget()); } -Q_DECLARE_METATYPE(QItemSelection) void tst_QAbstractItemView::QTBUG31411_noSelection() { QWidget window; diff --git a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp index 7663975794..f5e6facaad 100644 --- a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp +++ b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp index 2c3fdb1baa..8b80d52a5f 100644 --- a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp +++ b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,21 +23,29 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include <QtGui/QtGui> -#include <QtWidgets/QtWidgets> -#include <QtTest/QtTest> +#include <QDataWidgetMapper> +#include <QStandardItemModel> +#include <QLineEdit> +#include <QComboBox> +#include <QTextEdit> +#include <QVBoxLayout> +#include <QTest> +#include <QSignalSpy> +#include <QMetaType> class tst_QDataWidgetMapper: public QObject { Q_OBJECT private slots: + void initTestCase(); + void setModel(); void navigate(); void addMapping(); @@ -47,8 +55,12 @@ private slots: void mappedWidgetAt(); void comboBox(); + + void textEditDoesntChangeFocusOnTab_qtbug3305(); }; +Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint) + static QStandardItemModel *testModel(QObject *parent = 0) { QStandardItemModel *model = new QStandardItemModel(10, 10, parent); @@ -61,6 +73,11 @@ static QStandardItemModel *testModel(QObject *parent = 0) return model; } +void tst_QDataWidgetMapper::initTestCase() +{ + qRegisterMetaType<QAbstractItemDelegate::EndEditHint>(); +} + void tst_QDataWidgetMapper::setModel() { QDataWidgetMapper mapper; @@ -400,5 +417,63 @@ void tst_QDataWidgetMapper::mappedWidgetAt() QCOMPARE(mapper.mappedWidgetAt(4242), static_cast<QWidget *>(&lineEdit2)); } +void tst_QDataWidgetMapper::textEditDoesntChangeFocusOnTab_qtbug3305() +{ + QDataWidgetMapper mapper; + QAbstractItemModel *model = testModel(&mapper); + mapper.setModel(model); + + QSignalSpy closeEditorSpy(mapper.itemDelegate(), SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); + QVERIFY(closeEditorSpy.isValid()); + + QWidget container; + container.setLayout(new QVBoxLayout); + + QLineEdit *lineEdit = new QLineEdit; + mapper.addMapping(lineEdit, 0); + container.layout()->addWidget(lineEdit); + + QTextEdit *textEdit = new QTextEdit; + mapper.addMapping(textEdit, 1); + container.layout()->addWidget(textEdit); + + lineEdit->setFocus(); + + container.show(); + + QApplication::setActiveWindow(&container); + QVERIFY(QTest::qWaitForWindowActive(&container)); + + int closeEditorSpyCount = 0; + const QString textEditContents = textEdit->toPlainText(); + + QCOMPARE(closeEditorSpy.count(), closeEditorSpyCount); + QVERIFY(lineEdit->hasFocus()); + QVERIFY(!textEdit->hasFocus()); + + // this will generate a closeEditor for the tab key, and another for the focus out + QTest::keyClick(QApplication::focusWidget(), Qt::Key_Tab); + closeEditorSpyCount += 2; + QTRY_COMPARE(closeEditorSpy.count(), closeEditorSpyCount); + + QTRY_VERIFY(textEdit->hasFocus()); + QVERIFY(!lineEdit->hasFocus()); + + // now that the text edit is focused, a tab keypress will insert a tab, not change focus + QTest::keyClick(QApplication::focusWidget(), Qt::Key_Tab); + QTRY_COMPARE(closeEditorSpy.count(), closeEditorSpyCount); + + QVERIFY(!lineEdit->hasFocus()); + QVERIFY(textEdit->hasFocus()); + QCOMPARE(textEdit->toPlainText(), QLatin1Char('\t') + textEditContents); + + // now give focus back to the line edit and check closeEditor gets emitted + lineEdit->setFocus(); + QTRY_VERIFY(lineEdit->hasFocus()); + QVERIFY(!textEdit->hasFocus()); + ++closeEditorSpyCount; + QCOMPARE(closeEditorSpy.count(), closeEditorSpyCount); +} + QTEST_MAIN(tst_QDataWidgetMapper) #include "tst_qdatawidgetmapper.moc" diff --git a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp index 56a8d1f1f4..f12876f745 100644 --- a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp +++ b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp index 0102f2da0e..0bc972d0cb 100644 --- a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp +++ b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index e632af1262..21e4b82366 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -1,8 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2015 The Qt Company Ltd. ** Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -11,9 +11,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -24,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -176,6 +176,7 @@ private slots: void moveSectionAndRemove(); void saveRestore(); void defaultSectionSizeTest(); + void defaultSectionSizeTestStyles(); void defaultAlignment_data(); void defaultAlignment(); @@ -1710,6 +1711,41 @@ void tst_QHeaderView::defaultSectionSizeTest() QVERIFY(hv->sectionSize(2) == 0); // section is hidden. It should not be resized. } +class TestHeaderViewStyle : public QProxyStyle +{ +public: + TestHeaderViewStyle() : horizontalSectionSize(100) {} + int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const Q_DECL_OVERRIDE + { + if (metric == QStyle::PM_HeaderDefaultSectionSizeHorizontal) + return horizontalSectionSize; + else + return QProxyStyle::pixelMetric(metric, option, widget); + } + int horizontalSectionSize; +}; + +void tst_QHeaderView::defaultSectionSizeTestStyles() +{ + TestHeaderViewStyle style1; + TestHeaderViewStyle style2; + style1.horizontalSectionSize = 100; + style2.horizontalSectionSize = 200; + + QHeaderView hv(Qt::Horizontal); + hv.setStyle(&style1); + QCOMPARE(hv.defaultSectionSize(), style1.horizontalSectionSize); + hv.setStyle(&style2); + QCOMPARE(hv.defaultSectionSize(), style2.horizontalSectionSize); + hv.setDefaultSectionSize(70); + QCOMPARE(hv.defaultSectionSize(), 70); + hv.setStyle(&style1); + QCOMPARE(hv.defaultSectionSize(), 70); + hv.resetDefaultSectionSize(); + QCOMPARE(hv.defaultSectionSize(), style1.horizontalSectionSize); + hv.setStyle(&style2); + QCOMPARE(hv.defaultSectionSize(), style2.horizontalSectionSize); +} void tst_QHeaderView::defaultAlignment_data() { diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index f000907e0e..439eeff005 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -1083,8 +1083,6 @@ void tst_QItemDelegate::decoration() void tst_QItemDelegate::editorEvent_data() { - QTest::addColumn<QRect>("rect"); - QTest::addColumn<QString>("text"); QTest::addColumn<int>("checkState"); QTest::addColumn<int>("flags"); QTest::addColumn<bool>("inCheck"); @@ -1093,16 +1091,16 @@ void tst_QItemDelegate::editorEvent_data() QTest::addColumn<bool>("edited"); QTest::addColumn<int>("expectedCheckState"); - QTest::newRow("unchecked, checkable, release") - << QRect(0, 0, 20, 20) - << QString("foo") - << (int)(Qt::Unchecked) - << (int)(Qt::ItemIsEditable + const int defaultFlags = (int)(Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + |Qt::ItemIsDropEnabled); + + QTest::newRow("unchecked, checkable, release") + << (int)(Qt::Unchecked) + << defaultFlags << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) @@ -1110,15 +1108,8 @@ void tst_QItemDelegate::editorEvent_data() << (int)(Qt::Checked); QTest::newRow("checked, checkable, release") - << QRect(0, 0, 20, 20) - << QString("foo") << (int)(Qt::Checked) - << (int)(Qt::ItemIsEditable - |Qt::ItemIsSelectable - |Qt::ItemIsUserCheckable - |Qt::ItemIsEnabled - |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + << defaultFlags << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) @@ -1126,15 +1117,8 @@ void tst_QItemDelegate::editorEvent_data() << (int)(Qt::Unchecked); QTest::newRow("unchecked, checkable, release") - << QRect(0, 0, 20, 20) - << QString("foo") << (int)(Qt::Unchecked) - << (int)(Qt::ItemIsEditable - |Qt::ItemIsSelectable - |Qt::ItemIsUserCheckable - |Qt::ItemIsEnabled - |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + << defaultFlags << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) @@ -1142,15 +1126,8 @@ void tst_QItemDelegate::editorEvent_data() << (int)(Qt::Checked); QTest::newRow("unchecked, checkable, release, right button") - << QRect(0, 0, 20, 20) - << QString("foo") << (int)(Qt::Unchecked) - << (int)(Qt::ItemIsEditable - |Qt::ItemIsSelectable - |Qt::ItemIsUserCheckable - |Qt::ItemIsEnabled - |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + << defaultFlags << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::RightButton) @@ -1158,15 +1135,8 @@ void tst_QItemDelegate::editorEvent_data() << (int)(Qt::Unchecked); QTest::newRow("unchecked, checkable, release outside") - << QRect(0, 0, 20, 20) - << QString("foo") << (int)(Qt::Unchecked) - << (int)(Qt::ItemIsEditable - |Qt::ItemIsSelectable - |Qt::ItemIsUserCheckable - |Qt::ItemIsEnabled - |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + << defaultFlags << false << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) @@ -1174,15 +1144,8 @@ void tst_QItemDelegate::editorEvent_data() << (int)(Qt::Unchecked); QTest::newRow("unchecked, checkable, dblclick") - << QRect(0, 0, 20, 20) - << QString("foo") << (int)(Qt::Unchecked) - << (int)(Qt::ItemIsEditable - |Qt::ItemIsSelectable - |Qt::ItemIsUserCheckable - |Qt::ItemIsEnabled - |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + << defaultFlags << true << (int)(QEvent::MouseButtonDblClick) << (int)(Qt::LeftButton) @@ -1190,33 +1153,17 @@ void tst_QItemDelegate::editorEvent_data() << (int)(Qt::Unchecked); QTest::newRow("unchecked, tristate, release") - << QRect(0, 0, 20, 20) - << QString("foo") << (int)(Qt::Unchecked) - << (int)(Qt::ItemIsEditable - |Qt::ItemIsSelectable - |Qt::ItemIsUserCheckable - |Qt::ItemIsTristate - |Qt::ItemIsEnabled - |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + << (int)(defaultFlags | Qt::ItemIsTristate) << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) << true - << (int)(Qt::PartiallyChecked); + << (int)(Qt::Checked); QTest::newRow("partially checked, tristate, release") - << QRect(0, 0, 20, 20) - << QString("foo") << (int)(Qt::PartiallyChecked) - << (int)(Qt::ItemIsEditable - |Qt::ItemIsSelectable - |Qt::ItemIsUserCheckable - |Qt::ItemIsTristate - |Qt::ItemIsEnabled - |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + << (int)(defaultFlags | Qt::ItemIsTristate) << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) @@ -1224,16 +1171,35 @@ void tst_QItemDelegate::editorEvent_data() << (int)(Qt::Checked); QTest::newRow("checked, tristate, release") - << QRect(0, 0, 20, 20) - << QString("foo") << (int)(Qt::Checked) - << (int)(Qt::ItemIsEditable - |Qt::ItemIsSelectable - |Qt::ItemIsUserCheckable - |Qt::ItemIsTristate - |Qt::ItemIsEnabled - |Qt::ItemIsDragEnabled - |Qt::ItemIsDropEnabled) + << (int)(defaultFlags | Qt::ItemIsTristate) + << true + << (int)(QEvent::MouseButtonRelease) + << (int)(Qt::LeftButton) + << true + << (int)(Qt::Unchecked); + + QTest::newRow("unchecked, user-tristate, release") + << (int)(Qt::Unchecked) + << (int)(defaultFlags | Qt::ItemIsUserTristate) + << true + << (int)(QEvent::MouseButtonRelease) + << (int)(Qt::LeftButton) + << true + << (int)(Qt::PartiallyChecked); + + QTest::newRow("partially checked, user-tristate, release") + << (int)(Qt::PartiallyChecked) + << (int)(defaultFlags | Qt::ItemIsUserTristate) + << true + << (int)(QEvent::MouseButtonRelease) + << (int)(Qt::LeftButton) + << true + << (int)(Qt::Checked); + + QTest::newRow("checked, user-tristate, release") + << (int)(Qt::Checked) + << (int)(defaultFlags | Qt::ItemIsUserTristate) << true << (int)(QEvent::MouseButtonRelease) << (int)(Qt::LeftButton) @@ -1243,8 +1209,6 @@ void tst_QItemDelegate::editorEvent_data() void tst_QItemDelegate::editorEvent() { - QFETCH(QRect, rect); - QFETCH(QString, text); QFETCH(int, checkState); QFETCH(int, flags); QFETCH(bool, inCheck); @@ -1258,12 +1222,12 @@ void tst_QItemDelegate::editorEvent() QVERIFY(index.isValid()); QStandardItem *item = model.itemFromIndex(index); - item->setText(text); + item->setText("foo"); item->setCheckState((Qt::CheckState)checkState); item->setFlags((Qt::ItemFlags)flags); QStyleOptionViewItem option; - option.rect = rect; + option.rect = QRect(0, 0, 20, 20); option.state |= QStyle::State_Enabled; // mimic QStyledItemDelegate::initStyleOption logic option.features |= QStyleOptionViewItem::HasCheckIndicator | QStyleOptionViewItem::HasDisplay; @@ -1302,11 +1266,19 @@ void tst_QItemDelegate::enterKey_data() QTest::addColumn<bool>("expectedFocus"); QTest::newRow("lineedit enter") << LineEdit << int(Qt::Key_Enter) << false; + QTest::newRow("lineedit return") << LineEdit << int(Qt::Key_Return) << false; + QTest::newRow("lineedit tab") << LineEdit << int(Qt::Key_Tab) << false; + QTest::newRow("lineedit backtab") << LineEdit << int(Qt::Key_Backtab) << false; + QTest::newRow("textedit enter") << TextEdit << int(Qt::Key_Enter) << true; + QTest::newRow("textedit return") << TextEdit << int(Qt::Key_Return) << true; + QTest::newRow("textedit tab") << TextEdit << int(Qt::Key_Tab) << true; + QTest::newRow("textedit backtab") << TextEdit << int(Qt::Key_Backtab) << false; + QTest::newRow("plaintextedit enter") << PlainTextEdit << int(Qt::Key_Enter) << true; QTest::newRow("plaintextedit return") << PlainTextEdit << int(Qt::Key_Return) << true; - QTest::newRow("plaintextedit tab") << PlainTextEdit << int(Qt::Key_Tab) << false; - QTest::newRow("lineedit tab") << LineEdit << int(Qt::Key_Tab) << false; + QTest::newRow("plaintextedit tab") << PlainTextEdit << int(Qt::Key_Tab) << true; + QTest::newRow("plaintextedit backtab") << PlainTextEdit << int(Qt::Key_Backtab) << false; } void tst_QItemDelegate::enterKey() @@ -1364,10 +1336,11 @@ void tst_QItemDelegate::enterKey() QTest::keyClick(editor, Qt::Key(key)); QApplication::processEvents(); - // The line edit has already been destroyed, so avoid that case. - if (widget == TextEdit || widget == PlainTextEdit) { + if (expectedFocus) { QVERIFY(!editor.isNull()); - QCOMPARE(editor && editor->hasFocus(), expectedFocus); + QVERIFY(editor->hasFocus()); + } else { + QTRY_VERIFY(editor.isNull()); // editor deletion happens via deleteLater } } diff --git a/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp b/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp index d664b0cc29..15fd19ede9 100644 --- a/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp +++ b/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp index ee4ca6dea2..3a6f1f933d 100644 --- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp +++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp b/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp index 388ecdf37c..c108e9a122 100644 --- a/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp +++ b/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index b069b5e1cb..cea08435c9 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -2004,7 +2004,7 @@ void tst_QListView::taskQTBUG_9455_wrongScrollbarRanges() QStringList list; const int nrItems = 8; for (int i = 0; i < nrItems; i++) - list << QString().sprintf("item %d", i); + list << QString::asprintf("item %d", i); QStringListModel model(list); ListView_9455 w; diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index 6428bbba10..6786ae9aa2 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -123,7 +123,7 @@ private slots: void task258949_keypressHangup(); void QTBUG8086_currentItemChangedOnClick(); void QTBUG14363_completerWithAnyKeyPressedEditTriggers(); - + void mimeData(); protected slots: void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last) @@ -1082,6 +1082,9 @@ public: Q_UNUSED(item); return QListWidget::state() == QListWidget::EditingState; } + + using QListWidget::mimeData; + using QListWidget::indexFromItem; }; void tst_QListWidget::closeEditor() @@ -1662,7 +1665,57 @@ void tst_QListWidget::QTBUG14363_completerWithAnyKeyPressedEditTriggers() QCOMPARE(le->completer()->currentCompletion(), QString("completer")); } +void tst_QListWidget::mimeData() +{ + TestListWidget list; + + for (int x = 0; x < 10; ++x) { + QListWidgetItem *item = new QListWidgetItem(QStringLiteral("123")); + list.addItem(item); + } + + QList<QListWidgetItem *> tableWidgetItemList; + QModelIndexList modelIndexList; + + // do these checks more than once to ensure that the "cached indexes" work as expected + QVERIFY(!list.mimeData(tableWidgetItemList)); + QVERIFY(!list.model()->mimeData(modelIndexList)); + QVERIFY(!list.model()->mimeData(modelIndexList)); + QVERIFY(!list.mimeData(tableWidgetItemList)); + + tableWidgetItemList << list.item(1); + modelIndexList << list.indexFromItem(list.item(1)); + + QMimeData *data; + + QVERIFY(data = list.mimeData(tableWidgetItemList)); + delete data; + QVERIFY(data = list.model()->mimeData(modelIndexList)); + delete data; + + QVERIFY(data = list.model()->mimeData(modelIndexList)); + delete data; + + QVERIFY(data = list.mimeData(tableWidgetItemList)); + delete data; + + // check the saved data is actually the same + + QMimeData *data2; + + data = list.mimeData(tableWidgetItemList); + data2 = list.model()->mimeData(modelIndexList); + + const QString format = QStringLiteral("application/x-qabstractitemmodeldatalist"); + + QVERIFY(data->hasFormat(format)); + QVERIFY(data2->hasFormat(format)); + QVERIFY(data->data(format) == data2->data(format)); + + delete data; + delete data2; +} QTEST_MAIN(tst_QListWidget) #include "tst_qlistwidget.moc" diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 389ff6572d..a11d423896 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -195,15 +195,19 @@ private slots: void task191545_dragSelectRows(); void taskQTBUG_5062_spansInconsistency(); void taskQTBUG_4516_clickOnRichTextLabel(); +#ifndef QT_NO_WHEELEVENT void taskQTBUG_5237_wheelEventOnHeader(); +#endif void taskQTBUG_8585_crashForNoGoodReason(); void taskQTBUG_7774_RtoLVisualRegionForSelection(); void taskQTBUG_8777_scrollToSpans(); void taskQTBUG_10169_sizeHintForRow(); void taskQTBUG_30653_doItemsLayout(); +#ifndef QT_NO_WHEELEVENT void mouseWheel_data(); void mouseWheel(); +#endif void addColumnWhileEditing(); void task234926_setHeaderSorting(); @@ -3994,7 +3998,7 @@ void tst_QTableView::task248688_autoScrollNavigation() } } - +#ifndef QT_NO_WHEELEVENT void tst_QTableView::mouseWheel_data() { QTest::addColumn<int>("scrollMode"); @@ -4051,6 +4055,7 @@ void tst_QTableView::mouseWheel() QApplication::sendEvent(view.viewport(), &verticalEvent); QVERIFY(qAbs(view.verticalScrollBar()->value() - verticalPosition) < 10); } +#endif // !QT_NO_WHEELEVENT void tst_QTableView::addColumnWhileEditing() { @@ -4311,6 +4316,7 @@ void tst_QTableView::changeHeaderData() QVERIFY(view.verticalHeader()->width() > textWidth); } +#ifndef QT_NO_WHEELEVENT void tst_QTableView::taskQTBUG_5237_wheelEventOnHeader() { QTableView view; @@ -4327,6 +4333,7 @@ void tst_QTableView::taskQTBUG_5237_wheelEventOnHeader() int sbValueAfter = view.verticalScrollBar()->value(); QVERIFY(sbValueBefore != sbValueAfter); } +#endif class TestTableView : public QTableView { Q_OBJECT diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index 8335497c6c..a4c6e13979 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -93,6 +93,7 @@ private slots: void task219380_removeLastRow(); void task262056_sortDuplicate(); void itemWithHeaderItems(); + void mimeData(); private: QTableWidget *testWidget; @@ -1497,5 +1498,72 @@ void tst_QTableWidget::itemWithHeaderItems() QCOMPARE(table.item(0, 1), static_cast<QTableWidgetItem *>(0)); } +class TestTableWidget : public QTableWidget +{ + Q_OBJECT +public: + TestTableWidget(int rows, int columns, QWidget *parent = 0) + : QTableWidget(rows, columns, parent) + { + } + + using QTableWidget::mimeData; + using QTableWidget::indexFromItem; +}; + +void tst_QTableWidget::mimeData() +{ + TestTableWidget table(10, 10); + + for (int x = 0; x < 10; ++x) { + for (int y = 0; y < 10; ++y) { + QTableWidgetItem *item = new QTableWidgetItem(QStringLiteral("123")); + table.setItem(y, x, item); + } + } + + QList<QTableWidgetItem *> tableWidgetItemList; + QModelIndexList modelIndexList; + + // do these checks more than once to ensure that the "cached indexes" work as expected + QVERIFY(!table.mimeData(tableWidgetItemList)); + QVERIFY(!table.model()->mimeData(modelIndexList)); + QVERIFY(!table.model()->mimeData(modelIndexList)); + QVERIFY(!table.mimeData(tableWidgetItemList)); + + tableWidgetItemList << table.item(1, 1); + modelIndexList << table.indexFromItem(table.item(1, 1)); + + QMimeData *data; + + QVERIFY(data = table.mimeData(tableWidgetItemList)); + delete data; + + QVERIFY(data = table.model()->mimeData(modelIndexList)); + delete data; + + QVERIFY(data = table.model()->mimeData(modelIndexList)); + delete data; + + QVERIFY(data = table.mimeData(tableWidgetItemList)); + delete data; + + // check the saved data is actually the same + + QMimeData *data2; + + data = table.mimeData(tableWidgetItemList); + data2 = table.model()->mimeData(modelIndexList); + + const QString format = QStringLiteral("application/x-qabstractitemmodeldatalist"); + + QVERIFY(data->hasFormat(format)); + QVERIFY(data2->hasFormat(format)); + QVERIFY(data->data(format) == data2->data(format)); + + delete data; + delete data2; +} + QTEST_MAIN(tst_QTableWidget) #include "tst_qtablewidget.moc" diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 0ca836d946..3ead172d82 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index bdeaaf38db..5c881369a0 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ @@ -132,6 +132,8 @@ private slots: void task245280_sortChildren(); void task253109_itemHeight(); + void nonEditableTristate(); + // QTreeWidgetItem void itemOperatorLessThan(); void addChild(); @@ -639,8 +641,8 @@ void tst_QTreeWidget::setItemHidden2() top->setText(0, "ItemList"); for (int i = 1; i <= 4; i++) { leaf = new QTreeWidgetItem(top); - leaf->setText(0, QString().sprintf("%d", i)); - leaf->setText(1, QString().sprintf("Item %d", i)); + leaf->setText(0, QString::asprintf("%d", i)); + leaf->setText(1, QString::asprintf("Item %d", i)); } if (testWidget->topLevelItemCount() > 0) { @@ -1050,6 +1052,12 @@ void tst_QTreeWidget::checkState() QCOMPARE(item->checkState(0), Qt::Unchecked); QCOMPARE(firstChild->checkState(0), Qt::Unchecked); QCOMPARE(seccondChild->checkState(0), Qt::Unchecked); + + // Can't force the state to PartiallyChecked; state comes from children + item->setCheckState(0, Qt::PartiallyChecked); + QCOMPARE(item->checkState(0), Qt::Unchecked); + QCOMPARE(firstChild->checkState(0), Qt::Unchecked); + QCOMPARE(seccondChild->checkState(0), Qt::Unchecked); } void tst_QTreeWidget::findItems_data() @@ -3166,6 +3174,40 @@ void tst_QTreeWidget::task217309() QVERIFY(item.data(0, Qt::CheckStateRole) == Qt::Checked); } +void tst_QTreeWidget::nonEditableTristate() +{ + // A tree with checkable items, the parent is tristate + QTreeWidget *tree = new QTreeWidget; + QTreeWidgetItem *item = new QTreeWidgetItem(); + tree->insertTopLevelItem(0, item); + item->setFlags(item->flags() | Qt::ItemIsTristate); + item->setCheckState(0, Qt::Unchecked); + QTreeWidgetItem *subitem1 = new QTreeWidgetItem(item); + subitem1->setCheckState(0, Qt::Unchecked); + QTreeWidgetItem *subitem2 = new QTreeWidgetItem(item); + subitem2->setCheckState(0, Qt::Unchecked); + QCOMPARE(int(item->checkState(0)), int(Qt::Unchecked)); + tree->show(); + + // Test clicking on the parent item, it should become Checked (not PartiallyChecked) + QStyleOptionViewItem option; + option.rect = tree->visualRect(tree->model()->index(0, 0)); + option.state |= QStyle::State_Enabled; + option.features |= QStyleOptionViewItem::HasCheckIndicator | QStyleOptionViewItem::HasDisplay; + option.checkState = item->checkState(0); + + const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1; + QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0); + QTest::mouseClick(tree->viewport(), Qt::LeftButton, Qt::NoModifier, pos); + QCOMPARE(int(item->checkState(0)), int(Qt::Checked)); + + // Click again, it should become Unchecked. + QTest::mouseClick(tree->viewport(), Qt::LeftButton, Qt::NoModifier, pos); + QCOMPARE(int(item->checkState(0)), int(Qt::Unchecked)); + + delete tree; +} + class TreeWidgetItem : public QTreeWidgetItem { diff --git a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp index c3682864f6..490f87a7ef 100644 --- a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp +++ b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** 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 Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** 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. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** 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. ** ** $QT_END_LICENSE$ |