58 |
58 |
59 void QDeclarativeViewSection::setProperty(const QString &property) |
59 void QDeclarativeViewSection::setProperty(const QString &property) |
60 { |
60 { |
61 if (property != m_property) { |
61 if (property != m_property) { |
62 m_property = property; |
62 m_property = property; |
63 emit changed(); |
63 emit propertyChanged(); |
64 } |
64 } |
65 } |
65 } |
66 |
66 |
67 void QDeclarativeViewSection::setCriteria(QDeclarativeViewSection::SectionCriteria criteria) |
67 void QDeclarativeViewSection::setCriteria(QDeclarativeViewSection::SectionCriteria criteria) |
68 { |
68 { |
69 if (criteria != m_criteria) { |
69 if (criteria != m_criteria) { |
70 m_criteria = criteria; |
70 m_criteria = criteria; |
71 emit changed(); |
71 emit criteriaChanged(); |
72 } |
72 } |
73 } |
73 } |
74 |
74 |
75 void QDeclarativeViewSection::setDelegate(QDeclarativeComponent *delegate) |
75 void QDeclarativeViewSection::setDelegate(QDeclarativeComponent *delegate) |
76 { |
76 { |
94 { |
94 { |
95 public: |
95 public: |
96 FxListItem(QDeclarativeItem *i, QDeclarativeListView *v) : item(i), section(0), view(v) { |
96 FxListItem(QDeclarativeItem *i, QDeclarativeListView *v) : item(i), section(0), view(v) { |
97 attached = static_cast<QDeclarativeListViewAttached*>(qmlAttachedPropertiesObject<QDeclarativeListView>(item)); |
97 attached = static_cast<QDeclarativeListViewAttached*>(qmlAttachedPropertiesObject<QDeclarativeListView>(item)); |
98 if (attached) |
98 if (attached) |
99 attached->m_view = view; |
99 attached->setView(view); |
100 } |
100 } |
101 ~FxListItem() {} |
101 ~FxListItem() {} |
102 qreal position() const { |
102 qreal position() const { |
103 if (section) |
103 if (section) |
104 return (view->orientation() == QDeclarativeListView::Vertical ? section->y() : section->x()); |
104 return (view->orientation() == QDeclarativeListView::Vertical ? section->y() : section->x()); |
105 else |
105 else |
106 return (view->orientation() == QDeclarativeListView::Vertical ? item->y() : item->x()); |
106 return (view->orientation() == QDeclarativeListView::Vertical ? item->y() : item->x()); |
107 } |
107 } |
|
108 qreal itemPosition() const { |
|
109 return (view->orientation() == QDeclarativeListView::Vertical ? item->y() : item->x()); |
|
110 } |
108 qreal size() const { |
111 qreal size() const { |
109 if (section) |
112 if (section) |
110 return (view->orientation() == QDeclarativeListView::Vertical ? item->height()+section->height() : item->width()+section->height()); |
113 return (view->orientation() == QDeclarativeListView::Vertical ? item->height()+section->height() : item->width()+section->width()); |
111 else |
114 else |
112 return (view->orientation() == QDeclarativeListView::Vertical ? item->height() : item->width()); |
115 return (view->orientation() == QDeclarativeListView::Vertical ? item->height() : item->width()); |
|
116 } |
|
117 qreal itemSize() const { |
|
118 return (view->orientation() == QDeclarativeListView::Vertical ? item->height() : item->width()); |
|
119 } |
|
120 qreal sectionSize() const { |
|
121 if (section) |
|
122 return (view->orientation() == QDeclarativeListView::Vertical ? section->height() : section->width()); |
|
123 return 0.0; |
113 } |
124 } |
114 qreal endPosition() const { |
125 qreal endPosition() const { |
115 return (view->orientation() == QDeclarativeListView::Vertical |
126 return (view->orientation() == QDeclarativeListView::Vertical |
116 ? item->y() + (item->height() > 0 ? item->height() : 1) |
127 ? item->y() + (item->height() > 0 ? item->height() : 1) |
117 : item->x() + (item->width() > 0 ? item->width() : 1)) - 1; |
128 : item->x() + (item->width() > 0 ? item->width() : 1)) - 1; |
128 section->setX(pos); |
139 section->setX(pos); |
129 pos += section->width(); |
140 pos += section->width(); |
130 } |
141 } |
131 item->setX(pos); |
142 item->setX(pos); |
132 } |
143 } |
|
144 } |
|
145 void setSize(qreal size) { |
|
146 if (view->orientation() == QDeclarativeListView::Vertical) |
|
147 item->setHeight(size); |
|
148 else |
|
149 item->setWidth(size); |
133 } |
150 } |
134 bool contains(int x, int y) const { |
151 bool contains(int x, int y) const { |
135 return (x >= item->x() && x < item->x() + item->width() && |
152 return (x >= item->x() && x < item->x() + item->width() && |
136 y >= item->y() && y < item->y() + item->height()); |
153 y >= item->y() && y < item->y() + item->height()); |
137 } |
154 } |
254 if (FxListItem *item = visibleItem(modelIndex)) |
271 if (FxListItem *item = visibleItem(modelIndex)) |
255 return item->position(); |
272 return item->position(); |
256 if (!visibleItems.isEmpty()) { |
273 if (!visibleItems.isEmpty()) { |
257 if (modelIndex < visibleIndex) { |
274 if (modelIndex < visibleIndex) { |
258 int count = visibleIndex - modelIndex; |
275 int count = visibleIndex - modelIndex; |
259 return (*visibleItems.constBegin())->position() - count * (averageSize + spacing); |
276 qreal cs = 0; |
|
277 if (modelIndex == currentIndex && currentItem) { |
|
278 cs = currentItem->size() + spacing; |
|
279 --count; |
|
280 } |
|
281 return (*visibleItems.constBegin())->position() - count * (averageSize + spacing) - cs; |
260 } else { |
282 } else { |
261 int idx = visibleItems.count() - 1; |
283 int idx = visibleItems.count() - 1; |
262 while (idx >= 0 && visibleItems.at(idx)->index == -1) |
284 while (idx >= 0 && visibleItems.at(idx)->index == -1) |
263 --idx; |
285 --idx; |
264 if (idx < 0) |
286 if (idx < 0) |
573 if (modelIndex > 0) { |
595 if (modelIndex > 0) { |
574 if (FxListItem *item = visibleItem(modelIndex-1)) |
596 if (FxListItem *item = visibleItem(modelIndex-1)) |
575 listItem->attached->m_prevSection = item->attached->section(); |
597 listItem->attached->m_prevSection = item->attached->section(); |
576 else |
598 else |
577 listItem->attached->m_prevSection = sectionAt(modelIndex-1); |
599 listItem->attached->m_prevSection = sectionAt(modelIndex-1); |
|
600 } |
|
601 if (modelIndex < model->count()-1) { |
578 if (FxListItem *item = visibleItem(modelIndex+1)) |
602 if (FxListItem *item = visibleItem(modelIndex+1)) |
579 listItem->attached->m_nextSection = item->attached->section(); |
603 listItem->attached->m_nextSection = item->attached->section(); |
580 else if (modelIndex < model->count()-1) |
604 else |
581 listItem->attached->m_nextSection = sectionAt(modelIndex+1); |
605 listItem->attached->m_nextSection = sectionAt(modelIndex+1); |
582 } |
606 } |
583 } |
607 } |
584 if (model->completePending()) { |
608 if (model->completePending()) { |
585 // complete |
609 // complete |
712 minExtentDirty = true; |
736 minExtentDirty = true; |
713 maxExtentDirty = true; |
737 maxExtentDirty = true; |
714 if (visibleItems.count()) |
738 if (visibleItems.count()) |
715 visiblePos = (*visibleItems.constBegin())->position(); |
739 visiblePos = (*visibleItems.constBegin())->position(); |
716 updateAverage(); |
740 updateAverage(); |
|
741 if (currentIndex >= 0 && currentItem && !visibleItem(currentIndex)) { |
|
742 currentItem->setPosition(positionAt(currentIndex)); |
|
743 updateHighlight(); |
|
744 } |
|
745 |
717 if (sectionCriteria) |
746 if (sectionCriteria) |
718 updateCurrentSection(); |
747 updateCurrentSection(); |
719 if (header) |
748 if (header) |
720 updateHeader(); |
749 updateHeader(); |
721 if (footer) |
750 if (footer) |
881 { |
910 { |
882 if ((!currentItem && highlight) || (currentItem && !highlight)) |
911 if ((!currentItem && highlight) || (currentItem && !highlight)) |
883 createHighlight(); |
912 createHighlight(); |
884 if (currentItem && autoHighlight && highlight && !movingHorizontally && !movingVertically) { |
913 if (currentItem && autoHighlight && highlight && !movingHorizontally && !movingVertically) { |
885 // auto-update highlight |
914 // auto-update highlight |
886 highlightPosAnimator->to = currentItem->position(); |
915 highlightPosAnimator->to = currentItem->itemPosition(); |
887 highlightSizeAnimator->to = currentItem->size(); |
916 highlightSizeAnimator->to = currentItem->itemSize(); |
888 if (orient == QDeclarativeListView::Vertical) { |
917 if (orient == QDeclarativeListView::Vertical) { |
889 if (highlight->item->width() == 0) |
918 if (highlight->item->width() == 0) |
890 highlight->item->setWidth(currentItem->item->width()); |
919 highlight->item->setWidth(currentItem->item->width()); |
891 } else { |
920 } else { |
892 if (highlight->item->height() == 0) |
921 if (highlight->item->height() == 0) |
979 } |
1008 } |
980 |
1009 |
981 void QDeclarativeListViewPrivate::updateCurrentSection() |
1010 void QDeclarativeListViewPrivate::updateCurrentSection() |
982 { |
1011 { |
983 if (!sectionCriteria || visibleItems.isEmpty()) { |
1012 if (!sectionCriteria || visibleItems.isEmpty()) { |
984 currentSection = QString(); |
1013 currentSection.clear(); |
985 return; |
1014 return; |
986 } |
1015 } |
987 int index = 0; |
1016 int index = 0; |
988 while (visibleItems.at(index)->endPosition() < position() && index < visibleItems.count()) |
1017 while (index < visibleItems.count() && visibleItems.at(index)->endPosition() < position()) |
989 ++index; |
1018 ++index; |
990 |
1019 |
991 if (index < visibleItems.count()) |
1020 if (index < visibleItems.count()) |
992 currentSection = visibleItems.at(index)->attached->section(); |
1021 currentSection = visibleItems.at(index)->attached->section(); |
993 else |
1022 else |
1017 currentIndex = modelIndex; |
1046 currentIndex = modelIndex; |
1018 currentItem = createItem(modelIndex); |
1047 currentItem = createItem(modelIndex); |
1019 if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) |
1048 if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) |
1020 oldCurrentItem->attached->setIsCurrentItem(false); |
1049 oldCurrentItem->attached->setIsCurrentItem(false); |
1021 if (currentItem) { |
1050 if (currentItem) { |
1022 if (modelIndex == visibleIndex - 1) { |
1051 if (modelIndex == visibleIndex - 1 && visibleItems.count()) { |
1023 // We can calculate exact postion in this case |
1052 // We can calculate exact postion in this case |
1024 currentItem->setPosition(visibleItems.first()->position() - currentItem->size() - spacing); |
1053 currentItem->setPosition(visibleItems.first()->position() - currentItem->size() - spacing); |
1025 } else { |
1054 } else { |
1026 // Create current item now and position as best we can. |
1055 // Create current item now and position as best we can. |
1027 // Its position will be corrected when it becomes visible. |
1056 // Its position will be corrected when it becomes visible. |
1168 fixupDuration = oldDuration; |
1197 fixupDuration = oldDuration; |
1169 return; |
1198 return; |
1170 } |
1199 } |
1171 if (currentItem && haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { |
1200 if (currentItem && haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { |
1172 updateHighlight(); |
1201 updateHighlight(); |
1173 qreal currPos = currentItem->position(); |
1202 qreal currPos = currentItem->itemPosition(); |
1174 if (pos < currPos + currentItem->size() - highlightRangeEnd) |
1203 if (pos < currPos + currentItem->itemSize() - highlightRangeEnd) |
1175 pos = currPos + currentItem->size() - highlightRangeEnd; |
1204 pos = currPos + currentItem->itemSize() - highlightRangeEnd; |
1176 if (pos > currPos - highlightRangeStart) |
1205 if (pos > currPos - highlightRangeStart) |
1177 pos = currPos - highlightRangeStart; |
1206 pos = currPos - highlightRangeStart; |
1178 } |
1207 } |
1179 |
1208 |
1180 qreal dist = qAbs(data.move + pos); |
1209 qreal dist = qAbs(data.move + pos); |
1187 vTime = timeline.time(); |
1216 vTime = timeline.time(); |
1188 } |
1217 } |
1189 } else if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { |
1218 } else if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { |
1190 if (currentItem) { |
1219 if (currentItem) { |
1191 updateHighlight(); |
1220 updateHighlight(); |
1192 qreal pos = currentItem->position(); |
1221 qreal pos = currentItem->itemPosition(); |
1193 qreal viewPos = position(); |
1222 qreal viewPos = position(); |
1194 if (viewPos < pos + currentItem->size() - highlightRangeEnd) |
1223 if (viewPos < pos + currentItem->itemSize() - highlightRangeEnd) |
1195 viewPos = pos + currentItem->size() - highlightRangeEnd; |
1224 viewPos = pos + currentItem->itemSize() - highlightRangeEnd; |
1196 if (viewPos > pos - highlightRangeStart) |
1225 if (viewPos > pos - highlightRangeStart) |
1197 viewPos = pos - highlightRangeStart; |
1226 viewPos = pos - highlightRangeStart; |
1198 |
1227 |
1199 timeline.reset(data.move); |
1228 timeline.reset(data.move); |
1200 if (viewPos != position()) { |
1229 if (viewPos != position()) { |
1353 |
1382 |
1354 //---------------------------------------------------------------------------- |
1383 //---------------------------------------------------------------------------- |
1355 |
1384 |
1356 /*! |
1385 /*! |
1357 \qmlclass ListView QDeclarativeListView |
1386 \qmlclass ListView QDeclarativeListView |
|
1387 \ingroup qml-view-elements |
1358 \since 4.7 |
1388 \since 4.7 |
1359 \inherits Flickable |
1389 \inherits Flickable |
1360 \brief The ListView item provides a list view of items provided by a model. |
1390 \brief The ListView item provides a list view of items provided by a model. |
1361 |
1391 |
1362 A ListView displays data from models created from built-in QML elements like ListModel |
1392 A ListView displays data from models created from built-in QML elements like ListModel |
1383 Here, the ListView creates a \c ContactModel component for its model, and a \l Text element |
1413 Here, the ListView creates a \c ContactModel component for its model, and a \l Text element |
1384 for its delegate. The view will create a new \l Text component for each item in the model. Notice |
1414 for its delegate. The view will create a new \l Text component for each item in the model. Notice |
1385 the delegate is able to access the model's \c name and \c number data directly. |
1415 the delegate is able to access the model's \c name and \c number data directly. |
1386 |
1416 |
1387 An improved list view is shown below. The delegate is visually improved and is moved |
1417 An improved list view is shown below. The delegate is visually improved and is moved |
1388 into a separate \c contactDelegate component. Also, the currently selected item is highlighted |
1418 into a separate \c contactDelegate component. |
1389 with a blue \l Rectangle using the \l highlight property, and \c focus is set to \c true |
|
1390 to enable keyboard navigation for the list view. |
|
1391 |
1419 |
1392 \snippet doc/src/snippets/declarative/listview/listview.qml classdocs advanced |
1420 \snippet doc/src/snippets/declarative/listview/listview.qml classdocs advanced |
1393 \image listview-highlight.png |
1421 \image listview-highlight.png |
1394 |
1422 |
1395 In a GridView, delegates are instantiated as needed and may be destroyed at any time. |
1423 The currently selected item is highlighted with a blue \l Rectangle using the \l highlight property, |
|
1424 and \c focus is set to \c true to enable keyboard navigation for the list view. |
|
1425 The list view itself is a focus scope (see \l{qmlfocus#Acquiring Focus and Focus Scopes}{the focus documentation page} for more details). |
|
1426 |
|
1427 Delegates are instantiated as needed and may be destroyed at any time. |
1396 State should \e never be stored in a delegate. |
1428 State should \e never be stored in a delegate. |
1397 |
1429 |
1398 \note Views do not enable \e clip automatically. If the view |
1430 \note Views do not enable \e clip automatically. If the view |
1399 is not clipped by another item or the screen, it will be necessary |
1431 is not clipped by another item or the screen, it will be necessary |
1400 to set \e {clip: true} in order to have the out of view items clipped |
1432 to set \e {clip: true} in order to have the out of view items clipped |
1614 dataModel->setDelegate(delegate); |
1646 dataModel->setDelegate(delegate); |
1615 if (isComponentComplete()) { |
1647 if (isComponentComplete()) { |
1616 for (int i = 0; i < d->visibleItems.count(); ++i) |
1648 for (int i = 0; i < d->visibleItems.count(); ++i) |
1617 d->releaseItem(d->visibleItems.at(i)); |
1649 d->releaseItem(d->visibleItems.at(i)); |
1618 d->visibleItems.clear(); |
1650 d->visibleItems.clear(); |
|
1651 d->releaseItem(d->currentItem); |
|
1652 d->currentItem = 0; |
1619 refill(); |
1653 refill(); |
1620 d->moveReason = QDeclarativeListViewPrivate::SetIndex; |
1654 d->moveReason = QDeclarativeListViewPrivate::SetIndex; |
1621 d->updateCurrent(d->currentIndex); |
1655 d->updateCurrent(d->currentIndex); |
1622 if (d->highlight && d->currentItem) { |
1656 if (d->highlight && d->currentItem) { |
1623 d->highlight->setPosition(d->currentItem->position()); |
1657 d->highlight->setPosition(d->currentItem->position()); |
2333 d->minExtent = -d->startPosition(); |
2367 d->minExtent = -d->startPosition(); |
2334 if (d->header && d->visibleItems.count()) |
2368 if (d->header && d->visibleItems.count()) |
2335 d->minExtent += d->header->size(); |
2369 d->minExtent += d->header->size(); |
2336 if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { |
2370 if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { |
2337 d->minExtent += d->highlightRangeStart; |
2371 d->minExtent += d->highlightRangeStart; |
|
2372 if (d->sectionCriteria) { |
|
2373 if (d->visibleItem(0)) |
|
2374 d->minExtent -= d->visibleItem(0)->sectionSize(); |
|
2375 } |
2338 d->minExtent = qMax(d->minExtent, -(d->endPositionAt(0) - d->highlightRangeEnd + 1)); |
2376 d->minExtent = qMax(d->minExtent, -(d->endPositionAt(0) - d->highlightRangeEnd + 1)); |
2339 } |
2377 } |
2340 d->minExtentDirty = false; |
2378 d->minExtentDirty = false; |
2341 } |
2379 } |
2342 |
2380 |
2444 } |
2482 } |
2445 } |
2483 } |
2446 event->ignore(); |
2484 event->ignore(); |
2447 QDeclarativeFlickable::keyPressEvent(event); |
2485 QDeclarativeFlickable::keyPressEvent(event); |
2448 } |
2486 } |
|
2487 |
|
2488 void QDeclarativeListView::geometryChanged(const QRectF &newGeometry, |
|
2489 const QRectF &oldGeometry) |
|
2490 { |
|
2491 Q_D(QDeclarativeListView); |
|
2492 d->maxExtentDirty = true; |
|
2493 d->minExtentDirty = true; |
|
2494 QDeclarativeFlickable::geometryChanged(newGeometry, oldGeometry); |
|
2495 } |
|
2496 |
2449 |
2497 |
2450 /*! |
2498 /*! |
2451 \qmlmethod ListView::incrementCurrentIndex() |
2499 \qmlmethod ListView::incrementCurrentIndex() |
2452 |
2500 |
2453 Increments the current index. The current index will wrap |
2501 Increments the current index. The current index will wrap |
2570 qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent(); |
2618 qreal minExtent = d->orient == QDeclarativeListView::Vertical ? -minYExtent() : -minXExtent(); |
2571 pos = qMax(pos, minExtent); |
2619 pos = qMax(pos, minExtent); |
2572 d->moveReason = QDeclarativeListViewPrivate::Other; |
2620 d->moveReason = QDeclarativeListViewPrivate::Other; |
2573 cancelFlick(); |
2621 cancelFlick(); |
2574 d->setPosition(pos); |
2622 d->setPosition(pos); |
|
2623 if (d->highlight) { |
|
2624 d->highlight->setPosition(d->currentItem->itemPosition()); |
|
2625 d->highlight->setSize(d->currentItem->itemSize()); |
|
2626 d->updateHighlight(); |
|
2627 } |
2575 } |
2628 } |
2576 d->fixupPosition(); |
2629 d->fixupPosition(); |
2577 } |
2630 } |
2578 |
2631 |
2579 /*! |
2632 /*! |
2630 { |
2683 { |
2631 Q_D(QDeclarativeListView); |
2684 Q_D(QDeclarativeListView); |
2632 if (!d->trackedItem || !d->currentItem) |
2685 if (!d->trackedItem || !d->currentItem) |
2633 return; |
2686 return; |
2634 if (d->moveReason == QDeclarativeListViewPrivate::SetIndex) { |
2687 if (d->moveReason == QDeclarativeListViewPrivate::SetIndex) { |
2635 const qreal trackedPos = qCeil(d->trackedItem->position()); |
2688 qreal trackedPos = qCeil(d->trackedItem->position()); |
|
2689 qreal trackedSize = d->trackedItem->size(); |
|
2690 if (d->trackedItem != d->currentItem) { |
|
2691 trackedPos -= d->currentItem->sectionSize(); |
|
2692 trackedSize += d->currentItem->sectionSize(); |
|
2693 } |
2636 const qreal viewPos = d->position(); |
2694 const qreal viewPos = d->position(); |
2637 qreal pos = viewPos; |
2695 qreal pos = viewPos; |
2638 if (d->haveHighlightRange) { |
2696 if (d->haveHighlightRange) { |
2639 if (d->highlightRange == StrictlyEnforceRange) { |
2697 if (d->highlightRange == StrictlyEnforceRange) { |
2640 if (trackedPos > pos + d->highlightRangeEnd - d->trackedItem->size()) |
2698 if (trackedPos > pos + d->highlightRangeEnd - d->trackedItem->size()) |
2643 pos = trackedPos - d->highlightRangeStart; |
2701 pos = trackedPos - d->highlightRangeStart; |
2644 } else { |
2702 } else { |
2645 if (trackedPos < d->startPosition() + d->highlightRangeStart) { |
2703 if (trackedPos < d->startPosition() + d->highlightRangeStart) { |
2646 pos = d->startPosition(); |
2704 pos = d->startPosition(); |
2647 } else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) { |
2705 } else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) { |
2648 pos = d->endPosition() - d->size(); |
2706 pos = d->endPosition() - d->size() + 1; |
2649 if (pos < d->startPosition()) |
2707 if (pos < d->startPosition()) |
2650 pos = d->startPosition(); |
2708 pos = d->startPosition(); |
2651 } else { |
2709 } else { |
2652 if (trackedPos < viewPos + d->highlightRangeStart) { |
2710 if (trackedPos < viewPos + d->highlightRangeStart) { |
2653 pos = trackedPos - d->highlightRangeStart; |
2711 pos = trackedPos - d->highlightRangeStart; |
2654 } else if (trackedPos > viewPos + d->highlightRangeEnd - d->trackedItem->size()) { |
2712 } else if (trackedPos > viewPos + d->highlightRangeEnd - trackedSize) { |
2655 pos = trackedPos - d->highlightRangeEnd + d->trackedItem->size(); |
2713 pos = trackedPos - d->highlightRangeEnd + trackedSize; |
2656 } |
2714 } |
2657 } |
2715 } |
2658 } |
2716 } |
2659 } else { |
2717 } else { |
2660 if (trackedPos < viewPos && d->currentItem->position() < viewPos) { |
2718 if (trackedPos < viewPos && d->currentItem->position() < viewPos) { |
2661 pos = d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position(); |
2719 pos = d->currentItem->position() < trackedPos ? trackedPos : d->currentItem->position(); |
2662 } else if (d->trackedItem->endPosition() > viewPos + d->size() |
2720 } else if (d->trackedItem->endPosition() >= viewPos + d->size() |
2663 && d->currentItem->endPosition() > viewPos + d->size()) { |
2721 && d->currentItem->endPosition() >= viewPos + d->size()) { |
2664 if (d->trackedItem->endPosition() < d->currentItem->endPosition()) { |
2722 if (d->trackedItem->endPosition() <= d->currentItem->endPosition()) { |
2665 pos = d->trackedItem->endPosition() - d->size(); |
2723 pos = d->trackedItem->endPosition() - d->size() + 1; |
2666 if (d->trackedItem->size() > d->size()) |
2724 if (trackedSize > d->size()) |
2667 pos = trackedPos; |
2725 pos = trackedPos; |
2668 } else { |
2726 } else { |
2669 pos = d->currentItem->endPosition() - d->size(); |
2727 pos = d->currentItem->endPosition() - d->size() + 1; |
2670 if (d->currentItem->size() > d->size()) |
2728 if (d->currentItem->size() > d->size()) |
2671 pos = d->currentItem->position(); |
2729 pos = d->currentItem->position(); |
2672 } |
2730 } |
2673 } |
2731 } |
2674 } |
2732 } |
2897 break; |
2955 break; |
2898 } |
2956 } |
2899 } |
2957 } |
2900 |
2958 |
2901 if (removedVisible && d->visibleItems.isEmpty()) { |
2959 if (removedVisible && d->visibleItems.isEmpty()) { |
2902 d->visibleIndex = 0; |
|
2903 d->visiblePos = d->header ? d->header->size() : 0; |
|
2904 d->timeline.clear(); |
2960 d->timeline.clear(); |
2905 d->setPosition(0); |
|
2906 if (d->itemCount == 0) { |
2961 if (d->itemCount == 0) { |
|
2962 d->visibleIndex = 0; |
|
2963 d->visiblePos = d->header ? d->header->size() : 0; |
|
2964 d->setPosition(0); |
2907 d->updateHeader(); |
2965 d->updateHeader(); |
2908 d->updateFooter(); |
2966 d->updateFooter(); |
2909 update(); |
2967 update(); |
|
2968 } else { |
|
2969 if (modelIndex < d->visibleIndex) |
|
2970 d->visibleIndex = modelIndex+1; |
|
2971 d->visibleIndex = qMax(qMin(d->visibleIndex, d->itemCount-1), 0); |
2910 } |
2972 } |
2911 } |
2973 } |
2912 |
2974 |
2913 emit countChanged(); |
2975 emit countChanged(); |
2914 } |
2976 } |