delegate graphics to mulitchartview
This commit is contained in:
parent
f18ec5f9b7
commit
b87b254233
@ -21,13 +21,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
connect(dataService, SIGNAL(resultReady()), this, SLOT(handleResult()));
|
||||
dataServiceThread.start();
|
||||
*/
|
||||
connect(&dataQueue, SIGNAL(resultReady(QString)), this, SLOT(dataReady(QString)));
|
||||
//connect(&dataQueue, SIGNAL(finished()), &dataQueue, SLOT(deleteLater()));
|
||||
DataLoader *loader = new DataLoader();
|
||||
loader->moveToThread(&dataQueue);
|
||||
dataQueue.start();
|
||||
|
||||
connect(ui->requestDataBtn, SIGNAL(clicked(bool)), this, SLOT(requestData()));
|
||||
file = nix::File::open("/home/grewe/zwischenlager/2017-08-17-af-invivo-1/2017-08-17-af-invivo-1.nix",
|
||||
nix::FileMode::ReadOnly);
|
||||
|
||||
@ -37,39 +30,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
this->voltage = b.getDataArray("V-1");
|
||||
this->eod = b.getDataArray("EOD");
|
||||
|
||||
voltageChart = new Chart();
|
||||
voltageChart->legend()->hide();
|
||||
voltageChart->createDefaultAxes();
|
||||
|
||||
eodChart = new Chart();
|
||||
eodChart->legend()->hide();
|
||||
eodChart->createDefaultAxes();
|
||||
|
||||
|
||||
chartMap.insert(std::pair<std::string, Chart*>(voltage.id(), voltageChart));
|
||||
chartMap.insert(std::pair<std::string, Chart*>(eod.id(), eodChart));
|
||||
|
||||
voltageChart->setTitle(QString::fromStdString(this->voltage.name()));
|
||||
eodChart->setTitle(QString::fromStdString(this->eod.name()));
|
||||
QMargins margins = voltageChart->margins();
|
||||
int marg1 = margins.left();
|
||||
margins.setLeft(marg1 * 4);
|
||||
eodChart->setMargins(margins);
|
||||
voltageView = new ChartView(voltageChart);
|
||||
//voltageView->setRubberBand(QChartView::HorizontalRubberBand);
|
||||
voltageView->setLineWidth(1);
|
||||
eodView = new ChartView(eodChart);
|
||||
//eodView->setRubberBand(QChartView::HorizontalRubberBand);
|
||||
eodView->setLineWidth(1);
|
||||
voltageView->setRenderHint(QPainter::Antialiasing);
|
||||
eodView->setRenderHint(QPainter::Antialiasing);
|
||||
ui->vbox->addWidget(voltageView);
|
||||
ui->vbox->addWidget(eodView);
|
||||
|
||||
MultiChartView *mcv = new MultiChartView();
|
||||
ui->vbox->addWidget(mcv);
|
||||
|
||||
mcv->addArray(eod);
|
||||
mcv->addArray(voltage);
|
||||
ui->vbox->addWidget(mcv);
|
||||
}
|
||||
|
||||
|
||||
@ -77,61 +42,5 @@ MainWindow::~MainWindow() {
|
||||
if (file) {
|
||||
file.close();
|
||||
}
|
||||
//dataServiceThread.quit();
|
||||
//dataServiceThread.wait();
|
||||
dataQueue.stop();
|
||||
dataQueue.quit();
|
||||
dataQueue.wait();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::dataReady(QString requestId) {
|
||||
DataResult1D data = dataQueue.getData(requestId);
|
||||
if (data.id.empty()) {
|
||||
return;
|
||||
}
|
||||
ConvertToSeries *task = new ConvertToSeries();
|
||||
QLineSeries *series = new QLineSeries();
|
||||
task->setData(series, data);
|
||||
connect(task, SIGNAL(dataConverted(QLineSeries*,QString, double, double)), this, SLOT(dataConverted(QLineSeries*,QString, double, double)));
|
||||
QThreadPool::globalInstance()->start(task);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::dataConverted(QLineSeries *series, QString entityId, double ymin, double ymax) {
|
||||
Chart *chart = chartMap[entityId.toStdString()];
|
||||
series->setUseOpenGL(true);
|
||||
chart->addSeries(series);
|
||||
|
||||
QValueAxis *axisY = new QValueAxis;
|
||||
double range = ymax - ymin;
|
||||
axisY->setRange(ymin - 0.2 * range, ymax + 0.2 * range);
|
||||
axisY->setTickCount(10);
|
||||
axisY->applyNiceNumbers();
|
||||
axisY->setTitleText("Test");
|
||||
chart->setAxisY(axisY, series);
|
||||
|
||||
QValueAxis *axisX = new QValueAxis;
|
||||
axisX->setRange(series->at(0).x(), series->at(series->count()-1).x());
|
||||
axisX->setTickCount(10);
|
||||
axisX->setLabelFormat("%.4f");
|
||||
axisX->applyNiceNumbers();
|
||||
chart->setAxisX(axisX, series);
|
||||
connect(axisX, SIGNAL(rangeChanged(qreal,qreal)), chart, SLOT(XRangeChanged(qreal,qreal)));
|
||||
|
||||
QPen pen = series->pen();
|
||||
pen.setWidth(1);
|
||||
series->setPen(pen);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::requestData() {
|
||||
if (voltage && eod) {
|
||||
nix::NDSize count(1, 100000);
|
||||
nix::NDSize start(1, 0);
|
||||
std::string vId, eodId;
|
||||
dataQueue.requestData(voltage, count, start, vId);
|
||||
dataQueue.requestData(eod, count, start, eodId);
|
||||
}
|
||||
}
|
||||
|
13
mainwindow.h
13
mainwindow.h
@ -25,23 +25,10 @@ public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
void requestData();
|
||||
void dataReady(QString requestId);
|
||||
void dataConverted(QLineSeries *series, QString entityId, double ymin, double ymax);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
//QThread dataServiceThread;
|
||||
//DataService *dataService;
|
||||
DataQueue dataQueue;
|
||||
nix::DataArray voltage, eod;
|
||||
nix::File file;
|
||||
ChartView *voltageView;
|
||||
ChartView *eodView;
|
||||
Chart *voltageChart;
|
||||
Chart *eodChart;
|
||||
std::map<std::string, Chart*> chartMap;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include "multichartview.h"
|
||||
#include "ui_multichartview.h"
|
||||
#include "converttoseries.h"
|
||||
|
||||
using namespace QtCharts;
|
||||
|
||||
MultiChartView::MultiChartView(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
@ -8,6 +11,12 @@ MultiChartView::MultiChartView(QWidget *parent) :
|
||||
ui->setupUi(this);
|
||||
xRangeMax = 0.0;
|
||||
xRangeMin = 0.0;
|
||||
connect(&dataQueue, SIGNAL(resultReady(QString)), this, SLOT(dataReady(QString)));
|
||||
//connect(&dataQueue, SIGNAL(finished()), &dataQueue, SLOT(deleteLater()));
|
||||
DataLoader *loader = new DataLoader();
|
||||
loader->moveToThread(&dataQueue);
|
||||
dataQueue.start();
|
||||
|
||||
}
|
||||
|
||||
MultiChartView::~MultiChartView()
|
||||
@ -20,15 +29,22 @@ MultiChartView::~MultiChartView()
|
||||
for (vit = viewMap.begin(); vit != viewMap.end(); vit++) {
|
||||
delete vit->second;
|
||||
}
|
||||
|
||||
dataQueue.stop();
|
||||
dataQueue.quit();
|
||||
dataQueue.wait();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MultiChartView::addArray(const nix::DataArray &array) {
|
||||
while (dataQueue.isRunning()){
|
||||
// uncool!!!
|
||||
}
|
||||
|
||||
|
||||
this->arrayMap.insert(std::pair<std::string, nix::DataArray>(array.id(), array));
|
||||
ArrayInfo ai(array);
|
||||
this->infoMap.insert(std::pair<std::string, ArrayInfo*>(array.id(), &ai));
|
||||
this->infoMap.insert(std::pair<std::string, ArrayInfo*>(ai.arrayid, &ai));
|
||||
Chart* chart = createChart(ai);
|
||||
ChartView *view = createChartView(chart, ai);
|
||||
|
||||
@ -45,6 +61,7 @@ void MultiChartView::addArray(const nix::DataArray &array) {
|
||||
ui->scrollBar->setMaximum(100000);
|
||||
ui->scrollBar->setPageStep(100);
|
||||
ui->vBox->addWidget(view);
|
||||
loadData(ai);
|
||||
}
|
||||
|
||||
Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
||||
@ -71,3 +88,50 @@ ChartView* MultiChartView::createChartView(Chart *chart, const ArrayInfo &info)
|
||||
this->viewMap.insert(std::pair<std::string, ChartView*>(info.arrayid, view));
|
||||
return view;
|
||||
}
|
||||
|
||||
void MultiChartView::loadData(const ArrayInfo &info) {
|
||||
if (arrayMap.at(info.arrayid)) {
|
||||
nix::NDSize count(1, 100000);
|
||||
nix::NDSize start(1, 0);
|
||||
std::string vId, eodId;
|
||||
dataQueue.requestData(arrayMap.at(info.arrayid), count, start, vId);
|
||||
}
|
||||
}
|
||||
|
||||
void MultiChartView::dataReady(QString requestId){
|
||||
DataResult1D data = dataQueue.getData(requestId);
|
||||
if (data.id.empty()) {
|
||||
return;
|
||||
}
|
||||
ConvertToSeries *task = new ConvertToSeries();
|
||||
QLineSeries *series = new QLineSeries();
|
||||
task->setData(series, data);
|
||||
connect(task, SIGNAL(dataConverted(QLineSeries*,QString, double, double)), this, SLOT(dataConverted(QLineSeries*,QString, double, double)));
|
||||
QThreadPool::globalInstance()->start(task);
|
||||
}
|
||||
|
||||
void MultiChartView::dataConverted(QLineSeries *series, QString entityId, double ymin, double ymax) {
|
||||
Chart *chart = chartMap[entityId.toStdString()];
|
||||
series->setUseOpenGL(true);
|
||||
chart->addSeries(series);
|
||||
|
||||
QValueAxis *axisY = new QValueAxis;
|
||||
double range = ymax - ymin;
|
||||
axisY->setRange(ymin - 0.2 * range, ymax + 0.2 * range);
|
||||
axisY->setTickCount(10);
|
||||
axisY->applyNiceNumbers();
|
||||
axisY->setTitleText("Test");
|
||||
chart->setAxisY(axisY, series);
|
||||
|
||||
QValueAxis *axisX = new QValueAxis;
|
||||
axisX->setRange(series->at(0).x(), series->at(series->count()-1).x());
|
||||
axisX->setTickCount(10);
|
||||
axisX->setLabelFormat("%.4f");
|
||||
axisX->applyNiceNumbers();
|
||||
chart->setAxisX(axisX, series);
|
||||
connect(axisX, SIGNAL(rangeChanged(qreal,qreal)), chart, SLOT(XRangeChanged(qreal,qreal)));
|
||||
|
||||
QPen pen = series->pen();
|
||||
pen.setWidth(1);
|
||||
series->setPen(pen);
|
||||
}
|
||||
|
@ -2,14 +2,19 @@
|
||||
#define MULTICHARTVIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLineSeries>
|
||||
#include <QtCharts>
|
||||
#include <nix.hpp>
|
||||
|
||||
#include "dataqueue.h"
|
||||
#include "chart.h"
|
||||
#include "chartview.h"
|
||||
|
||||
struct ArrayInfo {
|
||||
|
||||
ArrayInfo(const nix::DataArray &array) {
|
||||
if (!array)
|
||||
std::cerr << "shiiii\n";
|
||||
arrayid = array.id();
|
||||
dataExtent = array.dataExtent();
|
||||
xDim = guessBestXdim(array);
|
||||
@ -86,8 +91,11 @@ public:
|
||||
~MultiChartView();
|
||||
|
||||
void addArray(const nix::DataArray &array);
|
||||
void loadData(const ArrayInfo &info);
|
||||
|
||||
private:
|
||||
Ui::MultiChartView *ui;
|
||||
DataQueue dataQueue;
|
||||
double xRangeMin, xRangeMax;
|
||||
std::map<std::string, nix::DataArray> arrayMap;
|
||||
std::map<std::string, Chart*> chartMap;
|
||||
@ -96,6 +104,11 @@ private:
|
||||
|
||||
Chart* createChart(const ArrayInfo &info);
|
||||
ChartView* createChartView(Chart *chart, const ArrayInfo &info);
|
||||
|
||||
public slots:
|
||||
void dataReady(QString requestId);
|
||||
void dataConverted(QLineSeries *series, QString entityId, double ymin, double ymax);
|
||||
|
||||
};
|
||||
|
||||
#endif // MULTICHARTVIEW_H
|
||||
|
Loading…
Reference in New Issue
Block a user