This commit is contained in:
Alex Spataru 2024-11-16 15:18:27 -05:00
parent a422280202
commit e44a1da0e1
7 changed files with 147 additions and 21 deletions

View File

@ -241,6 +241,8 @@ Widgets.Pane {
Cpp_UI_Dashboard.totalWidgetCount > 1
}
//
// Visualization controls
//
@ -313,8 +315,32 @@ Widgets.Pane {
text: Math.round(columns.value)
visible: Cpp_UI_Dashboard.totalWidgetCount > 1
}
//
// Show Legends
//
Label {
text: qsTr("Show Legends")
visible: Cpp_UI_Dashboard.totalWidgetCount > 0 && Cpp_UI_Dashboard.widgetCount(SerialStudio.DashboardMultiPlot) >= 1
} CheckBox {
Layout.leftMargin: -8
Layout.alignment: Qt.AlignLeft
checked: Cpp_UI_Dashboard.showLegends
visible: Cpp_UI_Dashboard.totalWidgetCount > 0 && Cpp_UI_Dashboard.widgetCount(SerialStudio.DashboardMultiPlot) >= 1
onCheckedChanged: {
if (checked !== Cpp_UI_Dashboard.showLegends)
Cpp_UI_Dashboard.showLegends = checked
}
} Item {
visible: Cpp_UI_Dashboard.totalWidgetCount > 0 && Cpp_UI_Dashboard.widgetCount(SerialStudio.DashboardMultiPlot) >= 1
}
}
//
// Show Legends
//
//
// Spacer
//

View File

