summaryrefslogtreecommitdiffstats
path: root/examples/ifvehiclefunctions/climate-widget/mainwindow.cpp
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2021-09-16 16:00:07 +0200
committerDominik Holland <dominik.holland@qt.io>2021-09-22 13:51:56 +0200
commitfe874d5625c324e76f2beccb16b8036498c26165 (patch)
tree6c832a2f4b42fd0b0bc4f94b53f3f3087f4c90fa /examples/ifvehiclefunctions/climate-widget/mainwindow.cpp
parent69377143cc5fab6cf68c892305252ef00c0a6d05 (diff)
Refactor examples and its documentation
* Remove -if- in example names * Replace _ in example names with - * Move all related docs and images to the example folder Pick-to: 6.2 Change-Id: I1fe38c7d4d735c48224c8bdf8622c701ab056070 Reviewed-by: Robert Griebl <robert.griebl@qt.io>
Diffstat (limited to 'examples/ifvehiclefunctions/climate-widget/mainwindow.cpp')
-rw-r--r--examples/ifvehiclefunctions/climate-widget/mainwindow.cpp156
1 files changed, 156 insertions, 0 deletions
diff --git a/examples/ifvehiclefunctions/climate-widget/mainwindow.cpp b/examples/ifvehiclefunctions/climate-widget/mainwindow.cpp
new file mode 100644
index 00000000..8f06010a
--- /dev/null
+++ b/examples/ifvehiclefunctions/climate-widget/mainwindow.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2019 Luxoft Sweden AB
+** Copyright (C) 2018 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtInterfaceFramework module 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 "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <QMessageBox>
+#include <QSpinBox>
+#include <QButtonGroup>
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow),
+ m_buttonGroup(new QButtonGroup(this)),
+ m_climateControl(nullptr)
+{
+ ui->setupUi(this);
+
+ m_buttonGroup->setExclusive(false);
+ m_buttonGroup->addButton(ui->cb_windshield);
+ m_buttonGroup->addButton(ui->cb_dashboard);
+ m_buttonGroup->addButton(ui->cb_floor);
+
+//![1]
+ m_climateControl = new QIfClimateControl(QString(), this);
+ m_climateControl->setDiscoveryMode(QIfAbstractFeature::LoadOnlySimulationBackends);
+ m_climateControl->startAutoDiscovery();
+
+ if (!m_climateControl->isValid())
+ QMessageBox::critical(this, tr("Auto Discovery Failed !"), tr("No Climate Backend available"));
+//![1]
+
+//![2]
+ //Air Flow Direction
+ setupFlowDirectionRadioButtons(m_climateControl->airflowDirections());
+ connect(m_buttonGroup, static_cast<void (QButtonGroup::*)(QAbstractButton *, bool)>(&QButtonGroup::buttonToggled),
+ this, &MainWindow::onFlowDirectionButtonToggled);
+
+ connect(m_climateControl, &QIfClimateControl::airflowDirectionsChanged,
+ this, &MainWindow::setupFlowDirectionRadioButtons);
+
+ //Air Condition
+ ui->cb_airCondition->setChecked(m_climateControl->isAirConditioningEnabled());
+ connect(m_climateControl, &QIfClimateControl::airConditioningEnabledChanged,
+ ui->cb_airCondition, &QCheckBox::setChecked);
+ connect(ui->cb_airCondition, &QCheckBox::clicked,
+ m_climateControl, &QIfClimateControl::setAirConditioningEnabled);
+
+ //Air Recirculation
+ ui->cb_airRecirculation->setChecked(m_climateControl->recirculationMode() == QtIfVehicleFunctions::RecirculationOn);
+ connect(m_climateControl, &QIfClimateControl::recirculationModeChanged,
+ this, &MainWindow::onAirRecirculationModeChanged);
+ connect(ui->cb_airRecirculation, &QCheckBox::clicked,
+ this, &MainWindow::setAirRecirculationEnabled);
+
+ //Heater
+ ui->cb_heater->setChecked(m_climateControl->isHeaterEnabled());
+ connect(m_climateControl, &QIfClimateControl::heaterEnabledChanged,
+ ui->cb_heater, &QCheckBox::setChecked);
+ connect(ui->cb_heater, &QCheckBox::clicked,
+ m_climateControl, &QIfClimateControl::setHeaterEnabled);
+}
+//![2]
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+void MainWindow::setAirRecirculationEnabled(bool enabled)
+{
+ if (enabled)
+ m_climateControl->setRecirculationMode(QtIfVehicleFunctions::RecirculationOn);
+ else
+ m_climateControl->setRecirculationMode(QtIfVehicleFunctions::RecirculationOff);
+}
+
+void MainWindow::onAirRecirculationModeChanged(QtIfVehicleFunctions::RecirculationMode mode)
+{
+ ui->cb_airRecirculation->setChecked(mode == QtIfVehicleFunctions::RecirculationOn);
+}
+
+//![3]
+void MainWindow::setupFlowDirectionRadioButtons(QtIfVehicleFunctions::AirflowDirections direction)
+{
+ ui->cb_windshield->setChecked(direction.testFlag(QtIfVehicleFunctions::Windshield));
+ ui->cb_dashboard->setChecked(direction.testFlag(QtIfVehicleFunctions::Dashboard));
+ ui->cb_floor->setChecked(direction.testFlag(QtIfVehicleFunctions::Floor));
+}
+
+void MainWindow::onFlowDirectionButtonToggled(QAbstractButton *button, bool checked)
+{
+ Q_UNUSED(button)
+ Q_UNUSED(checked)
+
+ QtIfVehicleFunctions::AirflowDirections direction;
+
+ if (ui->cb_windshield->isChecked())
+ direction |= QtIfVehicleFunctions::Windshield;
+ if (ui->cb_dashboard->isChecked())
+ direction |= QtIfVehicleFunctions::Dashboard;
+ if (ui->cb_floor->isChecked())
+ direction |= QtIfVehicleFunctions::Floor;
+
+ m_climateControl->setAirflowDirections(direction);
+}
+//![3]