Finish implementing Widgets on C++ side

This commit is contained in:
Alex Spataru 2020-11-27 00:11:24 -06:00
parent 2f06ff8e21
commit b42d3ac1d6
16 changed files with 669 additions and 146 deletions

View File

@ -140,17 +140,22 @@ SOURCES += \
src/main.cpp src/main.cpp
DISTFILES += \ DISTFILES += \
assets/qml/About.qml \
assets/qml/Components/Console.qml \ assets/qml/Components/Console.qml \
assets/qml/Components/DataGrid.qml \ assets/qml/Components/DataGrid.qml \
assets/qml/Components/DeviceManager.qml \ assets/qml/Components/DeviceManager.qml \
assets/qml/Components/GraphGrid.qml \
assets/qml/Components/ToolBar.qml \ assets/qml/Components/ToolBar.qml \
assets/qml/Components/WidgetGrid.qml \
assets/qml/UI.qml \ assets/qml/UI.qml \
assets/qml/Widgets/AccelerometerDelegate.qml \
assets/qml/Widgets/BarDelegate.qml \
assets/qml/Widgets/DataDelegate.qml \ assets/qml/Widgets/DataDelegate.qml \
assets/qml/Widgets/GaugeDelegate.qml \
assets/qml/Widgets/GraphDelegate.qml \ assets/qml/Widgets/GraphDelegate.qml \
assets/qml/Widgets/GroupDelegate.qml \ assets/qml/Widgets/GroupDelegate.qml \
assets/qml/Widgets/GyroDelegate.qml \
assets/qml/Widgets/LED.qml \ assets/qml/Widgets/LED.qml \
assets/qml/Widgets/MapDelegate.qml \ assets/qml/Widgets/MapDelegate.qml \
assets/qml/Widgets/TankDelegate.qml \
assets/qml/Widgets/Window.qml \ assets/qml/Widgets/Window.qml \
assets/qml/main.qml \ assets/qml/main.qml
assets/qml/About.qml

View File

@ -43,11 +43,17 @@
<file>qml/Components/DataGrid.qml</file> <file>qml/Components/DataGrid.qml</file>
<file>qml/Components/DeviceManager.qml</file> <file>qml/Components/DeviceManager.qml</file>
<file>qml/Components/ToolBar.qml</file> <file>qml/Components/ToolBar.qml</file>
<file>qml/Components/WidgetGrid.qml</file>
<file>qml/Widgets/AccelerometerDelegate.qml</file>
<file>qml/Widgets/BarDelegate.qml</file>
<file>qml/Widgets/DataDelegate.qml</file> <file>qml/Widgets/DataDelegate.qml</file>
<file>qml/Widgets/GaugeDelegate.qml</file>
<file>qml/Widgets/GraphDelegate.qml</file> <file>qml/Widgets/GraphDelegate.qml</file>
<file>qml/Widgets/GroupDelegate.qml</file> <file>qml/Widgets/GroupDelegate.qml</file>
<file>qml/Widgets/GyroDelegate.qml</file>
<file>qml/Widgets/LED.qml</file> <file>qml/Widgets/LED.qml</file>
<file>qml/Widgets/MapDelegate.qml</file> <file>qml/Widgets/MapDelegate.qml</file>
<file>qml/Widgets/TankDelegate.qml</file>
<file>qml/Widgets/Window.qml</file> <file>qml/Widgets/Window.qml</file>
<file>qml/About.qml</file> <file>qml/About.qml</file>
<file>qml/main.qml</file> <file>qml/main.qml</file>

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2020 Alex Spataru <https://github.com/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 {
}

View File

