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>
This commit is contained in:
Giuseppe D'Angelo 2021-05-27 15:00:26 +02:00
parent e650ea323f
commit 4059af81d3
4 changed files with 25 additions and 29 deletions

View File

@ -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;

View File

@ -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

View File

@ -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,

View File

@ -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)