@ -23,6 +23,8 @@
import QtQuick
import QtGraphs
import SerialStudio
import QtQuick.Layouts
import QtQuick.Controls
import "../"
@ -49,30 +51,87 @@ Item {
}
}
//
// Plot widget
//
Plot {
id: plot
RowLayout {
spacing: 4
anchors.margins: 8
anchors.fill: parent
xMin: root.model.minX
xMax: root.model.maxX
yMin: root.model.minY
yMax: root.model.maxY
xLabel: qsTr("Samples")
yLabel: root.model.yLabel
curveColors: root.model.colors
xAxis.tickInterval: root.model.xTickInterval
yAxis.tickInterval: root.model.yTickInterval
//
// Register curves
// Plot widget
//
Instantiator {
model: root.model.count
delegate: LineSeries {
Component.onCompleted: plot.graph.addSeries(this)
Plot {
id: plot
xMin: root.model.minX
xMax: root.model.maxX
yMin: root.model.minY
yMax: root.model.maxY
xLabel: qsTr("Samples")
Layout.fillWidth: true
Layout.fillHeight: true
yLabel: root.model.yLabel
curveColors: root.model.colors
xAxis.tickInterval: root.model.xTickInterval
yAxis.tickInterval: root.model.yTickInterval
//
// Register curves
//
Instantiator {
model: root.model.count
delegate: LineSeries {
Component.onCompleted: plot.graph.addSeries(this)
}
}
}
//
// Legends widget
//
Item {
Layout.fillHeight: true
visible: Cpp_UI_Dashboard.showLegends
implicitWidth: _legends.implicitWidth + 8
Rectangle {
width: parent.width
anchors.centerIn: parent
height: _legends.implicitHeight + 8
border.width: 1
color: Cpp_ThemeManager.colors["widget_base"]
border.color: Cpp_ThemeManager.colors["widget_border"]
ColumnLayout {
id: _legends
spacing: 4
anchors.margins: 4
anchors.fill: parent
Repeater {
model: root.model.count
delegate: RowLayout {
id: _label
spacing: 4
Layout.fillWidth: true
Rectangle {
width: 14
height: 14
color: root.model.colors[index]
Layout.alignment: Qt.AlignVCenter
}
Label {
elide: Qt.ElideMiddle
text: root.model.labels[index]
Layout.alignment: Qt.AlignVCenter
font: Cpp_Misc_CommonFonts.monoFont
Layout.maximumWidth: 128 - 14 - 8
}
}
}
}
}
}
}

View File

@ -71,8 +71,6 @@ Item {
marginLeft: root.yLabelVisible ? -8 : (root.xLabelVisible ? -40 : -60)
marginBottom: root.xLabelVisible ? -8 : (root.yLabelVisible ? -20 : -40)
//
// Set plot colors
//

View File

@ -37,6 +37,7 @@ UI::Dashboard::Dashboard()
: m_points(100)
, m_precision(2)
, m_widgetCount(0)
, m_showLegends(true)
, m_updateRequired(false)
, m_axisVisibility(SerialStudio::AxisXY)
{
@ -151,6 +152,15 @@ bool UI::Dashboard::available() const
return totalWidgetCount() > 0;
}
/**
* @brief Returns @c true whenever the user has enabled the option to show
* legends in multiplot widgets.
*/
bool UI::Dashboard::showLegends() const
{
return m_showLegends;
}
/**
* @brief Determines if the point-selector widget should be visible based on the
* presence of relevant widget groups or datasets.
@ -550,6 +560,21 @@ void UI::Dashboard::setPrecision(const int precision)
}
}
/**
* @brief Instructs multiplot widgets to display (or hide) the legend labels
* for each one of the curves that it contains.
*
* @param enabled The new enabled setting.
*/
void UI::Dashboard::setShowLegends(const bool enabled)
{
if (m_showLegends != enabled)
{
m_showLegends = enabled;
Q_EMIT showLegendsChanged();
}
}
/**
* @brief Resets all data in the dashboard, including plot values,
* widget structures, and actions. Emits relevant signals to notify the

View File

@ -68,6 +68,7 @@ class Dashboard : public QObject
Q_PROPERTY(int totalWidgetCount READ totalWidgetCount NOTIFY widgetCountChanged)
Q_PROPERTY(int precision READ precision WRITE setPrecision NOTIFY precisionChanged)
Q_PROPERTY(bool pointsWidgetVisible READ pointsWidgetVisible NOTIFY widgetCountChanged)
Q_PROPERTY(bool showLegends READ showLegends WRITE setShowLegends NOTIFY showLegendsChanged)
Q_PROPERTY(bool precisionWidgetVisible READ precisionWidgetVisible NOTIFY widgetCountChanged)
Q_PROPERTY(bool axisOptionsWidgetVisible READ axisOptionsWidgetVisible NOTIFY widgetCountChanged)
Q_PROPERTY(QStringList availableWidgetIcons READ availableWidgetIcons NOTIFY widgetCountChanged)
@ -81,6 +82,7 @@ signals:
void dataReset();
void pointsChanged();
void precisionChanged();
void showLegendsChanged();
void actionCountChanged();
void widgetCountChanged();
void axisVisibilityChanged();
@ -99,6 +101,7 @@ public:
const qreal multiplier = 0.2);
[[nodiscard]] bool available() const;
[[nodiscard]] bool showLegends() const;
[[nodiscard]] bool pointsWidgetVisible() const;
[[nodiscard]] bool precisionWidgetVisible() const;
[[nodiscard]] bool axisOptionsWidgetVisible() const;
@ -143,6 +146,7 @@ public slots:
void setPoints(const int points);
void activateAction(const int index);
void setPrecision(const int precision);
void setShowLegends(const bool enabled);
void resetData(const bool notify = true);
void setAxisVisibility(const SerialStudio::AxisVisibility option);
void setWidgetVisible(const SerialStudio::DashboardWidget widget,
@ -156,6 +160,7 @@ private:
int m_points;
int m_precision;
int m_widgetCount;
bool m_showLegends;
bool m_updateRequired;
SerialStudio::AxisVisibility m_axisVisibility;

View File

@ -46,6 +46,7 @@ Widgets::MultiPlot::MultiPlot(const int index, QQuickItem *parent)
m_maxY = std::numeric_limits<double>::lowest();
for (const auto &dataset : group.datasets())
{
m_labels.append(dataset.title());
m_minY = qMin(m_minY, dataset.min());
m_maxY = qMax(m_maxY, dataset.max());
}
@ -156,6 +157,15 @@ const QStringList &Widgets::MultiPlot::colors() const
return m_colors;
}
/**
* @brief Returns the labels of the datasets.
* @return The labels of the datasets.
*/
const QStringList &Widgets::MultiPlot::labels() const
{
return m_labels;
}
/**
* @brief Draws the data on the given QLineSeries.
* @param series The QLineSeries to draw the data on.

View File

@ -36,6 +36,7 @@ class MultiPlot : public QQuickItem
Q_OBJECT
Q_PROPERTY(qreal count READ count CONSTANT)
Q_PROPERTY(QString yLabel READ yLabel CONSTANT)
Q_PROPERTY(QStringList labels READ labels CONSTANT)
Q_PROPERTY(qreal minX READ minX NOTIFY rangeChanged)
Q_PROPERTY(qreal maxX READ maxX NOTIFY rangeChanged)
Q_PROPERTY(qreal minY READ minY NOTIFY rangeChanged)
@ -71,6 +72,7 @@ public:
[[nodiscard]] qreal yTickInterval() const;
[[nodiscard]] const QString &yLabel() const;
[[nodiscard]] const QStringList &colors() const;
[[nodiscard]] const QStringList &labels() const;
public slots:
void draw(QLineSeries *series, const int index);
@ -89,6 +91,7 @@ private:
qreal m_maxY;
QString m_yLabel;
QStringList m_colors;
QStringList m_labels;
QVector<QVector<QPointF>> m_data;
};
} // namespace Widgets