diff options
Diffstat (limited to 'src/widgets/kernel/qsizepolicy.h')
-rw-r--r-- | src/widgets/kernel/qsizepolicy.h | 78 |
1 files changed, 63 insertions, 15 deletions
diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h index 63b578fbf3..80bc8eacdb 100644 --- a/src/widgets/kernel/qsizepolicy.h +++ b/src/widgets/kernel/qsizepolicy.h @@ -45,6 +45,29 @@ 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 +# if defined(Q_COMPILER_CONSTEXPR) +# define QT_SIZEPOLICY_RETURN_BITS(E1, E2, E3, E4, E5, E6, E7, E8) \ + return Bits{ E1, E2, E3, E4, E5, E6, E7, E8 } +# endif // constexpr && uniform-init +# 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 +#ifndef QT_SIZEPOLICY_RETURN_BITS +# define QT_SIZEPOLICY_RETURN_BITS(E1, E2, E3, E4, E5, E6, E7, E8) \ + const Bits result = { E1, E2, E3, E4, E5, E6, E7, E8 }; return result +#endif class QVariant; class QSizePolicy; @@ -54,7 +77,6 @@ Q_DECL_CONST_FUNCTION inline uint qHash(QSizePolicy key, uint seed = 0) Q_DECL_N class Q_WIDGETS_EXPORT QSizePolicy { Q_GADGET - Q_FLAGS(ControlTypes) public: enum PolicyFlag { @@ -93,8 +115,9 @@ public: ToolButton = 0x00004000 }; Q_DECLARE_FLAGS(ControlTypes, ControlType) + Q_FLAG(ControlTypes) - QSizePolicy() : data(0) { } + QT_SIZEPOLICY_CONSTEXPR QSizePolicy() : data(0) { } QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType) : data(0) { @@ -102,48 +125,56 @@ public: bits.verPolicy = vertical; setControlType(type); } - Policy horizontalPolicy() const { return static_cast<Policy>(bits.horPolicy); } - Policy verticalPolicy() const { return static_cast<Policy>(bits.verPolicy); } + QT_SIZEPOLICY_CONSTEXPR Policy horizontalPolicy() const { return static_cast<Policy>(bits.horPolicy); } + QT_SIZEPOLICY_CONSTEXPR Policy verticalPolicy() const { return static_cast<Policy>(bits.verPolicy); } ControlType controlType() const; void setHorizontalPolicy(Policy d) { bits.horPolicy = d; } void setVerticalPolicy(Policy d) { bits.verPolicy = d; } void setControlType(ControlType type); - Qt::Orientations expandingDirections() const { + QT_SIZEPOLICY_CONSTEXPR Qt::Orientations expandingDirections() const { return ( (verticalPolicy() & ExpandFlag) ? Qt::Vertical : Qt::Orientations() ) | ( (horizontalPolicy() & ExpandFlag) ? Qt::Horizontal : Qt::Orientations() ) ; } - void setHeightForWidth(bool b) { bits.hfw = b; } - bool hasHeightForWidth() const { return bits.hfw; } + void setHeightForWidth(bool b) { bits.hfw = b; } + QT_SIZEPOLICY_CONSTEXPR bool hasHeightForWidth() const { return bits.hfw; } void setWidthForHeight(bool b) { bits.wfh = b; } - bool hasWidthForHeight() const { return bits.wfh; } + QT_SIZEPOLICY_CONSTEXPR bool hasWidthForHeight() const { return bits.wfh; } - bool operator==(const QSizePolicy& s) const { return data == s.data; } - bool operator!=(const QSizePolicy& s) const { return data != s.data; } + QT_SIZEPOLICY_CONSTEXPR bool operator==(const QSizePolicy& s) const { return data == s.data; } + QT_SIZEPOLICY_CONSTEXPR bool operator!=(const QSizePolicy& s) const { return data != s.data; } friend Q_DECL_CONST_FUNCTION uint qHash(QSizePolicy key, uint seed) Q_DECL_NOTHROW { return qHash(key.data, seed); } operator QVariant() const; - int horizontalStretch() const { return static_cast<int>(bits.horStretch); } - int verticalStretch() const { return static_cast<int>(bits.verStretch); } + QT_SIZEPOLICY_CONSTEXPR int horizontalStretch() const { return static_cast<int>(bits.horStretch); } + QT_SIZEPOLICY_CONSTEXPR int verticalStretch() const { return static_cast<int>(bits.verStretch); } void setHorizontalStretch(int stretchFactor) { bits.horStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); } void setVerticalStretch(int stretchFactor) { bits.verStretch = static_cast<quint32>(qBound(0, stretchFactor, 255)); } - bool retainSizeWhenHidden() const { return bits.retainSizeWhenHidden; } + QT_SIZEPOLICY_CONSTEXPR bool retainSizeWhenHidden() const { return bits.retainSizeWhenHidden; } void setRetainSizeWhenHidden(bool retainSize) { bits.retainSizeWhenHidden = retainSize; } void transpose(); - +#ifndef Q_QDOC + QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT +#endif + QSizePolicy transposed() const Q_DECL_NOTHROW Q_REQUIRED_RESULT + { + return QSizePolicy(bits.transposed()); + } private: #ifndef QT_NO_DATASTREAM friend Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &, const QSizePolicy &); friend Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &, QSizePolicy &); #endif - QSizePolicy(int i) : data(i) { } + QT_SIZEPOLICY_CONSTEXPR QSizePolicy(int i) : data(i) { } + struct Bits; + QT_SIZEPOLICY_CONSTEXPR explicit QSizePolicy(Bits b) Q_DECL_NOTHROW : bits(b) { } struct Bits { quint32 horStretch : 8; @@ -154,6 +185,19 @@ private: quint32 hfw : 1; quint32 wfh : 1; quint32 retainSizeWhenHidden : 1; + + QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT + Bits transposed() const Q_DECL_NOTHROW + { + QT_SIZEPOLICY_RETURN_BITS(verStretch, // \ swap + horStretch, // / + verPolicy, // \ swap + horPolicy, // / + ctype, + hfw, // \ don't swap (historic behavior) + wfh, // / + retainSizeWhenHidden); + } }; union { Bits bits; @@ -187,6 +231,10 @@ inline void QSizePolicy::transpose() { setVerticalStretch(hStretch); } +#undef QT_SIZEPOLICY_CONSTEXPR +#undef QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT +#undef QT_SIZEPOLICY_RETURN_BITS + QT_END_NAMESPACE #endif // QSIZEPOLICY_H |