From bd056a00ceb7bdfe69f845b1dbce0e601c42ab54 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Mon, 12 Jan 2026 09:57:44 +0100 Subject: [PATCH 1/2] Using the new QSortFilterProxyModel subclass of the core for the TableView. --- mainwindow.cpp | 6 +++++- mainwindow.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index d1e405d..797a5db 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -13,6 +13,7 @@ #include "dialogs/edititemdialog.h" #include "dialogs/newitemdialog.h" #include "genericcore.h" +#include "model/generalsortfiltermodel.h" #include "model/tablemodel.h" static QStandardPaths::StandardLocation standardLocation = QStandardPaths::HomeLocation; @@ -45,7 +46,10 @@ MainWindow::MainWindow(QWidget* parent) restoreState(settings.value("windowState").toByteArray()); m_tableModel = m_core->getModel(); - ui->tableView->setModel(m_tableModel.get()); + // ui->tableView->setModel(m_tableModel.get()); + m_sortModel = m_core->getSortFilterModel(); + ui->tableView->setModel((QAbstractItemModel*)m_sortModel.get()); + ui->tableView->setSortingEnabled(true); createActions(); createHelpMenu(); diff --git a/mainwindow.h b/mainwindow.h index 03a1103..195f6ca 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -16,6 +16,7 @@ QT_END_NAMESPACE class GenericCore; class TableModel; +class GeneralSortFilterModel; class NewItemDialog; class EditItemDialog; @@ -65,6 +66,7 @@ class MainWindow : public QMainWindow { // GenericCore* m_core; unique_ptr m_core; shared_ptr m_tableModel; + shared_ptr m_sortModel; QUndoStack* m_modelUndoStack; unique_ptr m_modelUndoView; From 8a0d37f8f9a9f1a95624706388e3d1e90bf1ac85 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Mon, 12 Jan 2026 10:15:05 +0100 Subject: [PATCH 2/2] Not using the TableModel directly anymore. Removing and appending items via GeneralSortFilterModel. --- mainwindow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 797a5db..e899cd7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -194,7 +194,7 @@ void MainWindow::deleteCurrentItem() { if (currentIndex == QModelIndex()) { qDebug() << "No current item. Nothing to remove."; } else { - m_tableModel->removeRows(currentIndex.row(), 1); + m_sortModel->removeRows(currentIndex.row(), 1); } } @@ -212,7 +212,7 @@ void MainWindow::deleteSelectedtItems() { const int topRow = iter->top(); const int bottomRow = iter->bottom(); const int nRows = bottomRow - topRow + 1; - m_tableModel->removeRows(topRow, nRows); + m_sortModel->removeRows(topRow, nRows); } } } @@ -444,8 +444,8 @@ void MainWindow::createGuiDialogs() { /// new item dialog m_newItemDialog = make_unique(this); m_newItemDialog->createContent(); - connect(m_newItemDialog.get(), &NewItemDialog::addItems, m_tableModel.get(), - &TableModel::appendItems); + connect(m_newItemDialog.get(), &NewItemDialog::addItems, m_sortModel.get(), + &GeneralSortFilterModel::appendItems); /// edit item dialog m_editItemDialog = make_unique(ui->tableView, this); m_editItemDialog->createContent();