q, movementEndingIdx, Qt::DirectConnection);
}
-QSGItem *QSGPathViewPrivate::getItem(int modelIndex)
+QSGItem *QSGPathViewPrivate::getItem(int modelIndex, bool onPath)
{
Q_Q(QSGPathView);
requestedIndex = modelIndex;
qPathViewAttachedType = 0;
if (att) {
att->m_view = q;
- att->setOnPath(true);
+ att->setOnPath(onPath);
}
item->setParentItem(q);
QSGItemPrivate *itemPrivate = QSGItemPrivate::get(item);
void QSGPathViewPrivate::clear()
{
+ if (currentItem) {
+ releaseItem(currentItem);
+ currentItem = 0;
+ }
for (int i=0; i<items.count(); i++){
QSGItem *p = items[i];
releaseItem(p);
if (d->model && d->modelCount)
idx = qAbs(idx % d->modelCount);
if (d->model && idx != d->currentIndex) {
- if (d->modelCount) {
- int itemIndex = (d->currentIndex - d->firstIndex + d->modelCount) % d->modelCount;
- if (itemIndex < d->items.count()) {
- if (QSGItem *item = d->items.at(itemIndex)) {
- if (QSGPathViewAttached *att = d->attached(item))
- att->setIsCurrentItem(false);
- }
- }
+ if (d->currentItem) {
+ if (QSGPathViewAttached *att = d->attached(d->currentItem))
+ att->setIsCurrentItem(false);
+ d->releaseItem(d->currentItem);
}
d->currentItem = 0;
d->moveReason = QSGPathViewPrivate::SetIndex;
d->currentIndex = idx;
if (d->modelCount) {
- if (d->haveHighlightRange && d->highlightRangeMode == QSGPathView::StrictlyEnforceRange)
- d->snapToCurrent();
int itemIndex = (idx - d->firstIndex + d->modelCount) % d->modelCount;
if (itemIndex < d->items.count()) {
- d->currentItem = d->items.at(itemIndex);
+ d->currentItem = d->model->item(d->currentIndex, true);
d->currentItem->setFocus(true);
if (QSGPathViewAttached *att = d->attached(d->currentItem))
att->setIsCurrentItem(true);
+ } else {
+ d->currentItem = d->getItem(d->currentIndex, false);
+ d->updateItem(d->currentItem, d->currentIndex < d->firstIndex ? 0.0 : 1.0);
+ if (QSGPathViewAttached *att = d->attached(d->currentItem))
+ att->setIsCurrentItem(true);
+ if (d->model->completePending())
+ d->model->completeItem();
}
+ if (d->haveHighlightRange && d->highlightRangeMode == QSGPathView::StrictlyEnforceRange)
+ d->snapToCurrent();
d->currentItemOffset = d->positionOfIndex(d->currentIndex);
d->updateHighlight();
}
}
}
+QSGItem *QSGPathView::currentItem() const
+{
+ Q_D(const QSGPathView);
+ return d->currentItem;
+}
+
void QSGPathView::incrementCurrentIndex()
{
Q_D(QSGPathView);
if (d->model->completePending())
item->setZ(idx+1);
if (d->currentIndex == idx) {
- item->setFocus(true);
- if (QSGPathViewAttached *att = d->attached(item))
- att->setIsCurrentItem(true);
currentVisible = true;
d->currentItemOffset = pos;
- d->currentItem = item;
}
if (d->items.count() == 0)
d->firstIndex = idx;
if (d->model->completePending())
item->setZ(idx+1);
if (d->currentIndex == idx) {
- item->setFocus(true);
- if (QSGPathViewAttached *att = d->attached(item))
- att->setIsCurrentItem(true);
currentVisible = true;
d->currentItemOffset = pos;
- d->currentItem = item;
}
d->items.prepend(item);
d->updateItem(item, pos);
}
}
- if (!currentVisible)
+ if (!currentVisible) {
d->currentItemOffset = 1.0;
+ if (d->currentItem) {
+ if (QSGPathViewAttached *att = d->attached(d->currentItem))
+ att->setOnPath(false);
+ } else if (d->currentIndex >= 0 && d->currentIndex < d->modelCount) {
+ d->currentItem = d->getItem(d->currentIndex, false);
+ d->updateItem(d->currentItem, d->currentIndex < d->firstIndex ? 0.0 : 1.0);
+ if (QSGPathViewAttached *att = d->attached(d->currentItem))
+ att->setIsCurrentItem(true);
+ if (d->model->completePending())
+ d->model->completeItem();
+ }
+ } else if (!d->currentItem) {
+ d->currentItem = d->model->item(d->currentIndex, true);
+ d->currentItem->setFocus(true);
+ if (QSGPathViewAttached *att = d->attached(d->currentItem))
+ att->setIsCurrentItem(true);
+ }
if (d->highlightItem && d->haveHighlightRange && d->highlightRangeMode == QSGPathView::StrictlyEnforceRange) {
d->updateItem(d->highlightItem, d->highlightRangeStart);
if (d->currentItem) {
if (QSGPathViewAttached *att = d->attached(d->currentItem))
att->setIsCurrentItem(true);
+ d->releaseItem(d->currentItem);
+ d->currentItem = 0;
}
currentChanged = true;
}
int idx = calcCurrentIndex();
if (model && idx != currentIndex) {
- int itemIndex = (currentIndex - firstIndex + modelCount) % modelCount;
- if (itemIndex < items.count()) {
- if (QSGItem *item = items.at(itemIndex)) {
- if (QSGPathViewAttached *att = attached(item))
- att->setIsCurrentItem(false);
- }
+ if (currentItem) {
+ if (QSGPathViewAttached *att = attached(currentItem))
+ att->setIsCurrentItem(false);
+ releaseItem(currentItem);
}
currentIndex = idx;
currentItem = 0;
- itemIndex = (idx - firstIndex + modelCount) % modelCount;
+ int itemIndex = (idx - firstIndex + modelCount) % modelCount;
if (itemIndex < items.count()) {
- currentItem = items.at(itemIndex);
+ currentItem = model->item(currentIndex, true);
currentItem->setFocus(true);
if (QSGPathViewAttached *att = attached(currentItem))
att->setIsCurrentItem(true);
+ } else if (currentIndex >= 0 && currentIndex < modelCount) {
+ currentItem = getItem(currentIndex, false);
+ updateItem(currentItem, currentIndex < firstIndex ? 0.0 : 1.0);
+ if (QSGPathViewAttached *att = attached(currentItem))
+ att->setIsCurrentItem(true);
+ if (model->completePending())
+ model->completeItem();
}
emit q->currentIndexChanged();
}
QTRY_COMPARE(findItems<QSGItem>(pathview, "wrapper").count(), 14);
QVERIFY(pathview->currentIndex() == 0);
+ QCOMPARE(pathview->currentItem(), findItem<QSGItem>(pathview, "wrapper", 0));
QSGText *text = findItem<QSGText>(pathview, "myText", 4);
QVERIFY(text);
text = findItem<QSGText>(pathview, "myText", 2);
QVERIFY(text);
QCOMPARE(text->text(), model.name(2));
+ QCOMPARE(pathview->currentItem(), findItem<QSGItem>(pathview, "wrapper", 0));
testObject->setPathItemCount(5);
QMetaObject::invokeMethod(canvas->rootObject(), "checkProperties");
QVERIFY(testItem == 0);
pathview->setCurrentIndex(1);
+ QCOMPARE(pathview->currentItem(), findItem<QSGItem>(pathview, "wrapper", 1));
+ QTest::qWait(100);
model.insertItem(2, "pink", "2");
QTest::qWait(100);
QTRY_COMPARE(findItems<QSGItem>(pathview, "wrapper").count(), 5);
QVERIFY(pathview->currentIndex() == 1);
+ QCOMPARE(pathview->currentItem(), findItem<QSGItem>(pathview, "wrapper", 1));
text = findItem<QSGText>(pathview, "myText", 2);
QVERIFY(text);
text = findItem<QSGText>(pathview, "myText", 3);
QVERIFY(text);
QCOMPARE(text->text(), model.name(3));
+ QCOMPARE(pathview->currentItem(), findItem<QSGItem>(pathview, "wrapper", 1));
model.moveItem(3, 5);
QTRY_COMPARE(findItems<QSGItem>(pathview, "wrapper").count(), 5);
foreach (QSGItem *item, items) {
QVERIFY(item->property("onPath").toBool());
}
+ QCOMPARE(pathview->currentItem(), findItem<QSGItem>(pathview, "wrapper", 1));
// QTBUG-14199
pathview->setOffset(7);
QTRY_COMPARE(firstItem->pos() + offset, start);
QCOMPARE(canvas->rootObject()->property("currentA").toInt(), 2);
QCOMPARE(canvas->rootObject()->property("currentB").toInt(), 2);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(true));
pathview->decrementCurrentIndex();
QTRY_COMPARE(pathview->currentIndex(), 1);
firstItem = findItem<QSGRectangle>(pathview, "wrapper", 1);
QVERIFY(firstItem);
QTRY_COMPARE(firstItem->pos() + offset, start);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(true));
pathview->decrementCurrentIndex();
QTRY_COMPARE(pathview->currentIndex(), 0);
firstItem = findItem<QSGRectangle>(pathview, "wrapper", 0);
QVERIFY(firstItem);
QTRY_COMPARE(firstItem->pos() + offset, start);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(true));
pathview->decrementCurrentIndex();
QTRY_COMPARE(pathview->currentIndex(), 3);
firstItem = findItem<QSGRectangle>(pathview, "wrapper", 3);
QVERIFY(firstItem);
QTRY_COMPARE(firstItem->pos() + offset, start);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(true));
pathview->incrementCurrentIndex();
QTRY_COMPARE(pathview->currentIndex(), 0);
firstItem = findItem<QSGRectangle>(pathview, "wrapper", 0);
QVERIFY(firstItem);
QTRY_COMPARE(firstItem->pos() + offset, start);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(true));
+
+ // Check the current item is still created when outside the bounds of pathItemCount.
+ pathview->setPathItemCount(2);
+ pathview->setHighlightRangeMode(QSGPathView::NoHighlightRange);
+ QVERIFY(findItem<QSGRectangle>(pathview, "wrapper", 0));
+ QVERIFY(findItem<QSGRectangle>(pathview, "wrapper", 1));
+ QVERIFY(!findItem<QSGRectangle>(pathview, "wrapper", 2));
+ QVERIFY(!findItem<QSGRectangle>(pathview, "wrapper", 3));
+
+ pathview->setCurrentIndex(2);
+ firstItem = findItem<QSGRectangle>(pathview, "wrapper", 2);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(false));
+
+ pathview->decrementCurrentIndex();
+ QTRY_COMPARE(pathview->currentIndex(), 1);
+ firstItem = findItem<QSGRectangle>(pathview, "wrapper", 1);
+ QVERIFY(firstItem);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(true));
+
+ pathview->decrementCurrentIndex();
+ QTRY_COMPARE(pathview->currentIndex(), 0);
+ firstItem = findItem<QSGRectangle>(pathview, "wrapper", 0);
+ QVERIFY(firstItem);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(true));
+
+ pathview->decrementCurrentIndex();
+ QTRY_COMPARE(pathview->currentIndex(), 3);
+ firstItem = findItem<QSGRectangle>(pathview, "wrapper", 3);
+ QVERIFY(firstItem);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(false));
+
+ pathview->incrementCurrentIndex();
+ QTRY_COMPARE(pathview->currentIndex(), 0);
+ firstItem = findItem<QSGRectangle>(pathview, "wrapper", 0);
+ QVERIFY(firstItem);
+ QCOMPARE(pathview->currentItem(), firstItem);
+ QCOMPARE(firstItem->property("onPath"), QVariant(true));
delete canvas;
}