Kirigami-addons

ListTableView.qml
1/*
2 * Copyright 2023 Evgeny Chesnokov <echesnokov@astralinux.ru>
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6import QtQuick
7import QtQuick.Controls as QQC2
8
9import org.kde.kirigami as Kirigami
10
11import "private" as Private
12
13Private.AbstractTable {
14 id: root
15
16 contentWidth: __columnsContentWidth()
17 contentHeight: listView.contentHeight
18
19 __rowCount: listView.count
20
21 ListView {
22 id: listView
23
24 anchors.fill: parent
25 model: root.model
26 interactive: false
27
28 header: QQC2.HorizontalHeaderView {
29 id: header
30
31 width: listView.width
32 height: root.__rowHeight
33
34 model: root.__columnModel
35 interactive: false
36
37 rowHeightProvider: () => root.__rowHeight
38 columnWidthProvider: function(column) {
39 if (!isColumnLoaded(index)) {
40 return;
41 }
42
43 return root.__columnWidth(column, explicitColumnWidth(column))
44 }
45
46 onLayoutChanged: {
47 for(let column = 0; column < root.columnCount; column++) {
48 const columnItem = root.__columnModel.get(column).headerComponent;
49 columnItem.width = columnWidthProvider(column)
50 }
51 }
52
53 delegate: Private.HeaderDelegate {
54 sortEnabled: headerComponent.role === root.sortRole
55 sortOrder: root.sortOrder
56 onClicked: root.columnClicked(column, headerComponent)
57 onDoubleClicked: root.columnDoubleClicked(column, headerComponent)
58 }
59 }
60
61 delegate: Private.ListRowDelegate {
62 id: delegate
63
64 highlighted: root.selectionModel?.isSelected(root.model.index(index, 0)) ?? false
65 alternatingRows: root.alternatingRows
66
67 Connections {
68 target: root.selectionModel
69
70 function onSelectionChanged(selected, deselected) {
71 delegate.highlighted = Qt.binding(() => root.selectionModel.isSelected(root.model.index(delegate.index, 0)))
72 }
73 }
74
75 onClicked: root.rowClicked(index)
76 onDoubleClicked: root.rowDoubleClicked(index)
77 }
78 }
79}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:05:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.