Kirigami-addons

KTableView.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: header.contentWidth
17 contentHeight: header.contentHeight + tableView.contentHeight
18 selectionBehavior: TableView.SelectCells
19
20 signal cellClicked(int row, int column)
21 signal cellDoubleClicked(int row, int column)
22
23 __rowCount: tableView.rows
24
25 QQC2.HorizontalHeaderView {
26 id: header
27
28 width: tableView.width
29 height: root.__rowHeight
30
31 model: root.__columnModel
32 syncView: tableView
33 interactive: false
34
35 rowHeightProvider: () => root.__rowHeight
36
37 delegate: Private.HeaderDelegate {
38 sortEnabled: headerComponent.role === root.sortRole
39 sortOrder: root.sortOrder
40 onClicked: root.columnClicked(column, headerComponent)
41 onDoubleClicked: root.columnDoubleClicked(column, headerComponent)
42 }
43 }
44
45 TableView {
46 id: tableView
47
48 anchors.fill: parent
49 anchors.topMargin: header.height
50 model: root.model
51 interactive: false
52
53 alternatingRows: root.alternatingRows
54 selectionModel: root.selectionModel
55 selectionMode: root.selectionMode
56 selectionBehavior: root.selectionBehavior
57
58 resizableColumns: false
59 resizableRows: false
60
61 rowHeightProvider: () => root.__rowHeight
62 columnWidthProvider: function(column) {
63 if (!isColumnLoaded(index)) {
64 return;
65 }
66
67 return root.__columnWidth(column, explicitColumnWidth(column))
68 }
69
70 delegate: Private.TableCellDelegate {
71 onClicked: root.cellClicked(row, column)
72 onDoubleClicked: root.cellDoubleClicked(row, column)
73 }
74 }
75
76 QQC2.SelectionRectangle {
77 target: tableView
78 topLeftHandle: null
79 bottomRightHandle: null
80 }
81
82 // TableView controls selection behavior only when user interact with table using keyboard and holding shift key
83 onCellClicked: function(row, column) {
84 if (root.selectionBehavior === TableView.SelectCells) {
85 __selectCell(row, column);
86 }
87
88 if (root.selectionBehavior === TableView.SelectRows) {
89 if (__isControlModifier || __isShiftModifier) {
90 __selectRow(row);
91 return
92 }
93
94 root.selectionModel.clearSelection();
95 root.selectionModel.clearCurrentIndex();
96 for (let _column = 0; _column < root.columnCount; _column++) {
97 root.selectionModel.setCurrentIndex(root.model.index(row, _column), ItemSelectionModel.Select);
98 }
99 }
100
101 if (root.selectionBehavior === TableView.SelectColumns) {
102 if (__isControlModifier || __isShiftModifier) {
103 __selectColumn(column);
104 return;
105 }
106
107 root.selectionModel.clearSelection();
108 root.selectionModel.clearCurrentIndex();
109 for (let _row = 0; _row < root.rowCount; _row++) {
110 root.selectionModel.setCurrentIndex(root.model.index(_row, column), ItemSelectionModel.Select);
111 }
112 }
113 }
114}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:51:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.