diff --git a/pglab/CatalogInspector.cpp b/pglab/CatalogInspector.cpp index c8063e4..4ee0a3d 100644 --- a/pglab/CatalogInspector.cpp +++ b/pglab/CatalogInspector.cpp @@ -1,154 +1,64 @@ #include "CatalogInspector.h" -#include "ui_TablesPage.h" - -#include "catalog/PgAttribute.h" -#include "catalog/PgDatabaseCatalog.h" -#include "catalog/PgIndexContainer.h" -#include "catalog/PgTriggerContainer.h" -#include "ColumnPage.h" -#include "ColumnTableModel.h" -#include "ConstraintModel.h" -#include "IconColumnDelegate.h" -#include "IndexModel.h" #include "OpenDatabase.h" -#include "PgLabItemDelegate.h" -#include "PropertiesPage.h" -#include "ResultTableModelUtil.h" -#include "SqlFormattingUtils.h" -#include "SqlSyntaxHighlighter.h" -#include "TriggerPage.h" #include "UserConfiguration.h" -#include "SqlCodePreview.h" -#include -#include #include "plugin_support/IPluginContentWidgetContext.h" +#include "widgets/CatalogFunctionsPage.h" +#include "widgets/CatalogSequencesPage.h" +#include "widgets/CatalogTablesPage.h" + +#include +#include +#include +#include +#include CatalogInspector::CatalogInspector(IPluginContentWidgetContext *context_, QWidget *parent) : PluginContentWidget(context_, parent) - , ui(new Ui::TablesPage) { - ui->setupUi(this); + m_tabWidget = new QTabWidget(this); + m_tablesPage = new CatalogTablesPage(this); + m_functionsPage = new CatalogFunctionsPage(this); + m_sequencesPage = new CatalogSequencesPage(this); - SetTableViewDefault(ui->tableListTable); - m_tablesModel = new TablesTableModel(this); - ui->tableListTable->setModel(m_tablesModel); - ui->tableListTable->setItemDelegate(new PgLabItemDelegate(this)); - ui->tableListTable->setSortingEnabled(true); - ui->tableListTable->sortByColumn(0, Qt::AscendingOrder); - ui->tableListTable->setSelectionBehavior(QAbstractItemView::SelectRows); + auto layout = new QVBoxLayout(this); + setLayout(layout); + layout->addWidget(m_tabWidget); + m_tabWidget->addTab(m_tablesPage, ""); + m_tabWidget->addTab(m_functionsPage, ""); + m_tabWidget->addTab(m_sequencesPage, ""); - // Constraints - SetTableViewDefault(ui->constraintsTable); - m_constraintModel = new ConstraintModel(this); - ui->constraintsTable->setModel(m_constraintModel); - ui->constraintsTable->setItemDelegateForColumn(0, new IconColumnDelegate(this)); - - // Indexes - SetTableViewDefault(ui->indexesTable); - m_indexModel = new IndexModel(this); - ui->indexesTable->setModel(m_indexModel); - ui->indexesTable->setItemDelegate(new PgLabItemDelegate(this)); - ui->indexesTable->setItemDelegateForColumn(0, new IconColumnDelegate(this)); - - // 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, this, - &CatalogInspector::tableListTable_currentRowChanged); - - connect(m_tablesModel, &QAbstractItemModel::layoutChanged, - this, &CatalogInspector::tableListTable_layoutChanged); - - //layoutChanged(const QList &parents = ..., QAbstractItemModel::LayoutChangeHint hint = ...) - - connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, - &CatalogInspector::constraintsTable_selectionChanged); - connect(ui->constraintsTable->model(), &QAbstractItemModel::modelReset, this, - &CatalogInspector::constraintsTable_modelReset); - - // React to changes in de selected indexes, does not trigger when model is reset - connect(ui->indexesTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, - &CatalogInspector::indexesTable_selectionChanged); - // Capture model reset independently - connect(ui->indexesTable->model(), &QAbstractItemModel::modelReset, this, - &CatalogInspector::indexesTable_modelReset); - - // Non designer based code - // - Columns page - m_columnsPage = new ColumnPage(this); - ui->twDetails->insertTab(0, m_columnsPage, ""); - - // - Properties page - m_propertiesPage = new PropertiesPage(this); - m_propertiesPage->setSourceModel(m_tablesModel); - ui->twDetails->addTab(m_propertiesPage, ""); - connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, - m_propertiesPage, &PropertiesPage::setActiveRow); - - // - Trigger page - m_triggerPage = new TriggerPage(this); - ui->twDetails->addTab(m_triggerPage, ""); - - // SQL tab - m_sqlCodePreview = new SqlCodePreview(this); - ui->twDetails->addTab(m_sqlCodePreview, ""); - - // Force focus on columns tab by default - ui->twDetails->setCurrentIndex(0); auto db = context_->getObject(); - setCatalog(db->catalog()); - retranslateUi(false); } - void CatalogInspector::retranslateUi(bool all) { - if (all) - ui->retranslateUi(this); - - auto set_tabtext = [this] (QWidget *widget, QString translation) { - ui->twDetails->setTabText(ui->twDetails->indexOf(widget), translation); - }; - - set_tabtext(m_columnsPage, QApplication::translate("TablesPage", "Columns", nullptr)); - set_tabtext(m_propertiesPage, QApplication::translate("TablesPage", "Properties", nullptr)); - set_tabtext(m_triggerPage, QApplication::translate("TablesPage", "Triggers", nullptr)); - set_tabtext(m_sqlCodePreview, QApplication::translate("TablesPage", "SQL", nullptr)); + m_tablesPage->retranslateUi(all); + m_tabWidget->setTabText(m_tabWidget->indexOf(m_tablesPage), + QApplication::translate("CatalogInspector", "Tables", nullptr)); + m_tabWidget->setTabText(m_tabWidget->indexOf(m_functionsPage), + QApplication::translate("CatalogInspector", "Functions", nullptr)); + m_tabWidget->setTabText(m_tabWidget->indexOf(m_sequencesPage), + QApplication::translate("CatalogInspector", "Sequences", nullptr)); } CatalogInspector::~CatalogInspector() { - delete ui; } void CatalogInspector::setCatalog(std::shared_ptr cat) { m_catalog = cat; - m_tablesModel->setCatalog(cat); - ui->tableListTable->resizeColumnsToContents(); - - m_triggerPage->setCatalog(cat); - - auto highlighter = new SqlSyntaxHighlighter(ui->constraintSqlEdit->document()); - highlighter->setTypes(*cat->types()); - highlighter = new SqlSyntaxHighlighter(ui->indexSqlEdit->document()); - highlighter->setTypes(*cat->types()); + m_tablesPage->setCatalog(cat); + m_functionsPage->setCatalog(cat); + m_sequencesPage->setCatalog(cat); } void CatalogInspector::setNamespaceFilter(TablesTableModel::NamespaceFilter filter) { - m_tablesModel->setNamespaceFilter(filter); + m_tablesPage->setNamespaceFilter(filter); QString hint = "Catalog instpector"; QString caption = "Inspector"; switch (filter) { @@ -166,147 +76,6 @@ void CatalogInspector::setNamespaceFilter(TablesTableModel::NamespaceFilter filt context()->setCaption(this, caption, hint); } - -void CatalogInspector::tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) -{ - if (current.row() != previous.row()) { - if (current.isValid()) { - PgClass table = m_tablesModel->getTable(current.row()); - selectedTableChanged(table); - } - else - selectedTableChanged({}); - } -} - - -void CatalogInspector::tableListTable_layoutChanged(const QList &, QAbstractItemModel::LayoutChangeHint ) -{ - auto&& index = ui->tableListTable->selectionModel()->currentIndex(); - if (index.isValid()) { - PgClass table = m_tablesModel->getTable(index.row()); - selectedTableChanged(table); - } - else - selectedTableChanged({}); -} - - -void CatalogInspector::selectedTableChanged(const std::optional &table) -{ - m_columnsPage->setData(m_catalog, table); - - m_constraintModel->setData(m_catalog, table); - ui->constraintsTable->resizeColumnsToContents(); - ui->constraintsTable->selectionModel()->reset(); - - m_indexModel->setData(m_catalog, table); - ui->indexesTable->resizeColumnsToContents(); - - m_triggerPage->setFilter(table); - - updateSqlTab(table); -} - -void CatalogInspector::constraintsTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) -{ - const auto indexes = ui->constraintsTable->selectionModel()->selectedIndexes(); - std::unordered_set 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 += getAlterTableConstraintDefinition(*m_catalog, constraint) % "\n"; - } - ui->constraintSqlEdit->setPlainText(drops % "\n" % creates); -} - -void CatalogInspector::constraintsTable_modelReset() -{ - ui->constraintSqlEdit->clear(); -} - -void CatalogInspector::indexesTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) -{ - const auto indexes = ui->indexesTable->selectionModel()->selectedIndexes(); - std::unordered_set rijen; - for (const auto &e : indexes) - rijen.insert(e.row()); - - QString drops; - QString creates; - for (auto rij : rijen) { - const PgIndex index = m_indexModel->getIndex(rij); - drops += index.dropSql() % "\n"; - creates += index.createSql() % "\n"; - } - ui->indexSqlEdit->setPlainText(drops % "\n" % creates); - -} - -void CatalogInspector::indexesTable_modelReset() -{ - ui->indexSqlEdit->clear(); -} - -void CatalogInspector::on_tableListTable_doubleClicked(const QModelIndex &index) -{ - PgClass table = m_tablesModel->getTable(index.row()); - if (table.oid() != InvalidOid) { - context()->moduleAction("pglab.crudpage", "open", { - { "oid", table.oid() } - }); - } -} - -void CatalogInspector::updateSqlTab(const std::optional &table) -{ - if (!table.has_value()) { - m_sqlCodePreview->clear(); - return; - } - - QString drop_sql; - QString create_sql; - // create table - create_sql += table->createSql(); - // - columns - // - constraints - // table details (inherits etc) - - // Indexes - drop_sql += "-- drop Indexes\n"; - create_sql += "-- create Indexes\n"; - auto && indexes = m_catalog->indexes()->getIndexesForTable(table->oid()); - for (auto && index : indexes) { - drop_sql += index.dropSql() % "\n"; - create_sql += index.createSql() % "\n"; - } - - // Triggers - drop_sql += "-- drop Triggers\n"; - create_sql += "-- create Triggers\n"; - auto && triggers = m_catalog->triggers()->getTriggersForRelation(table->oid()); - for (auto && trg : triggers) { - drop_sql += trg.dropSql() % "\n"; - create_sql += trg.createSql() % "\n"; - } - - // Privileges - create_sql += "-- set Privileges\n"; - create_sql += table->grantSql() % "\n"; - - // Comments - create_sql += "-- set Comments table + columns\n"; - // - m_sqlCodePreview->setPlainText(drop_sql % "\n\n" % create_sql); -} - - void CatalogInspectorModule::init() { registerModuleAction("open", diff --git a/pglab/CatalogInspector.h b/pglab/CatalogInspector.h index 8301398..d5e1153 100644 --- a/pglab/CatalogInspector.h +++ b/pglab/CatalogInspector.h @@ -3,32 +3,17 @@ #include #include -#include -#include #include "TablesTableModel.h" #include "plugin_support/PluginContentWidget.h" #include "plugin_support/PluginModule.h" -namespace Ui { -class TablesPage; -} +class CatalogFunctionsPage; +class CatalogSequencesPage; +class CatalogTablesPage; +class QTabWidget; -class TablesTableModel; -class ColumnPage; -class ColumnTableModel; -class ConstraintModel; -class PgDatabaseCatalog; -class NamespaceFilterWidget; -class IndexModel; -class PropertiesPage; -class TriggerPage; -class PgClass; -class SqlCodePreview; - -class CatalogInspector : public PluginContentWidget -{ +class CatalogInspector : public PluginContentWidget { Q_OBJECT - public: explicit CatalogInspector(IPluginContentWidgetContext *context, QWidget *parent = nullptr); ~CatalogInspector(); @@ -36,30 +21,15 @@ public: void setCatalog(std::shared_ptr cat); void setNamespaceFilter(TablesTableModel::NamespaceFilter filter); private: - Ui::TablesPage *ui; - ColumnPage *m_columnsPage; - PropertiesPage *m_propertiesPage; - TriggerPage *m_triggerPage; - SqlCodePreview *m_sqlCodePreview; + QTabWidget *m_tabWidget = nullptr; + CatalogTablesPage *m_tablesPage = nullptr; + CatalogFunctionsPage *m_functionsPage = nullptr; + CatalogSequencesPage *m_sequencesPage = nullptr; std::shared_ptr m_catalog; - TablesTableModel* m_tablesModel = nullptr; - ColumnTableModel* m_columnsModel = nullptr; - ConstraintModel* m_constraintModel = nullptr; - IndexModel* m_indexModel = nullptr; void retranslateUi(bool all = true); - void selectedTableChanged(const std::optional &table); - void updateSqlTab(const std::optional &table); private slots: - - void tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous); - void tableListTable_layoutChanged(const QList &parents, QAbstractItemModel::LayoutChangeHint hint); - void constraintsTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); - void constraintsTable_modelReset(); - void indexesTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); - void indexesTable_modelReset(); - void on_tableListTable_doubleClicked(const QModelIndex &index); }; class CatalogInspectorModule: public PluginModule { diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index caa5a1f..b111c1e 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -12,8 +12,6 @@ // Pages that should become modules #include "EditTableWidget.h" #include "CodeGenerator.h" -#include "FunctionsPage.h" -#include "SequencesPage.h" namespace pg = Pgsql; @@ -76,14 +74,6 @@ void DatabaseWindow::catalogLoaded() { "namespace-filter", f } }); - auto functions_page = new FunctionsPage(this); - functions_page->setCatalog(m_database->catalog()); - m_tabWidget->addTab(functions_page, "Functions"); - - auto sequences_page = new SequencesPage(this); - sequences_page->setCatalog(m_database->catalog()); - m_tabWidget->addTab(sequences_page, "Sequences"); - newCreateTablePage(); } catch (const OpenDatabaseException &ex) { QMessageBox::critical(this, "Error reading database", ex.text()); diff --git a/pglab/IconColumnDelegate.h b/pglab/IconColumnDelegate.h index 9d09e94..f9345b8 100644 --- a/pglab/IconColumnDelegate.h +++ b/pglab/IconColumnDelegate.h @@ -11,7 +11,7 @@ class IconColumnDelegate: public QStyledItemDelegate { public: IconColumnDelegate(QWidget *parent = nullptr); - ~IconColumnDelegate(); + ~IconColumnDelegate() override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, diff --git a/pglab/TablesPage.ui b/pglab/TablesPage.ui deleted file mode 100644 index 65e17f7..0000000 --- a/pglab/TablesPage.ui +++ /dev/null @@ -1,86 +0,0 @@ - - - TablesPage - - - - 0 - 0 - 993 - 754 - - - - Form - - - - - - Qt::Horizontal - - - - - - - - - - - - - - - - - - - - - 0 - - - - Constraints - - - - - - Qt::Vertical - - - - QAbstractItemView::SelectRows - - - - - - - - - - Indexes - - - - - - Qt::Vertical - - - - - - - - - - - - - - - diff --git a/pglab/TriggerPage.cpp b/pglab/TriggerPage.cpp index 3f10969..e2fb82c 100644 --- a/pglab/TriggerPage.cpp +++ b/pglab/TriggerPage.cpp @@ -1,47 +1,29 @@ #include "TriggerPage.h" #include "ResultTableModelUtil.h" #include "UserConfiguration.h" -#include #include "catalog/PgClass.h" #include "SqlCodePreview.h" #include "TriggerTableModel.h" #include "CustomFilterSortModel.h" #include "CustomDataRole.h" -#include "PgLabItemDelegate.h" +#include "PgLabTableView.h" #include #include TriggerPage::TriggerPage(QWidget *parent) - : QSplitter(Qt::Vertical, parent) + : CatalogPageBase(parent) { - m_tableView = new QTableView(this); - m_definitionView = new SqlCodePreview(this); - addWidget(m_tableView); - addWidget(m_definitionView); - - SetTableViewDefault(m_tableView); - m_model = new TriggerTableModel(this); - m_sortFilterProxy = new CustomFilterSortModel(this); m_sortFilterProxy->setSourceModel(m_model); - m_tableView->setModel(m_sortFilterProxy); - m_tableView->setSortingEnabled(true); - m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows); - - auto item_delegate = new PgLabItemDelegate(this); - m_tableView->setItemDelegate(item_delegate); - //auto icon_delegate = new IconColumnDelegate(this); connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TriggerPage::tableView_selectionChanged); } -void TriggerPage::setCatalog(std::shared_ptr cat) +void TriggerPage::catalogSet() { - m_catalog = cat; - m_definitionView->setCatalog(cat); - m_model->setCatalog(cat); + m_model->setCatalog(m_catalog); } @@ -54,10 +36,7 @@ void TriggerPage::setFilter(const std::optional &cls) void TriggerPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) { - auto&& indexes = m_tableView->selectionModel()->selectedIndexes(); - std::unordered_set rijen; - for (const auto &e : indexes) - rijen.insert(m_sortFilterProxy->mapToSource(e).row()); + auto rijen = selectedRows(); QString drops; QString creates; diff --git a/pglab/TriggerPage.h b/pglab/TriggerPage.h index 40b3918..b8f0f0f 100644 --- a/pglab/TriggerPage.h +++ b/pglab/TriggerPage.h @@ -1,37 +1,27 @@ #ifndef TRIGGERPAGE_H #define TRIGGERPAGE_H -#include -#include -#include +#include "widgets/CatalogPageBase.h" -class QTableView; -class SqlCodePreview; -class PgDatabaseCatalog; class PgClass; class TriggerTableModel; -class CustomFilterSortModel; class QItemSelection; -class TriggerPage : public QSplitter -{ +class TriggerPage : public CatalogPageBase { Q_OBJECT public: explicit TriggerPage(QWidget *parent = nullptr); // TriggerPage(QWidget *parent = nullptr); - void setCatalog(std::shared_ptr cat); void setFilter(const std::optional &cls); signals: public slots: +protected: + void catalogSet() override; private: - QTableView *m_tableView = nullptr; - SqlCodePreview *m_definitionView = nullptr; TriggerTableModel *m_model = nullptr; - CustomFilterSortModel *m_sortFilterProxy = nullptr; - std::shared_ptr m_catalog; private slots: void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); diff --git a/pglab/pglab.pro b/pglab/pglab.pro index 4d9e3a7..a99f3b7 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -71,12 +71,10 @@ PropertyProxyModel.cpp \ PropertiesPage.cpp \ PasswordPromptDialog.cpp \ ProcTableModel.cpp \ - FunctionsPage.cpp \ ColumnPage.cpp \ EditTableWidget.cpp \ EditColumnTableModel.cpp \ SequenceModel.cpp \ - SequencesPage.cpp \ DatabaseWindow.cpp \ PgLabTableView.cpp \ plugin_support/PluginModule.cpp \ @@ -91,7 +89,13 @@ PropertyProxyModel.cpp \ QueryToolModule.cpp \ CatalogInspector.cpp \ plugin_support/StaticAction.cpp \ - plugin_support/LMainMenu.cpp + plugin_support/LMainMenu.cpp \ + widgets/CatalogIndexPage.cpp \ + widgets/CatalogPageBase.cpp \ + widgets/CatalogConstraintPage.cpp \ + widgets/CatalogTablesPage.cpp \ + widgets/CatalogFunctionsPage.cpp \ + widgets/CatalogSequencesPage.cpp HEADERS += \ QueryResultModel.h \ @@ -140,12 +144,10 @@ CustomDataRole.h \ PropertiesPage.h \ PasswordPromptDialog.h \ ProcTableModel.h \ - FunctionsPage.h \ ColumnPage.h \ EditTableWidget.h \ EditColumnTableModel.h \ SequenceModel.h \ - SequencesPage.h \ DatabaseWindow.h \ PgLabTableView.h \ plugin_support/PluginModule.h \ @@ -162,7 +164,13 @@ CustomDataRole.h \ QueryToolModule.h \ CatalogInspector.h \ plugin_support/StaticAction.h \ - plugin_support/LMainMenu.h + plugin_support/LMainMenu.h \ + widgets/CatalogIndexPage.h \ + widgets/CatalogPageBase.h \ + widgets/CatalogConstraintPage.h \ + widgets/CatalogTablesPage.h \ + widgets/CatalogFunctionsPage.h \ + widgets/CatalogSequencesPage.h FORMS += \ ConnectionManagerWindow.ui \ @@ -172,7 +180,6 @@ FORMS += \ BackupDialog.ui \ ServerWindow.ui \ ProcessStdioWidget.ui \ - TablesPage.ui \ NamespaceFilterWidget.ui \ CrudTab.ui \ CodeGenerator.ui diff --git a/pglab/plugin_support/PluginContentWidgetContextBase.cpp b/pglab/plugin_support/PluginContentWidgetContextBase.cpp index f0f60e5..1749e61 100644 --- a/pglab/plugin_support/PluginContentWidgetContextBase.cpp +++ b/pglab/plugin_support/PluginContentWidgetContextBase.cpp @@ -59,6 +59,7 @@ void PluginContentWidgetContextBase::removeContentWidget(PluginContentWidget *wi m_widgetLst.erase(res); } + void PluginContentWidgetContextBase::addWidgetActionsToToolbar(PluginContentWidget *widget, QToolBar *toolbar) { auto && actions = widget->actions(); diff --git a/pglab/plugin_support/PluginContentWidgetContextBase.h b/pglab/plugin_support/PluginContentWidgetContextBase.h index 5059cde..0fa35e8 100644 --- a/pglab/plugin_support/PluginContentWidgetContextBase.h +++ b/pglab/plugin_support/PluginContentWidgetContextBase.h @@ -8,6 +8,28 @@ class LContextAction; class QToolBar; class QAction; +/// Maintains the list of actions added to a toolbar for a specific widget +/// it facilitates the removal of all those actions. +class WidgetToolbarActionList { +public: + QToolBar *m_toolBar; + std::vector m_actions; + void removeAll() + { +// for (auto && a : m_actions) +// m_toolBar->removeAction(a); + } +}; + +class WidgetToolbarManager { +public: + void addAction(QAction *action, QString section); + +private: + +}; + + class LWidgetData { public: LWidgetData(PluginModule *module); @@ -16,6 +38,7 @@ public: private: PluginModule *m_module; + WidgetToolbarManager m_toolbarManager; }; /// Provides base implementation of IPluginContentWidgetContext diff --git a/pglab/resources.qrc b/pglab/resources.qrc index 149bed8..476a271 100644 --- a/pglab/resources.qrc +++ b/pglab/resources.qrc @@ -27,5 +27,6 @@ icons/constraints/foreignkey.png icons/constraints/primarykey.png icons/constraints/unique.png + icons/constraints/index.png diff --git a/pglab/widgets/CatalogConstraintPage.cpp b/pglab/widgets/CatalogConstraintPage.cpp new file mode 100644 index 0000000..26d12a9 --- /dev/null +++ b/pglab/widgets/CatalogConstraintPage.cpp @@ -0,0 +1,42 @@ +#include "CatalogConstraintPage.h" +#include "ConstraintModel.h" +#include "CustomFilterSortModel.h" +#include "IconColumnDelegate.h" +#include "PgLabTableView.h" +#include "SqlCodePreview.h" +#include + +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 &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); +} diff --git a/pglab/widgets/CatalogConstraintPage.h b/pglab/widgets/CatalogConstraintPage.h new file mode 100644 index 0000000..ea8c212 --- /dev/null +++ b/pglab/widgets/CatalogConstraintPage.h @@ -0,0 +1,29 @@ +#ifndef CATALOGCONSTRAINTPAGE_H +#define CATALOGCONSTRAINTPAGE_H + +#include "CatalogPageBase.h" + +class ConstraintModel; +class PgClass; +class QItemSelection; + + +class CatalogConstraintPage : public CatalogPageBase { + Q_OBJECT +public: + explicit CatalogConstraintPage(QWidget *parent = nullptr); + + void setFilter(const std::optional &cls); + +protected: + void catalogSet() override; + +private: + + ConstraintModel *m_constraintModel = nullptr; + +private slots: + void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); +}; + +#endif // CATALOGCONSTRAINTPAGE_H diff --git a/pglab/FunctionsPage.cpp b/pglab/widgets/CatalogFunctionsPage.cpp similarity index 78% rename from pglab/FunctionsPage.cpp rename to pglab/widgets/CatalogFunctionsPage.cpp index a42fc69..ead3533 100644 --- a/pglab/FunctionsPage.cpp +++ b/pglab/widgets/CatalogFunctionsPage.cpp @@ -1,4 +1,4 @@ -#include "FunctionsPage.h" +#include "CatalogFunctionsPage.h" #include "ResultTableModelUtil.h" #include "CustomFilterSortModel.h" #include "CustomDataRole.h" @@ -10,7 +10,7 @@ #include #include -FunctionsPage::FunctionsPage(QWidget *parent) +CatalogFunctionsPage::CatalogFunctionsPage(QWidget *parent) : QSplitter(Qt::Horizontal, parent) { // create widgets @@ -39,12 +39,12 @@ FunctionsPage::FunctionsPage(QWidget *parent) m_functionTable->setSelectionBehavior(QAbstractItemView::SelectRows); connect(m_functionTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this, - &FunctionsPage::functionTable_currentRowChanged); + &CatalogFunctionsPage::functionTable_currentRowChanged); retranslateUi(); } -void FunctionsPage::retranslateUi() +void CatalogFunctionsPage::retranslateUi() { auto set_tabtext = [this] (QWidget *widget, QString translation) { m_detailTabs->setTabText(m_detailTabs->indexOf(widget), translation); @@ -53,13 +53,13 @@ void FunctionsPage::retranslateUi() set_tabtext(m_definitionView, QApplication::translate("FunctionsPage", "SQL", nullptr)); } -void FunctionsPage::setCatalog(std::shared_ptr cat) +void CatalogFunctionsPage::setCatalog(std::shared_ptr cat) { m_catalog = cat; m_model->setCatalog(cat); } -void FunctionsPage::functionTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) +void CatalogFunctionsPage::functionTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) { if (current.row() != previous.row()) { if (current.isValid()) { @@ -73,12 +73,12 @@ void FunctionsPage::functionTable_currentRowChanged(const QModelIndex ¤t, } } -void FunctionsPage::selectedProcChanged(const std::optional &proc) +void CatalogFunctionsPage::selectedProcChanged(const std::optional &proc) { updateSqlTab(proc); } -void FunctionsPage::updateSqlTab(const std::optional &proc) +void CatalogFunctionsPage::updateSqlTab(const std::optional &proc) { if (!proc.has_value()) { m_definitionView->clear(); diff --git a/pglab/FunctionsPage.h b/pglab/widgets/CatalogFunctionsPage.h similarity index 89% rename from pglab/FunctionsPage.h rename to pglab/widgets/CatalogFunctionsPage.h index e466f4f..64994f3 100644 --- a/pglab/FunctionsPage.h +++ b/pglab/widgets/CatalogFunctionsPage.h @@ -13,10 +13,10 @@ class QTabWidget; class SqlCodePreview; class PgProc; -class FunctionsPage : public QSplitter { +class CatalogFunctionsPage : public QSplitter { Q_OBJECT public: - explicit FunctionsPage(QWidget *parent = nullptr); + explicit CatalogFunctionsPage(QWidget *parent = nullptr); void setCatalog(std::shared_ptr cat); signals: diff --git a/pglab/widgets/CatalogIndexPage.cpp b/pglab/widgets/CatalogIndexPage.cpp new file mode 100644 index 0000000..b41f1bb --- /dev/null +++ b/pglab/widgets/CatalogIndexPage.cpp @@ -0,0 +1,43 @@ +#include "CatalogIndexPage.h" +#include "CustomFilterSortModel.h" +#include "IndexModel.h" +#include "PgLabTableView.h" +#include "SqlCodePreview.h" +#include +#include "IconColumnDelegate.h" + + +CatalogIndexPage::CatalogIndexPage(QWidget *parent) + : CatalogPageBase(parent) +{ + m_indexModel = new IndexModel(this); + m_sortFilterProxy->setSourceModel(m_indexModel); + + m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this)); + + connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged, + this, &CatalogIndexPage::tableView_selectionChanged); +} + +void CatalogIndexPage::catalogSet() +{ +} + +void CatalogIndexPage::setFilter(const std::optional &cls) +{ + m_indexModel->setData(m_catalog, cls); + m_tableView->resizeColumnsToContents(); +} + +void CatalogIndexPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) +{ + auto rijen = selectedRows(); + QString drops; + QString creates; + for (auto rij : rijen) { + const PgIndex index = m_indexModel->getIndex(rij); + drops += index.dropSql() % "\n"; + creates += index.createSql() % "\n"; + } + m_definitionView->setPlainText(drops % "\n" % creates); +} diff --git a/pglab/widgets/CatalogIndexPage.h b/pglab/widgets/CatalogIndexPage.h new file mode 100644 index 0000000..c8b68c2 --- /dev/null +++ b/pglab/widgets/CatalogIndexPage.h @@ -0,0 +1,29 @@ +#ifndef CATALOGINDEXPAGE_H +#define CATALOGINDEXPAGE_H + +#include "CatalogPageBase.h" + +class IndexModel; +class PgClass; +class QItemSelection; + + +class CatalogIndexPage : public CatalogPageBase { + Q_OBJECT +public: + explicit CatalogIndexPage(QWidget *parent = nullptr); + + void setFilter(const std::optional &cls); + +protected: + void catalogSet() override; + +private: + + IndexModel *m_indexModel = nullptr; + +private slots: + void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); +}; + +#endif // CATALOGINDEXPAGE_H diff --git a/pglab/widgets/CatalogPageBase.cpp b/pglab/widgets/CatalogPageBase.cpp new file mode 100644 index 0000000..3d57604 --- /dev/null +++ b/pglab/widgets/CatalogPageBase.cpp @@ -0,0 +1,35 @@ +#include "CatalogPageBase.h" +#include "CustomFilterSortModel.h" +#include "PgLabTableView.h" +#include "SqlCodePreview.h" + +CatalogPageBase::CatalogPageBase(QWidget *parent) + : QSplitter(Qt::Vertical, parent) +{ + m_tableView = new PgLabTableView(this); + m_definitionView = new SqlCodePreview(this); + addWidget(m_tableView); + addWidget(m_definitionView); + + m_sortFilterProxy = new CustomFilterSortModel(this); + + m_tableView->setModel(m_sortFilterProxy); + m_tableView->setSortingEnabled(true); + m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows); +} + +void CatalogPageBase::setCatalog(std::shared_ptr cat) +{ + m_catalog = cat; + m_definitionView->setCatalog(m_catalog); + catalogSet(); +} + +std::unordered_set CatalogPageBase::selectedRows() const +{ + auto&& indexes = m_tableView->selectionModel()->selectedIndexes(); + std::unordered_set rijen; + for (const auto &e : indexes) + rijen.insert(m_sortFilterProxy->mapToSource(e).row()); + return rijen; +} diff --git a/pglab/widgets/CatalogPageBase.h b/pglab/widgets/CatalogPageBase.h new file mode 100644 index 0000000..ffad416 --- /dev/null +++ b/pglab/widgets/CatalogPageBase.h @@ -0,0 +1,32 @@ +#ifndef CATALOGPAGEBASE_H +#define CATALOGPAGEBASE_H + +#include +#include +#include +#include + +class PgDatabaseCatalog; +class PgLabTableView; +class SqlCodePreview; +class CustomFilterSortModel; + + +class CatalogPageBase : public QSplitter { + Q_OBJECT +public: + CatalogPageBase(QWidget *parent = nullptr); + + void setCatalog(std::shared_ptr cat); + +protected: + PgLabTableView *m_tableView = nullptr; + SqlCodePreview *m_definitionView = nullptr; + CustomFilterSortModel *m_sortFilterProxy = nullptr; + std::shared_ptr m_catalog; + + virtual void catalogSet() {} + std::unordered_set selectedRows() const; +}; + +#endif // CATALOGPAGEBASE_H diff --git a/pglab/SequencesPage.cpp b/pglab/widgets/CatalogSequencesPage.cpp similarity index 72% rename from pglab/SequencesPage.cpp rename to pglab/widgets/CatalogSequencesPage.cpp index d7442eb..b6f9c44 100644 --- a/pglab/SequencesPage.cpp +++ b/pglab/widgets/CatalogSequencesPage.cpp @@ -1,4 +1,4 @@ -#include "SequencesPage.h" +#include "CatalogSequencesPage.h" #include "ResultTableModelUtil.h" #include "CustomFilterSortModel.h" #include "CustomDataRole.h" @@ -7,7 +7,8 @@ #include "SqlCodePreview.h" #include "PgLabTableView.h" -SequencesPage::SequencesPage(QWidget *parent) +CatalogSequencesPage::CatalogSequencesPage(QWidget *parent) + : QSplitter(Qt::Horizontal, parent) { m_sequenceTable = new PgLabTableView(this); m_definitionView = new SqlCodePreview(this); @@ -25,12 +26,12 @@ SequencesPage::SequencesPage(QWidget *parent) m_sequenceTable->setSelectionBehavior(QAbstractItemView::SelectRows); connect(m_sequenceTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this, - &SequencesPage::sequenceTable_currentRowChanged); + &CatalogSequencesPage::sequenceTable_currentRowChanged); retranslateUi(); } -void SequencesPage::retranslateUi() +void CatalogSequencesPage::retranslateUi() { // auto set_tabtext = [this] (QWidget *widget, QString translation) { // m_detailTabs->setTabText(m_detailTabs->indexOf(widget), translation); @@ -39,13 +40,13 @@ void SequencesPage::retranslateUi() // set_tabtext(m_definitionView, QApplication::translate("FunctionsPage", "SQL", nullptr)); } -void SequencesPage::setCatalog(std::shared_ptr cat) +void CatalogSequencesPage::setCatalog(std::shared_ptr cat) { m_catalog = cat; m_model->setCatalog(cat); } -void SequencesPage::sequenceTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) +void CatalogSequencesPage::sequenceTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) { if (current.row() != previous.row()) { if (current.isValid()) { @@ -59,12 +60,12 @@ void SequencesPage::sequenceTable_currentRowChanged(const QModelIndex ¤t, } } -void SequencesPage::selectedSequenceChanged(const std::optional &seq) +void CatalogSequencesPage::selectedSequenceChanged(const std::optional &seq) { updateSqlTab(seq); } -void SequencesPage::updateSqlTab(const std::optional &seq) +void CatalogSequencesPage::updateSqlTab(const std::optional &seq) { if (!seq.has_value()) { m_definitionView->clear(); diff --git a/pglab/SequencesPage.h b/pglab/widgets/CatalogSequencesPage.h similarity index 89% rename from pglab/SequencesPage.h rename to pglab/widgets/CatalogSequencesPage.h index 19b29c2..9780999 100644 --- a/pglab/SequencesPage.h +++ b/pglab/widgets/CatalogSequencesPage.h @@ -9,15 +9,13 @@ class PgLabTableView; class PgDatabaseCatalog; class SequenceModel; class CustomFilterSortModel; -//class QTabWidget; class SqlCodePreview; class PgSequence; - -class SequencesPage : public QSplitter { +class CatalogSequencesPage : public QSplitter { Q_OBJECT public: - SequencesPage(QWidget *parent = nullptr); + CatalogSequencesPage(QWidget *parent = nullptr); void setCatalog(std::shared_ptr cat); public slots: diff --git a/pglab/widgets/CatalogTablesPage.cpp b/pglab/widgets/CatalogTablesPage.cpp new file mode 100644 index 0000000..273008c --- /dev/null +++ b/pglab/widgets/CatalogTablesPage.cpp @@ -0,0 +1,189 @@ +#include "CatalogTablesPage.h" + +#include "ColumnPage.h" +#include "ColumnTableModel.h" +#include "ConstraintModel.h" +#include "PgLabTableView.h" +#include "PropertiesPage.h" +#include "ResultTableModelUtil.h" +#include "SqlCodePreview.h" +#include "TriggerPage.h" +#include "catalog/PgIndexContainer.h" +#include "catalog/PgTriggerContainer.h" +#include "widgets/CatalogConstraintPage.h" +#include "widgets/CatalogIndexPage.h" + +#include +#include +#include + +CatalogTablesPage::CatalogTablesPage(QWidget *parent) + : QSplitter(Qt::Horizontal, parent) +{ + m_tableView = new PgLabTableView(this); + m_detailsTabs = new QTabWidget(this); + + // Populate splitter + addWidget(m_tableView); + addWidget(m_detailsTabs); + + // Setup model(s) + m_tablesModel = new TablesTableModel(this); + m_tableView->setModel(m_tablesModel); + + // - Columns page + m_columnsPage = new ColumnPage(this); + m_detailsTabs->addTab(m_columnsPage, ""); + + // constrainst + m_constraintPage = new CatalogConstraintPage(this); + m_detailsTabs->addTab(m_constraintPage, ""); + + // - Index page + m_indexPage = new CatalogIndexPage(this); + m_detailsTabs->addTab(m_indexPage, ""); + + // - Properties page + m_propertiesPage = new PropertiesPage(this); + m_propertiesPage->setSourceModel(m_tablesModel); + m_detailsTabs->addTab(m_propertiesPage, ""); + + connect(m_tableView->selectionModel(), &QItemSelectionModel::currentRowChanged, + m_propertiesPage, &PropertiesPage::setActiveRow); + + // - Trigger page + m_triggerPage = new TriggerPage(this); + m_detailsTabs->addTab(m_triggerPage, ""); + + // SQL tab + m_tableSql = new SqlCodePreview(this); + m_detailsTabs->addTab(m_tableSql, ""); + + // Force focus on columns tab by default + m_detailsTabs->setCurrentIndex(0); + + // Signals + connect(m_tableView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, + &CatalogTablesPage::tableListTable_currentRowChanged); + + connect(m_tablesModel, &QAbstractItemModel::layoutChanged, + this, &CatalogTablesPage::tableListTable_layoutChanged); +} + +void CatalogTablesPage::retranslateUi(bool all) +{ + auto set_tabtext = [this] (QWidget *widget, QString translation) { + m_detailsTabs->setTabText(m_detailsTabs->indexOf(widget), translation); + }; + + set_tabtext(m_columnsPage, QApplication::translate("TablesPage", "Columns", nullptr)); + set_tabtext(m_constraintPage, QApplication::translate("TablesPage", "Constraints", nullptr)); + set_tabtext(m_indexPage, QApplication::translate("TablesPage", "Indexes", nullptr)); + set_tabtext(m_propertiesPage, QApplication::translate("TablesPage", "Properties", nullptr)); + set_tabtext(m_triggerPage, QApplication::translate("TablesPage", "Triggers", nullptr)); + set_tabtext(m_tableSql, QApplication::translate("TablesPage", "SQL", nullptr)); +} + +void CatalogTablesPage::setCatalog(std::shared_ptr cat) +{ + m_catalog = cat; + m_tablesModel->setCatalog(cat); + m_tableView->resizeColumnsToContents(); + + m_constraintPage->setCatalog(cat); + m_indexPage->setCatalog(cat); + m_triggerPage->setCatalog(cat); +} + +void CatalogTablesPage::setNamespaceFilter(TablesTableModel::NamespaceFilter filter) +{ + m_tablesModel->setNamespaceFilter(filter); +} + +void CatalogTablesPage::tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) +{ + if (current.row() != previous.row()) { + if (current.isValid()) { + PgClass table = m_tablesModel->getTable(current.row()); + selectedTableChanged(table); + } + else + selectedTableChanged({}); + } +} + + +void CatalogTablesPage::tableListTable_layoutChanged(const QList &, QAbstractItemModel::LayoutChangeHint ) +{ + auto&& index = m_tableView->selectionModel()->currentIndex(); + if (index.isValid()) { + PgClass table = m_tablesModel->getTable(index.row()); + selectedTableChanged(table); + } + else + selectedTableChanged({}); +} + +void CatalogTablesPage::on_tableListTable_doubleClicked(const QModelIndex &index) +{ + PgClass table = m_tablesModel->getTable(index.row()); + if (table.oid() != InvalidOid) { +// context()->moduleAction("pglab.crudpage", "open", { +// { "oid", table.oid() } +// }); + } +} + +void CatalogTablesPage::selectedTableChanged(const std::optional &table) +{ + m_columnsPage->setData(m_catalog, table); + + m_constraintPage->setFilter(table); + m_indexPage->setFilter(table); + m_triggerPage->setFilter(table); + + updateSqlTab(table); +} + +void CatalogTablesPage::updateSqlTab(const std::optional &table) +{ + if (!table.has_value()) { + m_tableSql->clear(); + return; + } + + QString drop_sql; + QString create_sql; + // create table + create_sql += table->createSql(); + // - columns + // - constraints + // table details (inherits etc) + + // Indexes + drop_sql += "-- drop Indexes\n"; + create_sql += "-- create Indexes\n"; + auto && indexes = m_catalog->indexes()->getIndexesForTable(table->oid()); + for (auto && index : indexes) { + drop_sql += index.dropSql() % "\n"; + create_sql += index.createSql() % "\n"; + } + + // Triggers + drop_sql += "-- drop Triggers\n"; + create_sql += "-- create Triggers\n"; + auto && triggers = m_catalog->triggers()->getTriggersForRelation(table->oid()); + for (auto && trg : triggers) { + drop_sql += trg.dropSql() % "\n"; + create_sql += trg.createSql() % "\n"; + } + + // Privileges + create_sql += "-- set Privileges\n"; + create_sql += table->grantSql() % "\n"; + + // Comments + create_sql += "-- set Comments table + columns\n"; + // + m_tableSql->setPlainText(drop_sql % "\n\n" % create_sql); +} diff --git a/pglab/widgets/CatalogTablesPage.h b/pglab/widgets/CatalogTablesPage.h new file mode 100644 index 0000000..7860107 --- /dev/null +++ b/pglab/widgets/CatalogTablesPage.h @@ -0,0 +1,57 @@ +#ifndef CATALOGTABLESPAGE_H +#define CATALOGTABLESPAGE_H + +#include +#include +#include "TablesTableModel.h" + +class CatalogConstraintPage; +class CatalogIndexPage; +class ColumnPage; +class ColumnTableModel; +class ConstraintModel; +class PgClass; +class PgDatabaseCatalog; +class PgLabTableView; +class PropertiesPage; +class QTabWidget; +class SqlCodePreview; +class TablesTableModel; +class TriggerPage; + + +class CatalogTablesPage: public QSplitter { + Q_OBJECT +public: + explicit CatalogTablesPage(QWidget * parent = nullptr); + + void setCatalog(std::shared_ptr cat); + void setNamespaceFilter(TablesTableModel::NamespaceFilter filter); + + void retranslateUi(bool all = true); +private: + PgLabTableView *m_tableView = nullptr; + TablesTableModel* m_tablesModel = nullptr; + + // Details + QTabWidget *m_detailsTabs = nullptr; + ColumnPage *m_columnsPage = nullptr; + CatalogConstraintPage *m_constraintPage = nullptr; + CatalogIndexPage *m_indexPage = nullptr; + PropertiesPage *m_propertiesPage = nullptr; + TriggerPage *m_triggerPage = nullptr; + SqlCodePreview *m_tableSql = nullptr; + + std::shared_ptr m_catalog; + + void selectedTableChanged(const std::optional &table); + void updateSqlTab(const std::optional &table); +private slots: + + void tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous); + void tableListTable_layoutChanged(const QList &parents, QAbstractItemModel::LayoutChangeHint hint); + void on_tableListTable_doubleClicked(const QModelIndex &index); + +}; + +#endif // CATALOGTABLESPAGE_H diff --git a/pglablib/catalog/PgConstraint.cpp b/pglablib/catalog/PgConstraint.cpp index 0c8f75b..9c06487 100644 --- a/pglablib/catalog/PgConstraint.cpp +++ b/pglablib/catalog/PgConstraint.cpp @@ -1,4 +1,5 @@ #include "PgConstraint.h" +#include "SqlFormattingUtils.h" void operator<<(ConstraintType &s, const Pgsql::Value &v) { @@ -172,3 +173,13 @@ QString PgConstraint::typeName() const { return "CONSTRAINT"; } + +QString PgConstraint::dropSql() const +{ + return getDropConstraintDefinition(catalog(), *this); +} + +QString PgConstraint::createSql() const +{ + return getAlterTableConstraintDefinition(catalog(), *this); +} diff --git a/pglablib/catalog/PgConstraint.h b/pglablib/catalog/PgConstraint.h index e27508e..e295b1d 100644 --- a/pglablib/catalog/PgConstraint.h +++ b/pglablib/catalog/PgConstraint.h @@ -77,6 +77,9 @@ public: using PgNamespaceObject::PgNamespaceObject; QString typeName() const override; + + QString dropSql() const override; + QString createSql() const override; }; diff --git a/pglablib/catalog/PgProc.cpp b/pglablib/catalog/PgProc.cpp index bf161aa..757cc69 100644 --- a/pglablib/catalog/PgProc.cpp +++ b/pglablib/catalog/PgProc.cpp @@ -245,7 +245,7 @@ QString PgProc::argSigList(const bool forScript) const } -const QString& PgProc::createSql() const +QString PgProc::createSql() const { if (createSqlCache.isEmpty()) { QString sql; diff --git a/pglablib/catalog/PgProc.h b/pglablib/catalog/PgProc.h index 8123e4f..2767769 100644 --- a/pglablib/catalog/PgProc.h +++ b/pglablib/catalog/PgProc.h @@ -86,7 +86,7 @@ public: ); const std::vector& args() const; - const QString& createSql() const; + QString createSql() const override; QString argListWithNames(bool multiline = false) const; QString argSigList(const bool forScript = false) const; QString volatility() const; diff --git a/pglablib/catalog/PgServerObject.cpp b/pglablib/catalog/PgServerObject.cpp index 68eb505..95c22fc 100644 --- a/pglablib/catalog/PgServerObject.cpp +++ b/pglablib/catalog/PgServerObject.cpp @@ -91,3 +91,13 @@ QString PgServerObject::aclAllPattern() const { return {}; } + +QString PgServerObject::dropSql() const +{ + return {}; +} + +QString PgServerObject::createSql() const +{ + return {}; +} diff --git a/pglablib/catalog/PgServerObject.h b/pglablib/catalog/PgServerObject.h index d05c291..f20469c 100644 --- a/pglablib/catalog/PgServerObject.h +++ b/pglablib/catalog/PgServerObject.h @@ -41,6 +41,9 @@ public: * @return A string containing all posible privileges for this type of object. */ virtual QString aclAllPattern() const; + + virtual QString dropSql() const; + virtual QString createSql() const; private: Oid m_ownerOid = InvalidOid; const PgAuthId * m_owner; diff --git a/pglablib/catalog/PgTrigger.cpp b/pglablib/catalog/PgTrigger.cpp index f34bfcc..ba1ef9c 100644 --- a/pglablib/catalog/PgTrigger.cpp +++ b/pglablib/catalog/PgTrigger.cpp @@ -5,7 +5,7 @@ #include "SqlFormattingUtils.h" #include -QString PgTrigger::dropSql() +QString PgTrigger::dropSql() const { if (m_dropSql.isEmpty()) { auto&& fqtablename = catalog().classes()->getByKey(relid)->fullyQualifiedQuotedObjectName(); // genFQTableName(catalog(), *catalog().classes()->getByKey(relid)); @@ -15,7 +15,7 @@ QString PgTrigger::dropSql() return m_dropSql; } -QString PgTrigger::createSql() +QString PgTrigger::createSql() const { if (m_createSql.isEmpty()) { auto&& fqtablename = catalog().classes()->getByKey(relid)->fullyQualifiedQuotedObjectName(); //genFQTableName(catalog(), *catalog().classes()->getByKey(relid)); diff --git a/pglablib/catalog/PgTrigger.h b/pglablib/catalog/PgTrigger.h index 108d67c..f376024 100644 --- a/pglablib/catalog/PgTrigger.h +++ b/pglablib/catalog/PgTrigger.h @@ -47,8 +47,8 @@ public: static constexpr int TriggerTypeTruncate = (1 << 5); static constexpr int TriggerTypeInstead = (1 << 6); - QString dropSql(); - QString createSql(); + QString dropSql() const override; + QString createSql() const override; bool isRow() const { return type & TriggerTypeRow; } bool isBefore() const { return type & TriggerTypeBefore; } QString typeFireWhen() const;