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/QGraphicsView>
|
||||
#include <QLineSeries>
|
||||
#include <QValueAxis>
|
||||
#include <iostream>
|
||||
#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);
|
||||
view.adjust(dwidth/2, dheight/2, -1.0 * dwidth/2, -1.0 * dheight/2);
|
||||
this->zoomIn(view);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Chart::XRangeChanged(qreal min, qreal max) {
|
||||
|
@ -3,8 +3,7 @@
|
||||
#include <QScrollBar>
|
||||
#include <iostream>
|
||||
ChartView::ChartView(QChart *chart, QWidget *parent) :
|
||||
QChartView(chart, parent),
|
||||
m_isTouching(false)
|
||||
QChartView(chart, parent)
|
||||
{
|
||||
setContentsMargins(0,0,0,0);
|
||||
}
|
||||
@ -23,7 +22,6 @@ void ChartView::mousePressEvent(QMouseEvent *event)
|
||||
void ChartView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
QPointF diff = mouseDownPos - event->localPos();
|
||||
qreal dx = event->localPos().x() - mouseDownPos.x();
|
||||
qreal dy = event->localPos().y() - mouseDownPos.y();
|
||||
mouseDownPos = event->localPos();
|
||||
@ -37,8 +35,6 @@ void ChartView::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
void ChartView::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton)
|
||||
mouseDown = false;
|
||||
QChartView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,6 @@ protected:
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
private:
|
||||
bool m_isTouching;
|
||||
bool mouseDown;
|
||||
QPointF mouseDownPos;
|
||||
};
|
||||
|
||||
|
@ -60,7 +60,6 @@ void MultiChartView::addArray(const nix::DataArray &array) {
|
||||
|
||||
Chart* MultiChartView::createChart(const ArrayInfo &info) {
|
||||
Chart *chart = new Chart();
|
||||
//chart->setTitle(QString::fromStdString(info.name));
|
||||
chart->setToolTip(QString::fromStdString(info.name));
|
||||
chart->legend()->hide();
|
||||
chart->createDefaultAxes();
|
||||
@ -82,6 +81,7 @@ 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)));
|
||||
|
||||
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) {
|
||||
Chart *chart = chartMap[entityId.toStdString()];
|
||||
Chart *chart = chartMap[entityId.toStdString()];
|
||||
series->setUseOpenGL(true);
|
||||
chart->addSeries(series);
|
||||
|
||||
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 (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);
|
||||
}
|
||||
|
||||
QPen pen = series->pen();
|
||||
|
Loading…
Reference in New Issue
Block a user