Created IndexModel for displaying the indexes on a table. Constraints can now show the SQL to drop and create them.
The keyword list is now directly based of the official keyword list from postgresql.
This commit is contained in:
parent
b436814eb5
commit
97d4e2a1a4
24 changed files with 754 additions and 228 deletions
|
|
@ -9,6 +9,11 @@
|
|||
#include "ConstraintModel.h"
|
||||
#include "NamespaceFilterWidget.h"
|
||||
#include "IconColumnDelegate.h"
|
||||
#include "IndexModel.h"
|
||||
#include "SqlFormattingUtils.h"
|
||||
#include "SqlSyntaxHighlighter.h"
|
||||
#include <QStringBuilder>
|
||||
#include <boost/container/flat_set.hpp>
|
||||
|
||||
TablesPage::TablesPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
|
|
@ -27,16 +32,32 @@ TablesPage::TablesPage(QWidget *parent) :
|
|||
SetTableViewDefault(ui->constraintsTable);
|
||||
m_constraintModel = new ConstraintModel(this);
|
||||
auto delegate = new IconColumnDelegate(this);
|
||||
|
||||
ui->constraintsTable->setModel(m_constraintModel);
|
||||
ui->constraintsTable->setItemDelegateForColumn(0, delegate);
|
||||
|
||||
QFont font;
|
||||
font.setFamily("Source Code Pro");
|
||||
font.setFixedPitch(true);
|
||||
font.setPointSize(10);
|
||||
ui->constraintSqlEdit->setFont(font);
|
||||
|
||||
SetTableViewDefault(ui->indexesTable);
|
||||
m_indexModel = new IndexModel(this);
|
||||
ui->indexesTable->setModel(m_indexModel);
|
||||
ui->indexesTable->setItemDelegateForColumn(0, delegate);
|
||||
|
||||
m_namespaceFilterWidget = new NamespaceFilterWidget(this);
|
||||
ui->verticalLayoutTableView->addWidget(m_namespaceFilterWidget);
|
||||
|
||||
|
||||
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&TablesPage::on_tableListTable_currentRowChanged);
|
||||
&TablesPage::on_tableListTable_currentRowChanged);
|
||||
|
||||
// connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
// &TablesPage::on_constraintsTable_currentRowChanged);
|
||||
|
||||
connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||
&TablesPage::on_constraintsTable_selectionChanged);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +72,10 @@ void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
|||
m_tablesModel->setCatalog(cat);
|
||||
ui->tableListTable->resizeColumnsToContents();
|
||||
m_namespaceFilterWidget->init(cat->namespaces());
|
||||
|
||||
auto highlighter = new SqlSyntaxHighlighter(ui->constraintSqlEdit->document());
|
||||
highlighter->setTypes(*cat->types());
|
||||
|
||||
}
|
||||
|
||||
void TablesPage::on_tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
|
|
@ -62,5 +87,37 @@ void TablesPage::on_tableListTable_currentRowChanged(const QModelIndex ¤t,
|
|||
|
||||
m_constraintModel->setData(m_catalog, table);
|
||||
ui->constraintsTable->resizeColumnsToContents();
|
||||
ui->constraintsTable->selectionModel()->reset();
|
||||
|
||||
m_indexModel->setData(m_catalog, table);
|
||||
ui->indexesTable->resizeColumnsToContents();
|
||||
}
|
||||
}
|
||||
|
||||
void TablesPage::on_constraintsTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||
{
|
||||
if (current.row() != previous.row()) {
|
||||
// QString drop_definition = m_constraintModel->dropDefinition(current.row());
|
||||
// QString create_definition = m_constraintModel->createDefinition(current.row());
|
||||
const PgConstraint& constraint = m_constraintModel->constraint(current.row());
|
||||
QString drop = getDropConstraintDefinition(*m_catalog, constraint);
|
||||
QString add = getConstraintDefinition(*m_catalog, constraint);
|
||||
|
||||
ui->constraintSqlEdit->setPlainText(drop % QString::fromUtf16(u"\n") % add);
|
||||
}
|
||||
}
|
||||
|
||||
void TablesPage::on_constraintsTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
|
||||
{
|
||||
const auto indexes = ui->constraintsTable->selectionModel()->selectedIndexes();
|
||||
boost::container::flat_set<int> rijen;
|
||||
for (const auto e : indexes) rijen.insert(e.row());
|
||||
QString drops;
|
||||
QString creates;
|
||||
for (auto rij : rijen) {
|
||||
const PgConstraint constraint = m_constraintModel->constraint(rij);
|
||||
drops += getDropConstraintDefinition(*m_catalog, constraint) % "\n";
|
||||
creates += getConstraintDefinition(*m_catalog, constraint) % "\n";
|
||||
}
|
||||
ui->constraintSqlEdit->setPlainText(drops % "\n" % creates);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue