Commit 6a597529 authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈
Browse files

simplify the way the tableview header works

tableview is so very annoying to use :(

- put header row into the model and theme the delegate accordingly
- throw away the manual row, it was incorrectly placed anyway
- throw away the layout code it is no longer necessary
- no longer elide the delegate we want scrollbars everywhere so we can
definitely fit all the data in the view
- space the columns using largespacing so they don't stick together
- use monospace font so the rwx shebang is aligned properly
parent e87f18a4
Pipeline #154455 passed with stage
in 38 seconds
......@@ -2,6 +2,7 @@
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2021 Danil Shein <dshein@altlinux.org>
SPDX-FileCopyrightText: 2021 Slava Aseev <nullptrnine@basealt.ru>
SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*/
#include "permissionshelper.h"
......@@ -12,6 +13,7 @@
#include <QDebug>
#include <QFileInfo>
#include <QMetaEnum>
#include <KLocalizedString>
#include "model.h"
#include "usermanager.h"
......@@ -69,7 +71,7 @@ PermissionsHelperModel::PermissionsHelperModel(PermissionsHelper *helper)
int PermissionsHelperModel::rowCount(const QModelIndex &) const
{
return parent->affectedPaths().count();
return parent->affectedPaths().count() + 1 /* header */;
}
int PermissionsHelperModel::columnCount(const QModelIndex &) const
......@@ -79,14 +81,32 @@ int PermissionsHelperModel::columnCount(const QModelIndex &) const
QVariant PermissionsHelperModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return {};
}
if (index.row() == 0 /* header */) {
switch (index.column()) {
case ColumnPath:
return i18nc("@title", "File Path");
case ColumnOldPermissions:
return i18nc("@title", "Current Permissions");
case ColumnNewPermissions:
return i18nc("@title", "Required Permissions");
};
}
if (role == Qt::DisplayRole) {
const int row = index.row() - 1 /* header */;
const auto &affectedPath = parent->affectedPaths().at(row);
switch (index.column()) {
case ColumnPath:
return parent->affectedPaths().at(index.row()).path;
return affectedPath.path;
case ColumnOldPermissions:
return QVariant::fromValue(permissionsToString(parent->affectedPaths().at(index.row()).oldPerm));
return QVariant::fromValue(permissionsToString(affectedPath.oldPerm));
case ColumnNewPermissions:
return QVariant::fromValue(permissionsToString(parent->affectedPaths().at(index.row()).newPerm));
return QVariant::fromValue(permissionsToString(affectedPath.newPerm));
};
}
......
/*
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2021 Slava Aseev <nullptrnine@basealt.ru>
SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*/
#pragma once
......@@ -25,7 +26,7 @@ public:
explicit PermissionsHelperModel(PermissionsHelper *helper);
int rowCount(const QModelIndex &parent = {}) const override;
int columnCount(const QModelIndex &parent = {}) const override;
Q_INVOKABLE int columnCount(const QModelIndex &parent = {}) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
......
/*
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
SPDX-FileCopyrightText: 2021 Slava Aseev <nullptrnine@basealt.ru>
SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*/
import QtQuick 2.12
......@@ -36,66 +37,26 @@ Item {
`, sambaPlugin.shareContext.path)
}
Row {
id: row
Layout.fillWidth: true
Repeater {
id: repeater
model: [
i18nc("@title", "File Path"),
i18nc("@title", "Current Permissions"),
i18nc("@title", "Required Permissions")
]
QQC2.Label {
width: row.width / repeater.count
text: modelData
}
}
}
QQC2.ScrollView {
Layout.fillWidth: true
Layout.fillHeight: true
contentItem: TableView {
id: view
property bool itemComplete: false
anchors.fill: parent
clip: true
interactive: false
model: sambaPlugin.permissionsHelper.model
columnWidthProvider: function (column) {
return view.model ? view.width / view.model.columnCount() : 0
}
Timer {
id: forceLayoutTimer
interval: 0
running: false
repeat: false
onTriggered: {
if (view.itemComplete) {
view.forceLayout()
}
}
}
onWidthChanged: forceLayoutTimer.start()
property int maxColumn: model.columnCount() - 1
delegate: RowLayout {
delegate: QQC2.Label {
font.bold: row == 0 /* header */ ? true : false
Layout.fillWidth: true
QQC2.Label {
Layout.fillWidth: true
text: display
elide: Text.ElideMiddle
}
text: display
font.family: "monospace"
rightPadding: column >= view.maxColumn ? 0 : Kirigami.Units.largeSpacing
}
Component.onCompleted: itemComplete = true
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment