Commit 8ea0d383 authored by David Redondo's avatar David Redondo 🏎
Browse files

Layout tables correctly in rtl case

- Reverse table columns because no rtl support in QQuickTableView
- Because of that need to read columnWidths from the end
- FirstCellDelgate needs to be in the last column
- The header correctly reverses so it needs to use the columnWidthProvider in reverse
- Align the header correctly
parent b9d73bac
......@@ -23,7 +23,7 @@ if(ECM_VERSION VERSION_GREATER_EQUAL 5.79)
endif()
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Quick Widgets DBus)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS I18n Config Declarative Service GlobalAccel KIO DBusAddons NewStuff)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS I18n Config Declarative Service GlobalAccel KIO DBusAddons NewStuff ItemModels)
find_package(KSysGuard ${PROJECT_VERSION} REQUIRED)
find_package(Qt5QuickControls2 ${QT_MIN_VERSION})
set_package_properties(Qt5QuickControls2 PROPERTIES
......
......@@ -69,6 +69,8 @@ Table.BaseTableView {
sortFilter.sortOrder = order
}
headerModel: sortFilter
model: KItemModels.KSortFilterProxyModel {
id: sortFilter
......@@ -158,7 +160,7 @@ Table.BaseTableView {
delegate: DelegateChooser {
role: "displayStyle"
DelegateChoice {
column: 0;
column: view.LayoutMirroring.enabled ? view.model.columnCount() - 1 : 0
Table.FirstCellDelegate {
iconName: {
var index = sortFilter.mapToSource(sortFilter.index(model.row, 0))
......
......@@ -20,7 +20,7 @@ SPDX-License-Identifier: LGPL-2.0-or-later
<default>name,usage,vmPSS,netInbound,netOutbound,ioCharactersActuallyReadRate,ioCharactersActuallyWrittenRate</default>
</entry>
<entry name="columnWidths" type="StringList">
<default>0.25,0.125,0.125,0.125,0.125,0.125,0.125,0.125</default>
<default>0.25,0.125,0.125,0.125,0.125,0.125,0.125</default>
</entry>
<entry name="sortColumn" type="String">
<default>name</default>
......
......@@ -156,7 +156,7 @@ Table.BaseTableView {
delegate: DelegateChooser {
role: "displayStyle"
DelegateChoice {
column: 0;
column: view.LayoutMirroring.enabled ? view.model.columnCount() - 1 : 0
Table.FirstCellDelegate {
id: delegate
treeDecorationVisible: !view.flatList
......
......@@ -10,11 +10,12 @@ import QtQuick.Layouts 1.12
import QtQml.Models 2.12
import org.kde.kirigami 2.2 as Kirigami
import org.kde.ksysguard.table 1.0 as Table
FocusScope {
id: root
property alias model: tableView.model
property var model
property alias delegate: tableView.delegate
property alias headerModel: heading.sourceModel
......@@ -71,8 +72,7 @@ FocusScope {
view: tableView
width: tableView.contentWidth + scrollView.rightPadding
width: scrollView.width
onSort: root.sort(column, order)
onResize: root.setColumnWidth(column, width)
......@@ -166,13 +166,13 @@ FocusScope {
anchors.fill: parent
anchors.topMargin: heading.height
property real innerWidth: width - rightPadding
property real innerWidth: LayoutMirroring.enabled ? width - leftPadding : width - rightPadding
background: Rectangle { color: Kirigami.Theme.backgroundColor; Kirigami.Theme.colorSet: Kirigami.Theme.View }
TableView {
id: tableView
anchors.left: parent.left
property ItemSelectionModel selectionModel: ItemSelectionModel {
id: selectionModel
model: tableView.model
......@@ -183,6 +183,15 @@ FocusScope {
onWidthChanged: forceLayout()
// FIXME Until Tableview correctly reverses its columns, see QTBUG-90547
model: root.model
Binding on model {
when: scrollView.LayoutMirroring.enabled
value: Table.ReverseColumnsProxyModel {
sourceModel: root.model
}
}
activeFocusOnTab: true
clip: true
......@@ -232,13 +241,17 @@ FocusScope {
}
columnWidthProvider: function(index) {
var width = root.columnWidths[index]
// FIXME Until Tableview correctly reverses its columns, see QTBUG-90547
if (scrollView.LayoutMirroring.enabled) {
var width = root.columnWidths[root.columnWidths.length - index - 1]
} else {
var width = root.columnWidths[index]
}
if (width === undefined || width === null) {
width = root.defaultColumnWidth
} else {
width = width
}
width = Math.max(Math.floor(width * scrollView.innerWidth), root.minimumColumnWidth)
return width
}
......
......@@ -4,6 +4,7 @@ set(table_SRCS
ColumnSortModel.cpp
ComponentCacheProxyModel.cpp
ProcessSortFilterModel.cpp
ReverseColumnsProxyModel.cpp
)
set(table_QML
......@@ -20,7 +21,7 @@ set(table_QML
)
add_library(TablePlugin SHARED ${table_SRCS})
target_link_libraries(TablePlugin Qt::Quick KSysGuard::Sensors KSysGuard::ProcessCore KF5::CoreAddons)
target_link_libraries(TablePlugin Qt::Quick KSysGuard::Sensors KSysGuard::ProcessCore KF5::CoreAddons KF5::ItemModels)
install(TARGETS TablePlugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/ksysguard/table)
install(FILES qmldir ${table_QML} DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/ksysguard/table)
/*
* SPDX-FileCopyrightText: 2021 David Redondo <kde@david-redondo.de>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "ReverseColumnsProxyModel.h"
ReverseColumnsProxyModel::ReverseColumnsProxyModel(QObject *parent)
: KRearrangeColumnsProxyModel(parent)
{
}
void ReverseColumnsProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
auto oldModel = this->sourceModel();
if (oldModel == sourceModel) {
return;
}
if (oldModel) {
oldModel->disconnect(this);
}
KRearrangeColumnsProxyModel::setSourceModel(sourceModel);
if (sourceModel) {
connect(sourceModel, &QAbstractItemModel::columnsInserted, this, &ReverseColumnsProxyModel::reverseColumns);
connect(sourceModel, &QAbstractItemModel::columnsRemoved, this, &ReverseColumnsProxyModel::reverseColumns);
connect(sourceModel, &QAbstractItemModel::modelReset, this, &ReverseColumnsProxyModel::reverseColumns);
reverseColumns();
}
}
void ReverseColumnsProxyModel::reverseColumns()
{
if (!sourceModel()) {
return;
}
QVector<int> columns(sourceModel()->columnCount());
std::iota(columns.rbegin(), columns.rend(), 0);
setSourceColumns(columns);
}
/*
* SPDX-FileCopyrightText: 2021 David Redondo <kde@david-redondo.de>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#pragma once
#include <KRearrangeColumnsProxyModel>
/**
* A proxy model to reverse the columns of a table. Needed because QML Tableview does not correctly
* reverse its columns when using a RTL language.
*/
class ReverseColumnsProxyModel : public KRearrangeColumnsProxyModel
{
public:
ReverseColumnsProxyModel(QObject *parent = nullptr);
void setSourceModel(QAbstractItemModel *sourceModel) override;
private:
void reverseColumns();
};
......@@ -12,6 +12,7 @@
#include "ColumnSortModel.h"
#include "ComponentCacheProxyModel.h"
#include "ProcessSortFilterModel.h"
#include "ReverseColumnsProxyModel.h"
void TablePlugin::registerTypes(const char *uri)
{
......@@ -21,4 +22,5 @@ void TablePlugin::registerTypes(const char *uri)
qmlRegisterType<ColumnDisplayModel>(uri, 1, 0, "ColumnDisplayModel");
qmlRegisterType<ComponentCacheProxyModel>(uri, 1, 0, "ComponentCacheProxyModel");
qmlRegisterType<ProcessSortFilterModel>(uri, 1, 0, "ProcessSortFilterModel");
qmlRegisterType<ReverseColumnsProxyModel>(uri, 1, 0, "ReverseColumnsProxyModel");
}
......@@ -17,7 +17,7 @@ import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
FocusScope {
id: heading
x: -view.contentX
x: LayoutMirroring.enabled ? view.contentWidth - view.width - view.contentX : -view.contentX
width: view.contentWidth
height: heightHelper.height
......@@ -47,7 +47,7 @@ FocusScope {
raised: false
sunken: false
properties: {
"headerpos": "end"
"headerpos": LayoutMirroring.enabled ? "beginning" : "end"
}
}
......@@ -80,7 +80,8 @@ FocusScope {
Row {
id: headerRow
anchors.left: parent.left
anchors.leftMargin: LayoutMirroring.enabled ? view.contentWidth - width : 0
property int currentIndex: 0
Repeater {
......@@ -93,8 +94,8 @@ FocusScope {
delegate: StylePrivate.StyleItem {
id: headerItem
width: heading.view.columnWidthProvider(model.row)
// FIXME Need to reverse the index order until TableView correctly supports it itself, see QTBUG-90547
width: heading.view.columnWidthProvider(LayoutMirroring.enabled ? repeater.count - model.row - 1 : model.row)
height: heightHelper.height
enabled: width > 0
......@@ -102,8 +103,10 @@ FocusScope {
if (repeater.count === 1) {
return "only";
}
return "beginning";
if (index == 0) {
return LayoutMirroring.enabled ? "end" : "beginning"
}
return "middle"
}
property string columnId: model[heading.idRole] !== undefined ? model[heading.idRole] : ""
......
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