Resolve "reload catalog" #84
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)
|
||||
{
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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*/)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue