From 8fe5e05f7d106ba3d6ba33cd006b75a4d4d2be2d Mon Sep 17 00:00:00 2001 From: eelke Date: Mon, 17 Jan 2022 17:30:53 +0100 Subject: [PATCH] fix table inspector showed details of wrong table. Caused by using a proxy index with a function that needed an index that was mapped to the source. Fow now mostly fixed by introducing multiple functions with clearer naming and using the correct one but would prefer when the helper could hide the details of there being two index spaces. --- pglab/PgLabTableViewHelper.h | 19 +++++++++++++++---- pglab/widgets/CatalogTablesPage.cpp | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pglab/PgLabTableViewHelper.h b/pglab/PgLabTableViewHelper.h index b8ff2cd..74e315d 100644 --- a/pglab/PgLabTableViewHelper.h +++ b/pglab/PgLabTableViewHelper.h @@ -42,7 +42,7 @@ public: m_tableView->resizeColumnsToContents(); } - QModelIndex currentIndex() const + QModelIndex currentSourceIndex() const { QModelIndex index = m_tableView->selectionModel()->currentIndex(); if (!index.isValid()) @@ -51,18 +51,29 @@ public: return m_sortFilter->mapToSource(index); } - typename TableModel::RowItem rowItem(int row) const + typename TableModel::RowItem rowItemForSourceRow(int row) const { return m_dataModel->rowItem(row); } + typename TableModel::RowItem rowItemForProxyIndex(QModelIndex index) + { + QModelIndex sourceIndex = m_sortFilter->mapToSource(index); + return m_dataModel->rowItem(sourceIndex.row()); + } + + typename TableModel::RowItem rowItemForProxyRow(int row) const + { + return rowItemForProxyIndex(m_sortFilter->index(row, 0, QModelIndex())); + } + std::optional currentRowItem() const { - auto index = currentIndex(); + auto index = currentSourceIndex(); if (!index.isValid()) return {}; - return rowItem(index.row()); + return rowItemForSourceRow(index.row()); } diff --git a/pglab/widgets/CatalogTablesPage.cpp b/pglab/widgets/CatalogTablesPage.cpp index 68e6eee..996f590 100644 --- a/pglab/widgets/CatalogTablesPage.cpp +++ b/pglab/widgets/CatalogTablesPage.cpp @@ -118,7 +118,7 @@ void CatalogTablesPage::setNamespaceFilter(NamespaceFilter filter) void CatalogTablesPage::tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) { if (current.row() != previous.row()) { - auto table = m_tablesTableView.rowItem(current.row()); + auto table = m_tablesTableView.rowItemForProxyIndex(current); selectedTableChanged(table); } }