pgLab/pglab/DatabaseWindow.h
eelke 1a2ec6a224 DatabaseWindow now provides some functionality to its child components through the IDatabaseWindow interface.
This way children do not need to include the full header to get access to some utility functions for changing
the titles and icons of tabpages (and in fact do not need to know that there are tabs, could be something else)
2019-08-16 08:29:27 +02:00

148 lines
4.2 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ConnectionConfig.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 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);
void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres);
QueryTool *GetActiveQueryTool();
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 *actionSaveSql = nullptr;
QAction *actionSaveSqlAs = nullptr;
QAction *actionSaveCopyOfSqlAs = nullptr;
QAction *actionShowConnectionManager = nullptr;
QMenu *menuEdit = nullptr;
QMenu *menuFile = nullptr;
QMenu *menuHelp = nullptr;
QMenu *menuQuery = 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 newCreateTablePage();
void createActions();
void initMenus();
QAction* seperator();
private slots:
void catalogLoaded();
// 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_actionSaveSql_triggered();
void on_actionSaveSqlAs_triggered();
void on_actionSaveCopyOfSqlAs_triggered();
void on_actionShowConnectionManager_triggered();
// 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