diff options
-rw-r--r-- | tests/auto/quick/qquicktableview/data/plaintableview.qml | 74 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/qquicktableview.pro | 14 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/testmodel.h | 87 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 96 | ||||
-rw-r--r-- | tests/auto/quick/quick.pro | 3 |
5 files changed, 273 insertions, 1 deletions
diff --git a/tests/auto/quick/qquicktableview/data/plaintableview.qml b/tests/auto/quick/qquicktableview/data/plaintableview.qml new file mode 100644 index 0000000000..7748f51aae --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/plaintableview.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 +import Qt.labs.tableview 1.0 + +Item { + width: 640 + height: 480 + + property alias tableView: tableView + + TableView { + id: tableView + anchors.fill: parent + anchors.margins: 1 + clip: true + delegate: tableViewDelegate + cacheBuffer: 0 + columnSpacing: 1 + rowSpacing: 1 + } + + Component { + id: tableViewDelegate + Rectangle { + implicitWidth: 100 + implicitHeight: 50 + color: "lightgray" + Text { + anchors.centerIn: parent + text: modelData + } + } + } + +} diff --git a/tests/auto/quick/qquicktableview/qquicktableview.pro b/tests/auto/quick/qquicktableview/qquicktableview.pro new file mode 100644 index 0000000000..f4d0265dd3 --- /dev/null +++ b/tests/auto/quick/qquicktableview/qquicktableview.pro @@ -0,0 +1,14 @@ +CONFIG += testcase +TARGET = tst_qquicktableview +macos:CONFIG -= app_bundle + +HEADERS += testmodel.h +SOURCES += tst_qquicktableview.cpp + +include (../../shared/util.pri) +include (../shared/util.pri) + +TESTDATA = data/* + +QT += core-private gui-private qml-private quick-private testlib + diff --git a/tests/auto/quick/qquicktableview/testmodel.h b/tests/auto/quick/qquicktableview/testmodel.h new file mode 100644 index 0000000000..8937aff766 --- /dev/null +++ b/tests/auto/quick/qquicktableview/testmodel.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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: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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** 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$ +** +****************************************************************************/ + +#include <QtCore/QtCore> +#include <QtGui/QStandardItemModel> + +class TestModel : public QAbstractTableModel +{ + Q_OBJECT + Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) + Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged) + +public: + TestModel(QObject *parent = nullptr) + : QAbstractTableModel(parent) + {} + + TestModel(int rows, int columns, QObject *parent = nullptr) + : QAbstractTableModel(parent) + , m_rows(rows) + , m_columns(columns) + {} + + int rowCount(const QModelIndex & = QModelIndex()) const override { return m_rows; } + void setRowCount(int count) { beginResetModel(); m_rows = count; emit rowCountChanged(); endResetModel(); } + + int columnCount(const QModelIndex & = QModelIndex()) const override { return m_columns; } + void setColumnCount(int count) { beginResetModel(); m_columns = count; emit columnCountChanged(); endResetModel(); } + + QVariant data(const QModelIndex &index, int role) const override + { + if (!index.isValid() || role != Qt::DisplayRole) + return QVariant(); + + int cell = index.row() + (index.column() * m_columns); + if (selectedCells.contains(cell)) + return QStringLiteral("selected"); + return QString("%1,%2").arg(index.column()).arg(index.row()); + } + + QHash<int, QByteArray> roleNames() const override + { + return { {Qt::DisplayRole, "display"} }; + } + + Q_INVOKABLE void selectCell(int row, int column) + { + int cell = row + (column * m_columns); + selectedCells.insert(cell); + auto index = createIndex(row, column, nullptr); + emit dataChanged(index, index); + } + +signals: + void rowCountChanged(); + void columnCountChanged(); + +private: + int m_rows = 0; + int m_columns = 0; + QSet<int> selectedCells; +}; diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp new file mode 100644 index 0000000000..3a615e1c3b --- /dev/null +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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: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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** 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$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QtQuick/qquickview.h> +#include <QtQuick/private/qquicktableview_p.h> + +#include <QtQml/qqmlengine.h> +#include <QtQml/qqmlcontext.h> +#include <QtQml/qqmlexpression.h> +#include <QtQml/qqmlincubator.h> +#include <QtQml/private/qqmlobjectmodel_p.h> +#include <QtQml/private/qqmllistmodel_p.h> +#include <QtQml/private/qqmldelegatemodel_p.h> + +#include "testmodel.h" + +#include "../../shared/util.h" +#include "../shared/viewtestutil.h" +#include "../shared/visualtestutil.h" + +using namespace QQuickViewTestUtil; +using namespace QQuickVisualTestUtil; + +#define CREATE_VAR_FROM_PROPERTY(name, T) \ + T *name = view->rootObject()->property(#name).value<T *>(); \ + QVERIFY(name) + +#define LOAD_TABLEVIEW(fileName) \ + QScopedPointer<QQuickView> view(createView()); \ + view->setSource(testFileUrl(fileName)); \ + view->show(); \ + QVERIFY(QTest::qWaitForWindowActive(view.data())); \ + CREATE_VAR_FROM_PROPERTY(tableView, QQuickTableView) + +class tst_QQuickTableView : public QQmlDataTest +{ + Q_OBJECT +public: + tst_QQuickTableView(); + +private slots: + void initTestCase() override; + + void setAndGetQAIM(); +}; + +tst_QQuickTableView::tst_QQuickTableView() +{ +} + +void tst_QQuickTableView::initTestCase() +{ + QQmlDataTest::initTestCase(); + qmlRegisterType<TestModel>("TestModel", 0, 1, "TestModel"); +} + +void tst_QQuickTableView::setAndGetQAIM() +{ + LOAD_TABLEVIEW("plaintableview.qml"); + + TestModel model(2, 2); + tableView->setModel(QVariant::fromValue<QObject *>(&model)); + auto returnModel = tableView->model().value<TestModel *>(); + QCOMPARE(&model, returnModel); +} + +QTEST_MAIN(tst_QQuickTableView) + +#include "tst_qquicktableview.moc" diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index a54a707f4a..a4b6076a34 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -66,6 +66,7 @@ QUICKTESTS += \ qquickitem2 \ qquickitemlayer \ qquicklistview \ + qquicktableview \ qquickloader \ qquickmousearea \ qquickmultipointtoucharea \ @@ -93,7 +94,7 @@ QUICKTESTS += \ SUBDIRS += $$PUBLICTESTS # Following tests are too slow on qemu + software backend -boot2qt: QUICKTESTS -= qquickgridview qquicklistview qquickpositioners +boot2qt: QUICKTESTS -= qquickgridview qquicklistview qquicktableview qquickpositioners !qtConfig(accessibility):QUICKTESTS -= qquickaccessible |