7import QtQuick.Controls as QQC2
9import org.kde.kirigami as Kirigami
14 Accessible.role: Accessible.Table
31 property list<AbstractHeaderComponent> headerComponents
32 onHeaderComponentsChanged: updateModel()
37 readonly property
int rowCount: __rowCount
42 readonly property
int columnCount: __columnCount
49 property
bool alternatingRows: true
57 property
bool compact: true
64 property alias actions: menu.contentData
74 property
int sortOrder
82 property
int sortRole: -1
94 property ItemSelectionModel selectionModel: ItemSelectionModel { model: root.model }
103 property int selectionBehavior: TableView.SelectRows
114 property int selectionMode: TableView.ExtendedSelection
116 signal columnClicked(
int column, var headerComponent)
117 signal columnDoubleClicked(
int column, var headerComponent)
119 signal rowClicked(
int row)
120 signal rowDoubleClicked(
int row)
122 readonly
property var __columnModel: ListModel { id: columnModel }
123 readonly
property real __rowHeight: root.compact ?
Kirigami.Units.gridUnit * 2
126 property int __rowCount
127 property int __columnCount: columnModel.count
129 property bool __isControlModifier:
false
130 property bool __isShiftModifier:
false
132 Keys.onPressed: function(event) {
133 __isControlModifier =
event.modifiers &
Qt.ControlModifier
134 __isShiftModifier =
event.modifiers &
Qt.ShiftModifier
137 Keys.onReleased: function(event) {
138 __isControlModifier =
event.modifiers &
Qt.ControlModifier
139 __isShiftModifier =
event.modifiers &
Qt.ShiftModifier
142 onRowClicked: function(row) {
143 __selectCell(row, 0);
146 QQC2.Menu { id: menu }
151 propagateComposedEvents:
true
152 acceptedButtons:
Qt.RightButton
153 onClicked: function(mouse) {
154 root.forceActiveFocus();
155 if (mouse.button ===
Qt.RightButton) {
156 if (menu.count > 0) {
160 mouse.accepted =
true
165 mouse.accepted =
false
169 function updateModel(): void {
170 __columnModel.
clear();
171 for(let index = 0; index < root.headerComponents.length; index++) {
172 let
object = root.headerComponents[index];
175 __columnModel.append({ headerComponent:
object });
180 function __columnsContentWidth(): real {
183 for(let index = 0; index < __columnModel.count; index++) {
184 let column = __columnModel.get(index).headerComponent;
186 if (column.visible) {
187 contentWidth += column.width;
194 function __columnWidth(column:
int, explicitWidth: real): real {
195 const columnItem = root.__columnModel.
get(column).headerComponent;
196 if (!columnItem.resizable) {
197 return columnItem.width;
200 if (explicitWidth > 0) {
201 if (explicitWidth < columnItem.minimumWidth) {
202 return columnItem.minimumWidth;
205 return explicitWidth;
208 return columnItem.width;
211 function __selectCell(row:
int, column:
int): void {
212 if (!root.selectionModel || root.selectionBehavior === TableView.SelectionDisabled) {
216 const modelIndex = root.model.index(row, column);
218 if (__isControlModifier && root.selectionMode !== TableView.SingleSelection) {
219 root.selectionModel.setCurrentIndex(modelIndex, ItemSelectionModel.Toggle);
221 if (!root.selectionModel.hasSelection) {
222 root.selectionModel.clearSelection();
223 root.selectionModel.clearCurrentIndex();
229 if (__isShiftModifier && root.selectionMode !== TableView.SingleSelection) {
230 const currentIndex = root.selectionModel.currentIndex;
232 const startRow = Math.min(row, currentIndex.row);
233 const endRow = Math.max(row, currentIndex.row);
234 const startColumn = Math.min(column, currentIndex.column);
235 const endColumn = Math.max(column, currentIndex.column);
237 for (let _row = startRow; _row <= endRow; _row++) {
238 for (let _column = startColumn; _column <= endColumn; _column++) {
239 root.selectionModel.select(root.model.index(_row, _column), ItemSelectionModel.Select);
246 root.selectionModel.setCurrentIndex(modelIndex, ItemSelectionModel.ClearAndSelect);
249 function __selectRow(row:
int): void {
250 for (let column = 0; column < root.__columnCount; column++) {
251 __selectCell(row, column);
255 function __selectColumn(column:
int): void {
256 for (let row = 0; row < root.__rowCount; row++) {
257 __selectCell(row, column);
KIOCORE_EXPORT TransferJob * get(const QUrl &url, LoadType reload=NoReload, JobFlags flags=DefaultFlags)