diff options
-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 |