diff options
Diffstat (limited to 'tests/manual')
20 files changed, 1025 insertions, 8 deletions
diff --git a/tests/manual/pointer/content/MultiButton.qml b/tests/manual/pointer/content/MultiButton.qml index 2a41967a36..ca9b16a957 100644 --- a/tests/manual/pointer/content/MultiButton.qml +++ b/tests/manual/pointer/content/MultiButton.qml @@ -35,6 +35,7 @@ Rectangle { property alias pressed: tap.pressed property bool checked: false property alias gesturePolicy: tap.gesturePolicy + property alias margin: tap.margin signal tapped width: label.implicitWidth * 1.5; height: label.implicitHeight * 2.0 diff --git a/tests/manual/pointer/map.qml b/tests/manual/pointer/map.qml index 6ab6badfd0..880f184adb 100644 --- a/tests/manual/pointer/map.qml +++ b/tests/manual/pointer/map.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the manual tests of the Qt Toolkit. @@ -48,6 +48,12 @@ Item { source: "resources/map.svgz" Component.onCompleted: { width = implicitWidth; height = implicitHeight } } + + Text { + anchors.centerIn: parent + text: image.sourceSize.width + " x " + image.sourceSize.height + + " scale " + map.scale.toFixed(2) + " active scale " + pinch.activeScale.toFixed(2) + } } PinchHandler { diff --git a/tests/manual/pointer/multibuttons.qml b/tests/manual/pointer/multibuttons.qml index cd7c5d0b19..28c3cc0f50 100644 --- a/tests/manual/pointer/multibuttons.qml +++ b/tests/manual/pointer/multibuttons.qml @@ -44,6 +44,7 @@ Item { label: "Launch Balloons" Layout.fillWidth: true gesturePolicy: TapHandler.WithinBounds + margin: 10 } Text { text: "the goons"; font.pointSize: 12 } MultiButton { @@ -51,6 +52,7 @@ Item { label: "Launch Missile" Layout.fillWidth: true gesturePolicy: TapHandler.ReleaseWithinBounds + margin: 10 onTapped: missileEmitter.burst(1) } MultiButton { @@ -58,6 +60,7 @@ Item { label: "Launch Fighters" Layout.fillWidth: true gesturePolicy: TapHandler.DragThreshold + margin: 10 } } ParticleSystem { diff --git a/tests/manual/pointer/pinchDragFlingMPTA.qml b/tests/manual/pointer/pinchDragFlingMPTA.qml index 2578d62466..0362832662 100644 --- a/tests/manual/pointer/pinchDragFlingMPTA.qml +++ b/tests/manual/pointer/pinchDragFlingMPTA.qml @@ -66,7 +66,7 @@ Rectangle { minimumPointCount: 3 minimumScale: 0.1 maximumScale: 10 - onActiveChanged: if (!active) fling.restart(centroidVelocity) + onActiveChanged: if (!active) fling.restart(centroid.velocity) } DragHandler { id: dragHandler diff --git a/tests/manual/pointer/pinchHandler.qml b/tests/manual/pointer/pinchHandler.qml index 409b852b55..36af1f53bd 100644 --- a/tests/manual/pointer/pinchHandler.qml +++ b/tests/manual/pointer/pinchHandler.qml @@ -153,7 +153,7 @@ Rectangle { maximumScale: 10 onActiveChanged: { if (!active) - anim.restart(centroidVelocity) + anim.restart(centroid.velocity) } } TapHandler { gesturePolicy: TapHandler.DragThreshold; onTapped: rect3.z = rect2.z + 1 } @@ -164,8 +164,8 @@ Rectangle { Rectangle { id: centroidIndicator property QtObject pincher: activePincher() - x: pincher.centroid.x - radius - y: pincher.centroid.y - radius + x: pincher.centroid.scenePosition.x - radius + y: pincher.centroid.scenePosition.y - radius z: 1 visible: pincher.active radius: width / 2 diff --git a/tests/manual/pointer/sidebar.qml b/tests/manual/pointer/sidebar.qml new file mode 100644 index 0000000000..ce2c770592 --- /dev/null +++ b/tests/manual/pointer/sidebar.qml @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the manual tests 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$ +** +****************************************************************************/ + +import QtQuick 2.12 +import Qt.labs.handlers 1.0 +import "content" + +Rectangle { + id: root + width: 640 + height: 480 + color: "#444" + + Component { + id: buttonsAndStuff + Column { + anchors.fill: parent + anchors.margins: 8 + spacing: 8 + + Rectangle { + objectName: "buttonWithMA" + width: parent.width + height: 30 + color: buttonMA.pressed ? "lightsteelblue" : "#999" + border.color: buttonMA.containsMouse ? "cyan" : "transparent" + + MouseArea { + id: buttonMA + objectName: "buttonMA" + hoverEnabled: true + anchors.fill: parent + onClicked: console.log("clicked MA") + } + + Text { + anchors.centerIn: parent + text: "MouseArea" + } + } + + Rectangle { + objectName: "buttonWithHH" + width: parent.width + height: 30 + color: flash ? "#999" : "white" + border.color: buttonHH.hovered ? "cyan" : "transparent" + property bool flash: true + + HoverHandler { + id: buttonHH + objectName: "buttonHH" + acceptedDevices: PointerDevice.AllDevices + } + + TapHandler { + onTapped: tapFlash.start() + } + + Text { + anchors.centerIn: parent + text: "HoverHandler" + } + + FlashAnimation on flash { + id: tapFlash + } + } + } + } + + Rectangle { + id: paddle + width: 100 + height: 40 + color: paddleHH.hovered ? "indianred" : "#888" + y: parent.height - 100 + radius: 10 + + HoverHandler { + id: paddleHH + objectName: "paddleHH" + } + + SequentialAnimation on x { + NumberAnimation { + to: root.width - paddle.width + duration: 2000 + easing { type: Easing.InOutQuad } + } + PauseAnimation { duration: 100 } + NumberAnimation { + to: 0 + duration: 2000 + easing { type: Easing.InOutQuad } + } + PauseAnimation { duration: 100 } + loops: Animation.Infinite + } + } + + Rectangle { + objectName: "topSidebar" + radius: 5 + antialiasing: true + x: -radius + y: -radius + width: 120 + height: 200 + border.color: topSidebarHH.hovered ? "cyan" : "black" + color: "#777" + + Rectangle { + color: "cyan" + width: 10 + height: width + radius: width / 2 + visible: topSidebarHH.hovered + x: topSidebarHH.point.position.x - width / 2 + y: topSidebarHH.point.position.y - height / 2 + z: 100 + } + + HoverHandler { + id: topSidebarHH + objectName: "topSidebarHH" + } + + Loader { + objectName: "topSidebarLoader" + sourceComponent: buttonsAndStuff + anchors.fill: parent + } + } + + Rectangle { + objectName: "bottomSidebar" + radius: 5 + antialiasing: true + x: -radius + anchors.bottom: parent.bottom + anchors.bottomMargin: -radius + width: 120 + height: 200 + border.color: bottomSidebarMA.containsMouse ? "cyan" : "black" + color: "#777" + + MouseArea { + id: bottomSidebarMA + objectName: "bottomSidebarMA" + hoverEnabled: true + anchors.fill: parent + } + + Loader { + objectName: "bottomSidebarLoader" + sourceComponent: buttonsAndStuff + anchors.fill: parent + } + } +} diff --git a/tests/manual/pointer/singlePointHandlerProperties.qml b/tests/manual/pointer/singlePointHandlerProperties.qml index c11042cf14..1c044f8167 100644 --- a/tests/manual/pointer/singlePointHandlerProperties.qml +++ b/tests/manual/pointer/singlePointHandlerProperties.qml @@ -63,7 +63,7 @@ Rectangle { anchors.centerIn: parent antialiasing: true Rectangle { - y: -40 + y: -56 anchors.horizontalCenter: parent.horizontalCenter color: "lightsteelblue" implicitWidth: label.implicitWidth @@ -71,7 +71,8 @@ Rectangle { Text { id: label text: 'id: ' + dragHandler.point.id.toString(16) + " uid: " + dragHandler.point.uniqueId.numericId + - '\npos: (' + dragHandler.point.position.x.toFixed(2) + ', ' + dragHandler.point.position.y.toFixed(2) + ')' + '\npos: (' + dragHandler.point.position.x.toFixed(2) + ', ' + dragHandler.point.position.y.toFixed(2) + ')' + + '\nmodifiers: ' + dragHandler.point.modifiers.toString(16) } } } diff --git a/tests/manual/tableview/abstracttablemodel/abstracttablemodel.pro b/tests/manual/tableview/abstracttablemodel/abstracttablemodel.pro new file mode 100644 index 0000000000..ade49c33a2 --- /dev/null +++ b/tests/manual/tableview/abstracttablemodel/abstracttablemodel.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = tableview_abstracttablemodel +QT += qml quick +SOURCES += main.cpp +RESOURCES += main.qml + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/tests/manual/tableview/abstracttablemodel/main.cpp b/tests/manual/tableview/abstracttablemodel/main.cpp new file mode 100644 index 0000000000..22dda5ca4a --- /dev/null +++ b/tests/manual/tableview/abstracttablemodel/main.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QAbstractTableModel> + +class TestTableModel : 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: + TestTableModel(QObject *parent = nullptr) : QAbstractTableModel(parent) { } + + 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_cols; } + void setColumnCount(int count) { beginResetModel(); m_cols = count; emit columnCountChanged(); endResetModel(); } + + QVariant headerData(int section, Qt::Orientation orientation, int role) const + { + Q_UNUSED(orientation); + Q_UNUSED(role); + return QStringLiteral("Column header"); + } + + QVariant data(const QModelIndex &index, int role) const override + { + if (!index.isValid() || role != Qt::DisplayRole) + return QVariant(); + return QString("[%1-%2]").arg(index.column()).arg(index.row()); + } + + QHash<int, QByteArray> roleNames() const override + { + return { {Qt::DisplayRole, "display"} }; + } + +signals: + void rowCountChanged(); + void columnCountChanged(); + +private: + int m_rows = 0; + int m_cols = 0; +}; + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + qmlRegisterType<TestTableModel>("TestTableModel", 0, 1, "TestTableModel"); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} + +#include "main.moc" diff --git a/tests/manual/tableview/abstracttablemodel/main.qml b/tests/manual/tableview/abstracttablemodel/main.qml new file mode 100644 index 0000000000..271752aaf1 --- /dev/null +++ b/tests/manual/tableview/abstracttablemodel/main.qml @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** 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 QtQml.Models 2.2 +import Qt.labs.tableview 1.0 +import TestTableModel 0.1 + +Window { + id: window + width: 640 + height: 480 + visible: true + + TestTableModel { + id: tableModel + rowCount: 200 + columnCount: 200 + } + + Rectangle { + anchors.fill: parent + anchors.margins: 10 + color: "darkgray" + + TableView { + id: tableView + anchors.fill: parent + anchors.margins: 1 + clip: true + + model: tableModel + delegate: tableViewDelegate + cacheBuffer: 500 + columnSpacing: 1 + rowSpacing: 1 + } + + Component { + id: tableViewDelegate + Rectangle { + TableView.cellWidth: column % 3 ? 80 : 50 + TableView.cellHeight: row % 3 ? 80 : 50 + + Text { + anchors.centerIn: parent + text: modelData + } + } + } + + } + +} diff --git a/tests/manual/tableview/listmodel/listmodel.pro b/tests/manual/tableview/listmodel/listmodel.pro new file mode 100644 index 0000000000..dbae0db2b1 --- /dev/null +++ b/tests/manual/tableview/listmodel/listmodel.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = tableview_listmodel +QT += qml quick +SOURCES += main.cpp +RESOURCES += main.qml + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/tests/manual/tableview/listmodel/main.cpp b/tests/manual/tableview/listmodel/main.cpp new file mode 100644 index 0000000000..2a3b90d392 --- /dev/null +++ b/tests/manual/tableview/listmodel/main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/tests/manual/tableview/listmodel/main.qml b/tests/manual/tableview/listmodel/main.qml new file mode 100644 index 0000000000..ca39e6a2b9 --- /dev/null +++ b/tests/manual/tableview/listmodel/main.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 +import QtQml.Models 2.2 + +Window { + id: window + width: 640 + height: 480 + visible: true + + ListModel { + id: listModel + Component.onCompleted: { + for (var i = 0; i < 30; ++i) + listModel.append({"name" : i}) + } + } + + Rectangle { + anchors.fill: parent + anchors.margins: 10 + color: "darkgray" + + TableView { + id: tableView + anchors.fill: parent + anchors.margins: 1 + clip: true + columnSpacing: 1 + rowSpacing: 1 + model: listModel + delegate: Component { + Rectangle { + id: tableDelegate + TableView.cellWidth: 100 + TableView.cellHeight: 50 + + Text { + anchors.centerIn: parent + text: name + "\n[" + column + ", " + row + "]" + } + } + } + } + } +} diff --git a/tests/manual/tableview/storagemodel/main.cpp b/tests/manual/tableview/storagemodel/main.cpp new file mode 100644 index 0000000000..97ae619ce4 --- /dev/null +++ b/tests/manual/tableview/storagemodel/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include "storagemodel.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + + qmlRegisterType<StorageModel>("StorageModel", 0, 1, "StorageModel"); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} + diff --git a/tests/manual/tableview/storagemodel/main.qml b/tests/manual/tableview/storagemodel/main.qml new file mode 100644 index 0000000000..f76da374e3 --- /dev/null +++ b/tests/manual/tableview/storagemodel/main.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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 +import StorageModel 0.1 + +Window { + id: window + width: 640 + height: 480 + visible: true + color: "darkgray" + title: "Storage Volumes" + + TableView { + id: table + anchors.fill: parent + anchors.margins: 10 + clip: true + model: StorageModel { } + columnSpacing: 1 + rowSpacing: 1 + delegate: Rectangle { + id: tableDelegate + TableView.cellWidth: displayText.implicitWidth + 8 + TableView.cellHeight: displayText.implicitHeight + 14 + + Text { + id: displayText + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.leftMargin: 4 + text: display + } + } + } +} diff --git a/tests/manual/tableview/storagemodel/storagemodel.cpp b/tests/manual/tableview/storagemodel/storagemodel.cpp new file mode 100644 index 0000000000..345d1cc63f --- /dev/null +++ b/tests/manual/tableview/storagemodel/storagemodel.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Ivan Komissarov +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "storagemodel.h" + +#include <QDir> +#include <QLocale> +#include <qmath.h> +#include <algorithm> +#include <cmath> + +StorageModel::StorageModel(QObject *parent) : + QAbstractTableModel(parent) +{ + refresh(); +} + +void StorageModel::refresh() +{ + beginResetModel(); + m_volumes = QStorageInfo::mountedVolumes(); + std::sort(m_volumes.begin(), m_volumes.end(), + [](const QStorageInfo &st1, const QStorageInfo &st2) { + static const QString rootSortString = QStringLiteral(" "); + return (st1.isRoot() ? rootSortString : st1.rootPath()) + < (st2.isRoot() ? rootSortString : st2.rootPath()); + }); + endResetModel(); +} + +int StorageModel::columnCount(const QModelIndex &/*parent*/) const +{ + return ColumnCount; +} + +int StorageModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + return m_volumes.count(); +} + +Qt::ItemFlags StorageModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags result = QAbstractTableModel::flags(index); + switch (index.column()) { + case ColumnAvailable: + case ColumnIsReady: + case ColumnIsReadOnly: + case ColumnIsValid: + result |= Qt::ItemIsUserCheckable; + break; + default: + break; + } + return result; +} + +QVariant StorageModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role == Qt::DisplayRole) { + const QStorageInfo &volume = m_volumes.at(index.row()); + switch (index.column()) { + case ColumnRootPath: + return QDir::toNativeSeparators(volume.rootPath()); + case ColumnName: + return volume.name(); + case ColumnDevice: + return volume.device(); + case ColumnFileSystemName: + return volume.fileSystemType(); + case ColumnTotal: + return QLocale().formattedDataSize(volume.bytesTotal()); + case ColumnFree: + return QLocale().formattedDataSize(volume.bytesFree()); + case ColumnAvailable: + return QLocale().formattedDataSize(volume.bytesAvailable()); + case ColumnIsReady: + return volume.isReady(); + case ColumnIsReadOnly: + return volume.isReadOnly(); + case ColumnIsValid: + return volume.isValid(); + default: + break; + } + } else if (role == Qt::CheckStateRole) { + const QStorageInfo &volume = m_volumes.at(index.row()); + switch (index.column()) { + case ColumnIsReady: + return volume.isReady(); + case ColumnIsReadOnly: + return volume.isReadOnly(); + case ColumnIsValid: + return volume.isValid(); + default: + break; + } + } else if (role == Qt::TextAlignmentRole) { + switch (index.column()) { + case ColumnTotal: + case ColumnFree: + case ColumnAvailable: + return Qt::AlignTrailing; + default: + break; + } + return Qt::AlignLeading; + } else if (role == Qt::ToolTipRole) { + QLocale locale; + const QStorageInfo &volume = m_volumes.at(index.row()); + return tr("Root path : %1\n" + "Name: %2\n" + "Display Name: %3\n" + "Device: %4\n" + "FileSystem: %5\n" + "Total size: %6\n" + "Free size: %7\n" + "Available size: %8\n" + "Is Ready: %9\n" + "Is Read-only: %10\n" + "Is Valid: %11\n" + "Is Root: %12" + ). + arg(QDir::toNativeSeparators(volume.rootPath())). + arg(volume.name()). + arg(volume.displayName()). + arg(QString::fromUtf8(volume.device())). + arg(QString::fromUtf8(volume.fileSystemType())). + arg(locale.formattedDataSize(volume.bytesTotal())). + arg(locale.formattedDataSize(volume.bytesFree())). + arg(locale.formattedDataSize(volume.bytesAvailable())). + arg(volume.isReady() ? tr("true") : tr("false")). + arg(volume.isReadOnly() ? tr("true") : tr("false")). + arg(volume.isValid() ? tr("true") : tr("false")). + arg(volume.isRoot() ? tr("true") : tr("false")); + } + return QVariant(); +} + +QVariant StorageModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation != Qt::Horizontal) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + switch (section) { + case ColumnRootPath: + return tr("Root Path"); + case ColumnName: + return tr("Volume Name"); + case ColumnDevice: + return tr("Device"); + case ColumnFileSystemName: + return tr("File System"); + case ColumnTotal: + return tr("Total"); + case ColumnFree: + return tr("Free"); + case ColumnAvailable: + return tr("Available"); + case ColumnIsReady: + return tr("Ready"); + case ColumnIsReadOnly: + return tr("Read-only"); + case ColumnIsValid: + return tr("Valid"); + default: + break; + } + + return QVariant(); +} diff --git a/tests/manual/tableview/storagemodel/storagemodel.h b/tests/manual/tableview/storagemodel/storagemodel.h new file mode 100644 index 0000000000..787b2f04de --- /dev/null +++ b/tests/manual/tableview/storagemodel/storagemodel.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Ivan Komissarov +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STORAGEMODEL_H +#define STORAGEMODEL_H + +#include <QAbstractTableModel> +#include <QStorageInfo> + +class StorageModel : public QAbstractTableModel +{ + Q_OBJECT + Q_DISABLE_COPY(StorageModel) +public: + enum Column { + ColumnRootPath = 0, + ColumnName, + ColumnDevice, + ColumnFileSystemName, + ColumnTotal, + ColumnFree, + ColumnAvailable, + ColumnIsReady, + ColumnIsReadOnly, + ColumnIsValid, + ColumnCount + }; + + explicit StorageModel(QObject *parent = nullptr); + + int columnCount(const QModelIndex &parent) const override; + int rowCount(const QModelIndex &parent) const override; + + QVariant data(const QModelIndex &index, int role) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + +public slots: + void refresh(); + +private: + QList<QStorageInfo> m_volumes; +}; + +#endif // STORAGEMODEL_H diff --git a/tests/manual/tableview/storagemodel/storagemodel.pro b/tests/manual/tableview/storagemodel/storagemodel.pro new file mode 100644 index 0000000000..c6a018239e --- /dev/null +++ b/tests/manual/tableview/storagemodel/storagemodel.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = tableview_storage +QT += qml quick +SOURCES += main.cpp storagemodel.cpp +HEADERS += storagemodel.h +RESOURCES += main.qml + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/tests/manual/tableview/tableview.pro b/tests/manual/tableview/tableview.pro new file mode 100644 index 0000000000..5040f0e747 --- /dev/null +++ b/tests/manual/tableview/tableview.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS += abstracttablemodel \ + listmodel \ + storagemodel diff --git a/tests/manual/touch/flicktext.qml b/tests/manual/touch/flicktext.qml index 6e8dcfded5..9e84261687 100644 --- a/tests/manual/touch/flicktext.qml +++ b/tests/manual/touch/flicktext.qml @@ -48,7 +48,7 @@ ** ****************************************************************************/ -import QtQuick 2.4 +import QtQuick 2.12 import "qrc:/quick/shared/" as Examples Rectangle { @@ -67,6 +67,7 @@ Rectangle { contentWidth: text.implicitWidth contentHeight: text.implicitHeight pixelAligned: pxAlignCB.checked + synchronousDrag: syncDragCB.checked Text { id: text text: "foo bar" @@ -366,10 +367,15 @@ Rectangle { } Column { + spacing: 2 Examples.CheckBox { id: pxAlignCB text: "pixel aligned" } + Examples.CheckBox { + id: syncDragCB + text: "synchronous drag" + } Text { text: "content X " + flick.contentX.toFixed(2) + " Y " + flick.contentY.toFixed(2) } |