From d86d278350f071a1d8ba873d696a8c89e99b6cfb Mon Sep 17 00:00:00 2001 From: eelke Date: Tue, 1 Jan 2019 14:34:14 +0100 Subject: [PATCH] Remove designer DatabaseForm generating widgets from code. Large part of toolbar and menu missing these will be recreated through plugin system. --- pglab/DatabaseWindow.cpp | 107 +++++++++++------ pglab/DatabaseWindow.h | 11 +- pglab/DatabaseWindow.ui | 248 --------------------------------------- pglab/pglab.pro | 3 +- 4 files changed, 77 insertions(+), 292 deletions(-) delete mode 100644 pglab/DatabaseWindow.ui diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index d48b0f5..58c4517 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -1,27 +1,31 @@ #include "DatabaseWindow.h" -#include "ui_DatabaseWindow.h" +//#include "ui_DatabaseWindow.h" #include "TablesPage.h" #include "FunctionsPage.h" #include "SequencesPage.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "QueryTab.h" #include "util.h" #include "plugin_support/PluginContentWidget.h" +#include "plugin_support/PluginContentWidgetContextBase.h" #include "CodeGenerator.h" #include "MasterController.h" #include "ScopeGuard.h" #include "EditTableWidget.h" -#include "plugin_support/PluginContentWidgetContextBase.h" #include "TaskExecutor.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace pg = Pgsql; @@ -111,11 +115,32 @@ void LMainWindow::addMenuAction(const MenuAction &ma) DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent) : LMainWindow(parent) - , ui(new Ui::DatabaseWindow) +// , ui(new Ui::DatabaseWindow) , m_masterController(master) { - ui->setupUi(this); - ui->tabWidget->setDocumentMode(true); +// ui->setupUi(this); +// ui->tabWidget->setDocumentMode(true); + +// auto centralWidget = new QWidget(this); +// auto verticalLayout_3 = new QVBoxLayout(centralWidget); +// verticalLayout_3->setSpacing(4); +// verticalLayout_3->setContentsMargins(4, 4, 4, 4); + + m_tabWidget = new QTabWidget(this); + m_tabWidget->setObjectName(QString::fromUtf8("tabWidget")); + m_tabWidget->setDocumentMode(true); +// verticalLayout_3->addWidget(m_tabWidget); + + setCentralWidget(m_tabWidget); + + auto menuBar = new QMenuBar(this); + setMenuBar(menuBar); + + m_mainToolBar = new QToolBar(this); + addToolBar(Qt::TopToolBarArea, m_mainToolBar); + + auto statusBar = new QStatusBar(this); + setStatusBar(statusBar); m_context = new DatabaseWindowContentContext(this); @@ -123,12 +148,14 @@ DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent) this, &DatabaseWindow::catalogLoaded); initModuleMenus(); + + QMetaObject::connectSlotsByName(this); } DatabaseWindow::~DatabaseWindow() { delete m_context; - delete ui; +// delete ui; } QueryTab* DatabaseWindow::newSqlPage() @@ -143,7 +170,7 @@ QueryTab* DatabaseWindow::newSqlPage() void DatabaseWindow::newCreateTablePage() { auto w = new EditTableWidget(m_database, this); - ui->tabWidget->addTab(w, "Create table"); + m_tabWidget->addTab(w, "Create table"); } void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr dbres) @@ -155,7 +182,7 @@ void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptrtabWidget->currentWidget(); + QWidget *widget = m_tabWidget->currentWidget(); QueryTab *qt = dynamic_cast(widget); return qt; } @@ -187,25 +214,25 @@ void DatabaseWindow::catalogLoaded() auto tt = new TablesPage(m_context, this); tt->setCatalog(m_database->catalog()); - ui->tabWidget->addTab(tt, "Tables"); + m_tabWidget->addTab(tt, "Tables"); auto pg_cat_tables = new TablesPage(m_context, this); pg_cat_tables->setNamespaceFilter(TablesTableModel::PgCatalog); pg_cat_tables->setCatalog(m_database->catalog()); - ui->tabWidget->addTab(pg_cat_tables, "pg_catalog"); + m_tabWidget->addTab(pg_cat_tables, "pg_catalog"); auto info_schema_tables = new TablesPage(m_context, this); info_schema_tables->setNamespaceFilter(TablesTableModel::InformationSchema); info_schema_tables->setCatalog(m_database->catalog()); - ui->tabWidget->addTab(info_schema_tables, "information_schema"); + m_tabWidget->addTab(info_schema_tables, "information_schema"); auto functions_page = new FunctionsPage(this); functions_page->setCatalog(m_database->catalog()); - ui->tabWidget->addTab(functions_page, "Functions"); + m_tabWidget->addTab(functions_page, "Functions"); auto sequences_page = new SequencesPage(this); sequences_page->setCatalog(m_database->catalog()); - ui->tabWidget->addTab(sequences_page, "Sequences"); + m_tabWidget->addTab(sequences_page, "Sequences"); newSqlPage(); newCreateTablePage(); @@ -269,7 +296,7 @@ void DatabaseWindow::on_actionExport_data_triggered() void DatabaseWindow::on_actionClose_triggered() { //close(); - on_tabWidget_tabCloseRequested(ui->tabWidget->currentIndex()); + on_tabWidget_tabCloseRequested(m_tabWidget->currentIndex()); } void DatabaseWindow::on_actionAbout_triggered() @@ -338,12 +365,13 @@ void DatabaseWindow::on_actionNew_SQL_triggered() void DatabaseWindow::on_tabWidget_tabCloseRequested(int index) { - QWidget *widget = ui->tabWidget->widget(index); + QWidget *widget = m_tabWidget->widget(index); PluginContentWidget *plg_page = dynamic_cast(widget); if (plg_page) { if (plg_page->canClose()) { removePage(plg_page); - ui->tabWidget->removeTab(index); + m_tabWidget->removeTab(index); + delete plg_page; } } else { @@ -351,11 +379,14 @@ void DatabaseWindow::on_tabWidget_tabCloseRequested(int index) // to PlgPage QueryTab *qt = dynamic_cast(widget); if (qt && qt->canClose()) { - ui->tabWidget->removeTab(index); + m_tabWidget->removeTab(index); + delete qt; } else if (index > 0) { - ui->tabWidget->removeTab(index); + m_tabWidget->removeTab(index); + delete widget; } + } } @@ -412,22 +443,22 @@ void DatabaseWindow::addToolBarButtonsForPage(PluginContentWidget *page) for (auto act : actions) { list.append(act); } - ui->mainToolBar->addActions(list); + m_mainToolBar->addActions(list); } void DatabaseWindow::removeToolBarButtonsForPage(PluginContentWidget *page) { std::vector actions = page->getToolbarActions(); for (auto act : actions) { - ui->mainToolBar->removeAction(act); + m_mainToolBar->removeAction(act); } } void DatabaseWindow::addPage(PluginContentWidget* page, QString caption) { - ui->tabWidget->addTab(page, caption); - ui->tabWidget->setCurrentWidget(page); + m_tabWidget->addTab(page, caption); + m_tabWidget->setCurrentWidget(page); //addToolBarButtonsForPage(page); } @@ -447,7 +478,7 @@ void DatabaseWindow::on_tabWidget_currentChanged(int index) // add buttons of new page PluginContentWidget * page = nullptr; if (index >= 0) { - QWidget *widget = ui->tabWidget->widget(index); + QWidget *widget = m_tabWidget->widget(index); page = dynamic_cast(widget); if (page) { addToolBarButtonsForPage(page); @@ -467,14 +498,14 @@ void DatabaseWindow::on_actionGenerate_code_triggered() void DatabaseWindow::setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint) { - auto index = ui->tabWidget->indexOf(widget); - ui->tabWidget->setTabText(index, caption); - ui->tabWidget->setTabToolTip(index, hint); + auto index = m_tabWidget->indexOf(widget); + m_tabWidget->setTabText(index, caption); + m_tabWidget->setTabToolTip(index, hint); } void DatabaseWindow::setTabIcon(QWidget *widget, const QString &iconname) { - auto index = ui->tabWidget->indexOf(widget); + auto index = m_tabWidget->indexOf(widget); auto n = ":/icons/16x16/" + iconname; - ui->tabWidget->setTabIcon(index, QIcon(n)); + m_tabWidget->setTabIcon(index, QIcon(n)); } diff --git a/pglab/DatabaseWindow.h b/pglab/DatabaseWindow.h index 2bd8bd1..c3301a5 100644 --- a/pglab/DatabaseWindow.h +++ b/pglab/DatabaseWindow.h @@ -22,9 +22,9 @@ #include #include -namespace Ui { - class DatabaseWindow; -} +//namespace Ui { +// class DatabaseWindow; +//} namespace Pgsql { class Connection; @@ -38,6 +38,8 @@ class OpenDatabase; class PgClass; class PluginContentWidget; +class QTabWidget; + namespace DatabaseWindow_details { class DatabaseWindowContentContext; } @@ -84,7 +86,8 @@ public: void addPage(PluginContentWidget* page, QString caption); private: - Ui::DatabaseWindow *ui; + QTabWidget *m_tabWidget = nullptr; + QToolBar *m_mainToolBar = nullptr; ConnectionConfig m_config; std::shared_ptr m_database; diff --git a/pglab/DatabaseWindow.ui b/pglab/DatabaseWindow.ui deleted file mode 100644 index 81bbb23..0000000 --- a/pglab/DatabaseWindow.ui +++ /dev/null @@ -1,248 +0,0 @@ - - - DatabaseWindow - - - - 0 - 0 - 993 - 804 - - - - pglab - database - - - - - 7 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - -1 - - - - - - - - - 0 - 0 - 993 - 20 - - - - - Fi&le - - - - - - - - - - - - - Help - - - - - - &Query - - - - - - Wi&ndow - - - - - - Edit - - - - - - - - - - - - - - - TopToolBarArea - - - false - - - - - - - - - - - - - - - - - - :/icons/folder.png:/icons/folder.png - - - &Load SQL - - - Ctrl+O - - - - - - :/icons/script_save.png:/icons/script_save.png - - - &Save SQL - - - Ctrl+S - - - - - - :/icons/table_save.png:/icons/table_save.png - - - &Export data - - - - - - :/icons/page_white_delete.png - - - - &Close - - - Ctrl+F4 - - - - - - :/icons/about.png - :/icons/information.png:/icons/about.png - - - &About - - - - - Sa&ve SQL as - - - - - Save copy &of SQL as - - - - - - :/icons/new_query_tab.png - :/icons/page_white_add.png:/icons/new_query_tab.png - - - &New SQL - - - Ctrl+N - - - - - &Show connection manager - - - - - - :/icons/page_white_copy.png - - - - &Copy - - - Ctrl+C - - - - - - :/icons/token_shortland_character.png - - - - Copy as C-&string - - - Ctrl+Alt+C - - - - - - :/icons/token_shortland_character.png - - - - Copy as raw C++-string - - - - - Generate code - - - - - - - - - diff --git a/pglab/pglab.pro b/pglab/pglab.pro index dfffeff..fea3323 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -169,8 +169,7 @@ FORMS += \ TablesPage.ui \ NamespaceFilterWidget.ui \ CrudTab.ui \ - CodeGenerator.ui \ - DatabaseWindow.ui + CodeGenerator.ui RESOURCES += \ resources.qrc