pgLab/pglab/widgets/CatalogConstraintPage.cpp

43 lines
1.2 KiB
C++
Raw Normal View History

#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();
}
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);
}