feat(GenericListView): Ability to display images, option for skipping empty roles

This commit is contained in:
Michał Cieślak 2024-06-13 13:58:18 +02:00 committed by Michał
parent 22be234f7c
commit 6cfef32204
1 changed files with 33 additions and 4 deletions

View File

@ -18,6 +18,9 @@ ListView {
// custom delegate height, when set to 0, delegate's implicitHeight is used // custom delegate height, when set to 0, delegate's implicitHeight is used
property int delegateHeight: 0 property int delegateHeight: 0
// skip role for given row if is empty or undefined
property bool skipEmptyRoles: false
// text to be displayed in a list view's header // text to be displayed in a list view's header
property string label property string label
@ -29,7 +32,7 @@ ListView {
ScrollBar.vertical: ScrollBar {} ScrollBar.vertical: ScrollBar {}
clip: true clip: true
spacing: 5 spacing: 10
leftMargin: margin leftMargin: margin
rightMargin: margin rightMargin: margin
@ -141,21 +144,29 @@ ListView {
Flow { Flow {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Repeater { Repeater {
model: rowModel model: rowModel
Label { delegate: Label {
readonly property var value: readonly property var value:
delegateRoot.topModel[roleName] delegateRoot.topModel[roleName]
readonly property bool mayBeImage: !!value &&
(value.toString().startsWith("file:")
|| value.toString().startsWith("data:image"))
readonly property var valueSanitized: readonly property var valueSanitized:
value === undefined ? "-" : value value === undefined ? "-" : value
readonly property bool last: index === rowModel.count - 1 readonly property bool last: index === rowModel.count - 1
readonly property string separator: last ? "" : "," readonly property string separator: last ? "" : ",  "
text: `${roleName}: ${valueSanitized}${separator}` visible: (value !== undefined && value !== "")
|| !root.skipEmptyRoles
text: `<u>${roleName}</u>: ${mayBeImage ? `<img src="${value}" width="15" height="15">`
: valueSanitized}${separator}`
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
@ -185,5 +196,23 @@ ListView {
root.moveRequested(from, to) root.moveRequested(from, to)
} }
} }
Rectangle {
anchors.top: parent.top
anchors.topMargin: -2
width: parent.width
height: 1
color: "lightgray"
}
Rectangle {
anchors.bottom: parent.bottom
anchors.bottomMargin: -2
width: parent.width
height: 1
color: "lightgray"
}
} }
} }