Added listing of triggers for selected table (not completely finished).

Used slightly different approach. This tab is fully build in source code
using subclasses to adjust behaviour of widgets for reuse in the other tabs.
Uses custom proxy model for filtering triggers for correct table and supporting
out of the box sorting by QTableView.

SqlCodePreview: QPlainTextEditor which sql highlighter and in readonly mode but allows copy.
This commit is contained in:
eelke 2018-10-07 19:40:06 +02:00
parent 446923ebaf
commit 2a75e86102
23 changed files with 697 additions and 67 deletions

View file

@ -3,19 +3,21 @@
#include "PgAttribute.h"
#include "PgDatabaseCatalog.h"
#include "TablesTableModel.h"
#include "ResultTableModelUtil.h"
#include "ColumnTableModel.h"
#include "ConstraintModel.h"
#include "PropertyProxyModel.h"
#include "IconColumnDelegate.h"
#include "IndexModel.h"
#include "SqlFormattingUtils.h"
#include "SqlSyntaxHighlighter.h"
#include <QStringBuilder>
#include <boost/container/flat_set.hpp>
#include "MainWindow.h"
#include "PgLabItemDelegate.h"
#include "PropertyProxyModel.h"
#include "ResultTableModelUtil.h"
#include "SqlFormattingUtils.h"
#include "SqlSyntaxHighlighter.h"
#include "TablesTableModel.h"
#include "TriggerPage.h"
#include "UserConfiguration.h"
#include <QStringBuilder>
#include <boost/container/flat_set.hpp>
TablesPage::TablesPage(MainWindow *parent)
: QWidget(parent)
@ -34,42 +36,43 @@ TablesPage::TablesPage(MainWindow *parent)
ui->tableListTable->setSortingEnabled(true);
ui->tableListTable->sortByColumn(0, Qt::AscendingOrder);
// Columns
SetTableViewDefault(ui->columnsTable);
m_columnsModel = new ColumnTableModel(this);
ui->columnsTable->setModel(m_columnsModel);
// Constraints
SetTableViewDefault(ui->constraintsTable);
m_constraintModel = new ConstraintModel(this);
ui->constraintsTable->setModel(m_constraintModel);
ui->constraintsTable->setItemDelegateForColumn(0, icon_delegate);
QFont font;
font.setFamily("Source Code Pro");
font.setFixedPitch(true);
font.setPointSize(10);
ui->constraintSqlEdit->setFont(font);
ui->indexSqlEdit->setFont(font);
// Indexes
SetTableViewDefault(ui->indexesTable);
m_indexModel = new IndexModel(this);
ui->indexesTable->setModel(m_indexModel);
ui->indexesTable->setItemDelegate(pglab_delegate);
ui->indexesTable->setItemDelegateForColumn(0, icon_delegate);
// Properties
PropertyProxyModel* property_model = new PropertyProxyModel(this);
property_model->setSourceModel(m_tablesModel);
SetTableViewDefault(ui->tablePropertiesTable);
ui->tablePropertiesTable->setModel(property_model);
ui->tablePropertiesTable->setItemDelegate(pglab_delegate);
// Set code editor fonts
QFont code_font = UserConfiguration::instance()->codeFont();
ui->constraintSqlEdit->setFont(code_font);
ui->indexSqlEdit->setFont(code_font);
// Connect signals
// ---------------
// Table selection
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged,
property_model, &PropertyProxyModel::setActiveRow);
//m_namespaceFilterWidget = new NamespaceFilterWidget(this);
//ui->verticalLayoutTableView->addWidget(m_namespaceFilterWidget);
// Table selection
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
&TablesPage::tableListTable_currentRowChanged);
@ -88,6 +91,29 @@ TablesPage::TablesPage(MainWindow *parent)
connect(ui->indexesTable->model(), &QAbstractItemModel::modelReset, this,
&TablesPage::indexesTable_modelReset);
// Non designer based code
m_triggerPage = new TriggerPage(this);
m_triggerTab = addDetailTab(m_triggerPage, tr("Triggers"));
retranslateUi(false);
}
void TablesPage::retranslateUi(bool all)
{
if (all)
ui->retranslateUi(this);
ui->twDetails->setTabText(ui->twDetails->indexOf(m_triggerTab), QApplication::translate("TablesPage", "Triggers", nullptr));
}
QWidget* TablesPage::addDetailTab(QWidget *contents, QString caption)
{
auto tab = new QWidget();
auto verticalLayout = new QVBoxLayout(tab);
verticalLayout->addWidget(contents);
ui->twDetails->addTab(tab, caption);
return tab;
}
TablesPage::~TablesPage()
@ -100,6 +126,8 @@ void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
m_catalog = cat;
m_tablesModel->setCatalog(cat);
ui->tableListTable->resizeColumnsToContents();
m_triggerPage->setCatalog(cat);
// m_namespaceFilterWidget->init(cat->namespaces());
auto highlighter = new SqlSyntaxHighlighter(ui->constraintSqlEdit->document());
@ -121,6 +149,8 @@ void TablesPage::tableListTable_currentRowChanged(const QModelIndex &current, co
m_indexModel->setData(m_catalog, table);
ui->indexesTable->resizeColumnsToContents();
m_triggerPage->setFilter(table);
}
}