QQuickApplication: do not filter LayoutDirectionChange events
authorJ-P Nurmi <jpnurmi@digia.com>
Fri, 20 Jun 2014 09:26:54 +0000 (11:26 +0200)
committerJ-P Nurmi <jpnurmi@digia.com>
Wed, 25 Jun 2014 15:32:01 +0000 (17:32 +0200)
The newly introduced QGuiApplication::layoutDirectionChanged() is much
cheaper to use than filtering events of the application object.

Change-Id: I356c94cc6bea806bf3644c31c2610501d90f6c35
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
src/quick/util/qquickapplication.cpp
src/quick/util/qquickapplication_p.h

index 7fee2ee..159d855 100644 (file)
 
 QT_BEGIN_NAMESPACE
 
-class QQuickApplicationPrivate : public QQmlApplicationPrivate
-{
-    Q_DECLARE_PUBLIC(QQuickApplication)
-public:
-    QQuickApplicationPrivate()
-        : direction(QGuiApplication::layoutDirection())
-    {
-    }
-
-private:
-    Qt::LayoutDirection direction;
-};
-
 /*
     This object and its properties are documented as part of the Qt object,
     in qqmlengine.cpp
 */
 
 QQuickApplication::QQuickApplication(QObject *parent)
-    : QQmlApplication(*new QQuickApplicationPrivate(), parent)
+    : QQmlApplication(parent)
 {
     if (qApp) {
-        qApp->installEventFilter(this);
-
+        connect(qApp, SIGNAL(layoutDirectionChanged(Qt::LayoutDirection)),
+                this, SIGNAL(layoutDirectionChanged()));
         connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
                 this, SIGNAL(stateChanged(Qt::ApplicationState)));
         connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
@@ -92,8 +79,7 @@ bool QQuickApplication::active() const
 
 Qt::LayoutDirection QQuickApplication::layoutDirection() const
 {
-    Q_D(const QQuickApplication);
-    return d->direction;
+    return QGuiApplication::layoutDirection();
 }
 
 bool QQuickApplication::supportsMultipleWindows() const
@@ -106,17 +92,4 @@ Qt::ApplicationState QQuickApplication::state() const
     return QGuiApplication::applicationState();
 }
 
-bool QQuickApplication::eventFilter(QObject *, QEvent *event)
-{
-    Q_D(QQuickApplication);
-    if (event->type() == QEvent::ApplicationLayoutDirectionChange) {
-        Qt::LayoutDirection newDirection = QGuiApplication::layoutDirection();
-        if (d->direction != newDirection) {
-            d->direction = newDirection;
-            emit layoutDirectionChanged();
-        }
-    }
-    return false;
-}
-
 QT_END_NAMESPACE
index 780fb1f..996ed67 100644 (file)
@@ -50,7 +50,6 @@
 QT_BEGIN_NAMESPACE
 
 
-class QQuickApplicationPrivate;
 class Q_AUTOTEST_EXPORT QQuickApplication : public QQmlApplication
 {
     Q_OBJECT
@@ -73,10 +72,7 @@ Q_SIGNALS:
     void stateChanged(Qt::ApplicationState state);
 
 private:
-    bool eventFilter(QObject *, QEvent *event);
-
     Q_DISABLE_COPY(QQuickApplication)
-    Q_DECLARE_PRIVATE(QQuickApplication)
 };
 
 QT_END_NAMESPACE