From af96dc62c8dac904fdb74ee0ba03690033fad429 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 5 May 2020 10:27:25 +0200 Subject: QGridLayoutEngine: port to QHVContainer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iadb069ecdf67d72fa1b3be9198e90eeda8e98d54 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Giuseppe D'Angelo --- src/gui/util/qgridlayoutengine_p.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/gui/util/qgridlayoutengine_p.h') diff --git a/src/gui/util/qgridlayoutengine_p.h b/src/gui/util/qgridlayoutengine_p.h index 872d1642e5..4c0ab1e56e 100644 --- a/src/gui/util/qgridlayoutengine_p.h +++ b/src/gui/util/qgridlayoutengine_p.h @@ -118,6 +118,10 @@ class QHVContainer { { return int(o) - 1; } + static constexpr int mapOther(Qt::Orientation o) noexcept + { + return 2 - int(o); + } public: constexpr QHVContainer(const T &h, const T &v) noexcept(std::is_nothrow_copy_constructible_v) @@ -127,6 +131,9 @@ public: constexpr T &operator[](Qt::Orientation o) noexcept { return m_data[map(o)]; } constexpr const T &operator[](Qt::Orientation o) const noexcept { return m_data[map(o)]; } + constexpr T &other(Qt::Orientation o) noexcept { return m_data[mapOther(o)]; } + constexpr const T &other(Qt::Orientation o) const noexcept { return m_data[mapOther(o)]; } + constexpr void transpose() noexcept { qSwap(m_data[0], m_data[1]); } constexpr QHVContainer transposed() const noexcept(std::is_nothrow_copy_constructible_v) @@ -375,8 +382,8 @@ public: int rowCount(Qt::Orientation orientation) const; int columnCount(Qt::Orientation orientation) const; - inline int rowCount() const { return q_infos[Ver].count; } - inline int columnCount() const { return q_infos[Hor].count; } + inline int rowCount() const { return q_infos[Qt::Vertical].count; } + inline int columnCount() const { return q_infos[Qt::Horizontal].count; } // returns the number of items inserted, which may be less than (rowCount * columnCount) int itemCount() const; QGridLayoutItem *itemAt(int index) const; @@ -472,8 +479,8 @@ protected: private: // User input QVector q_grid; - QLayoutParameter q_defaultSpacings[NOrientations]; - QGridLayoutRowInfo q_infos[NOrientations]; + QHVContainer> q_defaultSpacings; + QHVContainer q_infos; Qt::LayoutDirection m_visualDirection; // Configuration @@ -481,18 +488,18 @@ private: unsigned m_snapToPixelGrid : 1; // Lazily computed from the above user input - mutable int q_cachedEffectiveFirstRows[NOrientations]; - mutable int q_cachedEffectiveLastRows[NOrientations]; + mutable QHVContainer q_cachedEffectiveFirstRows; + mutable QHVContainer q_cachedEffectiveLastRows; mutable quint8 q_cachedConstraintOrientation : 3; // this is useful to cache - mutable QGridLayoutBox q_totalBoxes[NOrientations]; + mutable QHVContainer q_totalBoxes; enum { NotCached = -2, // Cache is empty. Happens when the engine is invalidated. CachedWithNoConstraint = -1 // cache has a totalBox without any HFW/WFH constraints. // >= 0 // cache has a totalBox with this specific constraint. }; - mutable qreal q_totalBoxCachedConstraints[NOrientations]; // holds the constraint used for the cached totalBox + mutable QHVContainer q_totalBoxCachedConstraints; // holds the constraint used for the cached totalBox // Layout item input mutable QGridLayoutRowData q_columnData; -- cgit v1.2.3