@ -70,13 +70,11 @@ Page {
TabBar { TabBar {
id: tabBar id: tabBar
contentHeight: 32 contentHeight: 32
palette.button: Qt.rgba(45/255, 96/255, 115/255, 1) enabled: opacity > 0
visible: CppQmlBridge.gpsSupported
enabled: CppQmlBridge.groupCount > 0
opacity: CppQmlBridge.groupCount > 0 ? 1 : 0
Behavior on opacity {NumberAnimation{}}
onVisibleChanged: dataButton.clicked() onVisibleChanged: dataButton.clicked()
opacity: CppSerialManager.connected ? 1 : 0
palette.button: Qt.rgba(45/255, 96/255, 115/255, 1)
Behavior on opacity {NumberAnimation{}}
anchors { anchors {
leftMargin: 3 leftMargin: 3
@ -93,8 +91,7 @@ Page {
} }
TabButton { TabButton {
text: qsTr("GPS Map") text: qsTr("Widgets")
enabled: CppQmlBridge.gpsSupported
} }
} }

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2020 Alex Spataru <https://github.com/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 {
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2020 Alex Spataru <https://github.com/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 {
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2020 Alex Spataru <https://github.com/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 {
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2020 Alex Spataru <https://github.com/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 {
}

View File

@ -37,8 +37,8 @@ ColumnLayout {
// //
// Real-time GPS coordinates components // Real-time GPS coordinates components
// //
property real latitude: CppQmlBridge.gpsLatitude property real latitude: 0
property real longitude: CppQmlBridge.gpsLongitude property real longitude: 0
// //
// Will be true if GPS coordinates are different from (0,0) // Will be true if GPS coordinates are different from (0,0)

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2020 Alex Spataru <https://github.com/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 {
}

View File

@ -82,7 +82,7 @@ bool Dataset::read(const QJsonObject &object)
auto units = object.value("u").toVariant().toString(); auto units = object.value("u").toVariant().toString();
auto widget = object.value("w").toVariant().toString(); auto widget = object.value("w").toVariant().toString();
if (!title.isEmpty() && !value.isEmpty()) if (!value.isEmpty())
{ {
m_graph = graph; m_graph = graph;
m_title = title; m_title = title;

View File

@ -114,10 +114,7 @@ bool Export::isOpen() const
/** /**
* Open a CSV file in the Explorer/Finder window * 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 * Open the current CSV file in the Explorer/Finder window

View File

@ -62,7 +62,7 @@ QString Group::title() const
*/ */
QString Group::widget() const QString Group::widget() const
{ {
return m_widget; return m_widget;
} }
/** /**

View File

@ -21,120 +21,457 @@
*/ */
#include "Group.h" #include "Group.h"
#include "Dataset.h"
#include "Widgets.h" #include "Widgets.h"
#include "QmlBridge.h" #include "QmlBridge.h"
static Widgets* INSTANCE = Q_NULLPTR; #include <cfloat>
#include <climits>
Widgets* Widgets::getInstance() { static Widgets *INSTANCE = Q_NULLPTR;
if (!INSTANCE)
INSTANCE = new Widgets;
return INSTANCE; Widgets::Widgets()
{
auto bridge = QmlBridge::getInstance();
connect(bridge, SIGNAL(updated()), this, SLOT(updateModels()));
} }
QList<Group*> Widgets::barGroups() const { Widgets *Widgets::getInstance()
return m_barGroups; {
if (!INSTANCE)
INSTANCE = new Widgets;
return INSTANCE;
} }
QList<Group*> Widgets::mapGroups() const { QList<Group *> Widgets::barGroup() const
return m_mapGroups; {
return m_barGroups;
} }
QList<Group*> Widgets::gyroGroups() const { QList<Group *> Widgets::mapGroup() const
return m_gyroGroups; {
return m_mapGroups;
} }
QList<Group*> Widgets::tankGroups() const { QList<Group *> Widgets::gyroGroup() const
return m_tankGroups; {
return m_gyroGroups;
} }
QList<Group*> Widgets::gaugeGroups() const { QList<Group *> Widgets::tankGroup() const
return m_gaugeGroups; {
return m_tankGroups;
} }
QList<Group*> Widgets::accelerometerGroups() const { QList<Group *> Widgets::gaugeGroup() const
return m_accelerometerGroups; {
return m_gaugeGroups;
} }
Group* Widgets::barGroupAt(const int index) { QList<Group *> Widgets::accelerometerGroup() const
if (barGroups().count() > index) {
return barGroups().at(index); return m_accelerometerGroups;
return Q_NULLPTR;
} }
Group* Widgets::mapGroupAt(const int index) { int Widgets::barGroupCount() const
if (mapGroups().count() > index) {
return mapGroups().at(index); return barGroup().count();
return Q_NULLPTR;
} }
Group* Widgets::gyroGroupAt(const int index) { int Widgets::mapGroupCount() const
if (gyroGroups().count() > index) {
return gyroGroups().at(index); return mapGroup().count();
return Q_NULLPTR;
} }
Group* Widgets::tankGroupAt(const int index) { int Widgets::gyroGroupCount() const
if (tankGroups().count() > index) {
return tankGroups().at(index); return gyroGroup().count();
return Q_NULLPTR;
} }
Group* Widgets::gaugeGroupAt(const int index) { int Widgets::tankGroupCount() const
if (gaugeGroups().count() > index) {
return gaugeGroups().at(index); return tankGroup().count();
return Q_NULLPTR;
} }
Group* Widgets::accelerometerGroupAt(const int index) { int Widgets::gaugeGroupCount() const
if (accelerometerGroups().count() > index) {
return accelerometerGroups().at(index); return gaugeGroup().count();
return Q_NULLPTR;
} }
qreal Widgets::gyroX(const int index) const {} int Widgets::accelerometerGroupCount() const
{
qreal Widgets::gyroY(const int index) const {} return accelerometerGroup().count();
}
qreal Widgets::gyroZ(const int index) const {}
Group *Widgets::barGroupAt(const int index)
qreal Widgets::accelerometerX(const int index) const {} {
if (barGroup().count() > index)
qreal Widgets::accelerometerY(const int index) const {} return barGroup().at(index);
qreal Widgets::accelerometerZ(const int index) const {} return Q_NULLPTR;
}
qreal Widgets::bar(const int index) const {}
Group *Widgets::mapGroupAt(const int index)
qreal Widgets::tank(const int index) const {} {
if (mapGroup().count() > index)
qreal Widgets::gauge(const int index) const {} return mapGroup().at(index);
qreal Widgets::barMin(const int index) const {} return Q_NULLPTR;
}
qreal Widgets::barMax(const int index) const {}
Group *Widgets::gyroGroupAt(const int index)
qreal Widgets::tankMin(const int index) const {} {
if (gyroGroup().count() > index)
qreal Widgets::tankMax(const int index) const {} return gyroGroup().at(index);
qreal Widgets::gaugeMin(const int index) const {} return Q_NULLPTR;
}
qreal Widgets::gaugeMax(const int index) const {}
Group *Widgets::tankGroupAt(const int index)
qreal Widgets::mapLatitude(const int index) const {} {
if (tankGroup().count() > index)
qreal Widgets::mapLongitude(const int index) const {} return tankGroup().at(index);
void Widgets::updateModels() {} return Q_NULLPTR;
}
QList<Group*> Widgets::getWidgetGroup(const QString& handle) {
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<Group *> Widgets::getWidgetGroup(const QString &handle)
{
QList<Group *> widgetGroup;
foreach (auto group, QmlBridge::getInstance()->groups())
{
if (group->widget().toLower() == handle)
widgetGroup.append(group);
}
return widgetGroup;
} }

View File

@ -27,63 +27,72 @@
#include <QObject> #include <QObject>
class Group; class Group;
class Widgets : public QObject { class Widgets : public QObject
Q_OBJECT {
Q_OBJECT
signals: signals:
void dataChanged(); void dataChanged();
public: public:
static Widgets* getInstance(); static Widgets *getInstance();
QList<Group*> barGroups() const; QList<Group *> barGroup() const;
QList<Group*> mapGroups() const; QList<Group *> mapGroup() const;
QList<Group*> gyroGroups() const; QList<Group *> gyroGroup() const;
QList<Group*> tankGroups() const; QList<Group *> tankGroup() const;
QList<Group*> gaugeGroups() const; QList<Group *> gaugeGroup() const;
QList<Group*> accelerometerGroups() const; QList<Group *> accelerometerGroup() const;
Group* barGroupAt(const int index); int barGroupCount() const;
Group* mapGroupAt(const int index); int mapGroupCount() const;
Group* gyroGroupAt(const int index); int gyroGroupCount() const;
Group* tankGroupAt(const int index); int tankGroupCount() const;
Group* gaugeGroupAt(const int index); int gaugeGroupCount() const;
Group* accelerometerGroupAt(const int index); int accelerometerGroupCount() const;
qreal gyroX(const int index) const; Group *barGroupAt(const int index);
qreal gyroY(const int index) const; Group *mapGroupAt(const int index);
qreal gyroZ(const int index) const; 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; double gyroX(const int index);
qreal accelerometerY(const int index) const; double gyroY(const int index);
qreal accelerometerZ(const int index) const; double gyroZ(const int index);
qreal bar(const int index) const; double accelerometerX(const int index);
qreal tank(const int index) const; double accelerometerY(const int index);
qreal gauge(const int index) const; double accelerometerZ(const int index);
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;
qreal mapLatitude(const int index) const; double bar(const int index);
qreal mapLongitude(const int index) const; 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: private slots:
void updateModels(); void updateModels();
private: private:
QList<Group*> getWidgetGroup(const QString& handle); Widgets();
QList<Group *> getWidgetGroup(const QString &handle);
private: private:
QList<Group*> m_barGroups; QList<Group *> m_barGroups;
QList<Group*> m_mapGroups; QList<Group *> m_mapGroups;
QList<Group*> m_gyroGroups; QList<Group *> m_gyroGroups;
QList<Group*> m_tankGroups; QList<Group *> m_tankGroups;
QList<Group*> m_gaugeGroups; QList<Group *> m_gaugeGroups;
QList<Group*> m_accelerometerGroups; QList<Group *> m_accelerometerGroups;
}; };
#endif #endif

View File

@ -32,6 +32,7 @@
#include "Export.h" #include "Export.h"
#include "AppInfo.h" #include "AppInfo.h"
#include "Widgets.h"
#include "QmlBridge.h" #include "QmlBridge.h"
#include "GraphProvider.h" #include "GraphProvider.h"
#include "SerialManager.h" #include "SerialManager.h"
@ -60,6 +61,7 @@ int main(int argc, char **argv)
// Init application modules // Init application modules
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
auto widgets = Widgets::getInstance();
auto csvExport = Export::getInstance(); auto csvExport = Export::getInstance();
auto qmlBridge = QmlBridge::getInstance(); auto qmlBridge = QmlBridge::getInstance();
auto updater = QSimpleUpdater::getInstance(); auto updater = QSimpleUpdater::getInstance();
@ -72,8 +74,9 @@ int main(int argc, char **argv)
// Init QML interface // Init QML interface
QQuickStyle::setStyle("Fusion"); QQuickStyle::setStyle("Fusion");
engine.rootContext()->setContextProperty("CppExport", csvExport);
engine.rootContext()->setContextProperty("CppUpdater", updater); engine.rootContext()->setContextProperty("CppUpdater", updater);
engine.rootContext()->setContextProperty("CppWidgets", widgets);
engine.rootContext()->setContextProperty("CppExport", csvExport);
engine.rootContext()->setContextProperty("CppQmlBridge", qmlBridge); engine.rootContext()->setContextProperty("CppQmlBridge", qmlBridge);
engine.rootContext()->setContextProperty("CppGraphProvider", graphProvider); engine.rootContext()->setContextProperty("CppGraphProvider", graphProvider);
engine.rootContext()->setContextProperty("CppSerialManager", serialManager); engine.rootContext()->setContextProperty("CppSerialManager", serialManager);