Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit ebdd5c7

Browse files
committed
fix: UnitSystem qml enum handling
Moved UnitSystem enum from ConfigInterface into dedicated enum class for type safe QML integration. Part of YIO-Remote/remote-software#473
1 parent 025dda0 commit ebdd5c7

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

src/yio-interface/configinterface.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <QVariant>
2525

26+
#include "unitsystem.h"
27+
2628
// HELP: anyone knows how to properly define "static const QString" constants across Qt plugin boundaries?
2729
// Workaround: use plain old macros with separated constant definitions in remote_software and the integration plugin.
2830
// Hope there's a better way...
@@ -48,17 +50,15 @@ class ConfigInterface {
4850
public:
4951
virtual ~ConfigInterface();
5052

51-
enum UnitSystem { METRIC = 0, IMPERIAL = 1 };
52-
53-
virtual QVariantMap getConfig() = 0;
54-
virtual void setConfig(const QVariantMap& getConfig) = 0;
55-
virtual QVariantMap getSettings() = 0;
56-
virtual QVariantMap getAllIntegrations() = 0;
57-
virtual QVariantMap getIntegration(const QString& type) = 0;
58-
virtual QVariantMap getAllEntities() = 0;
59-
virtual QVariantList getEntities(const QString& type) = 0;
60-
virtual QObject* getQMLObject(const QString& name) = 0;
61-
virtual UnitSystem getUnitSystem() = 0;
53+
virtual QVariantMap getConfig() = 0;
54+
virtual void setConfig(const QVariantMap& getConfig) = 0;
55+
virtual QVariantMap getSettings() = 0;
56+
virtual QVariantMap getAllIntegrations() = 0;
57+
virtual QVariantMap getIntegration(const QString& type) = 0;
58+
virtual QVariantMap getAllEntities() = 0;
59+
virtual QVariantList getEntities(const QString& type) = 0;
60+
virtual QObject* getQMLObject(const QString& name) = 0;
61+
virtual UnitSystem::Enum getUnitSystem() = 0;
6262
};
6363

6464
QT_BEGIN_NAMESPACE

src/yio-interface/unitsystem.h

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/******************************************************************************
2+
*
3+
* Copyright (C) 2020 Markus Zehnder <business@markuszehnder.ch>
4+
*
5+
* This file is part of the YIO-Remote software project.
6+
*
7+
* YIO-Remote software is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* YIO-Remote software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with YIO-Remote software. If not, see <https://www.gnu.org/licenses/>.
19+
*
20+
* SPDX-License-Identifier: GPL-3.0-or-later
21+
*****************************************************************************/
22+
23+
#pragma once
24+
25+
#include <QObject>
26+
27+
/**
28+
* @brief Enum class for unit system: metric or imperial.
29+
* @details Dedicated class for clearly separated enums and improved QML usability based on
30+
* https://www.embeddeduse.com/2017/09/15/passing-enum-properties-between-c-and-qml/
31+
*
32+
* Note: the "typedef style" described in https://qml.guide/enums-in-qt-qml/ unfortunately doesn't work with
33+
* "=== Strict Equality Comparison" in QML!
34+
*/
35+
class UnitSystem {
36+
Q_GADGET
37+
38+
public:
39+
enum Enum { METRIC = 0, IMPERIAL = 1 };
40+
Q_ENUM(Enum)
41+
42+
private:
43+
UnitSystem() {}
44+
};

yio-interfaces.pri

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ HEADERS += \
1111
$$PWD/src/yio-interface/integrationinterface.h \
1212
$$PWD/src/yio-interface/notificationsinterface.h \
1313
$$PWD/src/yio-interface/plugininterface.h \
14+
$$PWD/src/yio-interface/unitsystem.h \
1415
$$PWD/src/yio-interface/yioapiinterface.h \
1516
$$PWD/src/yio-interface/entities/blindinterface.h \
1617
$$PWD/src/yio-interface/entities/climateinterface.h \

0 commit comments

Comments
 (0)