mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Add groundwork for #44
This commit is contained in:
parent
21d0caa321
commit
5b71b86179
@ -95,5 +95,7 @@
|
|||||||
<file>qml/PlatformDependent/Menubar.qml</file>
|
<file>qml/PlatformDependent/Menubar.qml</file>
|
||||||
<file>qml/PlatformDependent/DecentMenuItem.qml</file>
|
<file>qml/PlatformDependent/DecentMenuItem.qml</file>
|
||||||
<file>qml/SetupPanes/MQTT.qml</file>
|
<file>qml/SetupPanes/MQTT.qml</file>
|
||||||
|
<file>qml/Widgets/CompassDelegate.qml</file>
|
||||||
|
<file>icons/compass.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
1
assets/icons/compass.svg
Normal file
1
assets/icons/compass.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M12 10.9c-.61 0-1.1.49-1.1 1.1s.49 1.1 1.1 1.1c.61 0 1.1-.49 1.1-1.1s-.49-1.1-1.1-1.1zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm2.19 12.19L6 18l3.81-8.19L18 6l-3.81 8.19z"/></svg>
|
After Width: | Height: | Size: 333 B |
50
assets/qml/Widgets/CompassDelegate.qml
Normal file
50
assets/qml/Widgets/CompassDelegate.qml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020-2021 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 SerialStudio 1.0
|
||||||
|
|
||||||
|
import "."
|
||||||
|
|
||||||
|
Window {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
//
|
||||||
|
// Window properties
|
||||||
|
//
|
||||||
|
spacing: -1
|
||||||
|
gradient: true
|
||||||
|
implicitWidth: 260
|
||||||
|
visible: opacity > 0
|
||||||
|
opacity: enabled ? 1 : 0
|
||||||
|
backgroundColor: "#09090c"
|
||||||
|
implicitHeight: implicitWidth + 96
|
||||||
|
icon.source: "qrc:/icons/compass.svg"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Custom properties
|
||||||
|
//
|
||||||
|
property int datasetIndex: 0
|
||||||
|
}
|
@ -59,6 +59,10 @@ Control {
|
|||||||
barGenerator.model = 0
|
barGenerator.model = 0
|
||||||
barGenerator.model = Cpp_UI_WidgetProvider.barDatasetCount()
|
barGenerator.model = Cpp_UI_WidgetProvider.barDatasetCount()
|
||||||
|
|
||||||
|
// Generate compass widgets
|
||||||
|
compassGenerator.model = 0
|
||||||
|
compassGenerator.model = Cpp_UI_WidgetProvider.compassDatasetCount()
|
||||||
|
|
||||||
// Generate map widgets
|
// Generate map widgets
|
||||||
mapGenerator.model = 0
|
mapGenerator.model = 0
|
||||||
mapGenerator.model = Cpp_UI_WidgetProvider.mapGroupCount()
|
mapGenerator.model = Cpp_UI_WidgetProvider.mapGroupCount()
|
||||||
@ -261,9 +265,52 @@ Control {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {
|
Repeater {
|
||||||
Layout.minimumHeight: 10
|
id: compassGenerator
|
||||||
|
|
||||||
|
delegate: Item {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.minimumWidth: root.minimumWidgetSize
|
||||||
|
Layout.minimumHeight: root.minimumWidgetSize
|
||||||
|
|
||||||
|
Widgets.CompassDelegate {
|
||||||
|
datasetIndex: index
|
||||||
|
anchors.fill: parent
|
||||||
|
onHeaderDoubleClicked: windowCompass.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
QtWindow.Window {
|
||||||
|
id: windowCompass
|
||||||
|
width: 640
|
||||||
|
height: 480
|
||||||
|
minimumWidth: root.minimumWidgetSize * 1.2
|
||||||
|
minimumHeight: root.minimumWidgetSize * 1.2
|
||||||
|
title: compass.title
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
anchors.fill: parent
|
||||||
|
color: compass.backgroundColor
|
||||||
|
}
|
||||||
|
|
||||||
|
Widgets.CompassDelegate {
|
||||||
|
id: compass
|
||||||
|
showIcon: true
|
||||||
|
gradient: false
|
||||||
|
headerHeight: 48
|
||||||
|
datasetIndex: index
|
||||||
|
anchors.margins: 0
|
||||||
|
anchors.fill: parent
|
||||||
|
borderColor: backgroundColor
|
||||||
|
headerDoubleClickEnabled: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
Layout.minimumHeight: 10
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,14 @@ QList<JSON::Dataset *> WidgetProvider::barDatasets() const
|
|||||||
return m_barDatasets;
|
return m_barDatasets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list with all the JSON datasets that implement a compass widget
|
||||||
|
*/
|
||||||
|
QList<JSON::Dataset *> WidgetProvider::compassDatasets() const
|
||||||
|
{
|
||||||
|
return m_compassDatasets;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list with all the JSON groups that implement a map widget
|
* Returns a list with all the JSON groups that implement a map widget
|
||||||
*/
|
*/
|
||||||
@ -106,9 +114,10 @@ int WidgetProvider::totalWidgetCount() const
|
|||||||
{
|
{
|
||||||
// clang-format off
|
// clang-format off
|
||||||
return mapGroupCount() +
|
return mapGroupCount() +
|
||||||
gyroGroupCount() +
|
gyroGroupCount() +
|
||||||
barDatasetCount() +
|
barDatasetCount() +
|
||||||
accelerometerGroupCount();
|
compassDatasetCount() +
|
||||||
|
accelerometerGroupCount();
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +145,14 @@ int WidgetProvider::gyroGroupCount() const
|
|||||||
return gyroGroup().count();
|
return gyroGroup().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of JSON datasets that implement a compass widget
|
||||||
|
*/
|
||||||
|
int WidgetProvider::compassDatasetCount() const
|
||||||
|
{
|
||||||
|
return compassDatasets().count();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of JSON groups that implement an accelerometer widget
|
* Returns the number of JSON groups that implement an accelerometer widget
|
||||||
*/
|
*/
|
||||||
@ -156,6 +173,18 @@ JSON::Dataset *WidgetProvider::barDatasetAt(const int index)
|
|||||||
return Q_NULLPTR;
|
return Q_NULLPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pointer to the JSON dataset that implements a compass widget
|
||||||
|
* with the given @a index.
|
||||||
|
*/
|
||||||
|
JSON::Dataset *WidgetProvider::compassDatasetAt(const int index)
|
||||||
|
{
|
||||||
|
if (compassDatasets().count() > index)
|
||||||
|
return compassDatasets().at(index);
|
||||||
|
|
||||||
|
return Q_NULLPTR;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the JSON group that implements a map widget
|
* Returns a pointer to the JSON group that implements a map widget
|
||||||
* with the given @a index
|
* with the given @a index
|
||||||
@ -192,6 +221,18 @@ JSON::Group *WidgetProvider::accelerometerGroupAt(const int index)
|
|||||||
return Q_NULLPTR;
|
return Q_NULLPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the direction in degrees for the compass widget at the given @a index
|
||||||
|
*/
|
||||||
|
int WidgetProvider::compass(const int index)
|
||||||
|
{
|
||||||
|
auto compass = compassDatasetAt(index);
|
||||||
|
if (compass)
|
||||||
|
return compass->value().toInt();
|
||||||
|
|
||||||
|
return INT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the yaw angle for the gyro widget at the given @a index
|
* Returns the yaw angle for the gyro widget at the given @a index
|
||||||
*/
|
*/
|
||||||
@ -397,9 +438,10 @@ double WidgetProvider::mapLongitude(const int index)
|
|||||||
void WidgetProvider::resetData()
|
void WidgetProvider::resetData()
|
||||||
{
|
{
|
||||||
m_widgetCount = 0;
|
m_widgetCount = 0;
|
||||||
m_barDatasets.clear();
|
|
||||||
m_mapGroups.clear();
|
m_mapGroups.clear();
|
||||||
m_gyroGroups.clear();
|
m_gyroGroups.clear();
|
||||||
|
m_barDatasets.clear();
|
||||||
|
m_compassDatasets.clear();
|
||||||
m_accelerometerGroups.clear();
|
m_accelerometerGroups.clear();
|
||||||
|
|
||||||
emit dataChanged();
|
emit dataChanged();
|
||||||
@ -412,9 +454,10 @@ void WidgetProvider::resetData()
|
|||||||
void WidgetProvider::updateModels()
|
void WidgetProvider::updateModels()
|
||||||
{
|
{
|
||||||
// Clear current groups
|
// Clear current groups
|
||||||
m_barDatasets.clear();
|
|
||||||
m_mapGroups.clear();
|
m_mapGroups.clear();
|
||||||
m_gyroGroups.clear();
|
m_gyroGroups.clear();
|
||||||
|
m_barDatasets.clear();
|
||||||
|
m_compassDatasets.clear();
|
||||||
m_accelerometerGroups.clear();
|
m_accelerometerGroups.clear();
|
||||||
|
|
||||||
// Check if frame is valid
|
// Check if frame is valid
|
||||||
@ -425,11 +468,19 @@ void WidgetProvider::updateModels()
|
|||||||
m_mapGroups = getWidgetGroup("map");
|
m_mapGroups = getWidgetGroup("map");
|
||||||
m_gyroGroups = getWidgetGroup("gyro");
|
m_gyroGroups = getWidgetGroup("gyro");
|
||||||
m_barDatasets = getWidgetDatasets("bar");
|
m_barDatasets = getWidgetDatasets("bar");
|
||||||
|
m_compassDatasets = getWidgetDatasets("compass");
|
||||||
m_accelerometerGroups = getWidgetGroup("accelerometer");
|
m_accelerometerGroups = getWidgetGroup("accelerometer");
|
||||||
|
|
||||||
// Check if widget count has changed
|
// Calculate total widget count
|
||||||
auto count = mapGroupCount() + gyroGroupCount() + barDatasetCount()
|
// clang-format off
|
||||||
+ accelerometerGroupCount();
|
auto count = mapGroupCount() +
|
||||||
|
gyroGroupCount() +
|
||||||
|
barDatasetCount() +
|
||||||
|
compassDatasetCount() +
|
||||||
|
accelerometerGroupCount();
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
// Tell UI to regenerate widget models if widget count has changed from last frame
|
||||||
if (count != m_widgetCount)
|
if (count != m_widgetCount)
|
||||||
{
|
{
|
||||||
m_widgetCount = count;
|
m_widgetCount = count;
|
||||||
|
@ -49,6 +49,7 @@ public:
|
|||||||
QList<JSON::Group *> mapGroup() const;
|
QList<JSON::Group *> mapGroup() const;
|
||||||
QList<JSON::Group *> gyroGroup() const;
|
QList<JSON::Group *> gyroGroup() const;
|
||||||
QList<JSON::Dataset *> barDatasets() const;
|
QList<JSON::Dataset *> barDatasets() const;
|
||||||
|
QList<JSON::Dataset *> compassDatasets() const;
|
||||||
QList<JSON::Group *> accelerometerGroup() const;
|
QList<JSON::Group *> accelerometerGroup() const;
|
||||||
|
|
||||||
int totalWidgetCount() const;
|
int totalWidgetCount() const;
|
||||||
@ -56,13 +57,17 @@ public:
|
|||||||
Q_INVOKABLE int mapGroupCount() const;
|
Q_INVOKABLE int mapGroupCount() const;
|
||||||
Q_INVOKABLE int gyroGroupCount() const;
|
Q_INVOKABLE int gyroGroupCount() const;
|
||||||
Q_INVOKABLE int barDatasetCount() const;
|
Q_INVOKABLE int barDatasetCount() const;
|
||||||
|
Q_INVOKABLE int compassDatasetCount() const;
|
||||||
Q_INVOKABLE int accelerometerGroupCount() const;
|
Q_INVOKABLE int accelerometerGroupCount() const;
|
||||||
|
|
||||||
Q_INVOKABLE JSON::Group *mapGroupAt(const int index);
|
Q_INVOKABLE JSON::Group *mapGroupAt(const int index);
|
||||||
Q_INVOKABLE JSON::Group *gyroGroupAt(const int index);
|
Q_INVOKABLE JSON::Group *gyroGroupAt(const int index);
|
||||||
Q_INVOKABLE JSON::Dataset *barDatasetAt(const int index);
|
Q_INVOKABLE JSON::Dataset *barDatasetAt(const int index);
|
||||||
|
Q_INVOKABLE JSON::Dataset *compassDatasetAt(const int index);
|
||||||
Q_INVOKABLE JSON::Group *accelerometerGroupAt(const int index);
|
Q_INVOKABLE JSON::Group *accelerometerGroupAt(const int index);
|
||||||
|
|
||||||
|
Q_INVOKABLE int compass(const int index);
|
||||||
|
|
||||||
Q_INVOKABLE double gyroYaw(const int index);
|
Q_INVOKABLE double gyroYaw(const int index);
|
||||||
Q_INVOKABLE double gyroRoll(const int index);
|
Q_INVOKABLE double gyroRoll(const int index);
|
||||||
Q_INVOKABLE double gyroPitch(const int index);
|
Q_INVOKABLE double gyroPitch(const int index);
|
||||||
@ -92,6 +97,7 @@ private:
|
|||||||
QList<JSON::Group *> m_mapGroups;
|
QList<JSON::Group *> m_mapGroups;
|
||||||
QList<JSON::Group *> m_gyroGroups;
|
QList<JSON::Group *> m_gyroGroups;
|
||||||
QList<JSON::Dataset *> m_barDatasets;
|
QList<JSON::Dataset *> m_barDatasets;
|
||||||
|
QList<JSON::Dataset *> m_compassDatasets;
|
||||||
QList<JSON::Group *> m_accelerometerGroups;
|
QList<JSON::Group *> m_accelerometerGroups;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user