summaryrefslogtreecommitdiffstats
path: root/src/widgets/graphicsview
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/graphicsview')
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout.cpp10
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp25
-rw-r--r--src/widgets/graphicsview/qgraphicsanchorlayout_p.h53
3 files changed, 47 insertions, 41 deletions
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout.cpp
index 4f1855a606..b7c83e32a0 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout.cpp
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout.cpp
@@ -238,8 +238,8 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout()
d->removeCenterConstraints(this, QGraphicsAnchorLayoutPrivate::Vertical);
d->deleteLayoutEdges();
- Q_ASSERT(d->itemCenterConstraints[0].isEmpty());
- Q_ASSERT(d->itemCenterConstraints[1].isEmpty());
+ Q_ASSERT(d->itemCenterConstraints[Qt::Horizontal].isEmpty());
+ Q_ASSERT(d->itemCenterConstraints[Qt::Vertical].isEmpty());
Q_ASSERT(d->items.isEmpty());
Q_ASSERT(d->m_vertexList.isEmpty());
}
@@ -372,7 +372,7 @@ void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
- d->spacings[0] = spacing;
+ d->spacings[Qt::Horizontal] = spacing;
invalidate();
}
@@ -385,7 +385,7 @@ void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
- d->spacings[1] = spacing;
+ d->spacings[Qt::Vertical] = spacing;
invalidate();
}
@@ -404,7 +404,7 @@ void QGraphicsAnchorLayout::setSpacing(qreal spacing)
{
Q_D(QGraphicsAnchorLayout);
- d->spacings[0] = d->spacings[1] = spacing;
+ d->spacings = {spacing, spacing};
invalidate();
}
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
index 78549e4c24..9934255d25 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -621,19 +621,6 @@ QString GraphPath::toString() const
QGraphicsAnchorLayoutPrivate::QGraphicsAnchorLayoutPrivate()
: calculateGraphCacheDirty(true), styleInfoDirty(true)
{
- for (int i = 0; i < NOrientations; ++i) {
- for (int j = 0; j < 3; ++j) {
- sizeHints[i][j] = -1;
- }
- interpolationProgress[i] = -1;
-
- spacings[i] = -1;
- graphHasConflicts[i] = false;
-
- layoutFirstVertex[i] = nullptr;
- layoutCentralVertex[i] = nullptr;
- layoutLastVertex[i] = nullptr;
- }
}
Qt::AnchorPoint QGraphicsAnchorLayoutPrivate::oppositeEdge(Qt::AnchorPoint edge)
@@ -2032,8 +2019,8 @@ QLayoutStyleInfo &QGraphicsAnchorLayoutPrivate::styleInfo() const
QStyle *style = w ? w->style() : QApplication::style();
cachedStyleInfo = QLayoutStyleInfo(style, wid);
- cachedStyleInfo.setDefaultSpacing(Qt::Horizontal, spacings[0]);
- cachedStyleInfo.setDefaultSpacing(Qt::Vertical, spacings[1]);
+ cachedStyleInfo.setDefaultSpacing(Qt::Horizontal, spacings[Qt::Horizontal]);
+ cachedStyleInfo.setDefaultSpacing(Qt::Vertical, spacings[Qt::Vertical]);
styleInfoDirty = false;
}
@@ -2953,9 +2940,9 @@ bool QGraphicsAnchorLayoutPrivate::hasConflicts() const
QGraphicsAnchorLayoutPrivate *that = const_cast<QGraphicsAnchorLayoutPrivate*>(this);
that->calculateGraphs();
- bool floatConflict = !m_floatItems[0].isEmpty() || !m_floatItems[1].isEmpty();
+ bool floatConflict = !m_floatItems[Qt::Horizontal].isEmpty() || !m_floatItems[Qt::Vertical].isEmpty();
- return graphHasConflicts[0] || graphHasConflicts[1] || floatConflict;
+ return graphHasConflicts[Qt::Horizontal] || graphHasConflicts[Qt::Vertical] || floatConflict;
}
#ifdef QT_DEBUG
@@ -2966,8 +2953,8 @@ void QGraphicsAnchorLayoutPrivate::dumpGraph(const QString &name)
qWarning("Could not write to %ls", qUtf16Printable(file.fileName()));
QString str = QString::fromLatin1("digraph anchorlayout {\nnode [shape=\"rect\"]\n%1}");
- QString dotContents = graph[0].serializeToDot();
- dotContents += graph[1].serializeToDot();
+ QString dotContents = graph[Qt::Horizontal].serializeToDot();
+ dotContents += graph[Qt::Vertical].serializeToDot();
file.write(str.arg(dotContents).toLocal8Bit());
file.close();
diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.h b/src/widgets/graphicsview/qgraphicsanchorlayout_p.h
index e3f1d139b9..35211c0182 100644
--- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.h
@@ -60,6 +60,10 @@
#include "qgraph_p.h"
#include "qsimplex_p.h"
+#include <QtGui/private/qgridlayoutengine_p.h>
+
+#include <array>
+
QT_REQUIRE_CONFIG(graphicsview);
QT_BEGIN_NAMESPACE
@@ -395,7 +399,22 @@ public:
enum Orientation {
Horizontal = 0,
Vertical,
- NOrientations
+ };
+
+ template <typename T>
+ class QHVContainer : public QT_PREPEND_NAMESPACE(QHVContainer)<T>
+ {
+ using Base = QT_PREPEND_NAMESPACE(QHVContainer)<T>;
+ static constexpr Qt::Orientation map(Orientation o) noexcept
+ { return static_cast<Qt::Orientation>(int(o) + 1); }
+ public:
+ using Base::Base;
+ using Base::operator[];
+
+ constexpr const T &operator[](Orientation o) const noexcept
+ { return this->operator[](map(o)); }
+ constexpr T &operator[](Orientation o) noexcept
+ { return this->operator[](map(o)); }
};
QGraphicsAnchorLayoutPrivate();
@@ -552,9 +571,9 @@ public:
#endif
- qreal spacings[NOrientations];
+ QHVContainer<qreal> spacings = {-1, -1};
// Size hints from simplex engine
- qreal sizeHints[2][3];
+ QHVContainer<std::array<qreal, 3>> sizeHints = {{-1, -1, -1}, {-1, -1, -1}};
// Items
QVector<QGraphicsLayoutItem *> items;
@@ -565,31 +584,31 @@ public:
QHash<QPair<QGraphicsLayoutItem*, Qt::AnchorPoint>, QPair<AnchorVertex *, int> > m_vertexList;
// Internal graph of anchorage points and anchors, for both orientations
- Graph<AnchorVertex, AnchorData> graph[2];
+ QHVContainer<Graph<AnchorVertex, AnchorData>> graph;
- AnchorVertex *layoutFirstVertex[2];
- AnchorVertex *layoutCentralVertex[2];
- AnchorVertex *layoutLastVertex[2];
+ QHVContainer<AnchorVertex *> layoutFirstVertex = {};
+ QHVContainer<AnchorVertex *> layoutCentralVertex = {};
+ QHVContainer<AnchorVertex *> layoutLastVertex = {};
// Combined anchors in order of creation
- QList<AnchorVertexPair *> simplifiedVertices[2];
- QList<AnchorData *> anchorsFromSimplifiedVertices[2];
+ QHVContainer<QList<AnchorVertexPair *>> simplifiedVertices;
+ QHVContainer<QList<AnchorData *>> anchorsFromSimplifiedVertices;
// Graph paths and constraints, for both orientations
- QMultiHash<AnchorVertex *, GraphPath> graphPaths[2];
- QList<QSimplexConstraint *> constraints[2];
- QList<QSimplexConstraint *> itemCenterConstraints[2];
+ QHVContainer<QMultiHash<AnchorVertex *, GraphPath>> graphPaths;
+ QHVContainer<QList<QSimplexConstraint *>> constraints;
+ QHVContainer<QList<QSimplexConstraint *>> itemCenterConstraints;
// The interpolation interval and progress based on the current size
// as well as the key values (minimum, preferred and maximum)
- Interval interpolationInterval[2];
- qreal interpolationProgress[2];
+ QHVContainer<Interval> interpolationInterval;
+ QHVContainer<qreal> interpolationProgress = {-1, -1};
- bool graphHasConflicts[2];
- QSet<QGraphicsLayoutItem *> m_floatItems[2];
+ QHVContainer<bool> graphHasConflicts = {};
+ QHVContainer<QSet<QGraphicsLayoutItem *>> m_floatItems;
#if defined(QT_DEBUG) || defined(QT_BUILD_INTERNAL)
- bool lastCalculationUsedSimplex[2];
+ QHVContainer<bool> lastCalculationUsedSimplex;
#endif
uint calculateGraphCacheDirty : 1;