First implementation
This commit is contained in:
136
cpp/window/GraphWindow/GraphWindow.cpp
Normal file
136
cpp/window/GraphWindow/GraphWindow.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, 2016 Hubert Denkmair <hubert@denkmair.de>
|
||||
|
||||
This file is part of cangaroo.
|
||||
|
||||
cangaroo is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
cangaroo is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with cangaroo. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "GraphWindow.h"
|
||||
#include "ui_GraphWindow.h"
|
||||
|
||||
#include <QDomDocument>
|
||||
|
||||
#include <core/Backend.h>
|
||||
#include <QtCharts/QChartView>
|
||||
|
||||
#define NUM_GRAPH_POINTS 20
|
||||
|
||||
GraphWindow::GraphWindow(QWidget *parent, Backend &backend) :
|
||||
ConfigurableWidget(parent),
|
||||
ui(new Ui::GraphWindow),
|
||||
_backend(backend)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
data_series = new QLineSeries();
|
||||
|
||||
for(uint32_t i=0; i<NUM_GRAPH_POINTS; i++)
|
||||
{
|
||||
data_series->append(i, i);
|
||||
}
|
||||
|
||||
data_chart = new QChart();
|
||||
data_chart->legend()->hide();
|
||||
data_chart->addSeries(data_series);
|
||||
data_chart->createDefaultAxes();
|
||||
data_chart->setTitle("Simple line chart example");
|
||||
|
||||
|
||||
// Have a box pop up that allows the user to select a signal from the loaded DBC to graph
|
||||
// On OK, add that CanDbMessage to a list.
|
||||
// Either sample the values regularly with a timer or somehow emit a signal when the message
|
||||
// is received that we catch here...
|
||||
|
||||
//backend.findDbMessage()
|
||||
|
||||
// CanDbMessage *result = 0;
|
||||
|
||||
// foreach (MeasurementNetwork *network, _networks) {
|
||||
// foreach (pCanDb db, network->_canDbs) {
|
||||
// result = db->getMessageById(msg.getRawId());
|
||||
// if (result != 0) {
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
|
||||
|
||||
|
||||
ui->chartView->setChart(data_chart);
|
||||
ui->chartView->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
// connect(ui->buttonTest, SIGNAL(released()), this, SLOT(testAddData()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GraphWindow::testAddData(qreal new_yval)
|
||||
{
|
||||
QLineSeries* serbuf = new QLineSeries();
|
||||
|
||||
// Start autorange at first point
|
||||
qreal ymin = data_series->at(1).y();
|
||||
qreal ymax = ymin;
|
||||
|
||||
// Copy all points but first one
|
||||
for(uint32_t i=1; i < data_series->count(); i++)
|
||||
{
|
||||
serbuf->append(data_series->at(i).x()-1, data_series->at(i).y());
|
||||
|
||||
// Autoranging
|
||||
if(data_series->at(i).y() < ymin)
|
||||
ymin = data_series->at(i).y();
|
||||
if(data_series->at(i).y() > ymax)
|
||||
ymax = data_series->at(i).y();
|
||||
}
|
||||
|
||||
// Apply Y margin and set range
|
||||
ymin -= 1;
|
||||
ymax += 1;
|
||||
data_chart->axisY()->setRange(ymin, ymax);
|
||||
|
||||
// Add new point in
|
||||
serbuf->append(serbuf->points().at(serbuf->count()-1).x() + 1, new_yval);
|
||||
testcount++;
|
||||
|
||||
// Replace data
|
||||
data_series->replace(serbuf->points());
|
||||
|
||||
delete serbuf;
|
||||
}
|
||||
|
||||
GraphWindow::~GraphWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete data_chart;
|
||||
delete data_series;
|
||||
}
|
||||
|
||||
bool GraphWindow::saveXML(Backend &backend, QDomDocument &xml, QDomElement &root)
|
||||
{
|
||||
if (!ConfigurableWidget::saveXML(backend, xml, root)) { return false; }
|
||||
root.setAttribute("type", "GraphWindow");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GraphWindow::loadXML(Backend &backend, QDomElement &el)
|
||||
{
|
||||
if (!ConfigurableWidget::loadXML(backend, el)) { return false; }
|
||||
return true;
|
||||
}
|
||||
58
cpp/window/GraphWindow/GraphWindow.h
Normal file
58
cpp/window/GraphWindow/GraphWindow.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, 2016 Hubert Denkmair <hubert@denkmair.de>
|
||||
|
||||
This file is part of cangaroo.
|
||||
|
||||
cangaroo is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
cangaroo is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with cangaroo. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <core/Backend.h>
|
||||
#include <core/ConfigurableWidget.h>
|
||||
#include <core/MeasurementSetup.h>
|
||||
#include <QtCharts/QChartView>
|
||||
#include <QtCharts/QtCharts>
|
||||
#include <QtCharts/QLineSeries>
|
||||
|
||||
namespace Ui {
|
||||
class GraphWindow;
|
||||
}
|
||||
|
||||
class QDomDocument;
|
||||
class QDomElement;
|
||||
|
||||
class GraphWindow : public ConfigurableWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GraphWindow(QWidget *parent, Backend &backend);
|
||||
~GraphWindow();
|
||||
virtual bool saveXML(Backend &backend, QDomDocument &xml, QDomElement &root);
|
||||
virtual bool loadXML(Backend &backend, QDomElement &el);
|
||||
|
||||
private slots:
|
||||
void testAddData(qreal new_yval);
|
||||
|
||||
private:
|
||||
QLineSeries *data_series;
|
||||
QChart *data_chart;
|
||||
uint32_t testcount;
|
||||
|
||||
Ui::GraphWindow *ui;
|
||||
Backend &_backend;
|
||||
};
|
||||
8
cpp/window/GraphWindow/GraphWindow.pri
Normal file
8
cpp/window/GraphWindow/GraphWindow.pri
Normal file
@@ -0,0 +1,8 @@
|
||||
SOURCES += \
|
||||
$$PWD/GraphWindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/GraphWindow.h
|
||||
|
||||
FORMS += \
|
||||
$$PWD/GraphWindow.ui
|
||||
77
cpp/window/GraphWindow/GraphWindow.ui
Normal file
77
cpp/window/GraphWindow/GraphWindow.ui
Normal file
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GraphWindow</class>
|
||||
<widget class="QWidget" name="GraphWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>870</width>
|
||||
<height>274</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>301</width>
|
||||
<height>274</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Graph</string>
|
||||
</property>
|
||||
<widget class="QChartView" name="chartView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>281</width>
|
||||
<height>231</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>281</width>
|
||||
<height>231</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="buttonTest">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>210</x>
|
||||
<y>250</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Test</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QChartView" name="graphicsView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>390</x>
|
||||
<y>30</y>
|
||||
<width>256</width>
|
||||
<height>192</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QChartView</class>
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>QtCharts</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user