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.
This commit is contained in:
eelke 2022-01-17 17:30:53 +01:00
parent 93a55047b6
commit 8fe5e05f7d
2 changed files with 16 additions and 5 deletions

View file

@ -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<typename TableModel::RowItem> currentRowItem() const
{
auto index = currentIndex();
auto index = currentSourceIndex();
if (!index.isValid())
return {};
return rowItem(index.row());
return rowItemForSourceRow(index.row());
}

View file

@ -118,7 +118,7 @@ void CatalogTablesPage::setNamespaceFilter(NamespaceFilter filter)
void CatalogTablesPage::tableListTable_currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
{
if (current.row() != previous.row()) {
auto table = m_tablesTableView.rowItem(current.row());
auto table = m_tablesTableView.rowItemForProxyIndex(current);
selectedTableChanged(table);
}
}