Remove designer DatabaseForm generating widgets from code.

Large part of toolbar and menu missing these will be recreated through plugin system.
This commit is contained in:
eelke 2019-01-01 14:34:14 +01:00
parent dc8a052544
commit d86d278350
4 changed files with 77 additions and 292 deletions

View file

@ -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 <QStandardPaths>
#include <QFileDialog>
#include <QMessageBox>
#include <QTextTable>
#include <QElapsedTimer>
#include <algorithm>
#include <QCloseEvent>
#include <QMetaObject>
#include <QMetaMethod>
#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 <QApplication>
#include <QCloseEvent>
#include <QElapsedTimer>
#include <QFileDialog>
#include <QMenuBar>
#include <QMessageBox>
#include <QMetaMethod>
#include <QMetaObject>
#include <QStandardPaths>
#include <QStatusBar>
#include <QTextTable>
#include <QToolBar>
#include <QVBoxLayout>
#include <algorithm>
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<const Pgsql::Result> dbres)
@ -155,7 +182,7 @@ void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::
QueryTab *DatabaseWindow::GetActiveQueryTab()
{
QWidget *widget = ui->tabWidget->currentWidget();
QWidget *widget = m_tabWidget->currentWidget();
QueryTab *qt = dynamic_cast<QueryTab*>(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<PluginContentWidget*>(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<QueryTab*>(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<QAction*> 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<PluginContentWidget*>(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));
}

View file

@ -22,9 +22,9 @@
#include <QFuture>
#include <QFutureWatcher>
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<OpenDatabase> m_database;

View file

@ -1,248 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DatabaseWindow</class>
<widget class="QMainWindow" name="DatabaseWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>993</width>
<height>804</height>
</rect>
</property>
<property name="windowTitle">
<string>pglab - database</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>7</number>
</property>
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>993</width>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuTest">
<property name="title">
<string>Fi&amp;le</string>
</property>
<addaction name="actionNew_SQL"/>
<addaction name="actionLoad_SQL"/>
<addaction name="actionSave_SQL"/>
<addaction name="actionSave_SQL_as"/>
<addaction name="actionSave_copy_of_SQL_as"/>
<addaction name="actionExport_data"/>
<addaction name="separator"/>
<addaction name="actionClose"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
<string>Help</string>
</property>
<addaction name="actionAbout"/>
</widget>
<widget class="QMenu" name="menuQuery">
<property name="title">
<string>&amp;Query</string>
</property>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>Wi&amp;ndow</string>
</property>
<addaction name="actionShow_connection_manager"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>Edit</string>
</property>
<addaction name="actionCopy"/>
<addaction name="actionCopy_as_C_string"/>
<addaction name="actionCopy_as_raw_Cpp_string"/>
<addaction name="actionGenerate_code"/>
</widget>
<addaction name="menuTest"/>
<addaction name="menuEdit"/>
<addaction name="menuQuery"/>
<addaction name="menuView"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionNew_SQL"/>
<addaction name="actionLoad_SQL"/>
<addaction name="actionSave_SQL"/>
<addaction name="actionExport_data"/>
<addaction name="actionClose"/>
<addaction name="separator"/>
<addaction name="actionCopy"/>
<addaction name="actionCopy_as_C_string"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="actionAbout"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="actionLoad_SQL">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/folder.png</normaloff>:/icons/folder.png</iconset>
</property>
<property name="text">
<string>&amp;Load SQL</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="actionSave_SQL">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/script_save.png</normaloff>:/icons/script_save.png</iconset>
</property>
<property name="text">
<string>&amp;Save SQL</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionExport_data">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/table_save.png</normaloff>:/icons/table_save.png</iconset>
</property>
<property name="text">
<string>&amp;Export data</string>
</property>
</action>
<action name="actionClose">
<property name="icon">
<iconset>
<normalon>:/icons/page_white_delete.png</normalon>
</iconset>
</property>
<property name="text">
<string>&amp;Close</string>
</property>
<property name="shortcut">
<string>Ctrl+F4</string>
</property>
</action>
<action name="actionAbout">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/about.png</normaloff>
<normalon>:/icons/information.png</normalon>:/icons/about.png</iconset>
</property>
<property name="text">
<string>&amp;About</string>
</property>
</action>
<action name="actionSave_SQL_as">
<property name="text">
<string>Sa&amp;ve SQL as</string>
</property>
</action>
<action name="actionSave_copy_of_SQL_as">
<property name="text">
<string>Save copy &amp;of SQL as</string>
</property>
</action>
<action name="actionNew_SQL">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/new_query_tab.png</normaloff>
<normalon>:/icons/page_white_add.png</normalon>:/icons/new_query_tab.png</iconset>
</property>
<property name="text">
<string>&amp;New SQL</string>
</property>
<property name="shortcut">
<string>Ctrl+N</string>
</property>
</action>
<action name="actionShow_connection_manager">
<property name="text">
<string>&amp;Show connection manager</string>
</property>
</action>
<action name="actionCopy">
<property name="icon">
<iconset>
<normalon>:/icons/page_white_copy.png</normalon>
</iconset>
</property>
<property name="text">
<string>&amp;Copy</string>
</property>
<property name="shortcut">
<string>Ctrl+C</string>
</property>
</action>
<action name="actionCopy_as_C_string">
<property name="icon">
<iconset>
<normalon>:/icons/token_shortland_character.png</normalon>
</iconset>
</property>
<property name="text">
<string>Copy as C-&amp;string</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+C</string>
</property>
</action>
<action name="actionCopy_as_raw_Cpp_string">
<property name="icon">
<iconset>
<normalon>:/icons/token_shortland_character.png</normalon>
</iconset>
</property>
<property name="text">
<string>Copy as raw C++-string</string>
</property>
</action>
<action name="actionGenerate_code">
<property name="text">
<string>Generate code</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -169,8 +169,7 @@ FORMS += \
TablesPage.ui \
NamespaceFilterWidget.ui \
CrudTab.ui \
CodeGenerator.ui \
DatabaseWindow.ui
CodeGenerator.ui
RESOURCES += \
resources.qrc