aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickstackview.cpp37
-rw-r--r--src/quicktemplates2/qquickstackview_p.cpp6
-rw-r--r--src/quicktemplates2/qquickstackview_p_p.h3
3 files changed, 32 insertions, 14 deletions
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp
index 6455731d..e5e2c39b 100644
--- a/src/quicktemplates2/qquickstackview.cpp
+++ b/src/quicktemplates2/qquickstackview.cpp
@@ -558,7 +558,14 @@ QQuickItem *QQuickStackView::find(const QJSValue &callback, LoadBehavior behavio
void QQuickStackView::push(QQmlV4Function *args)
{
Q_D(QQuickStackView);
- QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("push"));
+ const QString operationName = QStringLiteral("push");
+ if (d->modifyingElements) {
+ d->warnOfInterruption(operationName);
+ return;
+ }
+
+ QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
+ QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
if (args->length() <= 0) {
d->warn(QStringLiteral("missing arguments"));
args->setReturnValue(QV4::Encode::null());
@@ -651,14 +658,15 @@ void QQuickStackView::push(QQmlV4Function *args)
void QQuickStackView::pop(QQmlV4Function *args)
{
Q_D(QQuickStackView);
- if (d->removingElements) {
- d->warn(QStringLiteral("cannot pop while already in the process of removing elements"));
+ const QString operationName = QStringLiteral("pop");
+ if (d->modifyingElements) {
+ d->warnOfInterruption(operationName);
args->setReturnValue(QV4::Encode::null());
return;
}
- QScopedValueRollback<bool> removingElements(d->removingElements, true);
- QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("pop"));
+ QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
+ QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
int argc = args->length();
if (d->elements.count() <= 1 || argc > 2) {
if (argc > 2)
@@ -813,14 +821,15 @@ void QQuickStackView::pop(QQmlV4Function *args)
void QQuickStackView::replace(QQmlV4Function *args)
{
Q_D(QQuickStackView);
- if (d->removingElements) {
- d->warn(QStringLiteral("cannot replace while already in the process of removing elements"));
+ const QString operationName = QStringLiteral("replace");
+ if (d->modifyingElements) {
+ d->warnOfInterruption(operationName);
args->setReturnValue(QV4::Encode::null());
return;
}
- QScopedValueRollback<bool> removingElements(d->removingElements, true);
- QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("replace"));
+ QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
+ QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
if (args->length() <= 0) {
d->warn(QStringLiteral("missing arguments"));
args->setReturnValue(QV4::Encode::null());
@@ -916,12 +925,14 @@ void QQuickStackView::clear(Operation operation)
if (d->elements.isEmpty())
return;
- if (d->removingElements) {
- d->warn(QStringLiteral("cannot clear while already in the process of removing elements"));
+ const QString operationName = QStringLiteral("clear");
+ if (d->modifyingElements) {
+ d->warnOfInterruption(operationName);
return;
}
- QScopedValueRollback<bool> removingElements(d->removingElements, true);
+ QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
+ QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
if (operation != Immediate) {
QQuickStackElement *exit = d->elements.pop();
exit->removal = true;
@@ -1128,7 +1139,7 @@ void QQuickStackView::componentComplete()
QQuickControl::componentComplete();
Q_D(QQuickStackView);
- QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("initialItem"));
+ QScopedValueRollback<QString> operationNameRollback(d->operation, QStringLiteral("initialItem"));
QQuickStackElement *element = nullptr;
QString error;
int oldDepth = d->elements.count();
diff --git a/src/quicktemplates2/qquickstackview_p.cpp b/src/quicktemplates2/qquickstackview_p.cpp
index 1655ff36..ce81a929 100644
--- a/src/quicktemplates2/qquickstackview_p.cpp
+++ b/src/quicktemplates2/qquickstackview_p.cpp
@@ -56,6 +56,12 @@ void QQuickStackViewPrivate::warn(const QString &error)
qmlWarning(q) << operation << ": " << error;
}
+void QQuickStackViewPrivate::warnOfInterruption(const QString &attemptedOperation)
+{
+ Q_Q(QQuickStackView);
+ qmlWarning(q) << "cannot " << attemptedOperation << " while already in the process of completing a " << operation;
+}
+
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 b76a033c..0c64019d 100644
--- a/src/quicktemplates2/qquickstackview_p_p.h
+++ b/src/quicktemplates2/qquickstackview_p_p.h
@@ -73,6 +73,7 @@ public:
}
void warn(const QString &error);
+ void warnOfInterruption(const QString &attemptedOperation);
void setCurrentItem(QQuickStackElement *element);
@@ -94,7 +95,7 @@ public:
void depthChange(int newDepth, int oldDepth);
bool busy = false;
- bool removingElements = false;
+ bool modifyingElements = false;
QString operation;
QJSValue initialItem;
QQuickItem *currentItem = nullptr;