Qt: Fix QCustomPlot deprecation warnings.

Fix Qt 5.15 deprecation warnings in QCustomPlot, similar to 76d92ba7e7.

Use default flags constructors instead of 0.

Use QWheelEvent::angleDelta() instead of QWheelEvent::angle().

Use QWheelEvent::position() instead of QWheelEvent::pos().

Use date::startOfDay() instead of QDateTime(date).

Use QMultiMap instead of QMap where needed.
This commit is contained in:
Gerald Combs 2020-10-19 10:15:13 -07:00 committed by AndersBroman
parent fef3b86b38
commit 8b80b9111a
2 changed files with 32 additions and 14 deletions

View File

@ -1781,9 +1781,9 @@ void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &det
The current pixel position of the cursor on the QCustomPlot widget is accessible via \c
event->pos().
The \c event->delta() indicates how far the mouse wheel was turned, which is usually +/- 120 for
The \c event->angleDelta().y() indicates how far the mouse wheel was turned, which is usually +/- 120 for
single rotation steps. However, if the mouse wheel is turned rapidly, multiple steps may
accumulate to one event, making \c event->delta() larger. On the other hand, if the wheel has
accumulate to one event, making \c event->angleDelta().y() larger. On the other hand, if the wheel has
very smooth steps or none at all, the delta may be smaller.
The default implementation does nothing.
@ -4885,7 +4885,7 @@ Qt::Alignment QCPLayoutInset::insetAlignment(int index) const
else
{
qDebug() << Q_FUNC_INFO << "Invalid element index:" << index;
return 0;
return Qt::Alignment();
}
}
@ -6130,8 +6130,10 @@ double QCPAxisTickerDateTime::dateTimeToKey(const QDate date)
{
# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
return QDateTime(date).toTime_t();
# else
# elif QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
return QDateTime(date).toMSecsSinceEpoch()/1000.0;
# else
return date.startOfDay().toMSecsSinceEpoch()/1000.0;
# endif
}
/* end of 'src/axis/axistickerdatetime.cpp' */
@ -8922,10 +8924,14 @@ void QCPAxis::wheelEvent(QWheelEvent *event)
return;
}
const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
const double wheelSteps = event->angleDelta().y()/120.0; // a single step delta is +/-120 usually
const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y()));
#else
scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->position().x() : event->position().y()));
mParentPlot->replot();
#endif
}
/*! \internal
@ -12858,7 +12864,7 @@ QCustomPlot::QCustomPlot(QWidget *parent) :
mAutoAddPlottableToLegend(true),
mAntialiasedElements(QCP::aeNone),
mNotAntialiasedElements(QCP::aeNone),
mInteractions(0),
mInteractions(QCP::Interactions()),
mSelectionTolerance(8),
mNoAntialiasingOnDrag(false),
mBackgroundBrush(Qt::white, Qt::SolidPattern),
@ -14958,7 +14964,11 @@ void QCustomPlot::wheelEvent(QWheelEvent *event)
{
emit mouseWheel(event);
// forward event to layerable under cursor:
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QList<QCPLayerable*> candidates = layerableListAt(event->pos(), false);
#else
QList<QCPLayerable*> candidates = layerableListAt(event->position(), false);
#endif
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
@ -15292,7 +15302,7 @@ void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event)
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());
if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft()))
{
@ -15303,7 +15313,7 @@ void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event)
{
QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true);
if (!dataSel.isEmpty())
potentialSelections.insertMulti(dataSel.dataPointCount(), QPair<QCPAbstractPlottable*, QCPDataSelection>(plottable, dataSel));
potentialSelections.insert(dataSel.dataPointCount(), QPair<QCPAbstractPlottable*, QCPDataSelection>(plottable, dataSel));
}
}
@ -17908,8 +17918,8 @@ void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos)
dependent on the mouse wheel delta (which direction the wheel was rotated) to provide a natural
zooming feel. The Strength of the zoom can be controlled via \ref setRangeZoomFactor.
Note, that event->delta() is usually +/-120 for single rotation steps. However, if the mouse
wheel is turned rapidly, many steps may bunch up to one event, so the event->delta() may then be
Note, that event->angleDelta().y() is usually +/-120 for single rotation steps. However, if the mouse
wheel is turned rapidly, many steps may bunch up to one event, so the event->angleDelta().y() may then be
multiples of 120. This is taken into account here, by calculating \a wheelSteps and using it as
exponent of the range zoom factor. This takes care of the wheel direction automatically, by
inverting the factor, when the wheel step is negative (f^-1 = 1/f).
@ -17922,14 +17932,18 @@ void QCPAxisRect::wheelEvent(QWheelEvent *event)
if (mRangeZoom != 0)
{
double factor;
double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
double wheelSteps = event->angleDelta().y()/120.0; // a single step delta is +/-120 usually
if (mRangeZoom.testFlag(Qt::Horizontal))
{
factor = qPow(mRangeZoomFactorHorz, wheelSteps);
for (int i=0; i<mRangeZoomHorzAxis.size(); ++i)
{
if (!mRangeZoomHorzAxis.at(i).isNull())
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
mRangeZoomHorzAxis.at(i)->scaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x()));
#else
mRangeZoomHorzAxis.at(i)->scaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->position().x()));
#endif
}
}
if (mRangeZoom.testFlag(Qt::Vertical))
@ -17938,7 +17952,11 @@ void QCPAxisRect::wheelEvent(QWheelEvent *event)
for (int i=0; i<mRangeZoomVertAxis.size(); ++i)
{
if (!mRangeZoomVertAxis.at(i).isNull())
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
mRangeZoomVertAxis.at(i)->scaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y()));
#else
mRangeZoomVertAxis.at(i)->scaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->position().y()));
#endif
}
}
mParentPlot->replot();
@ -19578,7 +19596,7 @@ void QCPColorScale::setRangeDrag(bool enabled)
if (enabled)
mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType));
else
mAxisRect.data()->setRangeDrag(0);
mAxisRect.data()->setRangeDrag(Qt::Orientations());
}
/*!
@ -19598,7 +19616,7 @@ void QCPColorScale::setRangeZoom(bool enabled)
if (enabled)
mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType));
else
mAxisRect.data()->setRangeZoom(0);
mAxisRect.data()->setRangeZoom(Qt::Orientations());
}
/*!

View File

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