buffer for converted data
This commit is contained in:
parent
343e611fa4
commit
4f9d083e0f
@ -12,21 +12,30 @@ void ConvertToSeries::run() {
|
||||
double max = data.ydata[0];
|
||||
if (dataPresent) {
|
||||
for (size_t i = 0; i < data.xdata.size(); ++i) {
|
||||
this->series->append(data.xdata[i], data.ydata[i]);
|
||||
this->buffer->push_back({data.xdata[i], data.ydata[i]});
|
||||
if (data.ydata[i] < min)
|
||||
min = data.ydata[i];
|
||||
if (data.ydata[i] > max)
|
||||
max = data.ydata[i];
|
||||
}
|
||||
emit dataConverted(series, QString::fromStdString(data.entityId), min, max);
|
||||
emit dataConverted(QString::fromStdString(data.entityId), min, max);
|
||||
}
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void ConvertToSeries::setData(QLineSeries *series, const DataResult1D &data) {
|
||||
/*void ConvertToSeries::setData(QLineSeries *series, const DataResult1D &data) {
|
||||
mutex.lock();
|
||||
this->series = series;
|
||||
this->data = data;
|
||||
this->dataPresent = true;
|
||||
mutex.unlock();
|
||||
}
|
||||
*/
|
||||
|
||||
void ConvertToSeries::setData(QVector<QPointF> *buffer, const DataResult1D &data) {
|
||||
mutex.lock();
|
||||
this->buffer = buffer;
|
||||
this->data = data;
|
||||
this->dataPresent = true;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
@ -19,14 +19,15 @@ private:
|
||||
bool dataPresent = false;
|
||||
DataResult1D data;
|
||||
QLineSeries *series;
|
||||
|
||||
QVector<QPointF> *buffer;
|
||||
void run() override;
|
||||
|
||||
public:
|
||||
void setData(QLineSeries *series, const DataResult1D &data);
|
||||
void setData(QVector<QPointF> *buffer, const DataResult1D &data);
|
||||
|
||||
signals:
|
||||
void dataConverted(QLineSeries *series, QString entityId, double, double);
|
||||
void dataConverted(QString entityId, double, double);
|
||||
|
||||
};
|
||||
|
||||
|
@ -28,6 +28,10 @@ MultiChartView::~MultiChartView()
|
||||
for (vit = viewMap.begin(); vit != viewMap.end(); vit++) {
|
||||
delete vit->second;
|
||||
}
|
||||
std::map<std::string, QVector<QPointF>*>::iterator ait;
|
||||
for (ait = data_buffer.begin(); ait != data_buffer.end(); ait++) {
|
||||
delete ait->second;
|
||||
}
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -39,6 +43,8 @@ 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*>(ai.arrayid, &ai));
|
||||
QVector<QPointF> *buffer = new QVector<QPointF>();
|
||||
this->data_buffer.insert(std::pair<std::string, QVector<QPointF>*>(ai.arrayid, buffer));
|
||||
Chart* chart = createChart(ai);
|
||||
ChartView *view = createChartView(chart, ai);
|
||||
|
||||
@ -63,6 +69,7 @@ Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
||||
chart->setToolTip(QString::fromStdString(info.name));
|
||||
chart->legend()->hide();
|
||||
chart->createDefaultAxes();
|
||||
chart->entityId = info.arrayid;
|
||||
|
||||
QValueAxis *axisY = new QValueAxis;
|
||||
axisY->setTickCount(10);
|
||||
@ -81,9 +88,9 @@ Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
||||
axisX->setLabelsFont(tickLabelFont);
|
||||
axisX->applyNiceNumbers();
|
||||
chart->setAxisX(axisX);
|
||||
|
||||
connect(axisX, SIGNAL(rangeChanged(qreal,qreal)), chart, SLOT(XRangeChanged(qreal,qreal)));
|
||||
|
||||
connect(axisX, SIGNAL(rangeChanged(qreal,qreal)), chart, SLOT(XRangeChanged(qreal,qreal)));
|
||||
connect(chart, SIGNAL(newDataRequest(std::string,qreal)), this, SLOT(newDataRequest(std::string, qreal)));
|
||||
this->chartMap.insert(std::pair<std::string, Chart*>(info.arrayid, chart));
|
||||
return chart;
|
||||
}
|
||||
@ -113,36 +120,55 @@ void MultiChartView::loadData(const ArrayInfo &info) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultiChartView::newDataRequest(const std::string &entity_id, qreal max) {
|
||||
std::cerr << "request new data from: "<< entity_id << " with max: "<< max << std::endl;
|
||||
nix::NDSize offset(1, data_buffer[entity_id]->size());
|
||||
nix::NDSize count(1, 100000);
|
||||
std::string request_id;
|
||||
dataQueue->requestData(arrayMap[entity_id], count, offset, request_id);
|
||||
}
|
||||
|
||||
|
||||
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)));
|
||||
task->setData(data_buffer[data.entityId], data);
|
||||
connect(task, SIGNAL(dataConverted(QString, double, double)), this, SLOT(dataConverted(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);
|
||||
void MultiChartView::dataConverted(QString entityId, double ymin, double ymax) {
|
||||
Chart *chart = chartMap[entityId.toStdString()];
|
||||
QLineSeries *series;
|
||||
bool newSeries = false;
|
||||
if (chart->series().size() == 0) {
|
||||
series = new QLineSeries();
|
||||
series->replace(*data_buffer[entityId.toStdString()]);
|
||||
series->setUseOpenGL(true);
|
||||
chart->addSeries(series);
|
||||
QPen pen = series->pen();
|
||||
pen.setWidth(1);
|
||||
series->setPen(pen);
|
||||
newSeries = true;
|
||||
} else {
|
||||
series = static_cast<QLineSeries*>(chart->series().at(0));
|
||||
}
|
||||
|
||||
if (chart->axisX()->type() == QAbstractAxis::AxisTypeValue) {
|
||||
QValueAxis *axisX = static_cast<QValueAxis*>(chart->axisX());
|
||||
axisX->setRange(series->at(0).x(), series->at(series->count()-1).x());
|
||||
series->attachAxis(axisX);
|
||||
if (newSeries)
|
||||
series->attachAxis(axisX);
|
||||
}
|
||||
if (chart->axisY()->type() == QAbstractAxis::AxisTypeValue) {
|
||||
QValueAxis *axisY = static_cast<QValueAxis*>(chart->axisY());
|
||||
double range = ymax - ymin;
|
||||
axisY->setRange(ymin - 0.2 * range, ymax + 0.2 * range);
|
||||
series->attachAxis(axisY);
|
||||
if (newSeries)
|
||||
series->attachAxis(axisY);
|
||||
}
|
||||
|
||||
QPen pen = series->pen();
|
||||
pen.setWidth(1);
|
||||
series->setPen(pen);
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ private:
|
||||
std::map<std::string, Chart*> chartMap;
|
||||
std::map<std::string, ChartView*> viewMap;
|
||||
std::map<std::string, ArrayInfo*> infoMap;
|
||||
std::map<std::string, QVector<QPointF>*> data_buffer;
|
||||
QFont labelFont, tickLabelFont;
|
||||
|
||||
Chart* createChart(const ArrayInfo &info);
|
||||
@ -120,8 +121,8 @@ private:
|
||||
|
||||
public slots:
|
||||
void dataReady(QString requestId);
|
||||
void dataConverted(QLineSeries *series, QString entityId, double ymin, double ymax);
|
||||
|
||||
void dataConverted(QString entityId, double ymin, double ymax);
|
||||
void newDataRequest(const std::string &entity_id, qreal max);
|
||||
};
|
||||
|
||||
#endif // MULTICHARTVIEW_H
|
||||
|
Loading…
Reference in New Issue
Block a user