From e9b4cab80798e71b6d24c5df0e14b228b046b184 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 25 Oct 2016 15:18:13 +0200 Subject: QmlDesigner: Adding manual test for cpp mockups This is a typical test case for mocking cpp types. Change-Id: Ibd76429c3d1190c46a223062d77d676f728fec77 Reviewed-by: Tim Jenssen --- .../qml/testprojects/cppmockup/MainForm.ui.qml | 60 ++++++++++++++++++++++ .../qml/testprojects/cppmockup/MyComponent.qml | 51 ++++++++++++++++++ .../qml/testprojects/cppmockup/cppmockup.pro | 22 ++++++++ tests/manual/qml/testprojects/cppmockup/main.cpp | 42 +++++++++++++++ tests/manual/qml/testprojects/cppmockup/main.qml | 41 +++++++++++++++ .../cppmockup/mockups/MyPlugin/MyObject.qml | 5 ++ .../testprojects/cppmockup/mockups/MyPlugin/qmldir | 2 + .../qml/testprojects/cppmockup/mybackendobject.cpp | 41 +++++++++++++++ .../qml/testprojects/cppmockup/mybackendobject.h | 47 +++++++++++++++++ tests/manual/qml/testprojects/cppmockup/qml.qrc | 7 +++ 10 files changed, 318 insertions(+) create mode 100644 tests/manual/qml/testprojects/cppmockup/MainForm.ui.qml create mode 100644 tests/manual/qml/testprojects/cppmockup/MyComponent.qml create mode 100644 tests/manual/qml/testprojects/cppmockup/cppmockup.pro create mode 100644 tests/manual/qml/testprojects/cppmockup/main.cpp create mode 100644 tests/manual/qml/testprojects/cppmockup/main.qml create mode 100644 tests/manual/qml/testprojects/cppmockup/mockups/MyPlugin/MyObject.qml create mode 100644 tests/manual/qml/testprojects/cppmockup/mockups/MyPlugin/qmldir create mode 100644 tests/manual/qml/testprojects/cppmockup/mybackendobject.cpp create mode 100644 tests/manual/qml/testprojects/cppmockup/mybackendobject.h create mode 100644 tests/manual/qml/testprojects/cppmockup/qml.qrc diff --git a/tests/manual/qml/testprojects/cppmockup/MainForm.ui.qml b/tests/manual/qml/testprojects/cppmockup/MainForm.ui.qml new file mode 100644 index 0000000000..14aa092833 --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/MainForm.ui.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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. +** +****************************************************************************/ + +import QtQuick 2.7 + +Rectangle { + property alias mouseArea: mouseArea + property alias textEdit: textEdit + + width: 360 + height: 360 + + MouseArea { + id: mouseArea + anchors.fill: parent + + MyComponent { + id: myComponent + x: 174 + y: 180 + } + } + + TextEdit { + id: textEdit + text: qsTr("Enter some text...") + verticalAlignment: Text.AlignVCenter + anchors.top: parent.top + anchors.horizontalCenter: parent.horizontalCenter + anchors.topMargin: 20 + Rectangle { + anchors.fill: parent + anchors.margins: -10 + color: "transparent" + border.width: 1 + } + } +} diff --git a/tests/manual/qml/testprojects/cppmockup/MyComponent.qml b/tests/manual/qml/testprojects/cppmockup/MyComponent.qml new file mode 100644 index 0000000000..3e6cf1694c --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/MyComponent.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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. +** +****************************************************************************/ + +import QtQuick 2.6 +import MyPlugin 1.0 + +Item { + width: 40 + height: 40 + MyObject { + test: true + } + Rectangle { + anchors.fill: parent + gradient: Gradient { + GradientStop { + position: 0 + color: "#ffffff" + } + + GradientStop { + position: 1 + color: "#000000" + } + } + + } + +} diff --git a/tests/manual/qml/testprojects/cppmockup/cppmockup.pro b/tests/manual/qml/testprojects/cppmockup/cppmockup.pro new file mode 100644 index 0000000000..1f8ea65d42 --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/cppmockup.pro @@ -0,0 +1,22 @@ +TEMPLATE = app + +QT += qml quick +CONFIG += c++11 + +SOURCES += main.cpp \ + mybackendobject.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +### QML_IMPORT_PATH = $$PWD/mockups +QML_DESIGNER_IMPORT_PATH = $$PWD/mockups + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +HEADERS += \ + mybackenmodel.h \ + mybackendobject.h diff --git a/tests/manual/qml/testprojects/cppmockup/main.cpp b/tests/manual/qml/testprojects/cppmockup/main.cpp new file mode 100644 index 0000000000..32c7a2d472 --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/main.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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. +** +****************************************************************************/ + +#include + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + qmlRegisterType("MyPlugin", 1, 0, "MyObject"); + + return app.exec(); +} diff --git a/tests/manual/qml/testprojects/cppmockup/main.qml b/tests/manual/qml/testprojects/cppmockup/main.qml new file mode 100644 index 0000000000..aff0f6ae26 --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/main.qml @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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. +** +****************************************************************************/ + +import QtQuick 2.7 +import QtQuick.Window 2.2 + +Window { + visible: true + width: 640 + height: 480 + title: qsTr("Hello World") + + MainForm { + anchors.fill: parent + mouseArea.onClicked: { + console.log(qsTr('Clicked on background. Text: "' + textEdit.text + '"')) + } + } +} diff --git a/tests/manual/qml/testprojects/cppmockup/mockups/MyPlugin/MyObject.qml b/tests/manual/qml/testprojects/cppmockup/mockups/MyPlugin/MyObject.qml new file mode 100644 index 0000000000..0df2d30206 --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/mockups/MyPlugin/MyObject.qml @@ -0,0 +1,5 @@ +import QtQuick 2.6 + +QtObject { + property bool test +} diff --git a/tests/manual/qml/testprojects/cppmockup/mockups/MyPlugin/qmldir b/tests/manual/qml/testprojects/cppmockup/mockups/MyPlugin/qmldir new file mode 100644 index 0000000000..2ee4872b4b --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/mockups/MyPlugin/qmldir @@ -0,0 +1,2 @@ +module MyPlugin +MyObject 1.0 MyObject.qml diff --git a/tests/manual/qml/testprojects/cppmockup/mybackendobject.cpp b/tests/manual/qml/testprojects/cppmockup/mybackendobject.cpp new file mode 100644 index 0000000000..ea93896af0 --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/mybackendobject.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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. +** +****************************************************************************/ + +#include "mybackendobject.h" + +MyBackendObject::MyBackendObject(QObject *parent) : QObject(parent) +{ + +} + +bool MyBackendObject::test() const +{ + return false; +} + +void MyBackendObject::setTest(bool) +{ + +} diff --git a/tests/manual/qml/testprojects/cppmockup/mybackendobject.h b/tests/manual/qml/testprojects/cppmockup/mybackendobject.h new file mode 100644 index 0000000000..e637ac12a6 --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/mybackendobject.h @@ -0,0 +1,47 @@ + +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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. +** +****************************************************************************/ + +#ifndef MYBACKENDOBJECT_H +#define MYBACKENDOBJECT_H + +#include + +class MyBackendObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool test READ test write setTest) + +public: + explicit MyBackendObject(QObject *parent = 0); + + bool test() const; + void setTest(bool b); + +public slots: +}; + +#endif // MYBACKENDOBJECT_H diff --git a/tests/manual/qml/testprojects/cppmockup/qml.qrc b/tests/manual/qml/testprojects/cppmockup/qml.qrc new file mode 100644 index 0000000000..cabeffdb5a --- /dev/null +++ b/tests/manual/qml/testprojects/cppmockup/qml.qrc @@ -0,0 +1,7 @@ + + + main.qml + MainForm.ui.qml + MyComponent.qml + + -- cgit v1.2.1