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); } }