aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Tapsell <john.tapsell.ext@basyskom.de>2010-10-28 20:38:03 +0100
committerNatalia Dobrovolskaya <natalia.dobrovolskaya@nokia.com>2010-10-29 16:16:57 +0300
commited60fe0560fe2411609ac511d07c146639b808ed (patch)
treec50d545fbd1b9fe930ce6cd79b1e4f9afc9cc0fe
parent00dbec1dab5809391ec0636591c5f80c6cf832a0 (diff)
Changes: Fix resize problem with layouts
RevBy: TrustMe Details: Includes a benchmark test for the layouts
-rw-r--r--benchmarks/pt_mlayout/.gitignore1
-rw-r--r--benchmarks/pt_mlayout/pt_mlayout.cpp116
-rw-r--r--benchmarks/pt_mlayout/pt_mlayout.h50
-rw-r--r--benchmarks/pt_mlayout/pt_mlayout.pro7
-rw-r--r--src/corelib/layout/mlinearlayoutpolicy.cpp7
-rw-r--r--src/corelib/layout/mlinearlayoutpolicy_p.cpp10
-rw-r--r--src/corelib/layout/mlinearlayoutpolicy_p.h1
7 files changed, 186 insertions, 6 deletions
diff --git a/benchmarks/pt_mlayout/.gitignore b/benchmarks/pt_mlayout/.gitignore
new file mode 100644
index 00000000..10600a2d
--- /dev/null
+++ b/benchmarks/pt_mlayout/.gitignore
@@ -0,0 +1 @@
+pt_mlayout
diff --git a/benchmarks/pt_mlayout/pt_mlayout.cpp b/benchmarks/pt_mlayout/pt_mlayout.cpp
new file mode 100644
index 00000000..02b925da
--- /dev/null
+++ b/benchmarks/pt_mlayout/pt_mlayout.cpp
@@ -0,0 +1,116 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include <QObject>
+#include <MTheme>
+#include <MLayout>
+#include <MLinearLayoutPolicy>
+#include <MButton>
+#include <QGraphicsLinearLayout>
+#include <QGraphicsScene>
+#include <MApplication>
+
+#include "mclassfactory.h"
+#include "pt_mlayout.h"
+
+MApplication *app(NULL);
+
+void Pt_MLayout::initTestCase()
+{
+ static int argc = 1;
+ char *argv[1] = { (char *) "./pt_mlayout" };
+ app = new MApplication(argc, argv);
+
+}
+
+void Pt_MLayout::cleanupTestCase()
+{
+ delete app;
+ app = NULL;
+}
+
+void Pt_MLayout::init()
+{
+ m_scene = new QGraphicsScene;
+ m_form = new QGraphicsWidget;
+ m_scene->addItem(m_form);
+
+}
+
+void Pt_MLayout::cleanup()
+{
+}
+void Pt_MLayout::layoutPerformance_data()
+{
+ QTest::addColumn<bool>("qtOnly");
+ QTest::addColumn<bool>("testSizeHint");
+
+ QTest::newRow("MLayout") << false << false;
+ QTest::newRow("MLayout with sizeHint call") << false << true;
+ QTest::newRow("QGraphicsLayout") << true << false;
+ QTest::newRow("QGraphicsLayout with sizeHint call") << true << true;
+}
+
+void Pt_MLayout::layoutPerformance()
+{
+ QFETCH(bool, qtOnly);
+ QFETCH(bool, testSizeHint);
+
+ QGraphicsLinearLayout *qlayout;
+ MLayout *layout;
+ MLinearLayoutPolicy *policy;
+ if(qtOnly) {
+ qlayout = new QGraphicsLinearLayout(Qt::Vertical, m_form);
+ } else {
+ layout = new MLayout(m_form);
+ policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
+ }
+
+ MButton *a = new MButton;
+ MButton *b = new MButton;
+
+ if (qtOnly) {
+ qlayout->addItem(a);
+ qlayout->addItem(b);
+ } else {
+ policy->addItem(a);
+ policy->addItem(b);
+ }
+
+ while (MTheme::hasPendingRequests()) {
+ usleep(10000);
+ QCoreApplication::processEvents();
+ }
+
+ QBENCHMARK {
+ if (qtOnly) {
+ qlayout->invalidate();
+ qlayout->activate();
+ if(testSizeHint)
+ (void)qlayout->preferredSize();
+ } else {
+ layout->invalidate();
+ layout->activate();
+ if(testSizeHint)
+ (void)layout->preferredSize();
+ }
+ }
+}
+
+QTEST_APPLESS_MAIN(Pt_MLayout)
diff --git a/benchmarks/pt_mlayout/pt_mlayout.h b/benchmarks/pt_mlayout/pt_mlayout.h
new file mode 100644
index 00000000..131339c1
--- /dev/null
+++ b/benchmarks/pt_mlayout/pt_mlayout.h
@@ -0,0 +1,50 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#ifndef PT_MLAYOUT_H
+#define PT_MLAYOUT_H
+
+#include <QtTest/QtTest>
+#include <QObject>
+
+class QGraphicsWidget;
+class QGraphicsScene;
+
+class Pt_MLayout : public QObject
+{
+ Q_OBJECT
+
+public:
+ Pt_MLayout():m_form(NULL), m_scene(NULL) {};
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+
+ void layoutPerformance();
+ void layoutPerformance_data();
+
+private:
+ QGraphicsWidget *m_form;
+ QGraphicsScene *m_scene;
+};
+
+#endif
diff --git a/benchmarks/pt_mlayout/pt_mlayout.pro b/benchmarks/pt_mlayout/pt_mlayout.pro
new file mode 100644
index 00000000..b589f91a
--- /dev/null
+++ b/benchmarks/pt_mlayout/pt_mlayout.pro
@@ -0,0 +1,7 @@
+include(../common_top.pri)
+INCLUDEPATH += $$MSRCDIR/include $$MSRCDIR/corelib/theme
+DEPENDPATH += $$INCLUDEPATH
+TARGET = pt_mlayout
+
+SOURCES += pt_mlayout.cpp
+HEADERS += pt_mlayout.h
diff --git a/src/corelib/layout/mlinearlayoutpolicy.cpp b/src/corelib/layout/mlinearlayoutpolicy.cpp
index 674a7667..9ef873a0 100644
--- a/src/corelib/layout/mlinearlayoutpolicy.cpp
+++ b/src/corelib/layout/mlinearlayoutpolicy.cpp
@@ -200,7 +200,7 @@ void MLinearLayoutPolicy::relayout()
Q_D(MLinearLayoutPolicy);
d->engine->setMinimumSize(layout()->minimumSize());
d->engine->setMaximumSize(layout()->maximumSize());
- d->refreshEngine();
+ d->refreshEngineAndWidget();
d->engine->activate();
if (!isActive())
@@ -214,7 +214,10 @@ void MLinearLayoutPolicy::relayout()
void MLinearLayoutPolicy::invalidate()
{
Q_D(MLinearLayoutPolicy);
- d->engine->invalidate();
+ d->engine->setMinimumSize(QSizeF(-1, -1));
+ d->engine->setMaximumSize(QSizeF(-1, -1));
+ const_cast<MLinearLayoutPolicyPrivate *>(d)->refreshEngine();
+
MAbstractLayoutPolicy::invalidate();
}
diff --git a/src/corelib/layout/mlinearlayoutpolicy_p.cpp b/src/corelib/layout/mlinearlayoutpolicy_p.cpp
index 4564524b..5a37a98b 100644
--- a/src/corelib/layout/mlinearlayoutpolicy_p.cpp
+++ b/src/corelib/layout/mlinearlayoutpolicy_p.cpp
@@ -52,10 +52,8 @@ void MLinearLayoutPolicyPrivate::fixIndex(int *index) const
void MLinearLayoutPolicyPrivate::refreshEngine()
{
- bool directionChanged = engineWidget->layoutDirection() != layout->layoutDirection();
engineWidget->setLayoutDirection(layout->layoutDirection()); //Make sure that we have our RTL/LTR correct
- engine->invalidate();
for (int i = engine->count() - 1; i >= 0; --i) {
ProxyItem *item = static_cast<ProxyItem *>(engine->itemAt(i));
item->refresh();
@@ -65,15 +63,19 @@ void MLinearLayoutPolicyPrivate::refreshEngine()
engine->setContentsMargins(left, top, right, bottom);
engine->updateGeometry();
+}
+void MLinearLayoutPolicyPrivate::refreshEngineAndWidget() {
+ bool directionChanged = engineWidget->layoutDirection() != layout->layoutDirection();
+ refreshEngine();
//We need to make engine->geometry() equal the layout->geometry() so that the items are in the right place
qreal topMargin = layout->geometry().top();
qreal leftMargin = layout->geometry().left();
+ engineWidget->setContentsMargins(leftMargin, topMargin, 0, 0);
+
qreal width = layout->geometry().right();
qreal height = layout->geometry().bottom();
- engineWidget->setContentsMargins(leftMargin, topMargin, 0, 0);
engineWidget->resize(width, height);
-
//update layout positions here only if layout direction has changed
if( directionChanged && notifyWidgetsOfLayoutPositionEnabled )
notifyAllWidgetsOfLayoutPosition();
diff --git a/src/corelib/layout/mlinearlayoutpolicy_p.h b/src/corelib/layout/mlinearlayoutpolicy_p.h
index 87d703f2..ba0d098b 100644
--- a/src/corelib/layout/mlinearlayoutpolicy_p.h
+++ b/src/corelib/layout/mlinearlayoutpolicy_p.h
@@ -46,6 +46,7 @@ public:
void fixIndex(int *index) const;
void refreshEngine();
+ void refreshEngineAndWidget();
void notifyWidgetOfLayoutPosition(int index, M::Position position);
void notifyAffectedWidgetsOfLayoutPosition(int index, bool add);