attach series to axis to have updates on scrolling
This commit is contained in:
parent
8ad8af67b7
commit
d61ced8498
@ -3,6 +3,7 @@
|
|||||||
#include <QtWidgets/QGraphicsScene>
|
#include <QtWidgets/QGraphicsScene>
|
||||||
#include <QtWidgets/QGraphicsView>
|
#include <QtWidgets/QGraphicsView>
|
||||||
#include <QLineSeries>
|
#include <QLineSeries>
|
||||||
|
#include <QValueAxis>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QGraphicsSceneEvent>
|
#include <QGraphicsSceneEvent>
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ bool Chart::myWheelEvent(QGraphicsSceneWheelEvent *event) {
|
|||||||
qreal dheight = view.height() * (scale_x ? 0.0 : (in ? -1.0 : 1.0) * zoom/2);
|
qreal dheight = view.height() * (scale_x ? 0.0 : (in ? -1.0 : 1.0) * zoom/2);
|
||||||
view.adjust(dwidth/2, dheight/2, -1.0 * dwidth/2, -1.0 * dheight/2);
|
view.adjust(dwidth/2, dheight/2, -1.0 * dwidth/2, -1.0 * dheight/2);
|
||||||
this->zoomIn(view);
|
this->zoomIn(view);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chart::XRangeChanged(qreal min, qreal max) {
|
void Chart::XRangeChanged(qreal min, qreal max) {
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
ChartView::ChartView(QChart *chart, QWidget *parent) :
|
ChartView::ChartView(QChart *chart, QWidget *parent) :
|
||||||
QChartView(chart, parent),
|
QChartView(chart, parent)
|
||||||
m_isTouching(false)
|
|
||||||
{
|
{
|
||||||
setContentsMargins(0,0,0,0);
|
setContentsMargins(0,0,0,0);
|
||||||
}
|
}
|
||||||
@ -23,7 +22,6 @@ void ChartView::mousePressEvent(QMouseEvent *event)
|
|||||||
void ChartView::mouseMoveEvent(QMouseEvent *event)
|
void ChartView::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->buttons() & Qt::LeftButton) {
|
if (event->buttons() & Qt::LeftButton) {
|
||||||
QPointF diff = mouseDownPos - event->localPos();
|
|
||||||
qreal dx = event->localPos().x() - mouseDownPos.x();
|
qreal dx = event->localPos().x() - mouseDownPos.x();
|
||||||
qreal dy = event->localPos().y() - mouseDownPos.y();
|
qreal dy = event->localPos().y() - mouseDownPos.y();
|
||||||
mouseDownPos = event->localPos();
|
mouseDownPos = event->localPos();
|
||||||
@ -37,8 +35,6 @@ void ChartView::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void ChartView::mouseReleaseEvent(QMouseEvent *event)
|
void ChartView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->buttons() & Qt::LeftButton)
|
|
||||||
mouseDown = false;
|
|
||||||
QChartView::mouseReleaseEvent(event);
|
QChartView::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,6 @@ protected:
|
|||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isTouching;
|
|
||||||
bool mouseDown;
|
|
||||||
QPointF mouseDownPos;
|
QPointF mouseDownPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ void MultiChartView::addArray(const nix::DataArray &array) {
|
|||||||
|
|
||||||
Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
||||||
Chart *chart = new Chart();
|
Chart *chart = new Chart();
|
||||||
//chart->setTitle(QString::fromStdString(info.name));
|
|
||||||
chart->setToolTip(QString::fromStdString(info.name));
|
chart->setToolTip(QString::fromStdString(info.name));
|
||||||
chart->legend()->hide();
|
chart->legend()->hide();
|
||||||
chart->createDefaultAxes();
|
chart->createDefaultAxes();
|
||||||
@ -82,6 +81,7 @@ 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)));
|
||||||
|
|
||||||
this->chartMap.insert(std::pair<std::string, Chart*>(info.arrayid, chart));
|
this->chartMap.insert(std::pair<std::string, Chart*>(info.arrayid, chart));
|
||||||
@ -126,18 +126,20 @@ void MultiChartView::dataReady(QString requestId){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MultiChartView::dataConverted(QLineSeries *series, QString entityId, double ymin, double ymax) {
|
void MultiChartView::dataConverted(QLineSeries *series, QString entityId, double ymin, double ymax) {
|
||||||
Chart *chart = chartMap[entityId.toStdString()];
|
Chart *chart = chartMap[entityId.toStdString()];
|
||||||
series->setUseOpenGL(true);
|
series->setUseOpenGL(true);
|
||||||
chart->addSeries(series);
|
chart->addSeries(series);
|
||||||
|
|
||||||
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 (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);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPen pen = series->pen();
|
QPen pen = series->pen();
|
||||||
|
Loading…
Reference in New Issue
Block a user