diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-08-12 14:14:02 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-08-14 15:52:58 +0200 |
commit | 6f0df02d002356625f10683ef84da7685d92a2c4 (patch) | |
tree | 46713209af459ebda534c3404f48c5f5c80ba3f8 /src/widgets | |
parent | 44cce1a2ea9dadd8b2de93f40de34269dda703c0 (diff) |
Replace Qt CONSTEXPR defines with constexpr
Both normal and relaxed constexpr are required by our new minimum of
C++17.
Change-Id: Ic028b88a2e7a6cb7d5925f3133b9d54859a81744
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/itemviews/qlistview_p.h | 22 | ||||
-rw-r--r-- | src/widgets/kernel/qsizepolicy.h | 84 | ||||
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 6 | ||||
-rw-r--r-- | src/widgets/widgets/qcalendarwidget.cpp | 14 |
4 files changed, 46 insertions, 80 deletions
diff --git a/src/widgets/itemviews/qlistview_p.h b/src/widgets/itemviews/qlistview_p.h index 07f4ae4a90..cb41c87043 100644 --- a/src/widgets/itemviews/qlistview_p.h +++ b/src/widgets/itemviews/qlistview_p.h @@ -68,28 +68,28 @@ class QListViewItem friend class QListModeViewBase; friend class QIconModeViewBase; public: - Q_DECL_CONSTEXPR QListViewItem() + constexpr QListViewItem() : x(-1), y(-1), w(0), h(0), indexHint(-1), visited(0xffff) {} - Q_DECL_CONSTEXPR QListViewItem(QRect r, int i) + constexpr QListViewItem(QRect r, int i) : x(r.x()), y(r.y()), w(qMin(r.width(), SHRT_MAX)), h(qMin(r.height(), SHRT_MAX)), indexHint(i), visited(0xffff) {} - Q_DECL_CONSTEXPR bool operator==(const QListViewItem &other) const { + constexpr bool operator==(const QListViewItem &other) const { return (x == other.x && y == other.y && w == other.w && h == other.h && indexHint == other.indexHint); } - Q_DECL_CONSTEXPR bool operator!=(const QListViewItem &other) const + constexpr bool operator!=(const QListViewItem &other) const { return !(*this == other); } - Q_DECL_CONSTEXPR bool isValid() const + constexpr bool isValid() const { return rect().isValid() && (indexHint > -1); } - Q_DECL_RELAXED_CONSTEXPR void invalidate() + constexpr void invalidate() { x = -1; y = -1; w = 0; h = 0; } - Q_DECL_RELAXED_CONSTEXPR void resize(QSize size) + constexpr void resize(QSize size) { w = qMin(size.width(), SHRT_MAX); h = qMin(size.height(), SHRT_MAX); } - Q_DECL_RELAXED_CONSTEXPR void move(QPoint position) + constexpr void move(QPoint position) { x = position.x(); y = position.y(); } - Q_DECL_CONSTEXPR int width() const { return w; } - Q_DECL_CONSTEXPR int height() const { return h; } + constexpr int width() const { return w; } + constexpr int height() const { return h; } private: - Q_DECL_CONSTEXPR QRect rect() const + constexpr QRect rect() const { return QRect(x, y, w, h); } int x, y; short w, h; diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h index 245a3d069c..5056b91ea7 100644 --- a/src/widgets/kernel/qsizepolicy.h +++ b/src/widgets/kernel/qsizepolicy.h @@ -46,22 +46,6 @@ QT_BEGIN_NAMESPACE -// gcc < 4.8.0 has problems with init'ing variant members in constexpr ctors -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54922 -#if !defined(Q_CC_GNU) || defined(Q_CC_INTEL) || defined(Q_CC_CLANG) || Q_CC_GNU >= 408 -# define QT_SIZEPOLICY_CONSTEXPR Q_DECL_CONSTEXPR -# if defined(Q_COMPILER_UNIFORM_INIT) -# define QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT Q_DECL_CONSTEXPR -# endif // uniform-init -#endif - -#ifndef QT_SIZEPOLICY_CONSTEXPR -# define QT_SIZEPOLICY_CONSTEXPR -#endif -#ifndef QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT -# define QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT -#endif - class QVariant; class QSizePolicy; @@ -110,60 +94,47 @@ public: Q_DECLARE_FLAGS(ControlTypes, ControlType) Q_FLAG(ControlTypes) - QT_SIZEPOLICY_CONSTEXPR QSizePolicy() noexcept : data(0) { } + constexpr QSizePolicy() noexcept : data(0) { } -#if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_QDOC) - QT_SIZEPOLICY_CONSTEXPR QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType) noexcept + constexpr QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType) noexcept : bits{0, 0, quint32(horizontal), quint32(vertical), type == DefaultType ? 0 : toControlTypeFieldValue(type), 0, 0, 0} {} -#else - QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType) noexcept - : data(0) { - bits.horPolicy = horizontal; - bits.verPolicy = vertical; - setControlType(type); - } -#endif // uniform-init - QT_SIZEPOLICY_CONSTEXPR Policy horizontalPolicy() const noexcept { return static_cast<Policy>(bits.horPolicy); } - QT_SIZEPOLICY_CONSTEXPR Policy verticalPolicy() const noexcept { return static_cast<Policy>(bits.verPolicy); } + constexpr Policy horizontalPolicy() const noexcept { return static_cast<Policy>(bits.horPolicy); } + constexpr Policy verticalPolicy() const noexcept { return static_cast<Policy>(bits.verPolicy); } ControlType controlType() const noexcept; - Q_DECL_RELAXED_CONSTEXPR void setHorizontalPolicy(Policy d) noexcept { bits.horPolicy = d; } - Q_DECL_RELAXED_CONSTEXPR void setVerticalPolicy(Policy d) noexcept { bits.verPolicy = d; } + constexpr void setHorizontalPolicy(Policy d) noexcept { bits.horPolicy = d; } + constexpr void setVerticalPolicy(Policy d) noexcept { bits.verPolicy = d; } void setControlType(ControlType type) noexcept; - QT_SIZEPOLICY_CONSTEXPR Qt::Orientations expandingDirections() const noexcept { + constexpr Qt::Orientations expandingDirections() const noexcept { return ( (verticalPolicy() & ExpandFlag) ? Qt::Vertical : Qt::Orientations() ) | ( (horizontalPolicy() & ExpandFlag) ? Qt::Horizontal : Qt::Orientations() ) ; } - Q_DECL_RELAXED_CONSTEXPR void setHeightForWidth(bool b) noexcept { bits.hfw = b; } - QT_SIZEPOLICY_CONSTEXPR bool hasHeightForWidth() const noexcept { return bits.hfw; } - Q_DECL_RELAXED_CONSTEXPR void setWidthForHeight(bool b) noexcept { bits.wfh = b; } - QT_SIZEPOLICY_CONSTEXPR bool hasWidthForHeight() const noexcept { return bits.wfh; } + constexpr void setHeightForWidth(bool b) noexcept { bits.hfw = b; } + constexpr bool hasHeightForWidth() const noexcept { return bits.hfw; } + constexpr void setWidthForHeight(bool b) noexcept { bits.wfh = b; } + constexpr bool hasWidthForHeight() const noexcept { return bits.wfh; } - QT_SIZEPOLICY_CONSTEXPR bool operator==(const QSizePolicy& s) const noexcept { return data == s.data; } - QT_SIZEPOLICY_CONSTEXPR bool operator!=(const QSizePolicy& s) const noexcept { return data != s.data; } + constexpr bool operator==(const QSizePolicy& s) const noexcept { return data == s.data; } + constexpr bool operator!=(const QSizePolicy& s) const noexcept { return data != s.data; } friend Q_DECL_CONST_FUNCTION size_t qHash(QSizePolicy key, size_t seed) noexcept { return qHash(key.data, seed); } operator QVariant() const; - QT_SIZEPOLICY_CONSTEXPR int horizontalStretch() const noexcept { return static_cast<int>(bits.horStretch); } - QT_SIZEPOLICY_CONSTEXPR int verticalStretch() const noexcept { return static_cast<int>(bits.verStretch); } - Q_DECL_RELAXED_CONSTEXPR void setHorizontalStretch(int stretchFactor) { bits.horStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); } - Q_DECL_RELAXED_CONSTEXPR void setVerticalStretch(int stretchFactor) { bits.verStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); } + constexpr int horizontalStretch() const noexcept { return static_cast<int>(bits.horStretch); } + constexpr int verticalStretch() const noexcept { return static_cast<int>(bits.verStretch); } + constexpr void setHorizontalStretch(int stretchFactor) { bits.horStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); } + constexpr void setVerticalStretch(int stretchFactor) { bits.verStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); } - QT_SIZEPOLICY_CONSTEXPR bool retainSizeWhenHidden() const noexcept { return bits.retainSizeWhenHidden; } - Q_DECL_RELAXED_CONSTEXPR void setRetainSizeWhenHidden(bool retainSize) noexcept { bits.retainSizeWhenHidden = retainSize; } + constexpr bool retainSizeWhenHidden() const noexcept { return bits.retainSizeWhenHidden; } + constexpr void setRetainSizeWhenHidden(bool retainSize) noexcept { bits.retainSizeWhenHidden = retainSize; } - Q_DECL_RELAXED_CONSTEXPR void transpose() noexcept { *this = transposed(); } - Q_REQUIRED_RESULT -#ifndef Q_QDOC - QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT -#endif - QSizePolicy transposed() const noexcept + constexpr void transpose() noexcept { *this = transposed(); } + Q_REQUIRED_RESULT constexpr QSizePolicy transposed() const noexcept { return QSizePolicy(bits.transposed()); } @@ -173,11 +144,11 @@ private: friend Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &); friend Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &); #endif - QT_SIZEPOLICY_CONSTEXPR QSizePolicy(int i) noexcept : data(i) { } + constexpr QSizePolicy(int i) noexcept : data(i) { } struct Bits; - QT_SIZEPOLICY_CONSTEXPR explicit QSizePolicy(Bits b) noexcept : bits(b) { } + constexpr explicit QSizePolicy(Bits b) noexcept : bits(b) { } - static Q_DECL_RELAXED_CONSTEXPR quint32 toControlTypeFieldValue(ControlType type) noexcept + static constexpr quint32 toControlTypeFieldValue(ControlType type) noexcept { /* The control type is a flag type, with values 0x1, 0x2, 0x4, 0x8, 0x10, @@ -206,8 +177,7 @@ private: quint32 wfh : 1; quint32 retainSizeWhenHidden : 1; - QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT - Bits transposed() const noexcept + constexpr Bits transposed() const noexcept { return {verStretch, // \ swap horStretch, // / @@ -238,10 +208,6 @@ Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &); Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QSizePolicy &); #endif - -#undef QT_SIZEPOLICY_CONSTEXPR -#undef QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT - QT_END_NAMESPACE #endif // QSIZEPOLICY_H diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 1f1fc73727..bb646accf6 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -3194,9 +3194,9 @@ struct StaticPolygonF { QPointF data[N]; - Q_DECL_CONSTEXPR int size() const { return N; } - Q_DECL_CONSTEXPR const QPointF *cbegin() const { return data; } - Q_DECL_CONSTEXPR const QPointF &operator[](int idx) const { return data[idx]; } + constexpr int size() const { return N; } + constexpr const QPointF *cbegin() const { return data; } + constexpr const QPointF &operator[](int idx) const { return data[idx]; } }; static StaticPolygonF<3> calcArrow(const QStyleOptionSlider *dial, qreal &a) diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index be3d275375..68cd7e8451 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -426,7 +426,7 @@ QString QCalendarYearValidator::text(QDate date, QCalendar cal, int repeat) cons /////////////////////////////////// struct SectionToken { - Q_DECL_CONSTEXPR SectionToken(QCalendarDateSectionValidator *v, int rep) + constexpr SectionToken(QCalendarDateSectionValidator *v, int rep) : validator(v), repeat(rep) {} QCalendarDateSectionValidator *validator; @@ -826,9 +826,9 @@ class StaticDayOfWeekAssociativeArray { bool contained[7]; T data[7]; - static Q_DECL_CONSTEXPR int day2idx(Qt::DayOfWeek day) noexcept { return int(day) - 1; } // alt: day % 7 + static constexpr int day2idx(Qt::DayOfWeek day) noexcept { return int(day) - 1; } // alt: day % 7 public: - Q_DECL_CONSTEXPR StaticDayOfWeekAssociativeArray() noexcept(noexcept(T())) + constexpr StaticDayOfWeekAssociativeArray() noexcept(noexcept(T())) #ifdef Q_COMPILER_CONSTEXPR : contained{}, data{} // arrays require uniform initialization #else @@ -836,17 +836,17 @@ public: #endif {} - Q_DECL_CONSTEXPR bool contains(Qt::DayOfWeek day) const noexcept { return contained[day2idx(day)]; } - Q_DECL_CONSTEXPR const T &value(Qt::DayOfWeek day) const noexcept { return data[day2idx(day)]; } + constexpr bool contains(Qt::DayOfWeek day) const noexcept { return contained[day2idx(day)]; } + constexpr const T &value(Qt::DayOfWeek day) const noexcept { return data[day2idx(day)]; } - Q_DECL_RELAXED_CONSTEXPR T &operator[](Qt::DayOfWeek day) noexcept + constexpr T &operator[](Qt::DayOfWeek day) noexcept { const int idx = day2idx(day); contained[idx] = true; return data[idx]; } - Q_DECL_RELAXED_CONSTEXPR void insert(Qt::DayOfWeek day, T v) noexcept + constexpr void insert(Qt::DayOfWeek day, T v) noexcept { operator[](day).swap(v); } |