refactor use PgLabTableViewHelper on CatalogTablesPage

This commit is contained in:
eelke 2021-12-30 18:54:26 +01:00
parent 87ab22919f
commit 90851ef950
9 changed files with 68 additions and 54 deletions

View file

@ -3,6 +3,9 @@
#include <QTableWidget>
#include <QSortFilterProxyModel>
#include "PgLabTableView.h"
#include <optional>
class PgDatabaseCatalog;
template <typename TableModel>
class PgLabTableViewHelper {
@ -33,6 +36,36 @@ public:
return m_sortFilter;
}
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
{
m_dataModel->setCatalog(cat);
m_tableView->resizeColumnsToContents();
}
QModelIndex currentIndex() const
{
QModelIndex index = m_tableView->selectionModel()->currentIndex();
if (!index.isValid())
return index;
return m_sortFilter->mapToSource(index);
}
typename TableModel::RowItem rowItem(int row) const
{
return m_dataModel->rowItem(row);
}
std::optional<typename TableModel::RowItem> currentRowItem() const
{
auto index = currentIndex();
if (!index.isValid())
return {};
return rowItem(index.row());
}
private:
PgLabTableView *m_tableView = nullptr;
TableModel *m_dataModel = nullptr;