From 8bc2feb498cbbeafe0de52cda929ef7a881c0351 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 7 Jul 2017 14:34:22 +0200 Subject: 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 --- src/quicktemplates2/qquickdrawer.cpp | 25 ++++++++++++++++++++----- src/quicktemplates2/qquickdrawer_p_p.h | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src') 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 #include +#include #include #include #include @@ -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; -- cgit v1.2.3