working multiview
This commit is contained in:
parent
2195edd6cd
commit
f18ec5f9b7
@ -4,6 +4,7 @@
|
||||
#include <iostream>
|
||||
#include "chart.h"
|
||||
#include "chartview.h"
|
||||
#include "multichartview.h"
|
||||
|
||||
using namespace QtCharts;
|
||||
|
||||
@ -64,6 +65,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
eodView->setRenderHint(QPainter::Antialiasing);
|
||||
ui->vbox->addWidget(voltageView);
|
||||
ui->vbox->addWidget(eodView);
|
||||
|
||||
MultiChartView *mcv = new MultiChartView();
|
||||
mcv->addArray(eod);
|
||||
mcv->addArray(voltage);
|
||||
ui->vbox->addWidget(mcv);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,20 +1,73 @@
|
||||
#include "multichartview.h"
|
||||
#include "ui_multichartview.h"
|
||||
#include "chartview.h"
|
||||
|
||||
MultiChartView::MultiChartView(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::MultiChartView)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
xRangeMax = 0.0;
|
||||
xRangeMin = 0.0;
|
||||
}
|
||||
|
||||
MultiChartView::~MultiChartView()
|
||||
{
|
||||
std::map<std::string, Chart*>::iterator cit;
|
||||
for (cit = chartMap.begin(); cit != chartMap.end(); cit++) {
|
||||
delete cit->second;
|
||||
}
|
||||
std::map<std::string, ChartView*>::iterator vit;
|
||||
for (vit = viewMap.begin(); vit != viewMap.end(); vit++) {
|
||||
delete vit->second;
|
||||
}
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MultiChartView::addArray(const nix::DataArray &array) {
|
||||
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));
|
||||
Chart* chart = createChart(ai);
|
||||
ChartView *view = createChartView(chart, ai);
|
||||
|
||||
double absMin = 0.0, absMax = 0.0;
|
||||
std::map<std::string, ArrayInfo*>::iterator it;
|
||||
for (it = infoMap.begin(); it != infoMap.end(); it++) {
|
||||
if (it->second->xoffset < absMin)
|
||||
absMin = it->second->xoffset;
|
||||
if (it->second->xmax > absMax)
|
||||
absMax = it->second->xmax;
|
||||
}
|
||||
|
||||
ui->scrollBar->setMinimum(0);
|
||||
ui->scrollBar->setMaximum(100000);
|
||||
ui->scrollBar->setPageStep(100);
|
||||
ui->vBox->addWidget(view);
|
||||
}
|
||||
|
||||
Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
||||
Chart *chart = new Chart();
|
||||
chart->setTitle(QString::fromStdString(arrayMap.at(info.arrayid).name()));
|
||||
chart->legend()->hide();
|
||||
chart->createDefaultAxes();
|
||||
|
||||
this->chartMap.insert(std::pair<std::string, Chart*>(info.arrayid, chart));
|
||||
return chart;
|
||||
}
|
||||
|
||||
ChartView* MultiChartView::createChartView(Chart *chart, const ArrayInfo &info) {
|
||||
ChartView *view = new ChartView(chart);
|
||||
view->setLineWidth(1);
|
||||
view->setRenderHint(QPainter::Antialiasing);
|
||||
/*
|
||||
QMargins margins = voltageChart->margins();
|
||||
int marg1 = margins.left();
|
||||
margins.setLeft(marg1 * 4);
|
||||
eodChart->setMargins(margins);
|
||||
*/
|
||||
|
||||
this->viewMap.insert(std::pair<std::string, ChartView*>(info.arrayid, view));
|
||||
return view;
|
||||
}
|
||||
|
@ -4,6 +4,75 @@
|
||||
#include <QWidget>
|
||||
#include <nix.hpp>
|
||||
|
||||
#include "chart.h"
|
||||
#include "chartview.h"
|
||||
|
||||
struct ArrayInfo {
|
||||
|
||||
ArrayInfo(const nix::DataArray &array) {
|
||||
arrayid = array.id();
|
||||
dataExtent = array.dataExtent();
|
||||
xDim = guessBestXdim(array);
|
||||
nix::Dimension d = array.getDimension(xDim);
|
||||
dimType = d.dimensionType();
|
||||
|
||||
if (dimType == nix::DimensionType::Sample) {
|
||||
nix::SampledDimension sd = d.asSampledDimension();
|
||||
xoffset = sd.offset() ? *sd.offset() : 0.0;
|
||||
sampleinterval = sd.samplingInterval();
|
||||
xmax = dataExtent[xDim - 1] * sampleinterval + xoffset;
|
||||
} else if (dimType == nix::DimensionType::Range) {
|
||||
nix::RangeDimension rd = d.asRangeDimension();
|
||||
tics = rd.ticks();
|
||||
xoffset = tics.front();
|
||||
xmax = tics.back();
|
||||
sampleinterval = 0.0;
|
||||
} else { // SetDimension
|
||||
xoffset = 0.0;
|
||||
xmax = dataExtent[xDim - 1];
|
||||
sampleinterval = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string arrayid;
|
||||
int xDim;
|
||||
nix::DimensionType dimType;
|
||||
double xoffset, xmax, sampleinterval;
|
||||
std::vector<double> tics;
|
||||
nix::NDSize dataExtent;
|
||||
|
||||
int guessBestXdim(const nix::DataArray &array) const {
|
||||
if(dataExtent.size() == 0) {
|
||||
throw nix::IncompatibleDimensions("Array has dataExtent().size 0.", "guess_best_xdim");
|
||||
}
|
||||
if(dataExtent.size() > 2) {
|
||||
throw nix::IncompatibleDimensions("Array has more than two dimensions.", "guess_best_xdim");
|
||||
}
|
||||
if(dataExtent.size() == 1) {
|
||||
return 1;
|
||||
} else {
|
||||
nix::DimensionType d_1 = array.getDimension(1).dimensionType();
|
||||
nix::DimensionType d_2 = array.getDimension(2).dimensionType();
|
||||
|
||||
if(d_1 == nix::DimensionType::Sample) {
|
||||
return 1;
|
||||
} else if (d_2 == nix::DimensionType::Sample) {
|
||||
return 2;
|
||||
} else {
|
||||
if(d_1 == nix::DimensionType::Set && d_2 == nix::DimensionType::Range) {
|
||||
return 2;
|
||||
} else if (d_1 == nix::DimensionType::Range && d_2 == nix::DimensionType::Set){
|
||||
return 1;
|
||||
} else {
|
||||
std::cerr << "How did you manage to end up in Lineplotter with 2D Set Data? guess_best_xdims() failure?" << std::endl;
|
||||
throw nix::IncompatibleDimensions("Array contains 2D set data.", "guess_best_xdim");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class MultiChartView;
|
||||
}
|
||||
@ -20,6 +89,13 @@ public:
|
||||
private:
|
||||
Ui::MultiChartView *ui;
|
||||
double xRangeMin, xRangeMax;
|
||||
std::map<std::string, nix::DataArray> arrayMap;
|
||||
std::map<std::string, Chart*> chartMap;
|
||||
std::map<std::string, ChartView*> viewMap;
|
||||
std::map<std::string, ArrayInfo*> infoMap;
|
||||
|
||||
Chart* createChart(const ArrayInfo &info);
|
||||
ChartView* createChartView(Chart *chart, const ArrayInfo &info);
|
||||
};
|
||||
|
||||
#endif // MULTICHARTVIEW_H
|
||||
|
Loading…
Reference in New Issue
Block a user