Renamed MainWindow to DatabaseWindow so the name tells us the functionality provided by the window.

MainWindow was really a bad name as the app doesn't have a main window.
This commit is contained in:
eelke 2018-12-28 12:55:11 +01:00
parent 437736a023
commit 69473d65d2
10 changed files with 58 additions and 55 deletions

View file

@ -1,7 +1,7 @@
#include "CrudTab.h" #include "CrudTab.h"
#include "ui_CrudTab.h" #include "ui_CrudTab.h"
#include "CrudModel.h" #include "CrudModel.h"
#include "MainWindow.h" #include "DatabaseWindow.h"
#include "ResultTableModelUtil.h" #include "ResultTableModelUtil.h"
#include "PgLabItemDelegate.h" #include "PgLabItemDelegate.h"
#include "IntegerRange.h" #include "IntegerRange.h"
@ -12,7 +12,7 @@
#include <set> #include <set>
CrudTab::CrudTab(MainWindow *parent) CrudTab::CrudTab(DatabaseWindow *parent)
: PlgPage(parent) : PlgPage(parent)
, ui(new Ui::CrudTab) , ui(new Ui::CrudTab)
, m_window(parent) , m_window(parent)

View file

@ -13,14 +13,14 @@ namespace Ui {
class OpenDatabase; class OpenDatabase;
class CrudModel; class CrudModel;
class MainWindow; class DatabaseWindow;
class CrudTab : public PlgPage class CrudTab : public PlgPage
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit CrudTab(MainWindow *parent = 0); explicit CrudTab(DatabaseWindow *parent = 0);
~CrudTab() override; ~CrudTab() override;
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table); void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
@ -31,7 +31,7 @@ public:
private: private:
Ui::CrudTab *ui; Ui::CrudTab *ui;
MainWindow *m_window; DatabaseWindow *m_window;
std::shared_ptr<OpenDatabase> m_db; std::shared_ptr<OpenDatabase> m_db;
std::optional<PgClass> m_table; std::optional<PgClass> m_table;

View file

@ -1,4 +1,4 @@
#include "MainWindow.h" #include "DatabaseWindow.h"
#include "ui_MainWindow.h" #include "ui_MainWindow.h"
#include "TablesPage.h" #include "TablesPage.h"
#include "FunctionsPage.h" #include "FunctionsPage.h"
@ -26,7 +26,7 @@
namespace pg = Pgsql; namespace pg = Pgsql;
MainWindow::MainWindow(MasterController *master, QWidget *parent) DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
: ASyncWindow(parent) : ASyncWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, m_masterController(master) , m_masterController(master)
@ -35,13 +35,13 @@ MainWindow::MainWindow(MasterController *master, QWidget *parent)
ui->tabWidget->setDocumentMode(true); ui->tabWidget->setDocumentMode(true);
} }
MainWindow::~MainWindow() DatabaseWindow::~DatabaseWindow()
{ {
loader.reset(); loader.reset();
delete ui; delete ui;
} }
QueryTab* MainWindow::newSqlPage() QueryTab* DatabaseWindow::newSqlPage()
{ {
QueryTab *qt = new QueryTab(this); QueryTab *qt = new QueryTab(this);
qt->setConfig(m_config, m_database->catalog()); qt->setConfig(m_config, m_database->catalog());
@ -51,20 +51,20 @@ QueryTab* MainWindow::newSqlPage()
return qt; return qt;
} }
void MainWindow::newCreateTablePage() void DatabaseWindow::newCreateTablePage()
{ {
auto w = new EditTableWidget(m_database, this); auto w = new EditTableWidget(m_database, this);
ui->tabWidget->addTab(w, "Create table"); ui->tabWidget->addTab(w, "Create table");
} }
void MainWindow::newCrudPage(const PgClass &table) void DatabaseWindow::newCrudPage(const PgClass &table)
{ {
CrudTab *ct = new CrudTab(this); CrudTab *ct = new CrudTab(this);
ct->setConfig(m_database, table); ct->setConfig(m_database, table);
addPage(ct, table.objectName()); addPage(ct, table.objectName());
} }
void MainWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres) void DatabaseWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
{ {
auto cgtab = new CodeGenerator(this); auto cgtab = new CodeGenerator(this);
cgtab->Init(m_database->catalog(), query, dbres); cgtab->Init(m_database->catalog(), query, dbres);
@ -72,14 +72,14 @@ void MainWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Resu
} }
QueryTab *MainWindow::GetActiveQueryTab() QueryTab *DatabaseWindow::GetActiveQueryTab()
{ {
QWidget *widget = ui->tabWidget->currentWidget(); QWidget *widget = ui->tabWidget->currentWidget();
QueryTab *qt = dynamic_cast<QueryTab*>(widget); QueryTab *qt = dynamic_cast<QueryTab*>(widget);
return qt; return qt;
} }
void MainWindow::setConfig(const ConnectionConfig &config) void DatabaseWindow::setConfig(const ConnectionConfig &config)
{ {
m_config = config; m_config = config;
try { try {
@ -99,7 +99,7 @@ void MainWindow::setConfig(const ConnectionConfig &config)
} }
} }
void MainWindow::catalogLoaded() void DatabaseWindow::catalogLoaded()
{ {
try { try {
SCOPE_EXIT { loader.reset(); }; SCOPE_EXIT { loader.reset(); };
@ -127,7 +127,7 @@ void MainWindow::catalogLoaded()
} }
} }
void MainWindow::on_actionLoad_SQL_triggered() void DatabaseWindow::on_actionLoad_SQL_triggered()
{ {
QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory); QString home_dir = QStandardPaths::locate(QStandardPaths::HomeLocation, "", QStandardPaths::LocateDirectory);
QString file_name = QFileDialog::getOpenFileName(this, QString file_name = QFileDialog::getOpenFileName(this,
@ -139,7 +139,7 @@ void MainWindow::on_actionLoad_SQL_triggered()
} }
void MainWindow::on_actionSave_SQL_triggered() void DatabaseWindow::on_actionSave_SQL_triggered()
{ {
QueryTab *tab = GetActiveQueryTab(); QueryTab *tab = GetActiveQueryTab();
if (tab) { if (tab) {
@ -147,7 +147,7 @@ void MainWindow::on_actionSave_SQL_triggered()
} }
} }
void MainWindow::on_actionSave_SQL_as_triggered() void DatabaseWindow::on_actionSave_SQL_as_triggered()
{ {
QueryTab *tab = GetActiveQueryTab(); QueryTab *tab = GetActiveQueryTab();
if (tab) { if (tab) {
@ -156,7 +156,7 @@ void MainWindow::on_actionSave_SQL_as_triggered()
} }
void MainWindow::on_actionSave_copy_of_SQL_as_triggered() void DatabaseWindow::on_actionSave_copy_of_SQL_as_triggered()
{ {
QueryTab *tab = GetActiveQueryTab(); QueryTab *tab = GetActiveQueryTab();
if (tab) { if (tab) {
@ -164,7 +164,7 @@ void MainWindow::on_actionSave_copy_of_SQL_as_triggered()
} }
} }
void MainWindow::on_actionExport_data_triggered() void DatabaseWindow::on_actionExport_data_triggered()
{ {
QueryTab *tab = GetActiveQueryTab(); QueryTab *tab = GetActiveQueryTab();
if (tab) { if (tab) {
@ -176,13 +176,13 @@ void MainWindow::on_actionExport_data_triggered()
} }
} }
void MainWindow::on_actionClose_triggered() void DatabaseWindow::on_actionClose_triggered()
{ {
//close(); //close();
on_tabWidget_tabCloseRequested(ui->tabWidget->currentIndex()); on_tabWidget_tabCloseRequested(ui->tabWidget->currentIndex());
} }
void MainWindow::on_actionAbout_triggered() void DatabaseWindow::on_actionAbout_triggered()
{ {
QMessageBox::about(this, "pgLab 0.1", tr( QMessageBox::about(this, "pgLab 0.1", tr(
"Copyrights 2016-2017, Eelke Klein, All Rights Reserved.\n" "Copyrights 2016-2017, Eelke Klein, All Rights Reserved.\n"
@ -200,7 +200,7 @@ void MainWindow::on_actionAbout_triggered()
} }
void MainWindow::closeEvent(QCloseEvent* /*event*/) void DatabaseWindow::closeEvent(QCloseEvent* /*event*/)
{ {
// TODO collect which files need saving // TODO collect which files need saving
// std::vector<QString> files_to_save; // std::vector<QString> files_to_save;
@ -232,7 +232,7 @@ void MainWindow::closeEvent(QCloseEvent* /*event*/)
} }
void MainWindow::showEvent(QShowEvent *event) void DatabaseWindow::showEvent(QShowEvent *event)
{ {
if (!event->spontaneous()) { if (!event->spontaneous()) {
// m_queryTextChanged = false; // m_queryTextChanged = false;
@ -240,13 +240,13 @@ void MainWindow::showEvent(QShowEvent *event)
event->accept(); event->accept();
} }
void MainWindow::on_actionNew_SQL_triggered() void DatabaseWindow::on_actionNew_SQL_triggered()
{ {
newSqlPage(); newSqlPage();
} }
void MainWindow::on_tabWidget_tabCloseRequested(int index) void DatabaseWindow::on_tabWidget_tabCloseRequested(int index)
{ {
QWidget *widget = ui->tabWidget->widget(index); QWidget *widget = ui->tabWidget->widget(index);
PlgPage *plg_page = dynamic_cast<PlgPage*>(widget); PlgPage *plg_page = dynamic_cast<PlgPage*>(widget);
@ -270,12 +270,12 @@ void MainWindow::on_tabWidget_tabCloseRequested(int index)
} }
void MainWindow::on_actionShow_connection_manager_triggered() void DatabaseWindow::on_actionShow_connection_manager_triggered()
{ {
m_masterController->showConnectionManager(); m_masterController->showConnectionManager();
} }
void MainWindow::on_actionCopy_triggered() void DatabaseWindow::on_actionCopy_triggered()
{ {
// What should be copied? // What should be copied?
@ -295,7 +295,7 @@ void MainWindow::on_actionCopy_triggered()
} }
void MainWindow::on_actionCopy_as_C_string_triggered() void DatabaseWindow::on_actionCopy_as_C_string_triggered()
{ {
// Find which edit is active, copy the selected text or all text if no selection present // Find which edit is active, copy the selected text or all text if no selection present
// Put quote's around each line and add escapes. // Put quote's around each line and add escapes.
@ -307,7 +307,7 @@ void MainWindow::on_actionCopy_as_C_string_triggered()
} }
void MainWindow::on_actionCopy_as_raw_Cpp_string_triggered() void DatabaseWindow::on_actionCopy_as_raw_Cpp_string_triggered()
{ {
QueryTab *tab = GetActiveQueryTab(); QueryTab *tab = GetActiveQueryTab();
if (tab) { if (tab) {
@ -315,7 +315,7 @@ void MainWindow::on_actionCopy_as_raw_Cpp_string_triggered()
} }
} }
void MainWindow::addToolBarButtonsForPage(PlgPage *page) void DatabaseWindow::addToolBarButtonsForPage(PlgPage *page)
{ {
std::vector<QAction*> actions = page->getToolbarActions(); std::vector<QAction*> actions = page->getToolbarActions();
QList<QAction*> list; QList<QAction*> list;
@ -325,7 +325,7 @@ void MainWindow::addToolBarButtonsForPage(PlgPage *page)
ui->mainToolBar->addActions(list); ui->mainToolBar->addActions(list);
} }
void MainWindow::removeToolBarButtonsForPage(PlgPage *page) void DatabaseWindow::removeToolBarButtonsForPage(PlgPage *page)
{ {
std::vector<QAction*> actions = page->getToolbarActions(); std::vector<QAction*> actions = page->getToolbarActions();
for (auto act : actions) { for (auto act : actions) {
@ -334,7 +334,7 @@ void MainWindow::removeToolBarButtonsForPage(PlgPage *page)
} }
void MainWindow::addPage(PlgPage* page, QString caption) void DatabaseWindow::addPage(PlgPage* page, QString caption)
{ {
ui->tabWidget->addTab(page, caption); ui->tabWidget->addTab(page, caption);
ui->tabWidget->setCurrentWidget(page); ui->tabWidget->setCurrentWidget(page);
@ -342,12 +342,12 @@ void MainWindow::addPage(PlgPage* page, QString caption)
//addToolBarButtonsForPage(page); //addToolBarButtonsForPage(page);
} }
void MainWindow::removePage(PlgPage *) void DatabaseWindow::removePage(PlgPage *)
{ {
} }
void MainWindow::on_tabWidget_currentChanged(int index) void DatabaseWindow::on_tabWidget_currentChanged(int index)
{ {
// remove buttons of old page // remove buttons of old page
if (m_previousPage) { if (m_previousPage) {
@ -366,7 +366,7 @@ void MainWindow::on_tabWidget_currentChanged(int index)
m_previousPage = page; m_previousPage = page;
} }
void MainWindow::on_actionGenerate_code_triggered() void DatabaseWindow::on_actionGenerate_code_triggered()
{ {
QueryTab *tab = GetActiveQueryTab(); QueryTab *tab = GetActiveQueryTab();
if (tab) { if (tab) {

View file

@ -35,11 +35,14 @@ class OpenDatabase;
class PgClass; class PgClass;
class PlgPage; class PlgPage;
class MainWindow : public ASyncWindow { /** This is the class for windows that handle tasks for a specific database/catalog
*
*/
class DatabaseWindow : public ASyncWindow {
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(MasterController *master, QWidget *parent); explicit DatabaseWindow(MasterController *master, QWidget *parent);
~MainWindow(); ~DatabaseWindow();
void setConfig(const ConnectionConfig &config); void setConfig(const ConnectionConfig &config);

View file

@ -3,7 +3,7 @@
#include "ConnectionList.h" #include "ConnectionList.h"
#include "ConnectionListModel.h" #include "ConnectionListModel.h"
#include "PasswordManager.h" #include "PasswordManager.h"
#include "MainWindow.h" #include "DatabaseWindow.h"
#include "ServerWindow.h" #include "ServerWindow.h"
#include "BackupDialog.h" #include "BackupDialog.h"
#include "PasswordPromptDialog.h" #include "PasswordPromptDialog.h"
@ -80,7 +80,7 @@ void MasterController::openSqlWindowForConnection(size_t connection_index)
// TODO instead of directly openening the mainwindow // TODO instead of directly openening the mainwindow
// do async connect and only open window when we have // do async connect and only open window when we have
// working connection // working connection
auto w = new MainWindow(this, nullptr); auto w = new DatabaseWindow(this, nullptr);
w->setAttribute( Qt::WA_DeleteOnClose ); w->setAttribute( Qt::WA_DeleteOnClose );
w->setConfig(cc); w->setConfig(cc);
w->show(); w->show();

View file

@ -15,7 +15,7 @@
#include <QClipboard> #include <QClipboard>
#include "ExplainTreeModelItem.h" #include "ExplainTreeModelItem.h"
#include "json/json.h" #include "json/json.h"
#include "MainWindow.h" #include "DatabaseWindow.h"
#include "OpenDatabase.h" #include "OpenDatabase.h"
#include "catalog/PgDatabaseCatalog.h" #include "catalog/PgDatabaseCatalog.h"
#include "QueryParamListController.h" #include "QueryParamListController.h"
@ -23,7 +23,7 @@
#include "GlobalIoService.h" #include "GlobalIoService.h"
#include "UserConfiguration.h" #include "UserConfiguration.h"
QueryTab::QueryTab(MainWindow *win, QWidget *parent) : QueryTab::QueryTab(DatabaseWindow *win, QWidget *parent) :
PlgPage(parent), PlgPage(parent),
ui(new Ui::QueryTab), ui(new Ui::QueryTab),
m_win(win), m_win(win),

View file

@ -22,7 +22,7 @@ namespace Pgsql {
class QTableView; class QTableView;
class QTabWidget; class QTabWidget;
class MainWindow; class DatabaseWindow;
class SqlSyntaxHighlighter; class SqlSyntaxHighlighter;
class ExplainRoot; class ExplainRoot;
class QueryResultModel; class QueryResultModel;
@ -35,7 +35,7 @@ class PgDatabaseCatalog;
class QueryTab : public PlgPage { class QueryTab : public PlgPage {
Q_OBJECT Q_OBJECT
public: public:
QueryTab(MainWindow *win, QWidget *parent = nullptr); QueryTab(DatabaseWindow *win, QWidget *parent = nullptr);
~QueryTab(); ~QueryTab();
void setConfig(const ConnectionConfig &config, std::shared_ptr<PgDatabaseCatalog>cat); void setConfig(const ConnectionConfig &config, std::shared_ptr<PgDatabaseCatalog>cat);
@ -69,7 +69,7 @@ private:
using ResultTabContainer = std::vector<TuplesResultWidget*>; using ResultTabContainer = std::vector<TuplesResultWidget*>;
Ui::QueryTab *ui; Ui::QueryTab *ui;
MainWindow *m_win; DatabaseWindow *m_win;
SqlSyntaxHighlighter* highlighter; SqlSyntaxHighlighter* highlighter;
ConnectionConfig m_config; ConnectionConfig m_config;
StopWatch m_stopwatch; StopWatch m_stopwatch;

View file

@ -10,7 +10,7 @@
#include "ConstraintModel.h" #include "ConstraintModel.h"
#include "IconColumnDelegate.h" #include "IconColumnDelegate.h"
#include "IndexModel.h" #include "IndexModel.h"
#include "MainWindow.h" #include "DatabaseWindow.h"
#include "PgLabItemDelegate.h" #include "PgLabItemDelegate.h"
#include "PropertiesPage.h" #include "PropertiesPage.h"
#include "ResultTableModelUtil.h" #include "ResultTableModelUtil.h"
@ -23,7 +23,7 @@
#include <QStringBuilder> #include <QStringBuilder>
#include <unordered_set> #include <unordered_set>
TablesPage::TablesPage(MainWindow *parent) TablesPage::TablesPage(DatabaseWindow *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::TablesPage) , ui(new Ui::TablesPage)
, m_window(parent) , m_window(parent)

View file

@ -17,7 +17,7 @@ class ConstraintModel;
class PgDatabaseCatalog; class PgDatabaseCatalog;
class NamespaceFilterWidget; class NamespaceFilterWidget;
class IndexModel; class IndexModel;
class MainWindow; class DatabaseWindow;
class PropertiesPage; class PropertiesPage;
class TriggerPage; class TriggerPage;
class PgClass; class PgClass;
@ -28,13 +28,13 @@ class TablesPage : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit TablesPage(MainWindow *parent = nullptr); explicit TablesPage(DatabaseWindow *parent = nullptr);
~TablesPage(); ~TablesPage();
void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat); void setCatalog(std::shared_ptr<PgDatabaseCatalog> cat);
private: private:
Ui::TablesPage *ui; Ui::TablesPage *ui;
MainWindow *m_window; DatabaseWindow *m_window;
// QWidget *m_columnsTab; // QWidget *m_columnsTab;
ColumnPage *m_columnsPage; ColumnPage *m_columnsPage;
// QWidget *m_propertiesTab; // QWidget *m_propertiesTab;

View file

@ -40,7 +40,6 @@ SOURCES += main.cpp\
MasterController.cpp \ MasterController.cpp \
ParamTypeDelegate.cpp \ ParamTypeDelegate.cpp \
OpenDatabase.cpp \ OpenDatabase.cpp \
MainWindow.cpp \
SqlSyntaxHighlighter.cpp \ SqlSyntaxHighlighter.cpp \
ServerWindow.cpp \ ServerWindow.cpp \
ASyncWindow.cpp \ ASyncWindow.cpp \
@ -83,7 +82,8 @@ PropertyProxyModel.cpp \
EditTableWidget.cpp \ EditTableWidget.cpp \
EditColumnTableModel.cpp \ EditColumnTableModel.cpp \
SequenceModel.cpp \ SequenceModel.cpp \
SequencesPage.cpp SequencesPage.cpp \
DatabaseWindow.cpp
HEADERS += \ HEADERS += \
QueryResultModel.h \ QueryResultModel.h \
@ -99,7 +99,6 @@ HEADERS += \
MasterController.h \ MasterController.h \
ParamTypeDelegate.h \ ParamTypeDelegate.h \
OpenDatabase.h \ OpenDatabase.h \
MainWindow.h \
SqlSyntaxHighlighter.h \ SqlSyntaxHighlighter.h \
ServerWindow.h \ ServerWindow.h \
ASyncWindow.h \ ASyncWindow.h \
@ -144,7 +143,8 @@ CustomDataRole.h \
EditTableWidget.h \ EditTableWidget.h \
EditColumnTableModel.h \ EditColumnTableModel.h \
SequenceModel.h \ SequenceModel.h \
SequencesPage.h SequencesPage.h \
DatabaseWindow.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
ConnectionManagerWindow.ui \ ConnectionManagerWindow.ui \