diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-11-03 19:57:57 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-11-04 15:44:20 +0000 |
commit | 1bbbfa1af4fdb2413693f8b57d9e6c44009cedfa (patch) | |
tree | 0a5852a445df4cb4f9be1d9b31a42666e76312f1 /src/templates/qquickcontainer.cpp | |
parent | 99012cbe810b29e7b1b59eebeccc26e9177d7b5f (diff) |
Implement TabBar without ExclusiveGroup
Make use of auto-exclusivity introduced in a108298. Fixes also
the issue that the TabButton that corresponded currentIndex was
not checked at startup.
Change-Id: I44152e62c2dff30e8e0255c9403dcf46c4ea2f3a
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickcontainer.cpp')
-rw-r--r-- | src/templates/qquickcontainer.cpp | 100 |
1 files changed, 21 insertions, 79 deletions
diff --git a/src/templates/qquickcontainer.cpp b/src/templates/qquickcontainer.cpp index ef08161f..ce2031a5 100644 --- a/src/templates/qquickcontainer.cpp +++ b/src/templates/qquickcontainer.cpp @@ -36,7 +36,6 @@ #include "qquickcontainer_p.h" #include "qquickcontainer_p_p.h" -#include "qquickexclusivegroup_p.h" QT_BEGIN_NAMESPACE @@ -53,7 +52,7 @@ QT_BEGIN_NAMESPACE \sa {Container Controls} */ -QQuickContainerPrivate::QQuickContainerPrivate() : contentModel(Q_NULLPTR), currentIndex(-1), updatingCurrent(false), exclusiveGroup(Q_NULLPTR) +QQuickContainerPrivate::QQuickContainerPrivate() : contentModel(Q_NULLPTR), currentIndex(-1), updatingCurrent(false) { } @@ -89,13 +88,11 @@ void QQuickContainerPrivate::insertItem(int index, QQuickItem *item) { Q_Q(QQuickContainer); contentData.append(item); - if (exclusiveGroup && !exclusiveGroup->isCheckable(item)) + if (!q->isContent(item)) return; QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent); contentModel->insert(index, item); - if (exclusiveGroup) - exclusiveGroup->addCheckable(item); q->itemAdded(index, item); @@ -110,16 +107,12 @@ void QQuickContainerPrivate::moveItem(int from, int to) Q_Q(QQuickContainer); contentModel->move(from, to); updatingCurrent = true; - if (exclusiveGroup) { - q->setCurrentIndex(contentModel->indexOf(exclusiveGroup->current(), Q_NULLPTR)); - } else { - if (from == currentIndex) - q->setCurrentIndex(to); - else if (from < currentIndex && to >= currentIndex) - q->setCurrentIndex(currentIndex - 1); - else if (from > currentIndex && to <= currentIndex) - q->setCurrentIndex(currentIndex + 1); - } + if (from == currentIndex) + q->setCurrentIndex(to); + else if (from < currentIndex && to >= currentIndex) + q->setCurrentIndex(currentIndex - 1); + else if (from > currentIndex && to <= currentIndex) + q->setCurrentIndex(currentIndex + 1); updatingCurrent = false; } @@ -127,7 +120,7 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) { Q_Q(QQuickContainer); contentData.removeOne(item); - if (exclusiveGroup && !exclusiveGroup->isCheckable(item)) + if (!q->isContent(item)) return; bool currentChanged = false; @@ -141,8 +134,6 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent); item->setParentItem(Q_NULLPTR); contentModel->remove(index); - if (exclusiveGroup) - exclusiveGroup->removeCheckable(item); q->itemRemoved(index, item); @@ -150,13 +141,6 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) emit q->currentIndexChanged(); } -void QQuickContainerPrivate::_q_currentItemChanged() -{ - Q_Q(QQuickContainer); - if (!updatingCurrent) - q->setCurrentIndex(contentModel->indexOf(exclusiveGroup->current(), Q_NULLPTR)); -} - void QQuickContainerPrivate::_q_currentIndexChanged() { Q_Q(QQuickContainer); @@ -437,8 +421,6 @@ void QQuickContainer::setCurrentIndex(int index) d->currentIndex = index; emit currentIndexChanged(); emit currentItemChanged(); - if (d->exclusiveGroup && isComponentComplete()) - d->exclusiveGroup->setCurrent(d->contentModel->get(index)); } } @@ -453,48 +435,6 @@ QQuickItem *QQuickContainer::currentItem() const return itemAt(d->currentIndex); } -/*! - \qmlproperty bool Qt.labs.controls::Container::exclusive - - This property holds whether the container is considered exclusive. - An exclusive container manages the the content children with an - ExclusiveGroup. - - The default value is \c false. - - \sa ExclusiveGroup -*/ -bool QQuickContainer::isExclusive() const -{ - Q_D(const QQuickContainer); - return d->exclusiveGroup; -} - -void QQuickContainer::setExclusive(bool exclusive) -{ - Q_D(QQuickContainer); - if (exclusive == isExclusive()) - return; - - if (exclusive) { - if (!d->exclusiveGroup) { - d->exclusiveGroup = new QQuickExclusiveGroup(this); - connect(d->exclusiveGroup, &QQuickExclusiveGroup::currentChanged, this, &QQuickContainer::currentItemChanged); - QObjectPrivate::connect(d->exclusiveGroup, &QQuickExclusiveGroup::currentChanged, d, &QQuickContainerPrivate::_q_currentItemChanged); - - const int count = d->contentModel->count(); - for (int i = 0; i < count; ++i) { - QObject *object = d->contentModel->get(i); - if (d->exclusiveGroup->isCheckable(object)) - d->exclusiveGroup->addCheckable(object); - } - } - } else { - delete d->exclusiveGroup; - d->exclusiveGroup = Q_NULLPTR; - } -} - void QQuickContainer::itemChange(ItemChange change, const ItemChangeData &data) { Q_D(QQuickContainer); @@ -515,24 +455,26 @@ void QQuickContainer::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem if (oldItem) { QQuickItemPrivate::get(oldItem)->removeItemChangeListener(d, QQuickItemPrivate::Children); - if (!d->exclusiveGroup) { - int signalIndex = oldItem->metaObject()->indexOfSignal("currentIndexChanged()"); - if (signalIndex != -1) - QMetaObject::disconnect(oldItem, signalIndex, this, slotIndex); - } + int signalIndex = oldItem->metaObject()->indexOfSignal("currentIndexChanged()"); + if (signalIndex != -1) + QMetaObject::disconnect(oldItem, signalIndex, this, slotIndex); } if (newItem) { QQuickItemPrivate::get(newItem)->addItemChangeListener(d, QQuickItemPrivate::Children); - if (!d->exclusiveGroup) { - int signalIndex = newItem->metaObject()->indexOfSignal("currentIndexChanged()"); - if (signalIndex != -1) - QMetaObject::connect(newItem, signalIndex, this, slotIndex); - } + int signalIndex = newItem->metaObject()->indexOfSignal("currentIndexChanged()"); + if (signalIndex != -1) + QMetaObject::connect(newItem, signalIndex, this, slotIndex); } } +bool QQuickContainer::isContent(QQuickItem *item) const +{ + Q_UNUSED(item); + return true; +} + void QQuickContainer::itemAdded(int index, QQuickItem *item) { Q_UNUSED(index); |