ConstraintPage now reacts to refreshed signal.

This commit is contained in:
eelke 2019-10-06 14:17:07 +02:00
parent fa46971930
commit 23899b6bb6
3 changed files with 17 additions and 10 deletions

View file

@ -9,18 +9,23 @@ ConstraintModel::ConstraintModel(QObject *parent)
{
}
void ConstraintModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std::optional<PgClass> &table)
{
if (cat != m_catalog) {
m_catalog = cat;
refreshConnection = connect(m_catalog.get(), &PgDatabaseCatalog::refreshed, this, &ConstraintModel::refresh);
}
m_table = table;
refresh();
}
void ConstraintModel::refresh()
{
beginResetModel();
SCOPE_EXIT { endResetModel(); };
m_table = table;
m_catalog = cat;
if (table) {
m_constraints = cat->constraints()->getConstraintsForRelation(table->oid());
if (m_table) {
m_constraints = m_catalog->constraints()->getConstraintsForRelation(m_table->oid());
std::sort(m_constraints.begin(), m_constraints.end(),
[] (auto &l, auto &r) {
return l.type < r.type ||
@ -116,8 +121,6 @@ QString IconForConstraintType(ConstraintType ct)
return s;
}
QVariant ConstraintModel::getData(const QModelIndex &index) const
{
QVariant v;

View file

@ -48,6 +48,10 @@ private:
using t_Constraints = std::vector<PgConstraint>;
t_Constraints m_constraints;
QMetaObject::Connection refreshConnection;
private slots:
void refresh();
};
#endif // CONSTRAINTMODEL_H

View file

@ -16,6 +16,7 @@ CatalogConstraintPage::CatalogConstraintPage(QWidget *parent)
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &CatalogConstraintPage::tableView_selectionChanged);
connect(m_constraintModel, &ConstraintModel::modelReset, m_definitionView, &SqlCodePreview::clear);
}
void CatalogConstraintPage::catalogSet()
@ -26,7 +27,6 @@ void CatalogConstraintPage::setFilter(const std::optional<PgClass> &cls)
{
m_constraintModel->setData(m_catalog, cls);
m_tableView->resizeColumnsToContents();
m_definitionView->setPlainText({});
}
void CatalogConstraintPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)