List of tables now updates after reload of catalog.

This commit is contained in:
eelke 2019-10-09 18:36:54 +02:00
parent f4f514efb0
commit 5c586ea807
3 changed files with 22 additions and 9 deletions

View file

@ -1,4 +1,5 @@
#include "TablesTableModel.h"
#include "ScopeGuard.h"
#include "catalog/PgDatabaseCatalog.h"
#include "catalog/PgClass.h"
#include "catalog/PgClassContainer.h"
@ -15,23 +16,27 @@ TablesTableModel::TablesTableModel(QObject *parent)
void TablesTableModel::setNamespaceFilter(NamespaceFilter nsf)
{
m_namespaceFilter = nsf;
reloadData();
refresh();
}
void TablesTableModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
{
if (cat != m_catalog) {
m_catalog = cat;
reloadData();
refreshConnection = connect(m_catalog.get(), &PgDatabaseCatalog::refreshed,
this, &TablesTableModel::refresh);
}
refresh();
}
void TablesTableModel::reloadData()
void TablesTableModel::refresh()
{
beginResetModel();
SCOPE_EXIT { endResetModel(); };
if (!m_catalog)
return;
beginResetModel();
// Later afscheiden naar filter functie
auto classes = m_catalog->classes();
@ -59,7 +64,6 @@ void TablesTableModel::reloadData()
}
doSort(1);
endResetModel();
}
void TablesTableModel::setSortOrder(int so)

View file

@ -49,13 +49,16 @@ private:
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
NamespaceFilter m_namespaceFilter = NamespaceFilter::User;
t_Tables m_tables;
QMetaObject::Connection refreshConnection;
void reloadData();
Oid getType(int column) const;
QVariant getData(const QModelIndex &index) const;
// QString formatTableName(const PgClass &cls) const;
void doSort(int so);
private slots:
void refresh();
};
#endif // TABLESTABLEMODEL_H

View file

@ -72,6 +72,12 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent)
// Signals
connect(m_tableView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
&CatalogTablesPage::tableListTable_currentRowChanged);
connect(m_tablesModel, &TablesTableModel::modelReset,
[this] ()
{
selectedTableChanged({});
m_propertiesPage->setActiveRow({});
});
connect(m_tablesModel, &QAbstractItemModel::layoutChanged,
this, &CatalogTablesPage::tableListTable_layoutChanged);