aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickstackview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickstackview.cpp')
-rw-r--r--src/quicktemplates2/qquickstackview.cpp54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp
index b2a95731..135107ea 100644
--- a/src/quicktemplates2/qquickstackview.cpp
+++ b/src/quicktemplates2/qquickstackview.cpp
@@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE
/*!
\qmltype StackView
\inherits Control
- \instantiates QQuickStackView
+//! \instantiates QQuickStackView
\inqmlmodule QtQuick.Controls
\since 5.7
\ingroup qtquickcontrols2-navigation
@@ -365,8 +365,10 @@ QT_BEGIN_NAMESPACE
situation:
\list
- \li Set \l implicitWidth and \l implicitHeight on the StackView itself.
- \li Set \l implicitWidth and \l implicitHeight on the \l Rectangle.
+ \li Set \l[QtQuick]{Item::}{implicitWidth} and
+ \l[QtQuick]{Item::}{implicitHeight} on the StackView itself.
+ \li Set \l[QtQuick]{Item::}{implicitWidth} and
+ \l[QtQuick]{Item::}{implicitHeight} on the \l Rectangle.
\li Set \l {Popup::}{contentWidth} and \l {Popup::}{contentHeight} on
the Dialog.
\li Give the Dialog a size.
@@ -438,7 +440,7 @@ QQuickItem *QQuickStackView::currentItem() const
Returns the item at position \a index in the stack, or \c null if the index
is out of bounds.
- Supported behavior values:
+ Supported \a behavior values:
\value StackView.DontLoad The item is not forced to load (and \c null is returned if not yet loaded).
\value StackView.ForceLoad The item is forced to load.
*/
@@ -467,7 +469,7 @@ QQuickItem *QQuickStackView::get(int index, LoadBehavior behavior)
})
\endcode
- Supported behavior values:
+ Supported \a behavior values:
\value StackView.DontLoad Unloaded items are skipped (the callback function is not called for them).
\value StackView.ForceLoad Unloaded items are forced to load.
*/
@@ -556,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());
@@ -625,6 +634,9 @@ void QQuickStackView::push(QQmlV4Function *args)
items down to (but not including) the first item is popped.
If not specified, only the current item is popped.
+ \note A pop() operation on a stack with depth 1 or 0 does nothing. In such
+ cases, the stack can be emptied using the \l clear() method.
+
\include qquickstackview.qdocinc pop-ownership
An \a operation can be optionally specified as the last argument. Supported
@@ -649,7 +661,15 @@ void QQuickStackView::push(QQmlV4Function *args)
void QQuickStackView::pop(QQmlV4Function *args)
{
Q_D(QQuickStackView);
- QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("pop"));
+ const QString operationName = QStringLiteral("pop");
+ if (d->modifyingElements) {
+ d->warnOfInterruption(operationName);
+ args->setReturnValue(QV4::Encode::null());
+ return;
+ }
+
+ 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)
@@ -804,7 +824,15 @@ void QQuickStackView::pop(QQmlV4Function *args)
void QQuickStackView::replace(QQmlV4Function *args)
{
Q_D(QQuickStackView);
- QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("replace"));
+ const QString operationName = QStringLiteral("replace");
+ if (d->modifyingElements) {
+ d->warnOfInterruption(operationName);
+ args->setReturnValue(QV4::Encode::null());
+ 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());
@@ -900,6 +928,14 @@ void QQuickStackView::clear(Operation operation)
if (d->elements.isEmpty())
return;
+ const QString operationName = QStringLiteral("clear");
+ if (d->modifyingElements) {
+ d->warnOfInterruption(operationName);
+ return;
+ }
+
+ QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
+ QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
if (operation != Immediate) {
QQuickStackElement *exit = d->elements.pop();
exit->removal = true;
@@ -1106,7 +1142,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();