aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-05-20 19:27:24 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-05-23 06:59:17 +0000
commit56cb695c43321ef2c0052f60485db192dfb72225 (patch)
tree7b962e73b3928045353fc1c436a092635dd5da1a /src
parent83a91bc0738dd9336a36a230ebd8c5cacbff65bc (diff)
Add StackView::empty for convenience
"stack.empty" looks cleaner in bindings than "stack.depth === 0" Change-Id: Ia99ea8ff2a8cf76a752917c239874d24d2103312 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickstackview.cpp25
-rw-r--r--src/quicktemplates2/qquickstackview_p.cpp8
-rw-r--r--src/quicktemplates2/qquickstackview_p.h4
-rw-r--r--src/quicktemplates2/qquickstackview_p_p.h1
4 files changed, 33 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp
index e1740273..ee975056 100644
--- a/src/quicktemplates2/qquickstackview.cpp
+++ b/src/quicktemplates2/qquickstackview.cpp
@@ -517,7 +517,7 @@ void QQuickStackView::push(QQmlV4Function *args)
exit = d->elements.top();
if (d->pushElements(elements)) {
- emit depthChanged();
+ d->depthChange();
QQuickStackElement *enter = d->elements.top();
d->startTransition(QQuickStackTransition::pushEnter(operation, enter, this),
QQuickStackTransition::pushExit(operation, exit, this),
@@ -612,7 +612,7 @@ void QQuickStackView::pop(QQmlV4Function *args)
d->removing.insert(exit);
previousItem = exit->item;
}
- emit depthChanged();
+ d->depthChange();
d->startTransition(QQuickStackTransition::popExit(operation, exit, this),
QQuickStackTransition::popEnter(operation, enter, this),
operation == Immediate);
@@ -759,7 +759,7 @@ void QQuickStackView::replace(QQmlV4Function *args)
if (exit != target ? d->replaceElements(target, elements) : d->pushElements(elements)) {
if (depth != d->elements.count())
- emit depthChanged();
+ d->depthChange();
if (exit) {
exit->removal = true;
d->removing.insert(exit);
@@ -780,6 +780,21 @@ void QQuickStackView::replace(QQmlV4Function *args)
}
/*!
+ \since QtQuick.Controls 2.3
+ \qmlproperty bool QtQuick.Controls::StackView::empty
+ \readonly
+
+ This property holds whether the stack is empty.
+
+ \sa depth
+*/
+bool QQuickStackView::isEmpty() const
+{
+ Q_D(const QQuickStackView);
+ return d->elements.isEmpty();
+}
+
+/*!
\qmlmethod void QtQuick.Controls::StackView::clear(transition)
Removes all items from the stack.
@@ -808,7 +823,7 @@ void QQuickStackView::clear(Operation operation)
d->setCurrentItem(nullptr);
qDeleteAll(d->elements);
d->elements.clear();
- emit depthChanged();
+ d->depthChange();
}
/*!
@@ -1012,7 +1027,7 @@ void QQuickStackView::componentComplete()
if (!error.isEmpty()) {
d->warn(error);
} else if (d->pushElement(element)) {
- emit depthChanged();
+ d->depthChange();
d->setCurrentItem(element);
element->setStatus(QQuickStackView::Active);
}
diff --git a/src/quicktemplates2/qquickstackview_p.cpp b/src/quicktemplates2/qquickstackview_p.cpp
index 3c983d6b..69ad7848 100644
--- a/src/quicktemplates2/qquickstackview_p.cpp
+++ b/src/quicktemplates2/qquickstackview_p.cpp
@@ -297,4 +297,12 @@ void QQuickStackViewPrivate::setBusy(bool b)
emit q->busyChanged();
}
+void QQuickStackViewPrivate::depthChange()
+{
+ Q_Q(QQuickStackView);
+ emit q->depthChanged();
+ if (elements.count() <= 1)
+ emit q->emptyChanged();
+}
+
QT_END_NAMESPACE
diff --git a/src/quicktemplates2/qquickstackview_p.h b/src/quicktemplates2/qquickstackview_p.h
index 22392698..21c20f3a 100644
--- a/src/quicktemplates2/qquickstackview_p.h
+++ b/src/quicktemplates2/qquickstackview_p.h
@@ -72,6 +72,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickStackView : public QQuickControl
Q_PROPERTY(QQuickTransition *pushExit READ pushExit WRITE setPushExit NOTIFY pushExitChanged FINAL)
Q_PROPERTY(QQuickTransition *replaceEnter READ replaceEnter WRITE setReplaceEnter NOTIFY replaceEnterChanged FINAL)
Q_PROPERTY(QQuickTransition *replaceExit READ replaceExit WRITE setReplaceExit NOTIFY replaceExitChanged FINAL)
+ Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged FINAL REVISION 3)
public:
explicit QQuickStackView(QQuickItem *parent = nullptr);
@@ -134,6 +135,8 @@ public:
Q_INVOKABLE void pop(QQmlV4Function *args);
Q_INVOKABLE void replace(QQmlV4Function *args);
+ bool isEmpty() const;
+
public Q_SLOTS:
void clear(Operation operation = Immediate);
@@ -147,6 +150,7 @@ Q_SIGNALS:
void pushExitChanged();
void replaceEnterChanged();
void replaceExitChanged();
+ Q_REVISION(3) void emptyChanged();
protected:
void componentComplete() override;
diff --git a/src/quicktemplates2/qquickstackview_p_p.h b/src/quicktemplates2/qquickstackview_p_p.h
index 81ca9164..871891aa 100644
--- a/src/quicktemplates2/qquickstackview_p_p.h
+++ b/src/quicktemplates2/qquickstackview_p_p.h
@@ -92,6 +92,7 @@ public:
void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) override;
void setBusy(bool busy);
+ void depthChange();
bool busy;
QString operation;