diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2018-11-07 11:24:22 +0100 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2018-11-27 12:17:54 +0000 |
commit | 529ead91c4ffbe868d7d607666ea649af7bd3467 (patch) | |
tree | 95ff2b8c86c020de07630b7c7759d612e681ee33 | |
parent | b0125a461ddf7e8c1c4964592f7f5d76dbce3f83 (diff) |
Move the ConcreteWindowSimulation C++ implementation to QML
The QIviConcreteWindowControlSimulation.qml contains the new
QML implementation. The simulation.qml file loads this manual
written QML file and reuses the autogenerated simulation file
for the ClimateControl simulation.
Change-Id: I98546613c762aae6462ae51eea5c517d96ca4cf5
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r-- | src/ivivehiclefunctions/ivivehiclefunctions.qface | 3 | ||||
-rw-r--r-- | src/plugins/ivivehiclefunctions/QIviConcreteWindowControlSimulation.qml | 205 | ||||
-rw-r--r-- | src/plugins/ivivehiclefunctions/ivivehiclefunctions.pro | 10 | ||||
-rw-r--r-- | src/plugins/ivivehiclefunctions/qiviconcretewindowcontrolbackend.cpp | 210 | ||||
-rw-r--r-- | src/plugins/ivivehiclefunctions/qiviconcretewindowcontrolbackend.h | 97 | ||||
-rw-r--r-- | src/plugins/ivivehiclefunctions/qml.qrc | 6 | ||||
-rw-r--r-- | src/plugins/ivivehiclefunctions/simulation.qml (renamed from src/plugins/ivivehiclefunctions/ivivehiclefunctions.cpp) | 27 |
7 files changed, 225 insertions, 333 deletions
diff --git a/src/ivivehiclefunctions/ivivehiclefunctions.qface b/src/ivivehiclefunctions/ivivehiclefunctions.qface index 5eeb585..030c052 100644 --- a/src/ivivehiclefunctions/ivivehiclefunctions.qface +++ b/src/ivivehiclefunctions/ivivehiclefunctions.qface @@ -1,4 +1,5 @@ -@config: { qml_name: "QtIvi.VehicleFunctions", interfaceBuilder: "vehicleFunctionsInterfaceBuilder" } +@config: { qml_name: "QtIvi.VehicleFunctions" } +@config_simulator: { simulationFile: "qrc:/simulation/simulation.qml" } module QtIviVehicleFunctions 1.0; /** diff --git a/src/plugins/ivivehiclefunctions/QIviConcreteWindowControlSimulation.qml b/src/plugins/ivivehiclefunctions/QIviConcreteWindowControlSimulation.qml new file mode 100644 index 0000000..4437583 --- /dev/null +++ b/src/plugins/ivivehiclefunctions/QIviConcreteWindowControlSimulation.qml @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AG +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtIvi module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite 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$ +** +** SPDX-License-Identifier: LGPL-3.0 +** +****************************************************************************/ + +import QtQuick 2.0 +import qtivivehiclefunctions.simulation 1.0 + +QtObject { + property var settings : IviSimulator.findData(IviSimulator.simulationData, "QIviWindowControl") + property bool defaultInitialized: false + property var windowTimers : [] + property var blindTimers : [] + property Component comp : Component { + id: timerComp + Timer { + id: timer + + interval: 1000 + repeat: true + property var currentReply + property string zone + property bool isBlind: false + property int currentValue: 0 + property int goal: 4 + property bool opening: false + + function open(reply) { + if (currentReply && !currentReply.resultAvailable) + currentReply.setFailed(); + + currentReply = reply + opening = true + start(); + } + + function close(reply) { + if (currentReply && !currentReply.resultAvailable) + currentReply.setFailed(); + + currentReply = reply + opening = false + start(); + } + + onTriggered: { + if (opening) + currentValue++ + else + currentValue-- + + var state = QtIviVehicleFunctionsModule.Closed + if (currentValue <= 0) { + timer.stop(); + state = QtIviVehicleFunctionsModule.Closed + if (currentReply) + currentReply.setSuccess(true) + } else if (currentValue >= goal) { + timer.stop(); + state = QtIviVehicleFunctionsModule.FullyOpen + if (currentReply) + currentReply.setSuccess(true) + } else { + state = QtIviVehicleFunctionsModule.Open + } + + if (isBlind) + backend.zones[zone].blindState = state + else + backend.zones[zone].state = state + } + } + } + + property var backend : QIviWindowControlBackend { + + function initialize() { + print("QIviConcreteWindowControlSimulation INITIALIZE") + if (!defaultInitialized) { + IviSimulator.initializeDefault(settings, backend) + defaultInitialized = true + } + Base.initialize() + } + + function availableZones() { + var zones = settings.zones; + for (var zone in zones) { + windowTimers[zones[zone]] = timerComp.createObject(backend, { zone: zones[zone] }); + blindTimers[zones[zone]] = timerComp.createObject(backend, { zone: zones[zone], isBlind: true }); + } + + return zones; + } + + function open(reply, zone) { + windowTimers[zone].open(reply) + } + + function close(reply, zone) { + windowTimers[zone].close(reply) + } + + + function setHeaterMode(heaterMode, zone) { + if (IviSimulator.checkSettings(heaterMode, settings["heaterMode"], zone)) { + if (zone) { + console.log("SIMULATION heaterMode for zone: " + zone + " changed to: " + heaterMode); + backend.zones[zone].heaterMode = heaterMode + } else { + console.log("SIMULATION heaterMode changed to: " + heaterMode); + backend.heaterMode = heaterMode + } + } else { + setError("SIMULATION changing heaterMode is not possible: provided: " + heaterMode + "constraint: " + IviSimulator.constraint_string(settings["heaterMode"])); + } + } + + function setHeater(heater, zone) { + if (IviSimulator.checkSettings(heater, settings["heater"], zone)) { + console.log("SIMULATION heater changed to: " + heater); + if (zone) { + console.log("SIMULATION heater for zone: " + zone + " changed to: " + heater); + backend.zones[zone].heater = heater + } else { + console.log("SIMULATION heater changed to: " + heater); + backend.heater = heater + } + } else { + setError("SIMULATION changing heater is not possible: provided: " + heater + "constraint: " + IviSimulator.constraint_string(settings["heater"])); + } + } + + function setState(state, zone) { + if (IviSimulator.checkSettings(state, settings["state"], zone)) { + if (zone) { + console.log("SIMULATION state for zone: " + zone + " changed to: " + state); + backend.zones[zone].state = state + } else { + console.log("SIMULATION state changed to: " + state); + backend.state = state + } + } else { + setError("SIMULATION changing state is not possible: provided: " + state + "constraint: " + IviSimulator.constraint_string(settings["state"])); + } + } + + function setBlindMode(blindMode, zone) { + if (blindMode == QtIviVehicleFunctionsModule.BlindOpen) + blindTimers[zone].open(undefined) + else if (blindMode == QtIviVehicleFunctionsModule.BlindClosed) + blindTimers[zone].close(undefined) + } + + function setBlindState(blindState, zone) { + if (IviSimulator.checkSettings(blindState, settings["blindState"], zone)) { + if (zone) { + console.log("SIMULATION blindState for zone: " + zone + " changed to: " + blindState); + backend.zones[zone].blindState = blindState + } else { + console.log("SIMULATION blindState changed to: " + blindState); + backend.blindState = blindState + } + } else { + setError("SIMULATION changing blindState is not possible: provided: " + blindState + "constraint: " + IviSimulator.constraint_string(settings["blindState"])); + } + } + } +} diff --git a/src/plugins/ivivehiclefunctions/ivivehiclefunctions.pro b/src/plugins/ivivehiclefunctions/ivivehiclefunctions.pro index 38d8edc..c2f3ff3 100644 --- a/src/plugins/ivivehiclefunctions/ivivehiclefunctions.pro +++ b/src/plugins/ivivehiclefunctions/ivivehiclefunctions.pro @@ -9,13 +9,6 @@ QFACE_FORMAT = backend_simulator QFACE_MODULE_NAME = QtIviVehicleFunctions QFACE_SOURCES += ../../ivivehiclefunctions/ivivehiclefunctions.qface -SOURCES += \ - ivivehiclefunctions.cpp \ - qiviconcretewindowcontrolbackend.cpp - -HEADERS += \ - qiviconcretewindowcontrolbackend.h - OTHER_FILES += \ $$PWD/doc/*.qdocconf \ $$PWD/doc/src/*.qdoc @@ -25,3 +18,6 @@ PLUGIN_EXTENDS = ivivehiclefunctions PLUGIN_CLASS_NAME = QtIviVehicleFunctionsPlugin load(qt_plugin) + +RESOURCES += \ + qml.qrc diff --git a/src/plugins/ivivehiclefunctions/qiviconcretewindowcontrolbackend.cpp b/src/plugins/ivivehiclefunctions/qiviconcretewindowcontrolbackend.cpp deleted file mode 100644 index f32f4d9..0000000 --- a/src/plugins/ivivehiclefunctions/qiviconcretewindowcontrolbackend.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 Pelagicore AG -** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtIvi module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL-QTAS$ -** Commercial License Usage -** Licensees holding valid commercial Qt Automotive Suite 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$ -** -** SPDX-License-Identifier: LGPL-3.0 -** -****************************************************************************/ - -#include "qiviconcretewindowcontrolbackend.h" - -#include <QDebug> - -QT_BEGIN_NAMESPACE - -WindowTimer::WindowTimer(const QString &zone, bool isBlind, QIviConcreteWindowControlBackend *backend) - : QObject(backend) - , m_timer(new QTimer(this)) - , m_opening(true) - , m_currentValue(0) - , m_interval(4) - , m_zone(zone) - , m_blind(isBlind) - , m_backend(backend) -{ - m_timer->setInterval(1000); - connect(m_timer, &QTimer::timeout, this, &WindowTimer::checkValue); -} - -void WindowTimer::setOpeningTime(int intervalInSeconds) -{ - m_interval = intervalInSeconds; -} - -void WindowTimer::open(QIviPendingReply<void> reply) -{ - if (!m_pendingReply.isResultAvailable()) - m_pendingReply.setFailed(); - - m_pendingReply = reply; - - m_opening = true; - m_timer->start(); -} - -void WindowTimer::close(QIviPendingReply<void> reply) -{ - if (!m_pendingReply.isResultAvailable()) - m_pendingReply.setFailed(); - - m_pendingReply = reply; - - m_opening = false; - m_timer->start(); -} - -void WindowTimer::checkValue() -{ - if (m_opening) - m_currentValue++; - else - m_currentValue--; - - QtIviVehicleFunctionsModule::WindowState state = QtIviVehicleFunctionsModule::Closed; - if (m_currentValue <= 0) { - m_currentValue = 0; - m_timer->stop(); - state = QtIviVehicleFunctionsModule::Closed; - m_pendingReply.setSuccess(); - } else if (m_currentValue >= m_interval) { - m_currentValue = m_interval; - m_timer->stop(); - state = QtIviVehicleFunctionsModule::FullyOpen; - m_pendingReply.setSuccess(); - } else { - state = QtIviVehicleFunctionsModule::Open; - } - - if (m_blind) { - m_backend->setBlindState(state, m_zone); - } else { - m_backend->setWindowState(state, m_zone); - } -} - - -QIviConcreteWindowControlBackend::QIviConcreteWindowControlBackend(QObject *parent) - : QIviWindowControlBackend(parent) -{ - const auto zones = availableZones(); - for (const QString &zone : zones) { - m_zoneWindowTimers[zone] = new WindowTimer(zone, false, this); - m_zoneBlindTimers[zone] = new WindowTimer(zone, true, this); - } -} - -QIviConcreteWindowControlBackend::~QIviConcreteWindowControlBackend() -{ -} - -void QIviConcreteWindowControlBackend::setBlindMode(QtIviVehicleFunctionsModule::BlindMode blindMode, const QString &zone) -{ - if (!availableZones().contains(zone)) - return; - if (zoneAt(zone)->blindMode() == blindMode) - return; - - if (blindMode == QtIviVehicleFunctionsModule::BlindOpen) - m_zoneBlindTimers[zone]->open(QIviPendingReply<void>()); - else if (blindMode == QtIviVehicleFunctionsModule::BlindClosed) - m_zoneBlindTimers[zone]->close(QIviPendingReply<void>()); - - QIviWindowControlBackend::setBlindMode(blindMode, zone); -} - -QIviPendingReply<void> QIviConcreteWindowControlBackend::open(const QString &zone) -{ - if (!availableZones().contains(zone)) - return QIviPendingReply<void>::createFailedReply(); - - if (zoneAt(zone)->state() == QtIviVehicleFunctionsModule::Open) - return QIviPendingReply<void>::createFailedReply(); - - qWarning() << "SIMULATION open Window:" << zone; - QIviPendingReply<void> reply; - m_zoneWindowTimers[zone]->open(reply); - - return reply; -} - -QIviPendingReply<void> QIviConcreteWindowControlBackend::close(const QString &zone) -{ - if (!availableZones().contains(zone)) - return QIviPendingReply<void>::createFailedReply(); - - if (zoneAt(zone)->state() == QtIviVehicleFunctionsModule::Closed) - return QIviPendingReply<void>::createFailedReply(); - - qWarning() << "SIMULATION close Window:" << zone; - QIviPendingReply<void> reply; - m_zoneWindowTimers[zone]->close(reply); - - return reply; -} - -QtIviVehicleFunctionsModule::WindowState QIviConcreteWindowControlBackend::windowState(QString zone) -{ - Q_ASSERT(availableZones().contains(zone)); - return zoneAt(zone)->state(); -} - -void QIviConcreteWindowControlBackend::setWindowState(QtIviVehicleFunctionsModule::WindowState state, const QString &zone) -{ - if (zoneAt(zone)->state() == state) - return; - qWarning() << "SIMULATION window state for Zone" << zone << "changed to" << state; - zoneAt(zone)->setState(state); - emit stateChanged(state, zone); -} - -QtIviVehicleFunctionsModule::WindowState QIviConcreteWindowControlBackend::blindState(QString zone) -{ - Q_ASSERT(availableZones().contains(zone)); - return zoneAt(zone)->blindState(); -} - -void QIviConcreteWindowControlBackend::setBlindState(QtIviVehicleFunctionsModule::WindowState state, const QString &zone) -{ - if (zoneAt(zone)->blindState() == state) - return; - qWarning() << "SIMULATION blind state for Zone" << zone << "changed to" << state; - zoneAt(zone)->setBlindState(state); - emit blindStateChanged(state, zone); -} - - -QT_END_NAMESPACE diff --git a/src/plugins/ivivehiclefunctions/qiviconcretewindowcontrolbackend.h b/src/plugins/ivivehiclefunctions/qiviconcretewindowcontrolbackend.h deleted file mode 100644 index 4405274..0000000 --- a/src/plugins/ivivehiclefunctions/qiviconcretewindowcontrolbackend.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 Pelagicore AG -** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtIvi module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL-QTAS$ -** Commercial License Usage -** Licensees holding valid commercial Qt Automotive Suite 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$ -** -** SPDX-License-Identifier: LGPL-3.0 -** -****************************************************************************/ - -#ifndef QTIVIVEHICLEFUNCTIONS_QIVICONCRETEWINDOWCONTROLBACKEND_H_ -#define QTIVIVEHICLEFUNCTIONS_QIVICONCRETEWINDOWCONTROLBACKEND_H_ - -#include "qiviwindowcontrolbackend.h" -#include <QTimer> - -QT_BEGIN_NAMESPACE - -class QIviConcreteWindowControlBackend; -class WindowTimer : public QObject -{ -public: - WindowTimer(const QString &zone, bool isBlind, QIviConcreteWindowControlBackend *backend); - - void setOpeningTime(int intervalInSeconds); - void open(QIviPendingReply<void> reply); - void close(QIviPendingReply<void> reply); - -public slots: - void checkValue(); - -private: - QTimer *m_timer; - bool m_opening; - int m_currentValue; - int m_interval; - QString m_zone; - bool m_blind; - QIviConcreteWindowControlBackend *m_backend; - QIviPendingReply<void> m_pendingReply; -}; - -class QIviConcreteWindowControlBackend : public QIviWindowControlBackend -{ -public: - explicit QIviConcreteWindowControlBackend(QObject *parent = nullptr); - ~QIviConcreteWindowControlBackend(); - - virtual void setBlindMode(QtIviVehicleFunctionsModule::BlindMode blindMode, const QString &zone) override; - virtual QIviPendingReply<void> open(const QString &zone) override; - virtual QIviPendingReply<void> close(const QString &zone) override; - - QtIviVehicleFunctionsModule::WindowState windowState(QString zone); - void setWindowState(QtIviVehicleFunctionsModule::WindowState state, const QString &zone); - QtIviVehicleFunctionsModule::WindowState blindState(QString zone); - void setBlindState(QtIviVehicleFunctionsModule::WindowState state, const QString &zone); - -private: - QMap<QString,WindowTimer*> m_zoneWindowTimers; - QMap<QString,WindowTimer*> m_zoneBlindTimers; -}; - -QT_END_NAMESPACE - -#endif // QTIVIVEHICLEFUNCTIONS_QIVICONCRETEWINDOWCONTROLBACKEND_H_ diff --git a/src/plugins/ivivehiclefunctions/qml.qrc b/src/plugins/ivivehiclefunctions/qml.qrc new file mode 100644 index 0000000..b94e5bf --- /dev/null +++ b/src/plugins/ivivehiclefunctions/qml.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/simulation"> + <file>simulation.qml</file> + <file>QIviConcreteWindowControlSimulation.qml</file> + </qresource> +</RCC> diff --git a/src/plugins/ivivehiclefunctions/ivivehiclefunctions.cpp b/src/plugins/ivivehiclefunctions/simulation.qml index 8dded30..e2d0dfe 100644 --- a/src/plugins/ivivehiclefunctions/ivivehiclefunctions.cpp +++ b/src/plugins/ivivehiclefunctions/simulation.qml @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2018 Pelagicore AG -** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtIvi module of the Qt Toolkit. @@ -40,22 +39,14 @@ ** ****************************************************************************/ -#include "qiviclimatecontrolbackend.h" -#include "qiviconcretewindowcontrolbackend.h" -#include "qtivivehiclefunctionsplugin.h" +import QtQuick 2.0 +import qtivivehiclefunctions.simulation 1.0 -QT_BEGIN_NAMESPACE - -extern QVector<QIviFeatureInterface *> vehicleFunctionsInterfaceBuilder(QtIviVehicleFunctionsPlugin *plugin) -{ - const QStringList interafaces = plugin->interfaces(); - QVector<QIviFeatureInterface *> res; - Q_ASSERT(interafaces.size() == 2); - Q_ASSERT(interafaces.indexOf(QtIviVehicleFunctions_QIviClimateControl_iid) == 0); - Q_ASSERT(interafaces.indexOf(QtIviVehicleFunctions_QIviWindowControl_iid) == 1); - res << new QIviClimateControlBackend(plugin); - res << new QIviConcreteWindowControlBackend(plugin); - return res; +QtObject { + property var qiviclimatecontrol : QIviClimateControlSimulation { + id: qiviclimatecontrol + } + property var qiviwindowcontrol : QIviConcreteWindowControlSimulation { + id: qiviwindowcontrol + } } - -QT_END_NAMESPACE |