mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Add logical support for FFT widgets
This commit is contained in:
parent
ca798b8d11
commit
806685d1a6
1
assets/icons/fft.svg
Normal file
1
assets/icons/fft.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M7 18h2V6H7v12zm4 4h2V2h-2v20zm-8-8h2v-4H3v4zm12 4h2V6h-2v12zm4-8v4h2v-4h-2z"/></svg>
|
After Width: | Height: | Size: 235 B |
@ -73,5 +73,6 @@
|
||||
<file>hide-all.svg</file>
|
||||
<file>multiplot.svg</file>
|
||||
<file>points.svg</file>
|
||||
<file>fft.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -173,6 +173,17 @@ Widgets.Window {
|
||||
onCheckedChanged: (index, checked) => Cpp_UI_Dashboard.setMultiplotVisible(index, checked)
|
||||
}
|
||||
|
||||
//
|
||||
// FFT
|
||||
//
|
||||
ViewOptionsDelegate {
|
||||
title: qsTr("FFT plots")
|
||||
icon: "qrc:/icons/fft.svg"
|
||||
count: Cpp_UI_Dashboard.fftCount
|
||||
titles: Cpp_UI_Dashboard.fftTitles
|
||||
onCheckedChanged: (index, checked) => Cpp_UI_Dashboard.setFFTVisible(index, checked)
|
||||
}
|
||||
|
||||
//
|
||||
// Plots
|
||||
//
|
||||
|
@ -154,12 +154,12 @@ Widgets.Window {
|
||||
//
|
||||
Label {
|
||||
text: qsTr("Min value:")
|
||||
visible: widget.currentIndex == 1 || widget.currentIndex == 2
|
||||
visible: widget.currentIndex === 1 || widget.currentIndex === 2
|
||||
} TextField {
|
||||
id: min
|
||||
Layout.fillWidth: true
|
||||
text: Cpp_JSON_Editor.datasetWidgetMin(group, dataset)
|
||||
visible: widget.currentIndex == 1 || widget.currentIndex == 2
|
||||
visible: widget.currentIndex === 1 || widget.currentIndex === 2
|
||||
onTextChanged: Cpp_JSON_Editor.setDatasetWidgetMin(group, dataset, text)
|
||||
validator: DoubleValidator {
|
||||
top: parseFloat(max.text)
|
||||
@ -171,12 +171,12 @@ Widgets.Window {
|
||||
//
|
||||
Label {
|
||||
text: qsTr("Max value:")
|
||||
visible: widget.currentIndex == 1 || widget.currentIndex == 2
|
||||
visible: widget.currentIndex === 1 || widget.currentIndex === 2
|
||||
} TextField {
|
||||
id: max
|
||||
Layout.fillWidth: true
|
||||
text: Cpp_JSON_Editor.datasetWidgetMax(group, dataset)
|
||||
visible: widget.currentIndex == 1 || widget.currentIndex == 2
|
||||
visible: widget.currentIndex === 1 || widget.currentIndex === 2
|
||||
onTextChanged: Cpp_JSON_Editor.setDatasetWidgetMax(group, dataset, text)
|
||||
|
||||
validator: DoubleValidator {
|
||||
@ -189,12 +189,12 @@ Widgets.Window {
|
||||
//
|
||||
Label {
|
||||
text: qsTr("Alarm value:")
|
||||
visible: widget.currentIndex == 1 || widget.currentIndex == 2
|
||||
visible: widget.currentIndex === 1 || widget.currentIndex === 2
|
||||
} TextField {
|
||||
id: alarm
|
||||
Layout.fillWidth: true
|
||||
text: Cpp_JSON_Editor.datasetWidgetAlarm(group, dataset)
|
||||
visible: widget.currentIndex == 1 || widget.currentIndex == 2
|
||||
visible: widget.currentIndex === 1 || widget.currentIndex === 2
|
||||
onTextChanged: Cpp_JSON_Editor.setDatasetWidgetAlarm(group, dataset, text)
|
||||
|
||||
validator: DoubleValidator {
|
||||
|
@ -169,7 +169,7 @@ Widgets.Window {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Add dataset")
|
||||
icon.source: "qrc:/icons/add.svg"
|
||||
visible: widget.currentIndex === 0
|
||||
visible: widget.currentIndex === 0 || widget.currentIndex === 4
|
||||
icon.color: Cpp_ThemeManager.brightText
|
||||
onClicked: Cpp_JSON_Editor.addDataset(group)
|
||||
palette.buttonText: Cpp_ThemeManager.brightText
|
||||
|
@ -34,8 +34,9 @@ Dataset::Dataset(QObject *parent)
|
||||
, m_units("")
|
||||
, m_widget("")
|
||||
, m_index(0)
|
||||
, m_max("100")
|
||||
, m_max("0")
|
||||
, m_min("0")
|
||||
, m_alarm("0")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -850,8 +850,7 @@ bool Editor::setGroupWidget(const int group, const int widgetId)
|
||||
if (!(grp->m_datasets.isEmpty()) && widgetId != 4)
|
||||
{
|
||||
if (widgetId == 0 && grp->widget() == "multiplot")
|
||||
;
|
||||
// Do nothing
|
||||
grp->m_widget = "";
|
||||
|
||||
else
|
||||
{
|
||||
|
@ -80,8 +80,9 @@ QFont Dashboard::monoFont() const
|
||||
// clang-format off
|
||||
JSON::Group *Dashboard::getMap(const int index) { return getGroupWidget(m_mapWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getBar(const int index) { return getDatasetWidget(m_barWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getFFT(const int index) { return getDatasetWidget(m_fftWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getPlot(const int index) { return getDatasetWidget(m_plotWidgets, index); }
|
||||
JSON::Group *Dashboard::getGroups(const int index) { return getGroupWidget(m_groupWidgets, index); }
|
||||
JSON::Group *Dashboard::getGroups(const int index) { return getGroupWidget(m_groupWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getGauge(const int index) { return getDatasetWidget(m_gaugeWidgets, index); }
|
||||
JSON::Group *Dashboard::getGyroscope(const int index) { return getGroupWidget(m_gyroscopeWidgets, index); }
|
||||
JSON::Dataset *Dashboard::getCompass(const int index) { return getDatasetWidget(m_compassWidgets, index); }
|
||||
@ -145,6 +146,7 @@ int Dashboard::totalWidgetCount() const
|
||||
// clang-format off
|
||||
const int count = mapCount() +
|
||||
barCount() +
|
||||
fftCount() +
|
||||
plotCount() +
|
||||
gaugeCount() +
|
||||
groupCount() +
|
||||
@ -160,9 +162,10 @@ int Dashboard::totalWidgetCount() const
|
||||
// clang-format off
|
||||
int Dashboard::mapCount() const { return m_mapWidgets.count(); }
|
||||
int Dashboard::barCount() const { return m_barWidgets.count(); }
|
||||
int Dashboard::fftCount() const { return m_fftWidgets.count(); }
|
||||
int Dashboard::plotCount() const { return m_plotWidgets.count(); }
|
||||
int Dashboard::gaugeCount() const { return m_gaugeWidgets.count(); }
|
||||
int Dashboard::groupCount() const { return m_groupWidgets.count(); }
|
||||
int Dashboard::groupCount() const { return m_groupWidgets.count(); }
|
||||
int Dashboard::compassCount() const { return m_compassWidgets.count(); }
|
||||
int Dashboard::gyroscopeCount() const { return m_gyroscopeWidgets.count(); }
|
||||
int Dashboard::multiPlotCount() const { return m_multiPlotWidgets.count(); }
|
||||
@ -187,6 +190,7 @@ QVector<QString> Dashboard::widgetTitles() const
|
||||
// clang-format off
|
||||
return groupTitles() +
|
||||
multiPlotTitles() +
|
||||
fftTitles() +
|
||||
plotTitles() +
|
||||
barTitles() +
|
||||
gaugeTitles() +
|
||||
@ -232,8 +236,13 @@ int Dashboard::relativeIndex(const int globalIndex) const
|
||||
if (index < multiPlotCount())
|
||||
return index;
|
||||
|
||||
// Check if we should return plot widget
|
||||
// Check if we should return FFT widget
|
||||
index -= multiPlotCount();
|
||||
if (index < fftCount())
|
||||
return index;
|
||||
|
||||
// Check if we should return plot widget
|
||||
index -= fftCount();
|
||||
if (index < plotCount())
|
||||
return index;
|
||||
|
||||
@ -301,6 +310,9 @@ bool Dashboard::widgetVisible(const int globalIndex) const
|
||||
case WidgetType::MultiPlot:
|
||||
visible = multiPlotVisible(index);
|
||||
break;
|
||||
case WidgetType::FFT:
|
||||
visible = fftVisible(index);
|
||||
break;
|
||||
case WidgetType::Plot:
|
||||
visible = plotVisible(index);
|
||||
break;
|
||||
@ -356,6 +368,9 @@ QString Dashboard::widgetIcon(const int globalIndex) const
|
||||
case WidgetType::MultiPlot:
|
||||
return "qrc:/icons/multiplot.svg";
|
||||
break;
|
||||
case WidgetType::FFT:
|
||||
return "qrc:/icons/fft.svg";
|
||||
break;
|
||||
case WidgetType::Plot:
|
||||
return "qrc:/icons/plot.svg";
|
||||
break;
|
||||
@ -390,6 +405,7 @@ QString Dashboard::widgetIcon(const int globalIndex) const
|
||||
* - @c WidgetType::Unknown
|
||||
* - @c WidgetType::Group
|
||||
* - @c WidgetType::MultiPlot
|
||||
* - @c WidgetType::FFT
|
||||
* - @c WidgetType::Plot
|
||||
* - @c WidgetType::Bar
|
||||
* - @c WidgetType::Gauge
|
||||
@ -432,8 +448,13 @@ UI::Dashboard::WidgetType Dashboard::widgetType(const int globalIndex) const
|
||||
if (index < multiPlotCount())
|
||||
return WidgetType::MultiPlot;
|
||||
|
||||
// Check if we should return plot widget
|
||||
// Check if we should return FFT widget
|
||||
index -= multiPlotCount();
|
||||
if (index < fftCount())
|
||||
return WidgetType::FFT;
|
||||
|
||||
// Check if we should return plot widget
|
||||
index -= fftCount();
|
||||
if (index < plotCount())
|
||||
return WidgetType::Plot;
|
||||
|
||||
@ -477,6 +498,7 @@ UI::Dashboard::WidgetType Dashboard::widgetType(const int globalIndex) const
|
||||
|
||||
// clang-format off
|
||||
bool Dashboard::barVisible(const int index) const { return getVisibility(m_barVisibility, index); }
|
||||
bool Dashboard::fftVisible(const int index) const { return getVisibility(m_fftVisibility, index); }
|
||||
bool Dashboard::mapVisible(const int index) const { return getVisibility(m_mapVisibility, index); }
|
||||
bool Dashboard::plotVisible(const int index) const { return getVisibility(m_plotVisibility, index); }
|
||||
bool Dashboard::groupVisible(const int index) const { return getVisibility(m_groupVisibility, index); }
|
||||
@ -492,10 +514,11 @@ bool Dashboard::accelerometerVisible(const int index) const { return getVisibili
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
// clang-format off
|
||||
QVector<QString> Dashboard::barTitles() const { return datasetTitles(m_barWidgets); }
|
||||
QVector<QString> Dashboard::mapTitles() const { return groupTitles(m_mapWidgets); }
|
||||
QVector<QString> Dashboard::plotTitles() const { return datasetTitles(m_plotWidgets); }
|
||||
QVector<QString> Dashboard::groupTitles() const { return groupTitles(m_groupWidgets); }
|
||||
QVector<QString> Dashboard::barTitles() const { return datasetTitles(m_barWidgets); }
|
||||
QVector<QString> Dashboard::fftTitles() const { return datasetTitles(m_fftWidgets); }
|
||||
QVector<QString> Dashboard::plotTitles() const { return datasetTitles(m_plotWidgets); }
|
||||
QVector<QString> Dashboard::gaugeTitles() const { return datasetTitles(m_gaugeWidgets); }
|
||||
QVector<QString> Dashboard::compassTitles() const { return datasetTitles(m_compassWidgets); }
|
||||
QVector<QString> Dashboard::gyroscopeTitles() const { return groupTitles(m_gyroscopeWidgets); }
|
||||
@ -522,6 +545,7 @@ void Dashboard::setPoints(const int points)
|
||||
|
||||
// clang-format off
|
||||
void Dashboard::setBarVisible(const int i, const bool v) { setVisibility(m_barVisibility, i, v); }
|
||||
void Dashboard::setFFTVisible(const int i, const bool v) { setVisibility(m_fftVisibility, i, v); }
|
||||
void Dashboard::setMapVisible(const int i, const bool v) { setVisibility(m_mapVisibility, i, v); }
|
||||
void Dashboard::setPlotVisible(const int i, const bool v) { setVisibility(m_plotVisibility, i, v); }
|
||||
void Dashboard::setGroupVisible(const int i, const bool v) { setVisibility(m_groupVisibility, i, v); }
|
||||
@ -548,6 +572,7 @@ void Dashboard::resetData()
|
||||
|
||||
// Clear widget data
|
||||
m_barWidgets.clear();
|
||||
m_fftWidgets.clear();
|
||||
m_mapWidgets.clear();
|
||||
m_plotWidgets.clear();
|
||||
m_gaugeWidgets.clear();
|
||||
@ -559,6 +584,7 @@ void Dashboard::resetData()
|
||||
|
||||
// Clear widget visibility data
|
||||
m_barVisibility.clear();
|
||||
m_fftVisibility.clear();
|
||||
m_mapVisibility.clear();
|
||||
m_plotVisibility.clear();
|
||||
m_gaugeVisibility.clear();
|
||||
@ -583,6 +609,7 @@ void Dashboard::updateData()
|
||||
{
|
||||
// Save widget count
|
||||
int barC = barCount();
|
||||
int fftC = fftCount();
|
||||
int mapC = mapCount();
|
||||
int plotC = plotCount();
|
||||
int groupC = groupCount();
|
||||
@ -597,6 +624,7 @@ void Dashboard::updateData()
|
||||
|
||||
// Clear widget data
|
||||
m_barWidgets.clear();
|
||||
m_fftWidgets.clear();
|
||||
m_mapWidgets.clear();
|
||||
m_plotWidgets.clear();
|
||||
m_gaugeWidgets.clear();
|
||||
@ -611,6 +639,7 @@ void Dashboard::updateData()
|
||||
return;
|
||||
|
||||
// Update widget vectors
|
||||
m_fftWidgets = getFFTWidgets();
|
||||
m_plotWidgets = getPlotWidgets();
|
||||
m_groupWidgets = getWidgetGroups("");
|
||||
m_mapWidgets = getWidgetGroups("map");
|
||||
@ -636,6 +665,7 @@ void Dashboard::updateData()
|
||||
// Check if we need to regenerate widgets
|
||||
bool regenerateWidgets = false;
|
||||
regenerateWidgets |= (barC != barCount());
|
||||
regenerateWidgets |= (fftC != fftCount());
|
||||
regenerateWidgets |= (mapC != mapCount());
|
||||
regenerateWidgets |= (plotC != plotCount());
|
||||
regenerateWidgets |= (gaugeC != gaugeCount());
|
||||
@ -649,6 +679,7 @@ void Dashboard::updateData()
|
||||
if (regenerateWidgets)
|
||||
{
|
||||
m_barVisibility.clear();
|
||||
m_fftVisibility.clear();
|
||||
m_mapVisibility.clear();
|
||||
m_plotVisibility.clear();
|
||||
m_gaugeVisibility.clear();
|
||||
@ -661,6 +692,8 @@ void Dashboard::updateData()
|
||||
int i;
|
||||
for (i = 0; i < barCount(); ++i)
|
||||
m_barVisibility.append(true);
|
||||
for (i = 0; i < fftCount(); ++i)
|
||||
m_fftVisibility.append(true);
|
||||
for (i = 0; i < mapCount(); ++i)
|
||||
m_mapVisibility.append(true);
|
||||
for (i = 0; i < plotCount(); ++i)
|
||||
@ -703,6 +736,24 @@ void Dashboard::selectLatestJSON(const JFI_Object &frameInfo)
|
||||
// Widget utility functions
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a vector with all the datasets that need to be shown in the FFT widgets.
|
||||
*/
|
||||
QVector<JSON::Dataset *> Dashboard::getFFTWidgets() const
|
||||
{
|
||||
QVector<JSON::Dataset *> widgets;
|
||||
foreach (auto group, m_latestFrame.groups())
|
||||
{
|
||||
foreach (auto dataset, group->datasets())
|
||||
{
|
||||
if (dataset->fft())
|
||||
widgets.append(dataset);
|
||||
}
|
||||
}
|
||||
|
||||
return widgets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a vector with all the datasets that need to be plotted.
|
||||
*/
|
||||
|
@ -53,6 +53,9 @@ class Dashboard : public QObject
|
||||
Q_PROPERTY(int barCount
|
||||
READ barCount
|
||||
NOTIFY widgetCountChanged)
|
||||
Q_PROPERTY(int fftCount
|
||||
READ fftCount
|
||||
NOTIFY widgetCountChanged)
|
||||
Q_PROPERTY(int plotCount
|
||||
READ plotCount
|
||||
NOTIFY widgetCountChanged)
|
||||
@ -80,6 +83,9 @@ class Dashboard : public QObject
|
||||
Q_PROPERTY(QVector<QString> barTitles
|
||||
READ barTitles
|
||||
NOTIFY widgetCountChanged)
|
||||
Q_PROPERTY(QVector<QString> fftTitles
|
||||
READ fftTitles
|
||||
NOTIFY widgetCountChanged)
|
||||
Q_PROPERTY(QVector<QString> plotTitles
|
||||
READ plotTitles
|
||||
NOTIFY widgetCountChanged)
|
||||
@ -116,6 +122,7 @@ public:
|
||||
{
|
||||
Group,
|
||||
MultiPlot,
|
||||
FFT,
|
||||
Plot,
|
||||
Bar,
|
||||
Gauge,
|
||||
@ -131,6 +138,7 @@ public:
|
||||
|
||||
QFont monoFont() const;
|
||||
JSON::Group *getMap(const int index);
|
||||
JSON::Dataset *getFFT(const int index);
|
||||
JSON::Dataset *getBar(const int index);
|
||||
JSON::Group *getGroups(const int index);
|
||||
JSON::Dataset *getPlot(const int index);
|
||||
@ -146,6 +154,7 @@ public:
|
||||
|
||||
int totalWidgetCount() const;
|
||||
int mapCount() const;
|
||||
int fftCount() const;
|
||||
int barCount() const;
|
||||
int plotCount() const;
|
||||
int groupCount() const;
|
||||
@ -163,6 +172,7 @@ public:
|
||||
Q_INVOKABLE UI::Dashboard::WidgetType widgetType(const int globalIndex) const;
|
||||
|
||||
Q_INVOKABLE bool barVisible(const int index) const;
|
||||
Q_INVOKABLE bool fftVisible(const int index) const;
|
||||
Q_INVOKABLE bool mapVisible(const int index) const;
|
||||
Q_INVOKABLE bool plotVisible(const int index) const;
|
||||
Q_INVOKABLE bool groupVisible(const int index) const;
|
||||
@ -173,6 +183,7 @@ public:
|
||||
Q_INVOKABLE bool accelerometerVisible(const int index) const;
|
||||
|
||||
QVector<QString> barTitles() const;
|
||||
QVector<QString> fftTitles() const;
|
||||
QVector<QString> mapTitles() const;
|
||||
QVector<QString> plotTitles() const;
|
||||
QVector<QString> groupTitles() const;
|
||||
@ -185,6 +196,7 @@ public:
|
||||
public slots:
|
||||
void setPoints(const int points);
|
||||
void setBarVisible(const int index, const bool visible);
|
||||
void setFFTVisible(const int index, const bool visible);
|
||||
void setMapVisible(const int index, const bool visible);
|
||||
void setPlotVisible(const int index, const bool visible);
|
||||
void setGroupVisible(const int index, const bool visible);
|
||||
@ -202,6 +214,7 @@ private slots:
|
||||
private:
|
||||
Dashboard();
|
||||
|
||||
QVector<JSON::Dataset *> getFFTWidgets() const;
|
||||
QVector<JSON::Dataset *> getPlotWidgets() const;
|
||||
QVector<JSON::Group *> getWidgetGroups(const QString &handle) const;
|
||||
QVector<JSON::Dataset *> getWidgetDatasets(const QString &handle) const;
|
||||
@ -220,6 +233,7 @@ private:
|
||||
int m_points;
|
||||
|
||||
QVector<bool> m_barVisibility;
|
||||
QVector<bool> m_fftVisibility;
|
||||
QVector<bool> m_mapVisibility;
|
||||
QVector<bool> m_plotVisibility;
|
||||
QVector<bool> m_groupVisibility;
|
||||
@ -230,6 +244,7 @@ private:
|
||||
QVector<bool> m_accelerometerVisibility;
|
||||
|
||||
QVector<JSON::Dataset *> m_barWidgets;
|
||||
QVector<JSON::Dataset *> m_fftWidgets;
|
||||
QVector<JSON::Dataset *> m_plotWidgets;
|
||||
QVector<JSON::Dataset *> m_gaugeWidgets;
|
||||
QVector<JSON::Dataset *> m_compassWidgets;
|
||||
|
@ -240,6 +240,9 @@ void WidgetLoader::setWidgetIndex(const int index)
|
||||
case UI::Dashboard::WidgetType::MultiPlot:
|
||||
m_widget = new MultiPlot(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::FFT:
|
||||
m_widget = new QPushButton("FFT");
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Plot:
|
||||
m_widget = new Plot(relativeIndex());
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user