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];
|
double max = data.ydata[0];
|
||||||
if (dataPresent) {
|
if (dataPresent) {
|
||||||
for (size_t i = 0; i < data.xdata.size(); ++i) {
|
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)
|
if (data.ydata[i] < min)
|
||||||
min = data.ydata[i];
|
min = data.ydata[i];
|
||||||
if (data.ydata[i] > max)
|
if (data.ydata[i] > max)
|
||||||
max = data.ydata[i];
|
max = data.ydata[i];
|
||||||
}
|
}
|
||||||
emit dataConverted(series, QString::fromStdString(data.entityId), min, max);
|
emit dataConverted(QString::fromStdString(data.entityId), min, max);
|
||||||
}
|
}
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvertToSeries::setData(QLineSeries *series, const DataResult1D &data) {
|
/*void ConvertToSeries::setData(QLineSeries *series, const DataResult1D &data) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
this->series = series;
|
this->series = series;
|
||||||
this->data = data;
|
this->data = data;
|
||||||
this->dataPresent = true;
|
this->dataPresent = true;
|
||||||
mutex.unlock();
|
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;
|
bool dataPresent = false;
|
||||||
DataResult1D data;
|
DataResult1D data;
|
||||||
QLineSeries *series;
|
QLineSeries *series;
|
||||||
|
QVector<QPointF> *buffer;
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setData(QLineSeries *series, const DataResult1D &data);
|
void setData(QLineSeries *series, const DataResult1D &data);
|
||||||
|
void setData(QVector<QPointF> *buffer, const DataResult1D &data);
|
||||||
|
|
||||||
signals:
|
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++) {
|
for (vit = viewMap.begin(); vit != viewMap.end(); vit++) {
|
||||||
delete vit->second;
|
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;
|
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));
|
this->arrayMap.insert(std::pair<std::string, nix::DataArray>(array.id(), array));
|
||||||
ArrayInfo ai(array);
|
ArrayInfo ai(array);
|
||||||
this->infoMap.insert(std::pair<std::string, ArrayInfo*>(ai.arrayid, &ai));
|
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);
|
Chart* chart = createChart(ai);
|
||||||
ChartView *view = createChartView(chart, ai);
|
ChartView *view = createChartView(chart, ai);
|
||||||
|
|
||||||
@ -63,6 +69,7 @@ Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
|||||||
chart->setToolTip(QString::fromStdString(info.name));
|
chart->setToolTip(QString::fromStdString(info.name));
|
||||||
chart->legend()->hide();
|
chart->legend()->hide();
|
||||||
chart->createDefaultAxes();
|
chart->createDefaultAxes();
|
||||||
|
chart->entityId = info.arrayid;
|
||||||
|
|
||||||
QValueAxis *axisY = new QValueAxis;
|
QValueAxis *axisY = new QValueAxis;
|
||||||
axisY->setTickCount(10);
|
axisY->setTickCount(10);
|
||||||
@ -81,9 +88,9 @@ Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
|||||||
axisX->setLabelsFont(tickLabelFont);
|
axisX->setLabelsFont(tickLabelFont);
|
||||||
axisX->applyNiceNumbers();
|
axisX->applyNiceNumbers();
|
||||||
chart->setAxisX(axisX);
|
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));
|
this->chartMap.insert(std::pair<std::string, Chart*>(info.arrayid, chart));
|
||||||
return 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){
|
void MultiChartView::dataReady(QString requestId){
|
||||||
DataResult1D data = dataQueue->getData(requestId);
|
DataResult1D data = dataQueue->getData(requestId);
|
||||||
if (data.id.empty()) {
|
if (data.id.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ConvertToSeries *task = new ConvertToSeries();
|
ConvertToSeries *task = new ConvertToSeries();
|
||||||
QLineSeries *series = new QLineSeries();
|
task->setData(data_buffer[data.entityId], data);
|
||||||
task->setData(series, data);
|
connect(task, SIGNAL(dataConverted(QString, double, double)), this, SLOT(dataConverted(QString, double, double)));
|
||||||
connect(task, SIGNAL(dataConverted(QLineSeries*,QString, double, double)), this, SLOT(dataConverted(QLineSeries*,QString, double, double)));
|
|
||||||
QThreadPool::globalInstance()->start(task);
|
QThreadPool::globalInstance()->start(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiChartView::dataConverted(QLineSeries *series, QString entityId, double ymin, double ymax) {
|
void MultiChartView::dataConverted(QString entityId, double ymin, double ymax) {
|
||||||
Chart *chart = chartMap[entityId.toStdString()];
|
Chart *chart = chartMap[entityId.toStdString()];
|
||||||
series->setUseOpenGL(true);
|
QLineSeries *series;
|
||||||
chart->addSeries(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) {
|
if (chart->axisX()->type() == QAbstractAxis::AxisTypeValue) {
|
||||||
QValueAxis *axisX = static_cast<QValueAxis*>(chart->axisX());
|
QValueAxis *axisX = static_cast<QValueAxis*>(chart->axisX());
|
||||||
axisX->setRange(series->at(0).x(), series->at(series->count()-1).x());
|
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) {
|
if (chart->axisY()->type() == QAbstractAxis::AxisTypeValue) {
|
||||||
QValueAxis *axisY = static_cast<QValueAxis*>(chart->axisY());
|
QValueAxis *axisY = static_cast<QValueAxis*>(chart->axisY());
|
||||||
double range = ymax - ymin;
|
double range = ymax - ymin;
|
||||||
axisY->setRange(ymin - 0.2 * range, ymax + 0.2 * range);
|
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, Chart*> chartMap;
|
||||||
std::map<std::string, ChartView*> viewMap;
|
std::map<std::string, ChartView*> viewMap;
|
||||||
std::map<std::string, ArrayInfo*> infoMap;
|
std::map<std::string, ArrayInfo*> infoMap;
|
||||||
|
std::map<std::string, QVector<QPointF>*> data_buffer;
|
||||||
QFont labelFont, tickLabelFont;
|
QFont labelFont, tickLabelFont;
|
||||||
|
|
||||||
Chart* createChart(const ArrayInfo &info);
|
Chart* createChart(const ArrayInfo &info);
|
||||||
@ -120,8 +121,8 @@ private:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void dataReady(QString requestId);
|
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
|
#endif // MULTICHARTVIEW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user