2018-10-07 19:40:06 +02:00
|
|
|
|
#include "TriggerPage.h"
|
|
|
|
|
|
#include "ResultTableModelUtil.h"
|
|
|
|
|
|
#include "UserConfiguration.h"
|
2018-12-16 10:17:59 +01:00
|
|
|
|
#include "catalog/PgClass.h"
|
2018-10-07 19:40:06 +02:00
|
|
|
|
#include "SqlCodePreview.h"
|
|
|
|
|
|
#include "TriggerTableModel.h"
|
|
|
|
|
|
#include "CustomFilterSortModel.h"
|
|
|
|
|
|
#include "CustomDataRole.h"
|
2019-02-09 09:49:27 +01:00
|
|
|
|
#include "PgLabTableView.h"
|
2019-02-09 17:36:37 +01:00
|
|
|
|
#include "catalog/PgProcContainer.h"
|
2018-10-07 19:40:06 +02:00
|
|
|
|
#include <QStringBuilder>
|
2018-12-23 08:39:38 +01:00
|
|
|
|
#include <unordered_set>
|
2018-10-07 19:40:06 +02:00
|
|
|
|
|
|
|
|
|
|
TriggerPage::TriggerPage(QWidget *parent)
|
2019-02-09 09:49:27 +01:00
|
|
|
|
: CatalogPageBase(parent)
|
2018-10-07 19:40:06 +02:00
|
|
|
|
{
|
|
|
|
|
|
m_model = new TriggerTableModel(this);
|
|
|
|
|
|
m_sortFilterProxy->setSourceModel(m_model);
|
|
|
|
|
|
|
|
|
|
|
|
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
|
|
|
|
|
this, &TriggerPage::tableView_selectionChanged);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-02-09 09:49:27 +01:00
|
|
|
|
void TriggerPage::catalogSet()
|
2018-10-07 19:40:06 +02:00
|
|
|
|
{
|
2019-02-09 09:49:27 +01:00
|
|
|
|
m_model->setCatalog(m_catalog);
|
2018-10-07 19:40:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-18 20:24:27 +01:00
|
|
|
|
void TriggerPage::setFilter(const std::optional<PgClass> &cls)
|
2018-10-07 19:40:06 +02:00
|
|
|
|
{
|
2018-11-25 19:45:06 +01:00
|
|
|
|
m_sortFilterProxy->setOidFilterTable(cls ? cls->oid() : InvalidOid, FirstHiddenValue);
|
2018-12-16 20:38:57 +01:00
|
|
|
|
m_tableView->resizeColumnsToContents();
|
2018-10-07 19:40:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TriggerPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
|
|
|
|
|
{
|
2019-02-09 09:49:27 +01:00
|
|
|
|
auto rijen = selectedRows();
|
2018-10-07 19:40:06 +02:00
|
|
|
|
|
|
|
|
|
|
QString drops;
|
|
|
|
|
|
QString creates;
|
|
|
|
|
|
for (auto rij : rijen) {
|
|
|
|
|
|
auto&& t = m_model->trigger(rij);
|
2018-11-18 19:30:45 +01:00
|
|
|
|
drops += t.dropSql() % "\n";
|
|
|
|
|
|
creates += t.createSql() % "\n";
|
2019-02-09 17:36:37 +01:00
|
|
|
|
|
|
|
|
|
|
const PgProc *proc = m_catalog->procs()->getByKey(t.foid);
|
|
|
|
|
|
if (proc) {
|
|
|
|
|
|
creates += "\n" % proc->createSql() % "\n";
|
|
|
|
|
|
}
|
2018-10-07 19:40:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
m_definitionView->setPlainText(drops % "\n" % creates);
|
|
|
|
|
|
}
|