diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2017-07-07 14:34:22 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2017-07-07 13:42:51 +0000 |
commit | 8bc2feb498cbbeafe0de52cda929ef7a881c0351 (patch) | |
tree | d239e3edffff77a79252fb9fcd2679f0a532c362 | |
parent | cca6e8e3bd80824ff5aa3e17995a5b46ad48be28 (diff) |
Drawer: ignore and warn about invalid edge values
This fixes an issue where an application would crash when opening a
drawer by dragging it after an invalid edge value had been set.
Task-number: QTBUG-61843
Change-Id: Ie9b9ea0276b356b92927b858f2be355bfc042afb
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 25 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdrawer_p_p.h | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_drawer.qml | 10 |
3 files changed, 31 insertions, 6 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index 66c84ea2..20279b03 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -40,6 +40,7 @@ #include <QtGui/qstylehints.h> #include <QtGui/private/qguiapplication_p.h> +#include <QtQml/qqmlinfo.h> #include <QtQuick/private/qquickwindow_p.h> #include <QtQuick/private/qquickanimation_p.h> #include <QtQuick/private/qquicktransition_p.h> @@ -530,20 +531,32 @@ bool QQuickDrawerPrivate::prepareExitTransition() return QQuickPopupPrivate::prepareExitTransition(); } -void QQuickDrawerPrivate::setEdge(Qt::Edge e) +bool QQuickDrawerPrivate::setEdge(Qt::Edge e) { - edge = e; - if (edge == Qt::LeftEdge || edge == Qt::RightEdge) { + Q_Q(QQuickDrawer); + switch (e) { + case Qt::LeftEdge: + case Qt::RightEdge: allowVerticalMove = true; allowVerticalResize = true; allowHorizontalMove = false; allowHorizontalResize = false; - } else { + break; + case Qt::TopEdge: + case Qt::BottomEdge: allowVerticalMove = false; allowVerticalResize = false; allowHorizontalMove = true; allowHorizontalResize = true; + break; + default: + qmlWarning(q) << "invalid edge value - valid values are: " + << "Qt.TopEdge, Qt.LeftEdge, Qt.RightEdge, Qt.BottomEdge"; + return false; } + + edge = e; + return true; } QQuickDrawer::QQuickDrawer(QObject *parent) @@ -578,7 +591,9 @@ void QQuickDrawer::setEdge(Qt::Edge edge) if (d->edge == edge) return; - d->setEdge(edge); + if (!d->setEdge(edge)) + return; + if (isComponentComplete()) d->reposition(); emit edgeChanged(); diff --git a/src/quicktemplates2/qquickdrawer_p_p.h b/src/quicktemplates2/qquickdrawer_p_p.h index 8547bce5..6ed62cf5 100644 --- a/src/quicktemplates2/qquickdrawer_p_p.h +++ b/src/quicktemplates2/qquickdrawer_p_p.h @@ -86,7 +86,7 @@ public: bool prepareEnterTransition() override; bool prepareExitTransition() override; - void setEdge(Qt::Edge edge); + bool setEdge(Qt::Edge edge); Qt::Edge edge; qreal offset; diff --git a/tests/auto/controls/data/tst_drawer.qml b/tests/auto/controls/data/tst_drawer.qml index 11a57e2f..a33a4bf0 100644 --- a/tests/auto/controls/data/tst_drawer.qml +++ b/tests/auto/controls/data/tst_drawer.qml @@ -73,6 +73,16 @@ TestCase { compare(control.parent, ApplicationWindow.overlay) } + function test_invalidEdge() { + var control = createTemporaryObject(drawer, testCase) + compare(control.edge, Qt.LeftEdge) + + // Test an invalid value - it should warn and ignore it. + ignoreWarning(Qt.resolvedUrl("tst_drawer.qml") + ":65:9: QML Drawer: invalid edge value - valid values are: Qt.TopEdge, Qt.LeftEdge, Qt.RightEdge, Qt.BottomEdge") + control.edge = Drawer.Right + compare(control.edge, Qt.LeftEdge) + } + Component { id: rectDrawer |