aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp86
-rw-r--r--src/quicktemplates2/qquickcontainer.cpp2
-rw-r--r--src/quicktemplates2/qquickmenubar.cpp8
-rw-r--r--src/quicktemplates2/qquickmenubar_p_p.h2
-rw-r--r--src/quicktemplates2/qquicksplitview.cpp39
5 files changed, 34 insertions, 103 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index 21eecfe1..6b03bbf2 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -232,13 +232,9 @@ public:
void updateEditText();
void updateCurrentText();
void updateCurrentValue();
- void updateCurrentText(bool hasDelegateModelObject);
- void updateCurrentValue(bool hasDelegateModelObject);
void updateCurrentTextAndValue();
bool isValidIndex(int index) const;
- QString fastTextAt(int index) const;
- QVariant fastValueAt(int index) const;
void acceptInput();
QString tryComplete(const QString &inputText);
@@ -441,34 +437,10 @@ void QQuickComboBoxPrivate::updateEditText()
q->setEditText(text);
}
-// We have these two rather than just using default arguments
-// because QObjectPrivate::connect() doesn't accept lambdas.
void QQuickComboBoxPrivate::updateCurrentText()
{
- updateCurrentText(false);
-}
-
-void QQuickComboBoxPrivate::updateCurrentValue()
-{
- updateCurrentValue(false);
-}
-
-void QQuickComboBoxPrivate::updateCurrentText(bool hasDelegateModelObject)
-{
Q_Q(QQuickComboBox);
- QString text;
- // If a delegate model object was passed in, it means the calling code
- // has decided to reuse it for several function calls to speed things up.
- // So, use the faster (private) version in that case.
- // For other cases, we use the version that creates the delegate model object
- // itself in order to have neater, more convenient calling code.
- if (isValidIndex(currentIndex)) {
- if (hasDelegateModelObject)
- text = fastTextAt(currentIndex);
- else
- text = q->textAt(currentIndex);
- }
-
+ const QString text = q->textAt(currentIndex);
if (currentText != text) {
currentText = text;
if (!hasDisplayText)
@@ -483,19 +455,10 @@ void QQuickComboBoxPrivate::updateCurrentText(bool hasDelegateModelObject)
q->setEditText(currentText);
}
-void QQuickComboBoxPrivate::updateCurrentValue(bool hasDelegateModelObject)
+void QQuickComboBoxPrivate::updateCurrentValue()
{
Q_Q(QQuickComboBox);
- QVariant value;
- // If a delegate model object was passed in, it means the calling code
- // has decided to reuse it for several function calls to speed things up.
- // So, use the faster (private) version in that case.
- if (isValidIndex(currentIndex)) {
- if (hasDelegateModelObject)
- value = fastValueAt(currentIndex);
- else
- value = q->valueAt(currentIndex);
- }
+ const QVariant value = q->valueAt(currentIndex);
if (currentValue == value)
return;
@@ -505,15 +468,8 @@ void QQuickComboBoxPrivate::updateCurrentValue(bool hasDelegateModelObject)
void QQuickComboBoxPrivate::updateCurrentTextAndValue()
{
- QObject *object = nullptr;
- // For performance reasons, we reuse the same delegate model object: QTBUG-76029.
- if (isValidIndex(currentIndex))
- object = delegateModel->object(currentIndex);
- const bool hasDelegateModelObject = object != nullptr;
- updateCurrentText(hasDelegateModelObject);
- updateCurrentValue(hasDelegateModelObject);
- if (object)
- delegateModel->release(object);
+ updateCurrentText();
+ updateCurrentValue();
}
bool QQuickComboBoxPrivate::isValidIndex(int index) const
@@ -521,20 +477,6 @@ bool QQuickComboBoxPrivate::isValidIndex(int index) const
return delegateModel && index >= 0 && index < delegateModel->count();
}
-// For performance reasons (QTBUG-76029), both this and valueAt assume that
-// the index is valid and delegateModel->object(index) has been called.
-QString QQuickComboBoxPrivate::fastTextAt(int index) const
-{
- const QString effectiveTextRole = textRole.isEmpty() ? QStringLiteral("modelData") : textRole;
- return delegateModel->stringValue(index, effectiveTextRole);
-}
-
-QVariant QQuickComboBoxPrivate::fastValueAt(int index) const
-{
- const QString effectiveValueRole = valueRole.isEmpty() ? QStringLiteral("modelData") : valueRole;
- return delegateModel->variantValue(index, effectiveValueRole);
-}
-
void QQuickComboBoxPrivate::acceptInput()
{
Q_Q(QQuickComboBox);
@@ -1583,13 +1525,8 @@ QVariant QQuickComboBox::valueAt(int index) const
if (!d->isValidIndex(index))
return QVariant();
- QObject *object = d->delegateModel->object(index);
- QVariant value;
- if (object) {
- value = d->fastValueAt(index);
- d->delegateModel->release(object);
- }
- return value;
+ const QString effectiveValueRole = d->valueRole.isEmpty() ? QStringLiteral("modelData") : d->valueRole;
+ return d->delegateModel->variantValue(index, effectiveValueRole);
}
/*!
@@ -1626,13 +1563,8 @@ QString QQuickComboBox::textAt(int index) const
if (!d->isValidIndex(index))
return QString();
- QObject *object = d->delegateModel->object(index);
- QString text;
- if (object) {
- text = d->fastTextAt(index);
- d->delegateModel->release(object);
- }
- return text;
+ const QString effectiveTextRole = d->textRole.isEmpty() ? QStringLiteral("modelData") : d->textRole;
+ return d->delegateModel->stringValue(index, effectiveTextRole);
}
/*!
diff --git a/src/quicktemplates2/qquickcontainer.cpp b/src/quicktemplates2/qquickcontainer.cpp
index 609c2079..47aaa1e2 100644
--- a/src/quicktemplates2/qquickcontainer.cpp
+++ b/src/quicktemplates2/qquickcontainer.cpp
@@ -241,7 +241,7 @@ void QQuickContainerPrivate::insertItem(int index, QQuickItem *item)
updatingCurrent = true;
- item->setParentItem(effectiveContentItem(getContentItem()));
+ item->setParentItem(effectiveContentItem(q->contentItem()));
QQuickItemPrivate::get(item)->addItemChangeListener(this, changeTypes);
contentModel->insert(index, item);
diff --git a/src/quicktemplates2/qquickmenubar.cpp b/src/quicktemplates2/qquickmenubar.cpp
index 1761d999..f909193f 100644
--- a/src/quicktemplates2/qquickmenubar.cpp
+++ b/src/quicktemplates2/qquickmenubar.cpp
@@ -76,7 +76,7 @@ QT_BEGIN_NAMESPACE
{Focus Management in Qt Quick Controls}
*/
-QQuickItem *QQuickMenuBarPrivate::beginCreateItem()
+QQuickItem *QQuickMenuBarPrivate::beginCreateItem(QQuickMenu *menu)
{
Q_Q(QQuickMenuBar);
if (!delegate)
@@ -96,6 +96,8 @@ QQuickItem *QQuickMenuBarPrivate::beginCreateItem()
return nullptr;
}
+ if (QQuickMenuBarItem *menuBarItem = qobject_cast<QQuickMenuBarItem *>(item))
+ menuBarItem->setMenu(menu);
item->setParentItem(q);
QQml_setParent_noEvent(item, q);
@@ -112,9 +114,7 @@ void QQuickMenuBarPrivate::completeCreateItem()
QQuickItem *QQuickMenuBarPrivate::createItem(QQuickMenu *menu)
{
- QQuickItem *item = beginCreateItem();
- if (QQuickMenuBarItem *menuBarItem = qobject_cast<QQuickMenuBarItem *>(item))
- menuBarItem->setMenu(menu);
+ QQuickItem *item = beginCreateItem(menu);
completeCreateItem();
return item;
}
diff --git a/src/quicktemplates2/qquickmenubar_p_p.h b/src/quicktemplates2/qquickmenubar_p_p.h
index 75fbed73..c214962b 100644
--- a/src/quicktemplates2/qquickmenubar_p_p.h
+++ b/src/quicktemplates2/qquickmenubar_p_p.h
@@ -69,7 +69,7 @@ public:
QQmlListProperty<QQuickMenu> menus();
QQmlListProperty<QObject> contentData();
- QQuickItem *beginCreateItem();
+ QQuickItem *beginCreateItem(QQuickMenu *menu);
void completeCreateItem();
QQuickItem *createItem(QQuickMenu *menu);
diff --git a/src/quicktemplates2/qquicksplitview.cpp b/src/quicktemplates2/qquicksplitview.cpp
index 75cd9674..56392e9a 100644
--- a/src/quicktemplates2/qquicksplitview.cpp
+++ b/src/quicktemplates2/qquicksplitview.cpp
@@ -849,6 +849,8 @@ QQuickSplitViewPrivate::EffectiveSizeData QQuickSplitViewPrivate::effectiveSizeD
int QQuickSplitViewPrivate::handleIndexForSplitIndex(int splitIndex) const
{
+ // If it's the first and only item in the view, it doesn't have a handle,
+ // so return -1: splitIndex (0) - 1.
// If it's the last item in the view, it doesn't have a handle, so use
// the handle for the previous item.
return splitIndex == contentModel->count() - 1 ? splitIndex - 1 : splitIndex;
@@ -928,7 +930,6 @@ QQuickItem *QQuickSplitViewPrivate::getContentItem()
if (QQuickItem *item = QQuickContainerPrivate::getContentItem())
return item;
- // TODO: why are several created?
return new QQuickContentItem(q);
}
@@ -1016,11 +1017,13 @@ void QQuickSplitViewPrivate::itemVisibilityChanged(QQuickItem *item)
// of the corresponding handle (if one exists).
const int handleIndex = handleIndexForSplitIndex(itemIndex);
- QQuickItem *handleItem = m_handleItems.at(handleIndex);
- handleItem->setVisible(item->isVisible());
+ if (handleIndex != -1) {
+ QQuickItem *handleItem = m_handleItems.at(handleIndex);
+ handleItem->setVisible(item->isVisible());
- qCDebug(qlcQQuickSplitView) << "set visible property of handle item"
- << handleItem << "at index" << handleIndex << "to" << item->isVisible();
+ qCDebug(qlcQQuickSplitView) << "set visible property of handle item"
+ << handleItem << "at index" << handleIndex << "to" << item->isVisible();
+ }
updateHandleVisibilities();
updateFillIndex();
@@ -1337,10 +1340,6 @@ void QQuickSplitView::hoverMoveEvent(QHoverEvent *event)
qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << d->m_hoveredHandleIndex << "is no longer hovered";
d->m_hoveredHandleIndex = -1;
-
-#if QT_CONFIG(cursor)
- setCursor(Qt::ArrowCursor);
-#endif
} else {
// A child item of ours is hovered.
@@ -1353,23 +1352,23 @@ void QQuickSplitView::hoverMoveEvent(QHoverEvent *event)
}
// Now check if the newly hovered item is actually a handle.
- const int hoveredHandleIndex = d->m_handleItems.indexOf(hoveredItem);
- if (hoveredHandleIndex == -1)
- return;
+ d->m_hoveredHandleIndex = d->m_handleItems.indexOf(hoveredItem);
- // It's a handle, so it's now hovered.
- d->m_hoveredHandleIndex = hoveredHandleIndex;
+ if (d->m_hoveredHandleIndex != -1) {
+ QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
+ qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(hoveredItem, true));
+ QQuickSplitHandleAttachedPrivate::get(handleAttached)->setHovered(true);
- QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>(
- qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(hoveredItem, true));
- QQuickSplitHandleAttachedPrivate::get(handleAttached)->setHovered(true);
+ qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << d->m_hoveredHandleIndex << "is now hovered";
+ }
+ }
#if QT_CONFIG(cursor)
+ if (d->m_hoveredHandleIndex != -1)
setCursor(d->m_orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor);
+ else
+ setCursor(Qt::ArrowCursor);
#endif
-
- qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << d->m_hoveredHandleIndex << "is now hovered";
- }
}
void QQuickSplitView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)