summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-07 11:20:39 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-07 14:19:43 (GMT)
commitfd99d512fdb3864fe750015916b8e6a2a27401c2 (patch)
tree961b4064976b68a042834caf92c335a6f9c56601
parentdde11ce47c2d83bae685f3ff032ee9e6e372058f (diff)
downloadQt-fd99d512fdb3864fe750015916b8e6a2a27401c2.zip
Qt-fd99d512fdb3864fe750015916b8e6a2a27401c2.tar.gz
Qt-fd99d512fdb3864fe750015916b8e6a2a27401c2.tar.bz2
Store the floating items instead of the non-floating items.
Makes the code a bit easier to read and speeds up setItemsGeometries() in the normal use-case.
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp41
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.h6
2 files changed, 26 insertions, 21 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index 34071cc..296930c 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -2008,14 +2008,20 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation)
Use all visited Anchors on findPaths() so we can identify non-float Items.
*/
-void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems(QSet<AnchorData *> visited, Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems(const QSet<AnchorData *> &visited, Orientation orientation)
{
- m_nonFloatItems[orientation].clear();
+ QSet<QGraphicsLayoutItem *> nonFloating;
foreach (const AnchorData *ad, visited)
- identifyNonFloatItems_helper(ad, orientation);
+ identifyNonFloatItems_helper(ad, &nonFloating);
+
+ QSet<QGraphicsLayoutItem *> allItems;
+ foreach (QGraphicsLayoutItem *item, items)
+ allItems.insert(item);
+ m_floatItems[orientation] = allItems - nonFloating;
}
+
/*!
\internal
@@ -2023,22 +2029,22 @@ void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems(QSet<AnchorData *> visi
If the anchor is Sequential or Parallel, we must iterate on its children recursively until we reach
internal anchors (items).
*/
-void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems_helper(const AnchorData *ad, Orientation orientation)
+void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems_helper(const AnchorData *ad, QSet<QGraphicsLayoutItem *> *nonFloatingItemsIdentifiedSoFar)
{
Q_Q(QGraphicsAnchorLayout);
switch(ad->type) {
case AnchorData::Normal:
if (ad->from->m_item == ad->to->m_item && ad->to->m_item != q)
- m_nonFloatItems[orientation].insert(ad->to->m_item);
+ nonFloatingItemsIdentifiedSoFar->insert(ad->to->m_item);
break;
case AnchorData::Sequential:
foreach (const AnchorData *d, static_cast<const SequentialAnchorData *>(ad)->m_edges)
- identifyNonFloatItems_helper(d, orientation);
+ identifyNonFloatItems_helper(d, nonFloatingItemsIdentifiedSoFar);
break;
case AnchorData::Parallel:
- identifyNonFloatItems_helper(static_cast<const ParallelAnchorData *>(ad)->firstEdge, orientation);
- identifyNonFloatItems_helper(static_cast<const ParallelAnchorData *>(ad)->secondEdge, orientation);
+ identifyNonFloatItems_helper(static_cast<const ParallelAnchorData *>(ad)->firstEdge, nonFloatingItemsIdentifiedSoFar);
+ identifyNonFloatItems_helper(static_cast<const ParallelAnchorData *>(ad)->secondEdge, nonFloatingItemsIdentifiedSoFar);
break;
}
}
@@ -2070,7 +2076,10 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom)
foreach (QGraphicsLayoutItem *item, items) {
QRectF newGeom;
QSizeF itemPreferredSize = item->effectiveSizeHint(Qt::PreferredSize);
- if (m_nonFloatItems[Horizontal].contains(item)) {
+ if (m_floatItems[Horizontal].contains(item)) {
+ newGeom.setLeft(0);
+ newGeom.setRight(itemPreferredSize.width());
+ } else {
firstH = internalVertex(item, Qt::AnchorLeft);
secondH = internalVertex(item, Qt::AnchorRight);
@@ -2081,20 +2090,17 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom)
newGeom.setLeft(right - secondH->distance);
newGeom.setRight(right - firstH->distance);
}
- } else {
- newGeom.setLeft(0);
- newGeom.setRight(itemPreferredSize.width());
}
- if (m_nonFloatItems[Vertical].contains(item)) {
+ if (m_floatItems[Vertical].contains(item)) {
+ newGeom.setTop(0);
+ newGeom.setBottom(itemPreferredSize.height());
+ } else {
firstV = internalVertex(item, Qt::AnchorTop);
secondV = internalVertex(item, Qt::AnchorBottom);
newGeom.setTop(top + firstV->distance);
newGeom.setBottom(top + secondV->distance);
- } else {
- newGeom.setTop(0);
- newGeom.setBottom(itemPreferredSize.height());
}
item->setGeometry(newGeom);
@@ -2554,8 +2560,7 @@ bool QGraphicsAnchorLayoutPrivate::hasConflicts() const
QGraphicsAnchorLayoutPrivate *that = const_cast<QGraphicsAnchorLayoutPrivate*>(this);
that->calculateGraphs();
- bool floatConflict = (m_nonFloatItems[0].size() < items.size())
- || (m_nonFloatItems[1].size() < items.size());
+ bool floatConflict = !m_floatItems[0].isEmpty() || !m_floatItems[1].isEmpty();
return graphHasConflicts[0] || graphHasConflicts[1] || floatConflict;
}
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
index 24b25de..0f045e5 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
@@ -443,8 +443,8 @@ public:
void constraintsFromPaths(Orientation orientation);
QList<QSimplexConstraint *> constraintsFromSizeHints(const QList<AnchorData *> &anchors);
QList<QList<QSimplexConstraint *> > getGraphParts(Orientation orientation);
- void identifyNonFloatItems(QSet<AnchorData *> visited, Orientation orientation);
- void identifyNonFloatItems_helper(const AnchorData *ad, Orientation orientation);
+ void identifyNonFloatItems(const QSet<AnchorData *> &visited, Orientation orientation);
+ void identifyNonFloatItems_helper(const AnchorData *ad, QSet<QGraphicsLayoutItem *> *nonFloatingItemsIdentifiedSoFar);
inline AnchorVertex *internalVertex(const QPair<QGraphicsLayoutItem*, Qt::AnchorPoint> &itemEdge) const
{
@@ -511,7 +511,7 @@ public:
// ###
bool graphSimplified[2];
bool graphHasConflicts[2];
- QSet<QGraphicsLayoutItem *> m_nonFloatItems[2];
+ QSet<QGraphicsLayoutItem *> m_floatItems[2];
uint calculateGraphCacheDirty : 1;
};