aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-09-11 03:02:28 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-09-11 03:02:28 +0200
commitb9e7d9aadc8f70644c24469d802e9366a2a422bf (patch)
tree4445aff3e662916b5f5e5729da8e9dcbcc736430 /src
parent7e38097fb03b1b304a90630b475fe1f771a44d4e (diff)
parentb41a32bc8ed42001c59af22345af4b733398aa34 (diff)
Merge remote-tracking branch 'origin/5.11' into 5.12
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickmenu.cpp59
-rw-r--r--src/quicktemplates2/qquickmenu_p_p.h3
-rw-r--r--src/quicktemplates2/qquickswipeview.cpp8
3 files changed, 49 insertions, 21 deletions
diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp
index f52405c9..7086db91 100644
--- a/src/quicktemplates2/qquickmenu.cpp
+++ b/src/quicktemplates2/qquickmenu.cpp
@@ -251,6 +251,41 @@ void QQuickMenuPrivate::removeItem(int index, QQuickItem *item)
}
}
+void QQuickMenuPrivate::createAndAppendItem(QObject *object)
+{
+ Q_Q(QQuickMenu);
+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
+ if (!item) {
+ if (QQuickAction *action = qobject_cast<QQuickAction *>(object))
+ item = createItem(action);
+ else if (QQuickMenu *menu = qobject_cast<QQuickMenu *>(object))
+ item = createItem(menu);
+ }
+
+ if (item) {
+ if (QQuickItemPrivate::get(item)->isTransparentForPositioner()) {
+ QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::SiblingOrder);
+ item->setParentItem(contentItem);
+ } else if (contentModel->indexOf(item, nullptr) == -1) {
+ q->addItem(item);
+ }
+ } else {
+ contentData.append(object);
+ }
+}
+
+void QQuickMenuPrivate::recreateItems()
+{
+ // removeItem() will remove stuff from contentData, so we have to make a copy of it.
+ const auto originalContentData = contentData;
+
+ while (contentModel->count() > 0)
+ removeItem(0, itemAt(0));
+
+ for (QObject *object : originalContentData)
+ createAndAppendItem(object);
+}
+
QQuickItem *QQuickMenuPrivate::beginCreateItem()
{
Q_Q(QQuickMenu);
@@ -626,24 +661,14 @@ void QQuickMenuPrivate::contentData_append(QQmlListProperty<QObject> *prop, QObj
QQuickMenu *q = qobject_cast<QQuickMenu *>(prop->object);
QQuickMenuPrivate *p = QQuickMenuPrivate::get(q);
- QQuickItem *item = qobject_cast<QQuickItem *>(obj);
- if (!item) {
- if (QQuickAction *action = qobject_cast<QQuickAction *>(obj))
- item = p->createItem(action);
- else if (QQuickMenu *menu = qobject_cast<QQuickMenu *>(obj))
- item = p->createItem(menu);
- }
-
- if (item) {
- if (QQuickItemPrivate::get(item)->isTransparentForPositioner()) {
- QQuickItemPrivate::get(item)->addItemChangeListener(p, QQuickItemPrivate::SiblingOrder);
- item->setParentItem(p->contentItem);
- } else if (p->contentModel->indexOf(item, nullptr) == -1) {
- q->addItem(item);
- }
- } else {
+ if (!p->complete) {
+ // Don't add items until we're complete, as the delegate could change in the meantime.
+ // We'll add it to contentData and create it when we're complete.
p->contentData.append(obj);
+ return;
}
+
+ p->createAndAppendItem(obj);
}
int QQuickMenuPrivate::contentData_count(QQmlListProperty<QObject> *prop)
@@ -1356,7 +1381,7 @@ void QQuickMenu::componentComplete()
{
Q_D(QQuickMenu);
QQuickPopup::componentComplete();
- d->resizeItems();
+ d->recreateItems();
}
void QQuickMenu::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
diff --git a/src/quicktemplates2/qquickmenu_p_p.h b/src/quicktemplates2/qquickmenu_p_p.h
index 6146b960..c0bb2702 100644
--- a/src/quicktemplates2/qquickmenu_p_p.h
+++ b/src/quicktemplates2/qquickmenu_p_p.h
@@ -78,6 +78,9 @@ public:
void moveItem(int from, int to);
void removeItem(int index, QQuickItem *item);
+ void createAndAppendItem(QObject *object);
+ void recreateItems();
+
QQuickItem *beginCreateItem();
void completeCreateItem();
diff --git a/src/quicktemplates2/qquickswipeview.cpp b/src/quicktemplates2/qquickswipeview.cpp
index f887be7b..e6a88b47 100644
--- a/src/quicktemplates2/qquickswipeview.cpp
+++ b/src/quicktemplates2/qquickswipeview.cpp
@@ -72,10 +72,10 @@ QT_BEGIN_NAMESPACE
It is generally not advisable to add excessive amounts of pages to a
SwipeView. However, when the amount of pages grows larger, or individual
- pages are relatively complex, it may be desired free up resources by
- unloading pages that are outside the reach. The following example presents
- how to use \l Loader to keep a maximum of three pages simultaneously
- instantiated.
+ pages are relatively complex, it may be desirable to free up resources by
+ unloading pages that are outside the immediate reach of the user.
+ The following example presents how to use \l Loader to keep a maximum of
+ three pages simultaneously instantiated.
\code
SwipeView {