on xenial help sign in
Pass index using a property, because it gets lost through the Loader.
commitd6aae77daaee276695ad629dba8f573ea667f2c8 authorMichał Sawicz <michal.sawicz@canonical.com> dateTue 8 Jul 2014, 19:49 (12 years ago) parentc199553
4 files changed+9−2
qml/Components/BaseCarouselDelegate.qml+3 qml/Components/Carousel.qml+1−1 qml/Dash/CardCarousel.qml+3−1 tests/qmltests/Components/tst_Carousel.qml+2
qml/Components/BaseCarouselDelegate.qml+3
@@ -28,6 +28,9 @@ Item {
2828 /// True if this item is currently "focused" in the carousel.
2929 property bool explicitlyScaled
3030
31+ /// Model index for this delegate.
32+ property int index
33+
3134 /// Model data for this delegate.
3235 property var model
3336
qml/Components/Carousel.qml+1−1
@@ -306,8 +306,8 @@ Item {
306306 }
307307
308308 onLoaded: {
309− item.objectName = Qt.binding(function() { return "carouselDelegate" + index; });
310309 item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; });
310+ item.index = Qt.binding(function() { return index; });
311311 item.model = Qt.binding(function() { return model; });
312312 }
313313
qml/Dash/CardCarousel.qml+3−1
@@ -48,14 +48,16 @@ DashRenderer {
4848
4949 property bool explicitlyScaled
5050 property var model
51+ property int index
5152 enabled: false
5253
54+ objectName: "carouselDelegate" + index
55+
5356 function clicked() { cardCarousel.clicked(index, model.result) }
5457 function pressAndHold() { cardCarousel.pressAndHold(index, model.result) }
5558
5659 sourceComponent: cardTool.cardComponent
5760 onLoaded: {
58− item.objectName = "carouselDelegate" + index;
5961 item.fixedHeaderHeight = Qt.binding(function() { return carousel.headerHeight; });
6062 item.height = Qt.binding(function() { return cardTool.cardHeight; });
6163 item.cardData = Qt.binding(function() { return model; });
tests/qmltests/Components/tst_Carousel.qml+2
@@ -32,6 +32,8 @@ Item {
3232 property int destroyedDelegates: 0
3333
3434 itemComponent: BaseCarouselDelegate {
35+ objectName: "carouselDelegate" + index
36+
3537 Rectangle {
3638 anchors.fill: parent
3739 border.color: "black"