summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriano Rezende <adriano.rezende@openbossa.org>2011-11-21 02:41:32 -0800
committerJens Bache-Wiig <jens.bache-wiig@nokia.com>2011-11-21 02:41:32 -0800
commit91d9fb83f9a099e16a1ec7a74a48bb4aee54c30b (patch)
treed86684382b3f0fcf2ff29efdd9f230a3626e8802
parent259ee64d44a3015acb85dbe8f2690850f7f79e12 (diff)
downloadqtquickcontrols-91d9fb83f9a099e16a1ec7a74a48bb4aee54c30b.tar.gz
Merge layout requests to avoid unnecessary recalculations
It improves the layout performance by avoiding intermediate recalculations, merging all requests into a single one. Signed-off-by: Adriano Rezende <adriano.rezende@openbossa.org> Merge-request: 12 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@nokia.com>
-rw-r--r--src/qdeclarativelayout.cpp55
-rw-r--r--src/qdeclarativelayout.h7
-rw-r--r--src/qdeclarativelinearlayout.cpp19
-rw-r--r--src/qdeclarativelinearlayout.h1
4 files changed, 67 insertions, 15 deletions
diff --git a/src/qdeclarativelayout.cpp b/src/qdeclarativelayout.cpp
index ae675e17..64af622e 100644
--- a/src/qdeclarativelayout.cpp
+++ b/src/qdeclarativelayout.cpp
@@ -38,6 +38,8 @@
****************************************************************************/
#include "qdeclarativelayout.h"
+#include <QEvent>
+#include <QApplication>
#include <QtCore/qnumeric.h>
@@ -117,7 +119,8 @@ void QDeclarativeLayoutAttached::updateLayout()
QDeclarativeLayout::QDeclarativeLayout(QDeclarativeItem *parent)
- : QDeclarativeItem(parent)
+ : QDeclarativeItem(parent),
+ m_dirty(false)
{
}
@@ -138,3 +141,53 @@ QDeclarativeLayoutAttached *QDeclarativeLayout::qmlAttachedProperties(QObject *o
{
return new QDeclarativeLayoutAttached(object);
}
+
+bool QDeclarativeLayout::event(QEvent *e)
+{
+ if (e->type() == QEvent::LayoutRequest)
+ reconfigureTopDown();
+
+ return QDeclarativeItem::event(e);
+}
+
+void QDeclarativeLayout::invalidate()
+{
+ if (m_dirty)
+ return;
+
+ QDeclarativeLayout *layout = this;
+ QDeclarativeLayout *parentLayout = 0;
+
+ while (layout) {
+ layout->m_dirty = true;
+ parentLayout = qobject_cast<QDeclarativeLayout *>(layout->parentItem());
+
+ if (!parentLayout)
+ break;
+ else
+ layout = parentLayout;
+ }
+
+ QApplication::postEvent(layout, new QEvent(QEvent::LayoutRequest));
+}
+
+void QDeclarativeLayout::reconfigureTopDown()
+{
+ const QList<QGraphicsItem *> &children = childItems();
+
+ foreach (QGraphicsItem *child, children) {
+ QGraphicsObject *obj = child->toGraphicsObject();
+ QDeclarativeLayout *layout = obj ? qobject_cast<QDeclarativeLayout *>(obj) : 0;
+
+ if (layout && layout->m_dirty)
+ layout->reconfigureTopDown();
+ }
+
+ reconfigureLayout();
+ m_dirty = false;
+}
+
+void QDeclarativeLayout::reconfigureLayout()
+{
+
+}
diff --git a/src/qdeclarativelayout.h b/src/qdeclarativelayout.h
index 4abcd481..c5a8b470 100644
--- a/src/qdeclarativelayout.h
+++ b/src/qdeclarativelayout.h
@@ -63,10 +63,15 @@ public:
static QDeclarativeLayoutAttached *qmlAttachedProperties(QObject *object);
protected:
- virtual void invalidate() = 0;
+ void invalidate();
+ bool event(QEvent *e);
+ void reconfigureTopDown();
+ virtual void reconfigureLayout();
void setupItemLayout(QDeclarativeItem *item);
private:
+ bool m_dirty;
+
friend class QDeclarativeLayoutAttached;
};
diff --git a/src/qdeclarativelinearlayout.cpp b/src/qdeclarativelinearlayout.cpp
index 399d27f5..b28838a6 100644
--- a/src/qdeclarativelinearlayout.cpp
+++ b/src/qdeclarativelinearlayout.cpp
@@ -64,7 +64,7 @@ void QDeclarativeLinearLayout::setSpacing(qreal spacing)
return;
m_spacing = spacing;
- reconfigureLayout();
+ invalidate();
}
QDeclarativeLinearLayout::Orientation QDeclarativeLinearLayout::orientation() const
@@ -78,7 +78,7 @@ void QDeclarativeLinearLayout::setOrientation(Orientation orientation)
return;
m_orientation = orientation;
- reconfigureLayout();
+ invalidate();
emit orientationChanged();
}
@@ -87,7 +87,7 @@ void QDeclarativeLinearLayout::componentComplete()
{
QDeclarativeLayout::componentComplete();
updateLayoutItems();
- reconfigureLayout();
+ invalidate();
}
void QDeclarativeLinearLayout::updateLayoutItems()
@@ -127,7 +127,7 @@ QVariant QDeclarativeLinearLayout::itemChange(GraphicsItemChange change, const Q
void QDeclarativeLinearLayout::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
QDeclarativeLayout::geometryChanged(newGeometry, oldGeometry);
- reconfigureLayout();
+ invalidate();
}
void QDeclarativeLinearLayout::insertLayoutItem(QDeclarativeItem *item)
@@ -135,7 +135,7 @@ void QDeclarativeLinearLayout::insertLayoutItem(QDeclarativeItem *item)
m_items.append(item);
setupItemLayout(item);
- reconfigureLayout();
+ invalidate();
QObject::connect(item, SIGNAL(destroyed()), this, SLOT(onItemDestroyed()));
}
@@ -144,7 +144,7 @@ void QDeclarativeLinearLayout::removeLayoutItem(QDeclarativeItem *item)
if (!m_items.removeOne(item))
return;
- reconfigureLayout();
+ invalidate();
QObject::disconnect(item, SIGNAL(destroyed()), this, SLOT(onItemDestroyed()));
}
@@ -153,12 +153,7 @@ void QDeclarativeLinearLayout::onItemDestroyed()
if (!m_items.removeOne(static_cast<QDeclarativeItem *>(sender())))
return;
- reconfigureLayout();
-}
-
-void QDeclarativeLinearLayout::invalidate()
-{
- reconfigureLayout();
+ invalidate();
}
void QDeclarativeLinearLayout::reconfigureLayout()
diff --git a/src/qdeclarativelinearlayout.h b/src/qdeclarativelinearlayout.h
index 7e897356..ec207bfa 100644
--- a/src/qdeclarativelinearlayout.h
+++ b/src/qdeclarativelinearlayout.h
@@ -71,7 +71,6 @@ signals:
void orientationChanged();
protected:
- void invalidate();
void updateLayoutItems();
void reconfigureLayout();
void insertLayoutItem(QDeclarativeItem *item);