From 762d4ceb5fe19d97bcdbdba1dae74816126b7b75 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 23 Mar 2017 11:26:30 +0100 Subject: Add QQuickStackViewPrivate::warn() helper Store the current operation name internally to allow throwing informative warnings when component creation fails. Task-number: QTBUG-59634 Change-Id: I7506c5eb4be35878c8abd73a637357e0d8ae08a2 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickstackview.cpp | 16 ++++++++++------ src/quicktemplates2/qquickstackview_p.cpp | 10 ++++++++++ src/quicktemplates2/qquickstackview_p_p.h | 3 +++ 3 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp index a9922704..dbc8c7bb 100644 --- a/src/quicktemplates2/qquickstackview.cpp +++ b/src/quicktemplates2/qquickstackview.cpp @@ -39,6 +39,7 @@ #include "qquickstackelement_p_p.h" #include "qquickstacktransition_p_p.h" +#include #include #include #include @@ -474,8 +475,9 @@ QQuickItem *QQuickStackView::find(const QJSValue &callback, LoadBehavior behavio void QQuickStackView::push(QQmlV4Function *args) { Q_D(QQuickStackView); + QScopedValueRollback rollback(d->operation, QStringLiteral("push")); if (args->length() <= 0) { - qmlWarning(this) << "push: missing arguments"; + d->warn(QStringLiteral("missing arguments")); args->setReturnValue(QV4::Encode::null()); return; } @@ -499,7 +501,7 @@ void QQuickStackView::push(QQmlV4Function *args) } if (elements.isEmpty()) { - qmlWarning(this) << "push: nothing to push"; + d->warn(QStringLiteral("nothing to push")); args->setReturnValue(QV4::Encode::null()); return; } @@ -557,10 +559,11 @@ void QQuickStackView::push(QQmlV4Function *args) void QQuickStackView::pop(QQmlV4Function *args) { Q_D(QQuickStackView); + QScopedValueRollback rollback(d->operation, QStringLiteral("pop")); int argc = args->length(); if (d->elements.count() <= 1 || argc > 2) { if (argc > 2) - qmlWarning(this) << "pop: too many arguments"; + d->warn(QStringLiteral("too many arguments")); args->setReturnValue(QV4::Encode::null()); return; } @@ -580,7 +583,7 @@ void QQuickStackView::pop(QQmlV4Function *args) enter = d->findElement(item); if (!enter) { if (item != d->currentItem) - qmlWarning(this) << "pop: unknown argument: " << value->toQString(); // TODO: safe? + d->warn(QStringLiteral("unknown argument: ") + value->toQString()); // TODO: safe? args->setReturnValue(QV4::Encode::null()); d->elements.push(exit); // restore return; @@ -708,8 +711,9 @@ void QQuickStackView::pop(QQmlV4Function *args) void QQuickStackView::replace(QQmlV4Function *args) { Q_D(QQuickStackView); + QScopedValueRollback rollback(d->operation, QStringLiteral("replace")); if (args->length() <= 0) { - qmlWarning(this) << "replace: missing arguments"; + d->warn(QStringLiteral("missing arguments")); args->setReturnValue(QV4::Encode::null()); return; } @@ -731,7 +735,7 @@ void QQuickStackView::replace(QQmlV4Function *args) QList elements = d->parseElements(args, target ? 1 : 0); if (elements.isEmpty()) { - qmlWarning(this) << "replace: nothing to push"; + d->warn(QStringLiteral("nothing to push")); args->setReturnValue(QV4::Encode::null()); return; } diff --git a/src/quicktemplates2/qquickstackview_p.cpp b/src/quicktemplates2/qquickstackview_p.cpp index 89b3c6e3..077c13e3 100644 --- a/src/quicktemplates2/qquickstackview_p.cpp +++ b/src/quicktemplates2/qquickstackview_p.cpp @@ -38,6 +38,7 @@ #include "qquickstackelement_p_p.h" #include "qquickstacktransition_p_p.h" +#include #include #include #include @@ -53,6 +54,15 @@ QQuickStackViewPrivate::QQuickStackViewPrivate() { } +void QQuickStackViewPrivate::warn(const QString &error) +{ + Q_Q(QQuickStackView); + if (operation.isEmpty()) + qmlWarning(q) << error; + else + qmlWarning(q) << operation << ": " << error; +} + void QQuickStackViewPrivate::setCurrentItem(QQuickStackElement *element) { Q_Q(QQuickStackView); diff --git a/src/quicktemplates2/qquickstackview_p_p.h b/src/quicktemplates2/qquickstackview_p_p.h index ca610153..532a2b57 100644 --- a/src/quicktemplates2/qquickstackview_p_p.h +++ b/src/quicktemplates2/qquickstackview_p_p.h @@ -72,6 +72,8 @@ public: return view->d_func(); } + void warn(const QString &error); + void setCurrentItem(QQuickStackElement *element); QList parseElements(QQmlV4Function *args, int from = 0); @@ -91,6 +93,7 @@ public: void setBusy(bool busy); bool busy; + QString operation; QVariant initialItem; QQuickItem *currentItem; QSet removing; -- cgit v1.2.3