summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-05-27 15:00:26 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-06-13 15:05:32 +0200
commit4059af81d33bb1f6a7773b77d3039f2fc53fcd23 (patch)
treec0308c515ef615133d58fd821847d0707706e40a
parente650ea323f5d7146caa020b69d22ace437609883 (diff)
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 <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/kernel/qvariant.cpp26
-rw-r--r--src/corelib/time/qdatetime.cpp20
-rw-r--r--src/gui/kernel/qpalette.cpp2
-rw-r--r--src/gui/painting/qdrawhelper.cpp6
4 files changed, 25 insertions, 29 deletions
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<time_t>::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<time_t>::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 <QPixelLayout::BPP bpp> static
inline uint QT_FASTCALL fetch1Pixel(const uchar *, int)