ConstraintPage now reacts to refreshed signal.
This commit is contained in:
parent
fa46971930
commit
23899b6bb6
3 changed files with 17 additions and 10 deletions
|
|
@ -9,18 +9,23 @@ ConstraintModel::ConstraintModel(QObject *parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ConstraintModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std::optional<PgClass> &table)
|
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();
|
beginResetModel();
|
||||||
SCOPE_EXIT { endResetModel(); };
|
SCOPE_EXIT { endResetModel(); };
|
||||||
|
|
||||||
m_table = table;
|
if (m_table) {
|
||||||
m_catalog = cat;
|
m_constraints = m_catalog->constraints()->getConstraintsForRelation(m_table->oid());
|
||||||
if (table) {
|
|
||||||
m_constraints = cat->constraints()->getConstraintsForRelation(table->oid());
|
|
||||||
std::sort(m_constraints.begin(), m_constraints.end(),
|
std::sort(m_constraints.begin(), m_constraints.end(),
|
||||||
[] (auto &l, auto &r) {
|
[] (auto &l, auto &r) {
|
||||||
return l.type < r.type ||
|
return l.type < r.type ||
|
||||||
|
|
@ -116,8 +121,6 @@ QString IconForConstraintType(ConstraintType ct)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QVariant ConstraintModel::getData(const QModelIndex &index) const
|
QVariant ConstraintModel::getData(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,10 @@ private:
|
||||||
|
|
||||||
using t_Constraints = std::vector<PgConstraint>;
|
using t_Constraints = std::vector<PgConstraint>;
|
||||||
t_Constraints m_constraints;
|
t_Constraints m_constraints;
|
||||||
|
QMetaObject::Connection refreshConnection;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void refresh();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONSTRAINTMODEL_H
|
#endif // CONSTRAINTMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ CatalogConstraintPage::CatalogConstraintPage(QWidget *parent)
|
||||||
|
|
||||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||||
this, &CatalogConstraintPage::tableView_selectionChanged);
|
this, &CatalogConstraintPage::tableView_selectionChanged);
|
||||||
|
connect(m_constraintModel, &ConstraintModel::modelReset, m_definitionView, &SqlCodePreview::clear);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CatalogConstraintPage::catalogSet()
|
void CatalogConstraintPage::catalogSet()
|
||||||
|
|
@ -26,7 +27,6 @@ void CatalogConstraintPage::setFilter(const std::optional<PgClass> &cls)
|
||||||
{
|
{
|
||||||
m_constraintModel->setData(m_catalog, cls);
|
m_constraintModel->setData(m_catalog, cls);
|
||||||
m_tableView->resizeColumnsToContents();
|
m_tableView->resizeColumnsToContents();
|
||||||
m_definitionView->setPlainText({});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CatalogConstraintPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
void CatalogConstraintPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue