pgLab/pglab/DatabaseWindow.h
eelke 1a208a6a2d Crud page has now reload action.
F5 key is bound to the execute query, reload catalog and reload crud
actions. By using addAction to add these actions to the relevant pages
the ambiguity of the shortcut is resolved.
2019-10-13 07:31:48 +02:00

165 lines
4.9 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();
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 *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 closeTab(int index);
private slots:
void catalogLoaded();
void tableSelected(Oid tableoid);
// void tabWidget_tabCloseRequested(int index);
// void tabWidget_currentChanged(int index);
void on_actionAbout_triggered();
void on_actionCancelQuery_triggered();
void on_actionClose_triggered();
void on_actionCopy_triggered();
void on_actionCopyAsCString_triggered();
void on_actionCopyAsRawCppString_triggered();
void on_actionExecuteQuery_triggered();
void on_actionExplain_triggered();
void on_actionExplainAnalyze_triggered();
void on_actionExportData_triggered();
void on_actionGenerateCode_triggered();
void on_actionInspectInformationSchema_triggered();
void on_actionInspectPgCatalog_triggered();
void on_actionInspectUserSchemas_triggered();
void on_actionNewSql_triggered();
void on_actionOpenSql_triggered();
void on_actionPasteLangString_triggered();
void on_actionRefreshCatalog_triggered();
void on_actionRefreshCrud_triggered();
void on_actionSaveSql_triggered();
void on_actionSaveSqlAs_triggered();
void on_actionSaveCopyOfSqlAs_triggered();
void on_actionShowConnectionManager_triggered();
void on_m_tabWidget_tabCloseRequested(int index);
void on_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;
};
#endif // MAINWINDOW_H