When another table is selected the index and constraint list are reloaded and have no selection. So the SQL for the selection should be empty.
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include "CatalogConstraintPage.h"
|
|
#include "ConstraintModel.h"
|
|
#include "CustomFilterSortModel.h"
|
|
#include "IconColumnDelegate.h"
|
|
#include "PgLabTableView.h"
|
|
#include "SqlCodePreview.h"
|
|
#include <QStringBuilder>
|
|
|
|
CatalogConstraintPage::CatalogConstraintPage(QWidget *parent)
|
|
: CatalogPageBase(parent)
|
|
{
|
|
m_constraintModel = new ConstraintModel(this);
|
|
m_sortFilterProxy->setSourceModel(m_constraintModel);
|
|
|
|
m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this));
|
|
|
|
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
|
this, &CatalogConstraintPage::tableView_selectionChanged);
|
|
}
|
|
|
|
void CatalogConstraintPage::catalogSet()
|
|
{
|
|
}
|
|
|
|
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*/)
|
|
{
|
|
auto rijen = selectedRows();
|
|
QString drops;
|
|
QString creates;
|
|
for (auto rij : rijen) {
|
|
const PgConstraint constraint = m_constraintModel->constraint(rij);
|
|
drops += constraint.dropSql() % "\n";
|
|
creates += constraint.createSql() % "\n";
|
|
}
|
|
m_definitionView->setPlainText(drops % "\n" % creates);
|
|
}
|