From 215e5a45447f53047bfcc167da46714bf1496e8f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 10 Oct 2020 12:40:27 +0200 Subject: desktop: make divecomputer table sortable Add a small proxy-model on top of DiveComputerModel so that clicking on table headers makes the table sortable. The UI feature here is not as important as the fact that the UI does its own sorting and we can keep the device-table in the core sorted differently. Signed-off-by: Berthold Stoeger --- desktop-widgets/divecomputermanagementdialog.cpp | 4 +++- desktop-widgets/divecomputermanagementdialog.h | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/divecomputermanagementdialog.cpp b/desktop-widgets/divecomputermanagementdialog.cpp index f060e3715..bfeddf24f 100644 --- a/desktop-widgets/divecomputermanagementdialog.cpp +++ b/desktop-widgets/divecomputermanagementdialog.cpp @@ -20,7 +20,9 @@ DiveComputerManagementDialog::DiveComputerManagementDialog(QWidget *parent, Qt:: void DiveComputerManagementDialog::init() { model.reset(new DiveComputerModel); - ui.tableView->setModel(model.data()); + proxyModel.setSourceModel(model.get()); + ui.tableView->setModel(&proxyModel); + ui.tableView->setSortingEnabled(true); ui.tableView->resizeColumnsToContents(); ui.tableView->setColumnWidth(DiveComputerModel::REMOVE, 22); layout()->activate(); diff --git a/desktop-widgets/divecomputermanagementdialog.h b/desktop-widgets/divecomputermanagementdialog.h index 806ec8073..d80f8f9d3 100644 --- a/desktop-widgets/divecomputermanagementdialog.h +++ b/desktop-widgets/divecomputermanagementdialog.h @@ -1,9 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 #ifndef DIVECOMPUTERMANAGEMENTDIALOG_H #define DIVECOMPUTERMANAGEMENTDIALOG_H -#include + #include "ui_divecomputermanagementdialog.h" #include "qt-models/divecomputermodel.h" +#include +#include class QModelIndex; @@ -23,7 +25,8 @@ slots: private: explicit DiveComputerManagementDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); Ui::DiveComputerManagementDialog ui; - QScopedPointer model; + std::unique_ptr model; + DiveComputerSortedModel proxyModel; }; #endif // DIVECOMPUTERMANAGEMENTDIALOG_H -- cgit v1.2.3-70-g09d2