From 4059af81d33bb1f6a7773b77d3039f2fc53fcd23 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 27 May 2021 15:00:26 +0200 Subject: Stop using mixed enum arithmetic It's deprecated. Port some unnamed enumerations (used only to declare constants) to constexpr integers instead. Apply qToUnderlying as needed. Task-number: QTBUG-94059 Change-Id: Ifaa64ece966ce08df40dc71ffcfa7ac038110e0b Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/kernel/qvariant.cpp | 26 +++++++++++++------------- src/corelib/time/qdatetime.cpp | 20 +++++++++----------- src/gui/kernel/qpalette.cpp | 2 +- src/gui/painting/qdrawhelper.cpp | 6 ++---- 4 files changed, 25 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 0c58d0b314..c16e669c2c 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1155,17 +1155,17 @@ static const ushort mapIdFromQt3ToCurrent[MapFromThreeCount] = #endif }; -// enum values needed to map Qt5 based type id's to Qt6 based ones -enum Qt5Types { - Qt5UserType = 1024, - Qt5LastCoreType = QMetaType::QCborMap, - Qt5FirstGuiType = 64, - Qt5LastGuiType = 87, - Qt5SizePolicy = 121, - Qt5RegExp = 27, - Qt5KeySequence = 75, - Qt5QQuaternion = 85 -}; +// values needed to map Qt5 based type id's to Qt6 based ones +constexpr int Qt5UserType = 1024; +constexpr int Qt5LastCoreType = QMetaType::QCborMap; +constexpr int Qt5FirstGuiType = 64; +constexpr int Qt5LastGuiType = 87; +constexpr int Qt5SizePolicy = 121; +constexpr int Qt5RegExp = 27; +constexpr int Qt5KeySequence = 75; +constexpr int Qt5QQuaternion = 85; + +constexpr int Qt6ToQt5GuiTypeDelta = qToUnderlying(QMetaType::FirstGuiType) - Qt5FirstGuiType; /*! Internal function for loading a variant from stream \a s. Use the @@ -1205,7 +1205,7 @@ void QVariant::load(QDataStream &s) if (typeId == Qt5UserType) { typeId = QMetaType::User; } else if (typeId >= Qt5FirstGuiType && typeId <= Qt5LastGuiType) { - typeId += QMetaType::FirstGuiType - Qt5FirstGuiType; + typeId += Qt6ToQt5GuiTypeDelta; } else if (typeId == Qt5SizePolicy) { typeId = QMetaType::QSizePolicy; } else if (typeId == Qt5RegExp) { @@ -1273,7 +1273,7 @@ void QVariant::save(QDataStream &s) const typeId = Qt5UserType; saveAsUserType = true; } else if (typeId >= QMetaType::FirstGuiType && typeId <= QMetaType::LastGuiType) { - typeId -= QMetaType::FirstGuiType - Qt5FirstGuiType; + typeId -= Qt6ToQt5GuiTypeDelta; if (typeId > Qt5LastGuiType) { typeId = Qt5UserType; saveAsUserType = true; diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 319385bb1d..564eeccf6f 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -76,17 +76,15 @@ QT_BEGIN_NAMESPACE Date/Time Constants *****************************************************************************/ -enum : qint64 { - SECS_PER_DAY = 86400, - MSECS_PER_DAY = 86400000, - SECS_PER_HOUR = 3600, - MSECS_PER_HOUR = 3600000, - SECS_PER_MIN = 60, - MSECS_PER_MIN = 60000, - MSECS_PER_SEC = 1000, - TIME_T_MAX = std::numeric_limits::max(), - JULIAN_DAY_FOR_EPOCH = 2440588 // result of julianDayFromDate(1970, 1, 1) -}; +constexpr qint64 SECS_PER_DAY = 86400; +constexpr qint64 MSECS_PER_DAY = 86400000; +constexpr qint64 SECS_PER_HOUR = 3600; +constexpr qint64 MSECS_PER_HOUR = 3600000; +constexpr qint64 SECS_PER_MIN = 60; +constexpr qint64 MSECS_PER_MIN = 60000; +constexpr qint64 MSECS_PER_SEC = 1000; +constexpr qint64 TIME_T_MAX = std::numeric_limits::max(); +constexpr qint64 JULIAN_DAY_FOR_EPOCH = 2440588; // result of julianDayFromDate(1970, 1, 1) /***************************************************************************** QDate static helper functions diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 43521e1182..b313d545a5 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -52,7 +52,7 @@ static int qt_palette_count = 1; static constexpr QPalette::ResolveMask colorRoleOffset(QPalette::ColorGroup colorGroup) { - return QPalette::NColorRoles * colorGroup; + return qToUnderlying(QPalette::NColorRoles) * qToUnderlying(colorGroup); } static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGroup, diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index eb01487743..06eb08ea9c 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -71,10 +71,8 @@ Q_LOGGING_CATEGORY(lcQtGuiDrawHelper, "qt.gui.drawhelper") constants and structures */ -enum { - fixed_scale = 1 << 16, - half_point = 1 << 15 -}; +constexpr int fixed_scale = 1 << 16; +constexpr int half_point = 1 << 15; template static inline uint QT_FASTCALL fetch1Pixel(const uchar *, int) -- cgit v1.2.3