diff --git a/Serial-Studio.pro b/Serial-Studio.pro
index 92176ec3..7815cc89 100644
--- a/Serial-Studio.pro
+++ b/Serial-Studio.pro
@@ -140,17 +140,22 @@ SOURCES += \
src/main.cpp
DISTFILES += \
+ assets/qml/About.qml \
assets/qml/Components/Console.qml \
assets/qml/Components/DataGrid.qml \
assets/qml/Components/DeviceManager.qml \
- assets/qml/Components/GraphGrid.qml \
assets/qml/Components/ToolBar.qml \
+ assets/qml/Components/WidgetGrid.qml \
assets/qml/UI.qml \
+ assets/qml/Widgets/AccelerometerDelegate.qml \
+ assets/qml/Widgets/BarDelegate.qml \
assets/qml/Widgets/DataDelegate.qml \
+ assets/qml/Widgets/GaugeDelegate.qml \
assets/qml/Widgets/GraphDelegate.qml \
assets/qml/Widgets/GroupDelegate.qml \
+ assets/qml/Widgets/GyroDelegate.qml \
assets/qml/Widgets/LED.qml \
assets/qml/Widgets/MapDelegate.qml \
+ assets/qml/Widgets/TankDelegate.qml \
assets/qml/Widgets/Window.qml \
- assets/qml/main.qml \
- assets/qml/About.qml
+ assets/qml/main.qml
diff --git a/assets/assets.qrc b/assets/assets.qrc
index fa21901e..56e646ac 100644
--- a/assets/assets.qrc
+++ b/assets/assets.qrc
@@ -43,11 +43,17 @@
qml/Components/DataGrid.qml
qml/Components/DeviceManager.qml
qml/Components/ToolBar.qml
+ qml/Components/WidgetGrid.qml
+ qml/Widgets/AccelerometerDelegate.qml
+ qml/Widgets/BarDelegate.qml
qml/Widgets/DataDelegate.qml
+ qml/Widgets/GaugeDelegate.qml
qml/Widgets/GraphDelegate.qml
qml/Widgets/GroupDelegate.qml
+ qml/Widgets/GyroDelegate.qml
qml/Widgets/LED.qml
qml/Widgets/MapDelegate.qml
+ qml/Widgets/TankDelegate.qml
qml/Widgets/Window.qml
qml/About.qml
qml/main.qml
diff --git a/assets/qml/Components/WidgetGrid.qml b/assets/qml/Components/WidgetGrid.qml
new file mode 100644
index 00000000..1724bb49
--- /dev/null
+++ b/assets/qml/Components/WidgetGrid.qml
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 Alex Spataru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+import QtQuick 2.12
+import QtQuick.Layouts 1.12
+import QtQuick.Controls 2.12
+
+import Group 1.0
+import Dataset 1.0
+
+import "../Widgets"
+
+Item {
+
+}
diff --git a/assets/qml/UI.qml b/assets/qml/UI.qml
index 9a990da0..5f53845f 100644
--- a/assets/qml/UI.qml
+++ b/assets/qml/UI.qml
@@ -70,13 +70,11 @@ Page {
TabBar {
id: tabBar
contentHeight: 32
- palette.button: Qt.rgba(45/255, 96/255, 115/255, 1)
- visible: CppQmlBridge.gpsSupported
- enabled: CppQmlBridge.groupCount > 0
- opacity: CppQmlBridge.groupCount > 0 ? 1 : 0
- Behavior on opacity {NumberAnimation{}}
-
+ enabled: opacity > 0
onVisibleChanged: dataButton.clicked()
+ opacity: CppSerialManager.connected ? 1 : 0
+ palette.button: Qt.rgba(45/255, 96/255, 115/255, 1)
+ Behavior on opacity {NumberAnimation{}}
anchors {
leftMargin: 3
@@ -93,8 +91,7 @@ Page {
}
TabButton {
- text: qsTr("GPS Map")
- enabled: CppQmlBridge.gpsSupported
+ text: qsTr("Widgets")
}
}
diff --git a/assets/qml/Widgets/AccelerometerDelegate.qml b/assets/qml/Widgets/AccelerometerDelegate.qml
new file mode 100644
index 00000000..d661d629
--- /dev/null
+++ b/assets/qml/Widgets/AccelerometerDelegate.qml
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2020 Alex Spataru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+import QtQuick 2.12
+
+Item {
+
+}
diff --git a/assets/qml/Widgets/BarDelegate.qml b/assets/qml/Widgets/BarDelegate.qml
new file mode 100644
index 00000000..d661d629
--- /dev/null
+++ b/assets/qml/Widgets/BarDelegate.qml
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2020 Alex Spataru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+import QtQuick 2.12
+
+Item {
+
+}
diff --git a/assets/qml/Widgets/GaugeDelegate.qml b/assets/qml/Widgets/GaugeDelegate.qml
new file mode 100644
index 00000000..d661d629
--- /dev/null
+++ b/assets/qml/Widgets/GaugeDelegate.qml
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2020 Alex Spataru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+import QtQuick 2.12
+
+Item {
+
+}
diff --git a/assets/qml/Widgets/GyroDelegate.qml b/assets/qml/Widgets/GyroDelegate.qml
new file mode 100644
index 00000000..d661d629
--- /dev/null
+++ b/assets/qml/Widgets/GyroDelegate.qml
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2020 Alex Spataru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+import QtQuick 2.12
+
+Item {
+
+}
diff --git a/assets/qml/Widgets/MapDelegate.qml b/assets/qml/Widgets/MapDelegate.qml
index 5a77cfd2..3c92a7bf 100644
--- a/assets/qml/Widgets/MapDelegate.qml
+++ b/assets/qml/Widgets/MapDelegate.qml
@@ -37,8 +37,8 @@ ColumnLayout {
//
// Real-time GPS coordinates components
//
- property real latitude: CppQmlBridge.gpsLatitude
- property real longitude: CppQmlBridge.gpsLongitude
+ property real latitude: 0
+ property real longitude: 0
//
// Will be true if GPS coordinates are different from (0,0)
diff --git a/assets/qml/Widgets/TankDelegate.qml b/assets/qml/Widgets/TankDelegate.qml
new file mode 100644
index 00000000..d661d629
--- /dev/null
+++ b/assets/qml/Widgets/TankDelegate.qml
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2020 Alex Spataru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+import QtQuick 2.12
+
+Item {
+
+}
diff --git a/src/Dataset.cpp b/src/Dataset.cpp
index c0c26dcf..ab8c33a9 100644
--- a/src/Dataset.cpp
+++ b/src/Dataset.cpp
@@ -82,7 +82,7 @@ bool Dataset::read(const QJsonObject &object)
auto units = object.value("u").toVariant().toString();
auto widget = object.value("w").toVariant().toString();
- if (!title.isEmpty() && !value.isEmpty())
+ if (!value.isEmpty())
{
m_graph = graph;
m_title = title;
diff --git a/src/Export.cpp b/src/Export.cpp
index 2b0098c1..8da15471 100644
--- a/src/Export.cpp
+++ b/src/Export.cpp
@@ -114,10 +114,7 @@ bool Export::isOpen() const
/**
* Open a CSV file in the Explorer/Finder window
*/
-void Export::openCsv()
-{
-
-}
+void Export::openCsv() { }
/**
* Open the current CSV file in the Explorer/Finder window
diff --git a/src/Group.cpp b/src/Group.cpp
index f38ff882..60aaf7a5 100644
--- a/src/Group.cpp
+++ b/src/Group.cpp
@@ -62,7 +62,7 @@ QString Group::title() const
*/
QString Group::widget() const
{
- return m_widget;
+ return m_widget;
}
/**
diff --git a/src/Widgets.cpp b/src/Widgets.cpp
index 0ce1b72b..03410845 100644
--- a/src/Widgets.cpp
+++ b/src/Widgets.cpp
@@ -21,120 +21,457 @@
*/
#include "Group.h"
+#include "Dataset.h"
#include "Widgets.h"
#include "QmlBridge.h"
-static Widgets* INSTANCE = Q_NULLPTR;
+#include
+#include
-Widgets* Widgets::getInstance() {
- if (!INSTANCE)
- INSTANCE = new Widgets;
+static Widgets *INSTANCE = Q_NULLPTR;
- return INSTANCE;
+Widgets::Widgets()
+{
+ auto bridge = QmlBridge::getInstance();
+ connect(bridge, SIGNAL(updated()), this, SLOT(updateModels()));
}
-QList Widgets::barGroups() const {
- return m_barGroups;
+Widgets *Widgets::getInstance()
+{
+ if (!INSTANCE)
+ INSTANCE = new Widgets;
+
+ return INSTANCE;
}
-QList Widgets::mapGroups() const {
- return m_mapGroups;
+QList Widgets::barGroup() const
+{
+ return m_barGroups;
}
-QList Widgets::gyroGroups() const {
- return m_gyroGroups;
+QList Widgets::mapGroup() const
+{
+ return m_mapGroups;
}
-QList Widgets::tankGroups() const {
- return m_tankGroups;
+QList Widgets::gyroGroup() const
+{
+ return m_gyroGroups;
}
-QList Widgets::gaugeGroups() const {
- return m_gaugeGroups;
+QList Widgets::tankGroup() const
+{
+ return m_tankGroups;
}
-QList Widgets::accelerometerGroups() const {
- return m_accelerometerGroups;
+QList Widgets::gaugeGroup() const
+{
+ return m_gaugeGroups;
}
-Group* Widgets::barGroupAt(const int index) {
- if (barGroups().count() > index)
- return barGroups().at(index);
-
- return Q_NULLPTR;
+QList Widgets::accelerometerGroup() const
+{
+ return m_accelerometerGroups;
}
-Group* Widgets::mapGroupAt(const int index) {
- if (mapGroups().count() > index)
- return mapGroups().at(index);
-
- return Q_NULLPTR;
+int Widgets::barGroupCount() const
+{
+ return barGroup().count();
}
-Group* Widgets::gyroGroupAt(const int index) {
- if (gyroGroups().count() > index)
- return gyroGroups().at(index);
-
- return Q_NULLPTR;
+int Widgets::mapGroupCount() const
+{
+ return mapGroup().count();
}
-Group* Widgets::tankGroupAt(const int index) {
- if (tankGroups().count() > index)
- return tankGroups().at(index);
-
- return Q_NULLPTR;
+int Widgets::gyroGroupCount() const
+{
+ return gyroGroup().count();
}
-Group* Widgets::gaugeGroupAt(const int index) {
- if (gaugeGroups().count() > index)
- return gaugeGroups().at(index);
-
- return Q_NULLPTR;
+int Widgets::tankGroupCount() const
+{
+ return tankGroup().count();
}
-Group* Widgets::accelerometerGroupAt(const int index) {
- if (accelerometerGroups().count() > index)
- return accelerometerGroups().at(index);
-
- return Q_NULLPTR;
+int Widgets::gaugeGroupCount() const
+{
+ return gaugeGroup().count();
}
-qreal Widgets::gyroX(const int index) const {}
-
-qreal Widgets::gyroY(const int index) const {}
-
-qreal Widgets::gyroZ(const int index) const {}
-
-qreal Widgets::accelerometerX(const int index) const {}
-
-qreal Widgets::accelerometerY(const int index) const {}
-
-qreal Widgets::accelerometerZ(const int index) const {}
-
-qreal Widgets::bar(const int index) const {}
-
-qreal Widgets::tank(const int index) const {}
-
-qreal Widgets::gauge(const int index) const {}
-
-qreal Widgets::barMin(const int index) const {}
-
-qreal Widgets::barMax(const int index) const {}
-
-qreal Widgets::tankMin(const int index) const {}
-
-qreal Widgets::tankMax(const int index) const {}
-
-qreal Widgets::gaugeMin(const int index) const {}
-
-qreal Widgets::gaugeMax(const int index) const {}
-
-qreal Widgets::mapLatitude(const int index) const {}
-
-qreal Widgets::mapLongitude(const int index) const {}
-
-void Widgets::updateModels() {}
-
-QList Widgets::getWidgetGroup(const QString& handle) {
-
+int Widgets::accelerometerGroupCount() const
+{
+ return accelerometerGroup().count();
+}
+
+Group *Widgets::barGroupAt(const int index)
+{
+ if (barGroup().count() > index)
+ return barGroup().at(index);
+
+ return Q_NULLPTR;
+}
+
+Group *Widgets::mapGroupAt(const int index)
+{
+ if (mapGroup().count() > index)
+ return mapGroup().at(index);
+
+ return Q_NULLPTR;
+}
+
+Group *Widgets::gyroGroupAt(const int index)
+{
+ if (gyroGroup().count() > index)
+ return gyroGroup().at(index);
+
+ return Q_NULLPTR;
+}
+
+Group *Widgets::tankGroupAt(const int index)
+{
+ if (tankGroup().count() > index)
+ return tankGroup().at(index);
+
+ return Q_NULLPTR;
+}
+
+Group *Widgets::gaugeGroupAt(const int index)
+{
+ if (gaugeGroup().count() > index)
+ return gaugeGroup().at(index);
+
+ return Q_NULLPTR;
+}
+
+Group *Widgets::accelerometerGroupAt(const int index)
+{
+ if (accelerometerGroup().count() > index)
+ return accelerometerGroup().at(index);
+
+ return Q_NULLPTR;
+}
+
+double Widgets::gyroX(const int index)
+{
+ auto gyro = gyroGroupAt(index);
+
+ if (gyro)
+ {
+ foreach (auto dataset, gyro->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "x")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::gyroY(const int index)
+{
+ auto gyro = gyroGroupAt(index);
+
+ if (gyro)
+ {
+ foreach (auto dataset, gyro->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "y")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::gyroZ(const int index)
+{
+ auto gyro = gyroGroupAt(index);
+
+ if (gyro)
+ {
+ foreach (auto dataset, gyro->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "z")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::accelerometerX(const int index)
+{
+ auto accelerometer = accelerometerGroupAt(index);
+
+ if (accelerometer)
+ {
+ foreach (auto dataset, accelerometer->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "x")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::accelerometerY(const int index)
+{
+ auto accelerometer = accelerometerGroupAt(index);
+
+ if (accelerometer)
+ {
+ foreach (auto dataset, accelerometer->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "y")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::accelerometerZ(const int index)
+{
+ auto accelerometer = accelerometerGroupAt(index);
+
+ if (accelerometer)
+ {
+ foreach (auto dataset, accelerometer->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "z")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::bar(const int index)
+{
+ auto bar = barGroupAt(index);
+
+ if (bar)
+ {
+ foreach (auto dataset, bar->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "value")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::tank(const int index)
+{
+ auto tank = tankGroupAt(index);
+
+ if (tank)
+ {
+ foreach (auto dataset, tank->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "value")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::gauge(const int index)
+{
+ auto gauge = gaugeGroupAt(index);
+
+ if (gauge)
+ {
+ foreach (auto dataset, gauge->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "value")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::barMin(const int index)
+{
+ auto bar = barGroupAt(index);
+
+ if (bar)
+ {
+ foreach (auto dataset, bar->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "min")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::barMax(const int index)
+{
+ auto bar = barGroupAt(index);
+
+ if (bar)
+ {
+ foreach (auto dataset, bar->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "max")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::tankMin(const int index)
+{
+ auto tank = tankGroupAt(index);
+
+ if (tank)
+ {
+ foreach (auto dataset, tank->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "min")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::tankMax(const int index)
+{
+ auto tank = tankGroupAt(index);
+
+ if (tank)
+ {
+ foreach (auto dataset, tank->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "max")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::gaugeMin(const int index)
+{
+ auto gauge = gaugeGroupAt(index);
+
+ if (gauge)
+ {
+ foreach (auto dataset, gauge->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "min")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::gaugeMax(const int index)
+{
+ auto gauge = gaugeGroupAt(index);
+
+ if (gauge)
+ {
+ foreach (auto dataset, gauge->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "max")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::mapLatitude(const int index)
+{
+ auto map = mapGroupAt(index);
+
+ if (map)
+ {
+ foreach (auto dataset, map->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "lat")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+double Widgets::mapLongitude(const int index)
+{
+ auto map = mapGroupAt(index);
+
+ if (map)
+ {
+ foreach (auto dataset, map->datasets())
+ {
+ auto widget = dataset->widget();
+ if (widget.toLower() == "lon")
+ return dataset->value().toDouble();
+ }
+ }
+
+ return DBL_MAX;
+}
+
+void Widgets::updateModels()
+{
+ // Clear current groups
+ m_barGroups.clear();
+ m_mapGroups.clear();
+ m_gyroGroups.clear();
+ m_tankGroups.clear();
+ m_gaugeGroups.clear();
+ m_accelerometerGroups.clear();
+
+ // Update groups
+ m_barGroups = getWidgetGroup("bar");
+ m_mapGroups = getWidgetGroup("map");
+ m_gyroGroups = getWidgetGroup("gyro");
+ m_tankGroups = getWidgetGroup("tank");
+ m_gaugeGroups = getWidgetGroup("gauge");
+ m_accelerometerGroups = getWidgetGroup("accelerometer");
+
+ // Update UI
+ emit dataChanged();
+}
+
+QList Widgets::getWidgetGroup(const QString &handle)
+{
+ QList widgetGroup;
+
+ foreach (auto group, QmlBridge::getInstance()->groups())
+ {
+ if (group->widget().toLower() == handle)
+ widgetGroup.append(group);
+ }
+
+ return widgetGroup;
}
diff --git a/src/Widgets.h b/src/Widgets.h
index ca0d28f0..0ee0c094 100644
--- a/src/Widgets.h
+++ b/src/Widgets.h
@@ -27,63 +27,72 @@
#include
class Group;
-class Widgets : public QObject {
- Q_OBJECT
+class Widgets : public QObject
+{
+ Q_OBJECT
signals:
- void dataChanged();
+ void dataChanged();
public:
- static Widgets* getInstance();
+ static Widgets *getInstance();
- QList barGroups() const;
- QList mapGroups() const;
- QList gyroGroups() const;
- QList tankGroups() const;
- QList gaugeGroups() const;
- QList accelerometerGroups() const;
+ QList barGroup() const;
+ QList mapGroup() const;
+ QList gyroGroup() const;
+ QList tankGroup() const;
+ QList gaugeGroup() const;
+ QList accelerometerGroup() const;
- Group* barGroupAt(const int index);
- Group* mapGroupAt(const int index);
- Group* gyroGroupAt(const int index);
- Group* tankGroupAt(const int index);
- Group* gaugeGroupAt(const int index);
- Group* accelerometerGroupAt(const int index);
+ int barGroupCount() const;
+ int mapGroupCount() const;
+ int gyroGroupCount() const;
+ int tankGroupCount() const;
+ int gaugeGroupCount() const;
+ int accelerometerGroupCount() const;
- qreal gyroX(const int index) const;
- qreal gyroY(const int index) const;
- qreal gyroZ(const int index) const;
+ Group *barGroupAt(const int index);
+ Group *mapGroupAt(const int index);
+ Group *gyroGroupAt(const int index);
+ Group *tankGroupAt(const int index);
+ Group *gaugeGroupAt(const int index);
+ Group *accelerometerGroupAt(const int index);
- qreal accelerometerX(const int index) const;
- qreal accelerometerY(const int index) const;
- qreal accelerometerZ(const int index) const;
+ double gyroX(const int index);
+ double gyroY(const int index);
+ double gyroZ(const int index);
- qreal bar(const int index) const;
- qreal tank(const int index) const;
- qreal gauge(const int index) const;
- qreal barMin(const int index) const;
- qreal barMax(const int index) const;
- qreal tankMin(const int index) const;
- qreal tankMax(const int index) const;
- qreal gaugeMin(const int index) const;
- qreal gaugeMax(const int index) const;
+ double accelerometerX(const int index);
+ double accelerometerY(const int index);
+ double accelerometerZ(const int index);
- qreal mapLatitude(const int index) const;
- qreal mapLongitude(const int index) const;
+ double bar(const int index);
+ double tank(const int index);
+ double gauge(const int index);
+ double barMin(const int index);
+ double barMax(const int index);
+ double tankMin(const int index);
+ double tankMax(const int index);
+ double gaugeMin(const int index);
+ double gaugeMax(const int index);
+
+ double mapLatitude(const int index);
+ double mapLongitude(const int index);
private slots:
- void updateModels();
+ void updateModels();
private:
- QList getWidgetGroup(const QString& handle);
+ Widgets();
+ QList getWidgetGroup(const QString &handle);
private:
- QList m_barGroups;
- QList m_mapGroups;
- QList m_gyroGroups;
- QList m_tankGroups;
- QList m_gaugeGroups;
- QList m_accelerometerGroups;
+ QList m_barGroups;
+ QList m_mapGroups;
+ QList m_gyroGroups;
+ QList m_tankGroups;
+ QList m_gaugeGroups;
+ QList m_accelerometerGroups;
};
#endif
diff --git a/src/main.cpp b/src/main.cpp
index c01e673d..b7b9de06 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -32,6 +32,7 @@
#include "Export.h"
#include "AppInfo.h"
+#include "Widgets.h"
#include "QmlBridge.h"
#include "GraphProvider.h"
#include "SerialManager.h"
@@ -60,6 +61,7 @@ int main(int argc, char **argv)
// Init application modules
QQmlApplicationEngine engine;
+ auto widgets = Widgets::getInstance();
auto csvExport = Export::getInstance();
auto qmlBridge = QmlBridge::getInstance();
auto updater = QSimpleUpdater::getInstance();
@@ -72,8 +74,9 @@ int main(int argc, char **argv)
// Init QML interface
QQuickStyle::setStyle("Fusion");
- engine.rootContext()->setContextProperty("CppExport", csvExport);
engine.rootContext()->setContextProperty("CppUpdater", updater);
+ engine.rootContext()->setContextProperty("CppWidgets", widgets);
+ engine.rootContext()->setContextProperty("CppExport", csvExport);
engine.rootContext()->setContextProperty("CppQmlBridge", qmlBridge);
engine.rootContext()->setContextProperty("CppGraphProvider", graphProvider);
engine.rootContext()->setContextProperty("CppSerialManager", serialManager);