Skip to content
Snippets Groups Projects
Commit 90c360f9 authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

[Graph] Fixed crash when editing or removing a subscription

Fixes #5
parent 08b4338f
Branches
Tags
1 merge request!34[Graph] Fixed crash when editing or removing a subscription
Pipeline #9751 passed
......@@ -21,8 +21,8 @@
#include <Components/SubscriptionsPanel/SubscriptionsPanel.h>
#include <Core/MessageBroker/MessageBroker.h>
#include <QDebug>
#include <QTimer>
#include <algorithm>
Graph::Graph() : Module(ModuleId::GRAPH)
{
......@@ -146,42 +146,8 @@ void Graph::onFilterAdded(const Filter& filter)
MessageBroker::getInstance().subscribe(
filter, this,
[&](const Message& message, const Filter& filter)
{
if (stopped && !lines.contains(filter))
return;
if (!message.getFields().contains("timestamp"))
return;
for (auto field : filter.getFields())
{
if (field == "timestamp")
continue;
auto& line = lines[filter].first[field];
QVector<double>& bufferX = line.bufferX;
QVector<double>& bufferY = line.bufferY;
double x =
message.getField("timestamp").getUnsignedInteger() / 1e6;
double y = message.getField(field).getDouble();
lines[filter].first[field].graph->setName(field + ": " +
QString::number(y));
// Check if the timestamp resets
if (lastTimestamp - 1 > x)
onClearClicked();
lastTimestamp = x;
bufferX.append(x);
bufferY.append(y);
}
// Flag the data as updated
lines[filter].second = true;
});
[this](const Message& message, const Filter& filter)
{ onMessageReceived(message, filter); });
}
void Graph::onFilterRemoved(const Filter& filter)
......@@ -197,6 +163,12 @@ void Graph::onFilterRemoved(const Filter& filter)
}
lines.remove(filter);
MessageBroker::getInstance().unsubscribe(filter, this);
}
else
{
qWarning() << "Removing filter not found in the graph";
}
}
......@@ -246,6 +218,42 @@ void Graph::onUpdateTimerTick()
}
}
void Graph::onMessageReceived(const Message& message, const Filter& filter)
{
if (stopped && !lines.contains(filter))
return;
if (!message.getFields().contains("timestamp"))
return;
for (auto field : filter.getFields())
{
if (field == "timestamp")
continue;
auto& line = lines[filter].first[field];
QVector<double>& bufferX = line.bufferX;
QVector<double>& bufferY = line.bufferY;
double x = message.getField("timestamp").getUnsignedInteger() / 1e6;
double y = message.getField(field).getDouble();
lines[filter].first[field].graph->setName(field + ": " +
QString::number(y));
// Check if the timestamp resets
if (lastTimestamp - 1 > x)
onClearClicked();
lastTimestamp = x;
bufferX.append(x);
bufferY.append(y);
}
// Flag the data as updated
lines[filter].second = true;
}
void Graph::setupUi()
{
QHBoxLayout* outerLayout = new QHBoxLayout;
......
......@@ -49,6 +49,8 @@ private slots:
void onUpdateTimerTick();
void onMessageReceived(const Message& message, const Filter& filter);
private:
void setupUi();
void customContextMenuActionSetup();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment