Skip to content

Use creationContext of the Component as the starting point in DelegateRecycler

Sharaf Zaman requested to merge szaman/kirigami:fixes-delegate-recycler into master

Otherwise we lose access to the context (id) where the component was declared. I wouldn't call myself a QML expert, so I'm not sure if this is the right way to go.

Toy Example:

main.qml:

import QtQuick 2.6
import QtQuick.Controls 2.12 as Controls
import org.kde.kirigami 2.4 as Kirigami


MyCardsView {
    id: notRoot

}

MyCardsView.qml:

import QtQuick 2.6
import QtQuick.Controls 2.12 as Controls
import org.kde.kirigami 2.4 as Kirigami

Kirigami.CardsGridView {

    id: root
    property int myWidth: 50

    model: 5
    delegate: Rectangle {
        width: root.myWidth
        height: root.myWidth
        color: "blue"
    }
}

Running without the patch gives:

~/w/kirigami-bug [master] λ qmlscene main.qml
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:13: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:12: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:13: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:12: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:13: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:12: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:0: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:0: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:0: ReferenceError: root is not defined
file:///home/sh_zam/workspace/kirigami-bug/MyCardsView.qml:0: ReferenceError: root is not defined

Merge request reports