diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 1f5c2e8342a..ebcab57a361 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -98,3 +98,4 @@ add_subdirectory(studiowelcome) add_subdirectory(qnx) add_subdirectory(webassembly) add_subdirectory(mcusupport) +add_subdirectory(saferenderer) diff --git a/src/plugins/plugins.qbs b/src/plugins/plugins.qbs index 72484ef4f0a..69ed458bfa4 100644 --- a/src/plugins/plugins.qbs +++ b/src/plugins/plugins.qbs @@ -70,6 +70,7 @@ Project { "qtsupport/qtsupport.qbs", "remotelinux/remotelinux.qbs", "resourceeditor/resourceeditor.qbs", + "saferenderer/saferenderer.qbs", "scxmleditor/scxmleditor.qbs", "serialterminal/serialterminal.qbs", "silversearcher/silversearcher.qbs", diff --git a/src/plugins/saferenderer/CMakeLists.txt b/src/plugins/saferenderer/CMakeLists.txt new file mode 100644 index 00000000000..739332de42d --- /dev/null +++ b/src/plugins/saferenderer/CMakeLists.txt @@ -0,0 +1,8 @@ +add_qtc_plugin(SafeRenderer + DEPENDS + QtCreator::Core QtCreator::ProjectExplorer + SOURCES + saferenderer.qrc + saferenderer.cpp + saferenderer.h +) diff --git a/src/plugins/saferenderer/SafeRenderer.json.in b/src/plugins/saferenderer/SafeRenderer.json.in new file mode 100644 index 00000000000..c8a6e3ee795 --- /dev/null +++ b/src/plugins/saferenderer/SafeRenderer.json.in @@ -0,0 +1,20 @@ +{ + \"Name\" : \"SafeRenderer\", + \"Version\" : \"$$QTCREATOR_VERSION\", + \"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\", + \"DisabledByDefault\" : true, + \"Vendor\" : \"The Qt Company Ltd\", + \"Copyright\" : \"(C) $$QTCREATOR_COPYRIGHT_YEAR The Qt Company Ltd\", + \"License\" : [ \"Commercial Usage\", + \"\", + \"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt 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.\", + \"\", + \"GNU General Public License Usage\", + \"\", + \"Alternatively, this plugin 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 plugin. 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.\" + ], + \"Category\" : \"Device Support\", + \"Description\" : \"Helper plugin for Qt Safe Renderer projects.\", + \"Url\" : \"https://www.qt.io\", + $$dependencyList +} diff --git a/src/plugins/saferenderer/saferenderer.cpp b/src/plugins/saferenderer/saferenderer.cpp new file mode 100644 index 00000000000..115b7c8728b --- /dev/null +++ b/src/plugins/saferenderer/saferenderer.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "saferenderer.h" + +#include + +namespace SafeRenderer::Internal { + +SafeRendererPlugin::SafeRendererPlugin() +{ +} + +SafeRendererPlugin::~SafeRendererPlugin() +{ +} + +bool SafeRendererPlugin::initialize(const QStringList &arguments, QString *errorString) +{ + Q_UNUSED(arguments) + Q_UNUSED(errorString) + + // Add Qt Creator project wizard path + ProjectExplorer::JsonWizardFactory::addWizardPath(":/saferenderer/wizards/"); + + return true; +} + +} // namespace SafeRenderer::Internal diff --git a/src/plugins/saferenderer/saferenderer.h b/src/plugins/saferenderer/saferenderer.h new file mode 100644 index 00000000000..1fabbff9ee1 --- /dev/null +++ b/src/plugins/saferenderer/saferenderer.h @@ -0,0 +1,22 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include + +namespace SafeRenderer::Internal { + +class SafeRendererPlugin : public ExtensionSystem::IPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "SafeRenderer.json") + +public: + SafeRendererPlugin(); + ~SafeRendererPlugin() override; + + bool initialize(const QStringList &arguments, QString *errorString) override; +}; + +} // namespace SafeRenderer::Internal diff --git a/src/plugins/saferenderer/saferenderer.qbs b/src/plugins/saferenderer/saferenderer.qbs new file mode 100644 index 00000000000..7945054eaec --- /dev/null +++ b/src/plugins/saferenderer/saferenderer.qbs @@ -0,0 +1,14 @@ +import qbs + +QtcPlugin { + name: "SafeRenderer" + + Depends { name: "Core" } + Depends { name: "ProjectExplorer" } + + files: [ + "saferenderer.cpp", + "saferenderer.h", + "saferenderer.qrc", + ] +} diff --git a/src/plugins/saferenderer/saferenderer.qrc b/src/plugins/saferenderer/saferenderer.qrc new file mode 100644 index 00000000000..28baa346473 --- /dev/null +++ b/src/plugins/saferenderer/saferenderer.qrc @@ -0,0 +1,12 @@ + + + wizards/icon.png + wizards/icon@2x.png + wizards/qsrapp/file.pro + wizards/qsrapp/main.cpp.tpl + wizards/qsrapp/main.qml.tpl + wizards/qsrapp/qml.qrc.tpl + wizards/qsrapp/safeasset.qrc.tpl + wizards/qsrapp/wizard.json + + diff --git a/src/plugins/saferenderer/wizards/icon.png b/src/plugins/saferenderer/wizards/icon.png new file mode 100644 index 00000000000..88826ce9fb0 Binary files /dev/null and b/src/plugins/saferenderer/wizards/icon.png differ diff --git a/src/plugins/saferenderer/wizards/icon@2x.png b/src/plugins/saferenderer/wizards/icon@2x.png new file mode 100644 index 00000000000..1838ac95117 Binary files /dev/null and b/src/plugins/saferenderer/wizards/icon@2x.png differ diff --git a/src/plugins/saferenderer/wizards/qsrapp/file.pro b/src/plugins/saferenderer/wizards/qsrapp/file.pro new file mode 100644 index 00000000000..0302daad207 --- /dev/null +++ b/src/plugins/saferenderer/wizards/qsrapp/file.pro @@ -0,0 +1,52 @@ +QT = qtsaferenderer qsrplatformadaptation + +CONFIG += c++17 + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \\ + %{CppFileName} + + +# List of language codes that your application supports. For example, SAFE_LANGUAGES = en fi. +#SAFE_LANGUAGES = en + +# List of translation file names excluding the language code. For example, SAFE_TRANSLATION = $$PWD/safeui. +#SAFE_TRANSLATION = $$PWD/safeui + +# List of translation file names including the language code. There must be one file +# for each language listed in SAFE_LANGUAGES. For example, TRANSLATIONS += safeui_en.ts safeui_fi.ts. +#TRANSLATIONS += safeui_en.ts + +# You can use an lupdate_only{...} conditional statement to specify the QML files that contain texts. +#lupdate_only { +# SOURCES += main.qml +#} + + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = $$PWD/imports + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + + +CONFIG += qtsaferenderer exceptions +SAFE_QML = $$PWD/main.qml +SAFE_LAYOUT_PATH = $$PWD/layoutData +SAFE_RESOURCES += safeasset.qrc + +!cross_compile: DEFINES += HOST_BUILD +!cross_compile: QT += widgets quick svg + +DISTFILES += main.qml diff --git a/src/plugins/saferenderer/wizards/qsrapp/main.cpp.tpl b/src/plugins/saferenderer/wizards/qsrapp/main.cpp.tpl new file mode 100644 index 00000000000..4f36c6f6fa3 --- /dev/null +++ b/src/plugins/saferenderer/wizards/qsrapp/main.cpp.tpl @@ -0,0 +1,66 @@ +%{Cpp:LicenseTemplate}\ +%{JS: QtSupport.qtIncludes([ 'QtCore/QCoreApplication' ], + [ 'QtCore/QCoreApplication' ]) }\ + +#include +#include +#include + +#if defined(HOST_BUILD) +#include +#include +#include +#endif + +#if defined(USE_OUTPUTVERIFIER) +#include +#include "testverifier.h" +#endif + +#include "safewindow.h" +#include "eventhandler.h" + +int main(int argc, char *argv[]) +{ + Q_UNUSED(argc); + Q_UNUSED(argv); + + static SafeRenderer::QSafeLayoutResourceReader layout("/layoutData/main/main.srl"); + +#if defined(USE_OUTPUTVERIFIER) + static OutputVerifier outputVerifier; +#if defined(HOST_BUILD) + //In host environment the TestVerifier must be explicitly created. + //In OpeWFD adaptation the MISRVerifier instance is created in the SafeWindow adaptation. + static TestVerifier testVerifier(outputVerifier); +#endif + SafeWindow telltaleWindow(layout.size(), QSafePoint(0U, 0U), outputVerifier); +#else + SafeWindow telltaleWindow(layout.size(), QSafePoint(0U, 0U)); +#endif + static SafeRenderer::StateManager stateManager(telltaleWindow, layout); + telltaleWindow.requestUpdate(); //Request is required because eventHandler is not running yet. + +#if defined(USE_OUTPUTVERIFIER) + EventHandler msgHandler(stateManager, telltaleWindow, outputVerifier); +#else + EventHandler msgHandler(stateManager, telltaleWindow); +#endif + +#if defined(HOST_BUILD) + //Mixing the Qt and Qt Safe Renderer renderers is done here only for demonstration purposes on host, not for production purposes of any kind. + QQmlApplicationEngine engine; + const QUrl url(QStringLiteral("qrc:/main.qml")); + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, qApp, + [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) + qDebug() << "Failed to start the main.qml"; + }, Qt::QueuedConnection); + engine.addImportPath(":/imports"); + engine.load(url); +#endif + + msgHandler.handleEvents(); + + return 0; +} diff --git a/src/plugins/saferenderer/wizards/qsrapp/main.qml.tpl b/src/plugins/saferenderer/wizards/qsrapp/main.qml.tpl new file mode 100644 index 00000000000..94fccebcb2a --- /dev/null +++ b/src/plugins/saferenderer/wizards/qsrapp/main.qml.tpl @@ -0,0 +1,26 @@ +import Qt.SafeRenderer 2.0 +import QtQuick.Window 2.15 + +Window { + id: window + width: 640 + height: 480 + visible: true + title: qsTr("Hello QSR") + + SafeText { + id: safeText + objectName: "safetextitem" + x: 206 + y: 208 + width: 340 + height: 34 + color: "#8ae234" + fillColor: "black" + text: "Hello Qt Safe Renderer!" + font.family: "Lato" + horizontalAlignment: Text.AlignLeft + font.pixelSize: 32 + runtimeEditable: true + } +} diff --git a/src/plugins/saferenderer/wizards/qsrapp/qml.qrc.tpl b/src/plugins/saferenderer/wizards/qsrapp/qml.qrc.tpl new file mode 100644 index 00000000000..5f6483ac33f --- /dev/null +++ b/src/plugins/saferenderer/wizards/qsrapp/qml.qrc.tpl @@ -0,0 +1,5 @@ + + + main.qml + + diff --git a/src/plugins/saferenderer/wizards/qsrapp/safeasset.qrc.tpl b/src/plugins/saferenderer/wizards/qsrapp/safeasset.qrc.tpl new file mode 100644 index 00000000000..601b61fc4c2 --- /dev/null +++ b/src/plugins/saferenderer/wizards/qsrapp/safeasset.qrc.tpl @@ -0,0 +1,2 @@ + + diff --git a/src/plugins/saferenderer/wizards/qsrapp/wizard.json b/src/plugins/saferenderer/wizards/qsrapp/wizard.json new file mode 100644 index 00000000000..e05e5f7971a --- /dev/null +++ b/src/plugins/saferenderer/wizards/qsrapp/wizard.json @@ -0,0 +1,103 @@ +{ + "version": 1, + "supportedProjectTypes": [ "Qt4ProjectManager.Qt4Project" ], + "id": "E.QSRApp", + "category": "D.QtSafeRendererApplication", + "trDescription": "Creates a Qt Safe Renderer project with simple UI and project setup.", + "trDisplayName": "Qt Safe Renderer Application", + "trDisplayCategory": "Application (Qt Safe Renderer)", + "icon": "../icon.png", + "iconKind": "Themed", + "featuresRequired": [ "QtSupport.Wizards.FeatureQt" ], + "enabled": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0 || value('Plugins').indexOf('CMakeProjectManager') >= 0}", + + "options": + [ + { "key": "ProjectFile", "value": "%{JS: value('BuildSystem') == 'qmake' ? value('ProFile') : value('CMakeFile')}" }, + { "key": "ProFile", "value": "%{JS: Util.fileName(value('ProjectDirectory') + '/' + value('ProjectName'), 'pro')}" }, + { "key": "HasTranslation", "value": "%{JS: value('TsFileName') !== ''}" }, + { "key": "CppFileName", "value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src')}" } + ], + + "pages": + [ + { + "trDisplayName": "Project Location", + "trShortTitle": "Location", + "typeId": "Project", + "data": { "trDescription": "This wizard creates a simple Qt Safe Renderer application." } + }, + { + "trDisplayName": "Define Build System", + "trShortTitle": "Build System", + "typeId": "Fields", + "enabled": "%{JS: !value('IsSubproject')}", + "data": + [ + { + "name": "BuildSystem", + "trDisplayName": "Build system:", + "type": "ComboBox", + "persistenceKey": "BuildSystemType", + "data": + { + "index": 0, + "items": + [ + { + "trKey": "qmake", + "value": "qmake", + "condition": "%{JS: value('Plugins').indexOf('QmakeProjectManager') >= 0}" + } + ] + } + } + ] + }, + { + "trDisplayName": "Kit Selection", + "trShortTitle": "Kits", + "typeId": "Kits", + "enabled": "%{JS: !value('IsSubproject')}", + "data": { "projectFilePath": "%{ProjectFile}" } + }, + { + "trDisplayName": "Project Management", + "trShortTitle": "Summary", + "typeId": "Summary" + } + ], + "generators": + [ + { + "typeId": "File", + "data": + [ + { + "source": "file.pro", + "target": "%{ProFile}", + "openAsProject": true, + "condition": "%{JS: value('BuildSystem') === 'qmake'}" + }, + { + "source": "main.cpp.tpl", + "target": "%{CppFileName}", + "openInEditor": false + }, + { + "source": "safeasset.qrc.tpl", + "target": "safeasset.qrc" + }, + { + "source": "qml.qrc.tpl", + "target": "qml.qrc" + }, + { + "source": "main.qml.tpl", + "target": "main.qml", + "openInEditor": true + } + ] + } + ] +}