QCustomPlot: Fix build for Qt 6.0

This commit is contained in:
Nodir Temirkhodjaev 2020-05-13 16:06:50 +03:00
parent 7d99d09736
commit 01a66b0a6f
2 changed files with 27 additions and 18 deletions

View File

@ -1104,8 +1104,10 @@ void QCPLayer::setMode(QCPLayer::LayerMode mode)
if (mMode != mode) if (mMode != mode)
{ {
mMode = mode; mMode = mode;
if (!mPaintBuffer.isNull()) if (!mPaintBuffer.isNull()) {
mPaintBuffer.data()->setInvalidated(); auto paintBufferRef = mPaintBuffer.toStrongRef();
paintBufferRef.data()->setInvalidated();
}
} }
} }
@ -1142,14 +1144,15 @@ void QCPLayer::drawToPaintBuffer()
{ {
if (!mPaintBuffer.isNull()) if (!mPaintBuffer.isNull())
{ {
if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) auto paintBufferRef = mPaintBuffer.toStrongRef();
if (QCPPainter *painter = paintBufferRef.data()->startPainting())
{ {
if (painter->isActive()) if (painter->isActive())
draw(painter); draw(painter);
else else
qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter";
delete painter; delete painter;
mPaintBuffer.data()->donePainting(); paintBufferRef.data()->donePainting();
} else } else
qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter";
} else } else
@ -1175,9 +1178,10 @@ void QCPLayer::replot()
{ {
if (!mPaintBuffer.isNull()) if (!mPaintBuffer.isNull())
{ {
mPaintBuffer.data()->clear(Qt::transparent); auto paintBufferRef = mPaintBuffer.toStrongRef();
paintBufferRef.data()->clear(Qt::transparent);
drawToPaintBuffer(); drawToPaintBuffer();
mPaintBuffer.data()->setInvalidated(false); paintBufferRef.data()->setInvalidated(false);
mParentPlot->update(); mParentPlot->update();
} else } else
qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer";
@ -1203,8 +1207,10 @@ void QCPLayer::addChild(QCPLayerable *layerable, bool prepend)
mChildren.prepend(layerable); mChildren.prepend(layerable);
else else
mChildren.append(layerable); mChildren.append(layerable);
if (!mPaintBuffer.isNull()) if (!mPaintBuffer.isNull()) {
mPaintBuffer.data()->setInvalidated(); auto paintBufferRef = mPaintBuffer.toStrongRef();
paintBufferRef.data()->setInvalidated();
}
} else } else
qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast<quintptr>(layerable); qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast<quintptr>(layerable);
} }
@ -1222,8 +1228,10 @@ void QCPLayer::removeChild(QCPLayerable *layerable)
{ {
if (mChildren.removeOne(layerable)) if (mChildren.removeOne(layerable))
{ {
if (!mPaintBuffer.isNull()) if (!mPaintBuffer.isNull()) {
mPaintBuffer.data()->setInvalidated(); auto paintBufferRef = mPaintBuffer.toStrongRef();
paintBufferRef.data()->setInvalidated();
}
} else } else
qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast<quintptr>(layerable); qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast<quintptr>(layerable);
} }
@ -8932,9 +8940,9 @@ void QCPAxis::wheelEvent(QWheelEvent *event)
return; return;
} }
const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually const double wheelSteps = (orientation() == Qt::Horizontal ? event->angleDelta().x() : event->angleDelta().y()) / 120; // a single step delta is +/-120 usually
const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps);
scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->position().x() : event->position().y()));
mParentPlot->replot(); mParentPlot->replot();
} }
@ -14968,7 +14976,7 @@ void QCustomPlot::wheelEvent(QWheelEvent *event)
{ {
emit mouseWheel(event); emit mouseWheel(event);
// forward event to layerable under cursor: // forward event to layerable under cursor:
QList<QCPLayerable*> candidates = layerableListAt(event->pos(), false); QList<QCPLayerable*> candidates = layerableListAt(event->position(), false);
for (int i=0; i<candidates.size(); ++i) for (int i=0; i<candidates.size(); ++i)
{ {
event->accept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list event->accept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list
@ -15302,7 +15310,7 @@ void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event)
if (mInteractions.testFlag(QCP::iSelectPlottables)) if (mInteractions.testFlag(QCP::iSelectPlottables))
{ {
QMap<int, QPair<QCPAbstractPlottable*, QCPDataSelection> > potentialSelections; // map key is number of selected data points, so we have selections sorted by size QMultiMap<int, QPair<QCPAbstractPlottable*, QCPDataSelection> > potentialSelections; // map key is number of selected data points, so we have selections sorted by size
QRectF rectF(rect.normalized()); QRectF rectF(rect.normalized());
if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft()))
{ {
@ -17932,23 +17940,24 @@ void QCPAxisRect::wheelEvent(QWheelEvent *event)
if (mRangeZoom != 0) if (mRangeZoom != 0)
{ {
double factor; double factor;
double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
if (mRangeZoom.testFlag(Qt::Horizontal)) if (mRangeZoom.testFlag(Qt::Horizontal))
{ {
const double wheelSteps = event->angleDelta().x() / 120; // a single step delta is +/-120 usually
factor = qPow(mRangeZoomFactorHorz, wheelSteps); factor = qPow(mRangeZoomFactorHorz, wheelSteps);
for (int i=0; i<mRangeZoomHorzAxis.size(); ++i) for (int i=0; i<mRangeZoomHorzAxis.size(); ++i)
{ {
if (!mRangeZoomHorzAxis.at(i).isNull()) if (!mRangeZoomHorzAxis.at(i).isNull())
mRangeZoomHorzAxis.at(i)->scaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); mRangeZoomHorzAxis.at(i)->scaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->position().x()));
} }
} }
if (mRangeZoom.testFlag(Qt::Vertical)) if (mRangeZoom.testFlag(Qt::Vertical))
{ {
const double wheelSteps = event->angleDelta().y() / 120; // a single step delta is +/-120 usually
factor = qPow(mRangeZoomFactorVert, wheelSteps); factor = qPow(mRangeZoomFactorVert, wheelSteps);
for (int i=0; i<mRangeZoomVertAxis.size(); ++i) for (int i=0; i<mRangeZoomVertAxis.size(); ++i)
{ {
if (!mRangeZoomVertAxis.at(i).isNull()) if (!mRangeZoomVertAxis.at(i).isNull())
mRangeZoomVertAxis.at(i)->scaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); mRangeZoomVertAxis.at(i)->scaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->position().y()));
} }
} }
mParentPlot->replot(); mParentPlot->replot();

View File

@ -1762,7 +1762,7 @@ public:
protected: protected:
// property members: // property members:
QMap<double, QString> mTicks; QMultiMap<double, QString> mTicks;
int mSubTickCount; int mSubTickCount;
// reimplemented virtual methods: // reimplemented virtual methods: