pgLab/pglab/DatabaseWindow.h
eelke 683853e72e Do not rely on connectSlotsByName anymore as it breaks easily.
In the process I also made the initialisation of the actions more compact.
2021-07-08 16:28:32 +02:00

187 lines
5.6 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ConnectionConfig.h"
#include "CatalogInspector.h"
#include "OpenDatabase.h"
#include "Pgsql_Connection.h"
#include "ControllableTask.h"
#include "IDatabaseWindow.h"
#include <QFutureWatcher>
#include <QMainWindow>
#include <memory>
namespace Pgsql {
class Connection;
}
class CrudTab;
class MasterController;
class QCloseEvent;
class OpenDatabase;
class QueryTool;
class PgClass;
class QAction;
class QMenu;
class QTabWidget;
class QToolBar;
/** This is the class for windows that handle tasks for a specific database/catalog
*
*/
class DatabaseWindow : public QMainWindow, public IDatabaseWindow {
Q_OBJECT
public:
DatabaseWindow(MasterController *master, QWidget *parent);
~DatabaseWindow();
void setConfig(const ConnectionConfig &config);
std::shared_ptr<OpenDatabase> getDatabase() { return m_database; }
void setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint);
void setTabIcon(QWidget *widget, const QString &iconname);
/// Called when a newly created page is added to the QTabWidget
void addPage(QWidget* page, QString caption);
virtual void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres) override;
QueryTool *GetActiveQueryTool();
CrudTab *GetActiveCrud();
protected:
virtual void closeEvent(QCloseEvent *event) override;
private:
QTabWidget *m_tabWidget = nullptr;
QToolBar *m_mainToolBar = nullptr;
ConnectionConfig m_config;
std::shared_ptr<OpenDatabase> m_database;
MasterController *m_masterController;
// Standard menu's
QMenu *m_fileMenu = nullptr;
// Standard actions
QAction *actionAbout = nullptr;
QAction *actionCancelQuery = nullptr;
QAction *actionClose = nullptr;
QAction *actionCopy = nullptr;
QAction *actionCopyAsCString = nullptr;
QAction *actionCopyAsRawCppString = nullptr;
QAction *actionExecuteQuery = nullptr;
QAction *actionExplain = nullptr;
QAction *actionExplainAnalyze = nullptr;
QAction *actionExportData = nullptr;
QAction *actionGenerateCode = nullptr;
QAction *actionInspectInformationSchema = nullptr; ///< Create or switch to pgcatalog tab
QAction *actionInspectPgCatalog = nullptr; ///< Create or switch to pgcatalog tab
QAction *actionInspectUserSchemas = nullptr; ///< Create or switch to pgcatalog tab
QAction *actionServerInspector = nullptr;
QAction *actionNewSql = nullptr;
QAction *actionOpenSql = nullptr;
QAction *actionPasteLangString = nullptr;
QAction *actionRefreshCatalog = nullptr;
QAction *actionRefreshCrud = nullptr;
QAction *actionSaveSql = nullptr;
QAction *actionSaveSqlAs = nullptr;
QAction *actionSaveCopyOfSqlAs = nullptr;
QAction *actionShowConnectionManager = nullptr;
QMenu *menuEdit = nullptr;
QMenu *menuFile = nullptr;
QMenu *menuHelp = nullptr;
QMenu *menuQuery = nullptr;
QMenu *menuCatalog = nullptr;
QMenu *menuCrud = nullptr;
QMenu *menuWindow = nullptr;
class LoadCatalog: public ControllableTask<OpenDatabase::OpenDatabaseSPtr> {
public:
LoadCatalog(ConnectionConfig config)
: m_config(config)
{}
OpenDatabase::OpenDatabaseSPtr run(TaskControl& ) override
{
return OpenDatabase::createOpenDatabase(m_config);
}
private:
ConnectionConfig m_config;
};
QFutureWatcher<LoadCatalog::Result> loadWatcher;
void createActions();
void initMenus();
QAction* seperator();
void newCreateTablePage();
void newCrudPage(Oid tableoid);
void newCatalogInspectorPage(QString caption, NamespaceFilter filter);
void newServerInspectorPage();
void closeTab(int index);
bool canCloseTab(int index) const;
void openSqlFile(QString file_name);
/// Uses introspection to determine if the specific widget has a copy function.
/// If it has it invokes this method using reflection.
static void InvokeCopyIfPresent(QWidget *w);
QAction* createAction(QString icon, QString caption, void (DatabaseWindow::*func)());
QAction* createAction(QString caption, void (DatabaseWindow::*func)());
private slots:
void catalogLoaded();
void tableSelected(Oid tableoid);
// void tabWidget_tabCloseRequested(int index);
// void tabWidget_currentChanged(int index);
void actionAbout_triggered();
void actionCancelQuery_triggered();
void actionClose_triggered();
void actionCopy_triggered();
void actionCopyAsCString_triggered();
void actionCopyAsRawCppString_triggered();
void actionExecuteQuery_triggered();
void actionExplain_triggered();
void actionExplainAnalyze_triggered();
void actionExportData_triggered();
void actionGenerateCode_triggered();
void actionInspectInformationSchema_triggered();
void actionInspectPgCatalog_triggered();
void actionInspectUserSchemas_triggered();
void actionServerInspector_triggered();
void actionNewSql_triggered();
void actionOpenSql_triggered();
void actionPasteLangString_triggered();
void actionRefreshCatalog_triggered();
void actionRefreshCrud_triggered();
void actionSaveSql_triggered();
void actionSaveSqlAs_triggered();
void actionSaveCopyOfSqlAs_triggered();
void actionShowConnectionManager_triggered();
void m_tabWidget_tabCloseRequested(int index);
void m_tabWidget_currentChanged(int index);
// IDatabaseWindow interface
public:
virtual void setTitleForWidget(QWidget *widget, QString title, QString hint) override;
virtual void setIconForWidget(QWidget *widget, QIcon icon) override;
virtual std::shared_ptr<OpenDatabase> openDatabase() override;
virtual void showStatusBarMessage(QString message) override;
// QWidget interface
protected:
virtual void dragEnterEvent(QDragEnterEvent *event) override;
virtual void dropEvent(QDropEvent *event) override;
};
#endif // MAINWINDOW_H