mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Fix #35 & improve performance
This commit is contained in:
parent
eb11413bc4
commit
56d9ce101a
@ -277,13 +277,13 @@ ApplicationWindow {
|
||||
// Hide console & device manager when we receive first valid packet
|
||||
//
|
||||
Connections {
|
||||
target: Cpp_JSON_Generator
|
||||
target: Cpp_UI_Provider
|
||||
enabled: !app.firstValidPacket
|
||||
function onFrameChanged() {
|
||||
if ((Cpp_IO_Manager.connected || Cpp_CSV_Player.isOpen) && Cpp_JSON_Generator.frameValid()) {
|
||||
function onUpdated() {
|
||||
if ((Cpp_IO_Manager.connected || Cpp_CSV_Player.isOpen) && Cpp_UI_Provider.frameValid()) {
|
||||
app.firstValidPacket = true
|
||||
setup.hide()
|
||||
toolbar.dataClicked()
|
||||
app.showDashboard()
|
||||
} else {
|
||||
toolbar.consoleClicked()
|
||||
setup.show()
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
bool read(const QJsonObject &object);
|
||||
Q_INVOKABLE Group *getGroup(const int index);
|
||||
|
||||
inline bool isValid() const { return !title().isEmpty() && groupCount() > 0; }
|
||||
|
||||
private:
|
||||
QString m_title;
|
||||
QVector<Group *> m_groups;
|
||||
|
@ -71,14 +71,6 @@ Generator *Generator::getInstance()
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current JSON frame
|
||||
*/
|
||||
Frame *Generator::frame()
|
||||
{
|
||||
return &m_frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JSON map data from the loaded file as a string
|
||||
*/
|
||||
@ -270,9 +262,6 @@ void Generator::setJsonDocument(const QJsonDocument &document, const QDateTime &
|
||||
if (csvOpen || devOpen)
|
||||
{
|
||||
m_document = document;
|
||||
if (m_frame.read(m_document.object()))
|
||||
emit frameChanged();
|
||||
|
||||
emit jsonChanged(document, time);
|
||||
}
|
||||
|
||||
@ -286,10 +275,7 @@ void Generator::setJsonDocument(const QJsonDocument &document, const QDateTime &
|
||||
*/
|
||||
void Generator::reset()
|
||||
{
|
||||
m_frame.clear();
|
||||
m_document = QJsonDocument::fromJson(QByteArray("{}"));
|
||||
|
||||
emit frameChanged();
|
||||
emit jsonChanged(document(), QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,6 @@ class Generator : public QObject
|
||||
// clang-format on
|
||||
|
||||
signals:
|
||||
void frameChanged();
|
||||
void jsonFileMapChanged();
|
||||
void operationModeChanged();
|
||||
void jsonChanged(const QJsonDocument &document, const QDateTime &time);
|
||||
@ -93,21 +92,12 @@ public:
|
||||
public:
|
||||
static Generator *getInstance();
|
||||
|
||||
Frame *frame();
|
||||
QString jsonMapData() const;
|
||||
QJsonDocument document() const;
|
||||
QString jsonMapFilename() const;
|
||||
QString jsonMapFilepath() const;
|
||||
OperationMode operationMode() const;
|
||||
|
||||
Q_INVOKABLE bool frameValid()
|
||||
{
|
||||
if (frame())
|
||||
return frame()->groupCount() > 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void loadJsonMap();
|
||||
void setOperationMode(const OperationMode mode);
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <CSV/Player.h>
|
||||
#include <JSON/Generator.h>
|
||||
#include <ConsoleAppender.h>
|
||||
#include <Misc/TimerEvents.h>
|
||||
|
||||
using namespace UI;
|
||||
|
||||
@ -44,9 +45,11 @@ DataProvider::DataProvider()
|
||||
auto cp = CSV::Player::getInstance();
|
||||
auto io = IO::Manager::getInstance();
|
||||
auto ge = JSON::Generator::getInstance();
|
||||
auto te = Misc::TimerEvents::getInstance();
|
||||
connect(cp, SIGNAL(openChanged()), this, SLOT(resetData()));
|
||||
connect(ge, SIGNAL(frameChanged()), this, SIGNAL(updated()));
|
||||
connect(te, SIGNAL(timeout42Hz()), this, SLOT(updateData()));
|
||||
connect(io, SIGNAL(connectedChanged()), this, SLOT(resetData()));
|
||||
connect(ge, &JSON::Generator::jsonChanged, this, &DataProvider::selectLatestJSON);
|
||||
LOG_TRACE() << "Class initialized";
|
||||
}
|
||||
|
||||
@ -66,7 +69,7 @@ DataProvider *DataProvider::getInstance()
|
||||
*/
|
||||
QString DataProvider::title()
|
||||
{
|
||||
return JSON::Generator::getInstance()->frame()->title();
|
||||
return m_latestFrame.title();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +77,23 @@ QString DataProvider::title()
|
||||
*/
|
||||
int DataProvider::groupCount()
|
||||
{
|
||||
return JSON::Generator::getInstance()->frame()->groupCount();
|
||||
return m_latestFrame.groupCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the latest frame
|
||||
*/
|
||||
JSON::Frame *DataProvider::latestFrame()
|
||||
{
|
||||
return &m_latestFrame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns @c true if the latest frame contains data
|
||||
*/
|
||||
bool DataProvider::frameValid() const
|
||||
{
|
||||
return m_latestFrame.isValid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +102,7 @@ int DataProvider::groupCount()
|
||||
JSON::Group *DataProvider::getGroup(const int index)
|
||||
{
|
||||
if (index < groupCount())
|
||||
return JSON::Generator::getInstance()->frame()->groups().at(index);
|
||||
return m_latestFrame.groups().at(index);
|
||||
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
@ -98,7 +117,37 @@ void DataProvider::resetData()
|
||||
if (IO::Manager::getInstance()->connected() || CSV::Player::getInstance()->isOpen())
|
||||
return;
|
||||
|
||||
// Make latest frame invalid
|
||||
m_latestJsonFrame
|
||||
= qMakePair<QDateTime, QJsonObject>(QDateTime::currentDateTime(), QJsonObject());
|
||||
|
||||
// Update UI
|
||||
emit updated();
|
||||
emit dataReset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interprets the most recent JSON frame & signals the UI to regenerate itself.
|
||||
*/
|
||||
void DataProvider::updateData()
|
||||
{
|
||||
if (m_latestFrame.read(m_latestJsonFrame.second))
|
||||
emit updated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that only the most recent JSON document will be displayed on the user
|
||||
* interface.
|
||||
*/
|
||||
void DataProvider::selectLatestJSON(const QJsonDocument &document, const QDateTime &time)
|
||||
{
|
||||
if (m_latestJsonFrame.first < time)
|
||||
{
|
||||
auto json = document.object();
|
||||
if (json.isEmpty())
|
||||
return;
|
||||
|
||||
auto pair = qMakePair<QDateTime, QJsonObject>(time, json);
|
||||
m_latestJsonFrame = pair;
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,9 @@ public:
|
||||
QString title();
|
||||
int groupCount();
|
||||
|
||||
JSON::Frame *latestFrame();
|
||||
|
||||
Q_INVOKABLE bool frameValid() const;
|
||||
Q_INVOKABLE JSON::Group *getGroup(const int index);
|
||||
|
||||
private:
|
||||
@ -57,6 +60,12 @@ private:
|
||||
|
||||
private slots:
|
||||
void resetData();
|
||||
void updateData();
|
||||
void selectLatestJSON(const QJsonDocument &document, const QDateTime &time);
|
||||
|
||||
private:
|
||||
JSON::Frame m_latestFrame;
|
||||
QPair<QDateTime, QJsonObject> m_latestJsonFrame;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "GraphProvider.h"
|
||||
|
||||
#include <QtMath>
|
||||
@ -30,7 +31,6 @@
|
||||
#include <CSV/Player.h>
|
||||
#include <IO/Manager.h>
|
||||
#include <IO/Console.h>
|
||||
#include <JSON/Generator.h>
|
||||
#include <ConsoleAppender.h>
|
||||
#include <Misc/TimerEvents.h>
|
||||
|
||||
@ -67,11 +67,9 @@ GraphProvider::GraphProvider()
|
||||
// Module signals/slots
|
||||
auto cp = CSV::Player::getInstance();
|
||||
auto io = IO::Manager::getInstance();
|
||||
auto ge = JSON::Generator::getInstance();
|
||||
auto te = Misc::TimerEvents::getInstance();
|
||||
connect(cp, SIGNAL(openChanged()), this, SLOT(resetData()));
|
||||
connect(te, SIGNAL(timeout42Hz()), this, SIGNAL(dataUpdated()));
|
||||
connect(ge, SIGNAL(frameChanged()), this, SLOT(updateValues()));
|
||||
connect(te, SIGNAL(timeout42Hz()), this, SLOT(drawGraphs()));
|
||||
connect(io, SIGNAL(connectedChanged()), this, SLOT(resetData()));
|
||||
|
||||
// Avoid issues when CSV player goes backwards
|
||||
@ -237,20 +235,21 @@ void GraphProvider::resetData()
|
||||
m_datasets.clear();
|
||||
m_maximumValues.clear();
|
||||
m_minimumValues.clear();
|
||||
|
||||
emit dataUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the latest values from the datasets that support/need to be graphed
|
||||
*/
|
||||
void GraphProvider::updateValues()
|
||||
void GraphProvider::drawGraphs()
|
||||
{
|
||||
// Clear dataset & latest values list
|
||||
m_datasets.clear();
|
||||
|
||||
// Get latest frame
|
||||
auto frame = JSON::Generator::getInstance()->frame();
|
||||
// Get frame, abort if frame is invalid
|
||||
auto frame = DataProvider::getInstance()->latestFrame();
|
||||
if (!frame->isValid())
|
||||
return;
|
||||
|
||||
// Create list with datasets that need to be graphed
|
||||
for (int i = 0; i < frame->groupCount(); ++i)
|
||||
@ -297,6 +296,9 @@ void GraphProvider::updateValues()
|
||||
// Add values
|
||||
m_points.at(i)->append(getValue(i));
|
||||
}
|
||||
|
||||
// Update UI
|
||||
emit dataUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,7 +77,7 @@ private:
|
||||
|
||||
private slots:
|
||||
void resetData();
|
||||
void updateValues();
|
||||
void drawGraphs();
|
||||
void csvPlayerFixes();
|
||||
|
||||
private:
|
||||
|
@ -20,6 +20,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "WidgetProvider.h"
|
||||
|
||||
#include <cfloat>
|
||||
@ -28,7 +29,6 @@
|
||||
#include <CSV/Player.h>
|
||||
#include <IO/Manager.h>
|
||||
#include <IO/Console.h>
|
||||
#include <JSON/Generator.h>
|
||||
#include <ConsoleAppender.h>
|
||||
#include <Misc/TimerEvents.h>
|
||||
|
||||
@ -48,11 +48,9 @@ WidgetProvider::WidgetProvider()
|
||||
// Module signals/slots
|
||||
auto cp = CSV::Player::getInstance();
|
||||
auto io = IO::Manager::getInstance();
|
||||
auto ge = JSON::Generator::getInstance();
|
||||
auto te = Misc::TimerEvents::getInstance();
|
||||
connect(cp, SIGNAL(openChanged()), this, SLOT(resetData()));
|
||||
connect(te, SIGNAL(timeout42Hz()), this, SIGNAL(dataChanged()));
|
||||
connect(ge, SIGNAL(frameChanged()), this, SLOT(updateModels()));
|
||||
connect(te, SIGNAL(timeout42Hz()), this, SLOT(updateModels()));
|
||||
connect(io, SIGNAL(connectedChanged()), this, SLOT(resetData()));
|
||||
LOG_TRACE() << "Class initialized";
|
||||
}
|
||||
@ -419,6 +417,10 @@ void WidgetProvider::updateModels()
|
||||
m_gyroGroups.clear();
|
||||
m_accelerometerGroups.clear();
|
||||
|
||||
// Check if frame is valid
|
||||
if (!DataProvider::getInstance()->latestFrame()->isValid())
|
||||
return;
|
||||
|
||||
// Update groups
|
||||
m_mapGroups = getWidgetGroup("map");
|
||||
m_gyroGroups = getWidgetGroup("gyro");
|
||||
@ -433,6 +435,9 @@ void WidgetProvider::updateModels()
|
||||
m_widgetCount = count;
|
||||
emit widgetCountChanged();
|
||||
}
|
||||
|
||||
// Update UI
|
||||
emit dataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -443,7 +448,7 @@ QList<JSON::Group *> WidgetProvider::getWidgetGroup(const QString &handle)
|
||||
{
|
||||
QList<JSON::Group *> widgetGroup;
|
||||
|
||||
auto frame = JSON::Generator::getInstance()->frame();
|
||||
auto frame = DataProvider::getInstance()->latestFrame();
|
||||
foreach (auto group, frame->groups())
|
||||
{
|
||||
if (group->widget().toLower() == handle)
|
||||
@ -461,7 +466,7 @@ QList<JSON::Dataset *> WidgetProvider::getWidgetDatasets(const QString &handle)
|
||||
{
|
||||
QList<JSON::Dataset *> widgetDatasets;
|
||||
|
||||
auto frame = JSON::Generator::getInstance()->frame();
|
||||
auto frame = DataProvider::getInstance()->latestFrame();
|
||||
foreach (auto group, frame->groups())
|
||||
{
|
||||
foreach (auto dataset, group->datasets())
|
||||
|
Loading…
x
Reference in New Issue
Block a user