2016-12-26 16:06:55 +01:00
|
|
|
|
#ifndef MAINWINDOW_H
|
|
|
|
|
|
#define MAINWINDOW_H
|
|
|
|
|
|
|
2017-08-23 13:27:23 +02:00
|
|
|
|
#include "ASyncDBConnection.h"
|
|
|
|
|
|
#include "ConnectionConfig.h"
|
2017-12-25 15:33:10 +01:00
|
|
|
|
#include "OpenDatabase.h"
|
2017-01-08 15:16:16 +01:00
|
|
|
|
#include <QLabel>
|
2017-12-28 07:23:20 +01:00
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
#include <QRunnable>
|
2016-12-27 15:41:11 +01:00
|
|
|
|
#include <QSocketNotifier>
|
2016-12-26 16:06:55 +01:00
|
|
|
|
#include <memory>
|
2016-12-27 21:22:49 +01:00
|
|
|
|
#include <future>
|
2017-08-26 11:45:50 +02:00
|
|
|
|
#include "Pgsql_Connection.h"
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#include "ControllableTask.h"
|
2017-01-16 18:56:07 +01:00
|
|
|
|
#include <chrono>
|
2017-01-15 21:01:40 +01:00
|
|
|
|
#include <deque>
|
|
|
|
|
|
#include <mutex>
|
2016-12-26 16:06:55 +01:00
|
|
|
|
|
2017-12-28 07:23:20 +01:00
|
|
|
|
#include <QMutex>
|
|
|
|
|
|
#include <QWaitCondition>
|
2018-12-30 15:46:15 +01:00
|
|
|
|
#include <QMainWindow>
|
|
|
|
|
|
#include <QFuture>
|
|
|
|
|
|
#include <QFutureWatcher>
|
2017-12-28 07:23:20 +01:00
|
|
|
|
|
2019-01-01 14:34:14 +01:00
|
|
|
|
//namespace Ui {
|
|
|
|
|
|
// class DatabaseWindow;
|
|
|
|
|
|
//}
|
2016-12-26 16:06:55 +01:00
|
|
|
|
|
2016-12-27 15:41:11 +01:00
|
|
|
|
namespace Pgsql {
|
|
|
|
|
|
class Connection;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-01 11:15:16 +01:00
|
|
|
|
class MenuAction;
|
2017-01-21 08:09:12 +01:00
|
|
|
|
class QueryTab;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
class MasterController;
|
2017-01-19 17:48:44 +01:00
|
|
|
|
class QCloseEvent;
|
2017-02-04 11:55:49 +01:00
|
|
|
|
class OpenDatabase;
|
2018-01-09 20:39:43 +01:00
|
|
|
|
class PgClass;
|
2018-12-29 18:59:54 +01:00
|
|
|
|
class PluginContentWidget;
|
|
|
|
|
|
|
2019-01-01 14:34:14 +01:00
|
|
|
|
class QTabWidget;
|
|
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
namespace DatabaseWindow_details {
|
|
|
|
|
|
class DatabaseWindowContentContext;
|
|
|
|
|
|
}
|
2016-12-30 10:14:26 +01:00
|
|
|
|
|
2019-01-01 11:15:16 +01:00
|
|
|
|
class LMainWindow : public QMainWindow {
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
LMainWindow(QWidget *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
void initModuleMenus();
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
|
|
DatabaseWindow_details::DatabaseWindowContentContext *m_context;
|
|
|
|
|
|
|
|
|
|
|
|
void addModuleMenuActions();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
QMenu *m_fileMenu = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
void addMenuAction(const MenuAction &ma);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-28 12:55:11 +01:00
|
|
|
|
/** This is the class for windows that handle tasks for a specific database/catalog
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2019-01-01 11:15:16 +01:00
|
|
|
|
class DatabaseWindow : public LMainWindow {
|
2016-12-26 16:06:55 +01:00
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
2019-01-01 11:15:16 +01:00
|
|
|
|
DatabaseWindow(MasterController *master, QWidget *parent);
|
2018-12-28 12:55:11 +01:00
|
|
|
|
~DatabaseWindow();
|
2016-12-26 16:06:55 +01:00
|
|
|
|
|
2017-01-15 21:01:40 +01:00
|
|
|
|
void setConfig(const ConnectionConfig &config);
|
2016-12-30 10:14:26 +01:00
|
|
|
|
|
2017-12-25 10:31:58 +01:00
|
|
|
|
std::shared_ptr<OpenDatabase> getDatabase() { return m_database; }
|
2018-01-09 20:39:43 +01:00
|
|
|
|
|
2018-09-18 11:53:19 +02:00
|
|
|
|
void newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres);
|
2018-12-28 08:51:02 +01:00
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
void setTabCaptionForWidget(QWidget *widget, const QString &caption, const QString &hint);
|
|
|
|
|
|
void setTabIcon(QWidget *widget, const QString &iconname);
|
2018-12-31 15:20:55 +01:00
|
|
|
|
|
|
|
|
|
|
/// Called when a newly created page is added to the QTabWidget
|
|
|
|
|
|
void addPage(PluginContentWidget* page, QString caption);
|
2016-12-26 16:06:55 +01:00
|
|
|
|
private:
|
2017-01-25 06:54:21 +01:00
|
|
|
|
|
2019-01-01 14:34:14 +01:00
|
|
|
|
QTabWidget *m_tabWidget = nullptr;
|
|
|
|
|
|
QToolBar *m_mainToolBar = nullptr;
|
2017-01-21 18:16:57 +01:00
|
|
|
|
|
2017-01-15 21:01:40 +01:00
|
|
|
|
ConnectionConfig m_config;
|
2017-12-25 10:31:58 +01:00
|
|
|
|
std::shared_ptr<OpenDatabase> m_database;
|
2017-01-15 21:01:40 +01:00
|
|
|
|
|
2017-02-01 18:01:02 +01:00
|
|
|
|
MasterController *m_masterController;
|
2018-12-29 18:59:54 +01:00
|
|
|
|
PluginContentWidget *m_previousPage = nullptr; ///< tracks which pages buttons were previously being displayed
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
// class QLoad : public QueuedBackgroundTask {
|
|
|
|
|
|
// public:
|
|
|
|
|
|
// explicit QLoad(ConnectionConfig config, CompletionFunction on_completion)
|
|
|
|
|
|
// : QueuedBackgroundTask(on_completion)
|
|
|
|
|
|
// , m_config(config)
|
|
|
|
|
|
// {}
|
|
|
|
|
|
|
|
|
|
|
|
// OpenDatabase::OpenDatabaseSPtr GetResult()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (hasException()) rethrow();
|
|
|
|
|
|
// return result;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// protected:
|
|
|
|
|
|
|
|
|
|
|
|
// OpenDatabase::OpenDatabaseSPtr result;
|
|
|
|
|
|
// virtual void doRun()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// auto res = OpenDatabase::createOpenDatabase(m_config);
|
|
|
|
|
|
// result = res.get();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// private:
|
|
|
|
|
|
|
|
|
|
|
|
// ConnectionConfig m_config;
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
// std::shared_ptr<QLoad> loader;
|
|
|
|
|
|
|
|
|
|
|
|
class LoadCatalog: public ControllableTask<OpenDatabase::OpenDatabaseSPtr> {
|
2017-12-28 07:23:20 +01:00
|
|
|
|
public:
|
2018-12-30 15:46:15 +01:00
|
|
|
|
LoadCatalog(ConnectionConfig config)
|
|
|
|
|
|
: m_config(config)
|
2017-12-28 07:23:20 +01:00
|
|
|
|
{}
|
|
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
OpenDatabase::OpenDatabaseSPtr run(TaskControl& ) override
|
2017-12-28 07:23:20 +01:00
|
|
|
|
{
|
|
|
|
|
|
auto res = OpenDatabase::createOpenDatabase(m_config);
|
2018-12-30 15:46:15 +01:00
|
|
|
|
return res.get();
|
2017-12-28 07:23:20 +01:00
|
|
|
|
}
|
2017-02-12 08:13:38 +01:00
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
private:
|
2017-12-28 07:23:20 +01:00
|
|
|
|
ConnectionConfig m_config;
|
|
|
|
|
|
};
|
2017-02-12 08:13:38 +01:00
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
QFutureWatcher<LoadCatalog::Result> loadWatcher;
|
2017-01-08 15:16:16 +01:00
|
|
|
|
|
2017-01-21 18:16:57 +01:00
|
|
|
|
QueryTab *GetActiveQueryTab();
|
2016-12-26 16:06:55 +01:00
|
|
|
|
|
2017-01-19 17:48:44 +01:00
|
|
|
|
void closeEvent(QCloseEvent *event);
|
2017-01-21 08:09:12 +01:00
|
|
|
|
void showEvent(QShowEvent *event);
|
2017-01-22 08:50:41 +01:00
|
|
|
|
QueryTab *newSqlPage();
|
2018-12-15 20:27:40 +01:00
|
|
|
|
void newCreateTablePage();
|
2017-01-25 06:54:21 +01:00
|
|
|
|
|
2017-12-25 15:33:10 +01:00
|
|
|
|
|
2018-05-14 20:24:41 +02:00
|
|
|
|
/// Called when a page is completely removed from the QTabWidget
|
2018-12-29 18:59:54 +01:00
|
|
|
|
void removePage(PluginContentWidget *page);
|
2018-05-14 20:24:41 +02:00
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
void addToolBarButtonsForPage(PluginContentWidget *page);
|
|
|
|
|
|
void removeToolBarButtonsForPage(PluginContentWidget *page);
|
2018-05-14 20:24:41 +02:00
|
|
|
|
//class PageData
|
2016-12-26 16:06:55 +01:00
|
|
|
|
private slots:
|
2016-12-27 15:41:11 +01:00
|
|
|
|
|
2018-12-30 15:46:15 +01:00
|
|
|
|
void catalogLoaded();
|
|
|
|
|
|
|
2017-01-09 07:39:09 +01:00
|
|
|
|
void on_actionLoad_SQL_triggered();
|
|
|
|
|
|
void on_actionSave_SQL_triggered();
|
|
|
|
|
|
void on_actionExport_data_triggered();
|
|
|
|
|
|
void on_actionClose_triggered();
|
|
|
|
|
|
void on_actionAbout_triggered();
|
2017-01-21 08:09:12 +01:00
|
|
|
|
void on_actionSave_SQL_as_triggered();
|
2017-01-21 08:19:47 +01:00
|
|
|
|
void on_actionSave_copy_of_SQL_as_triggered();
|
2017-01-21 18:16:57 +01:00
|
|
|
|
void on_actionNew_SQL_triggered();
|
2017-01-22 08:50:41 +01:00
|
|
|
|
void on_tabWidget_tabCloseRequested(int index);
|
2017-02-01 18:01:02 +01:00
|
|
|
|
void on_actionShow_connection_manager_triggered();
|
2017-02-04 11:55:49 +01:00
|
|
|
|
void on_actionCopy_triggered();
|
2017-02-05 08:23:06 +01:00
|
|
|
|
void on_actionCopy_as_C_string_triggered();
|
2017-10-05 16:02:06 +02:00
|
|
|
|
void on_actionCopy_as_raw_Cpp_string_triggered();
|
2018-05-14 20:24:41 +02:00
|
|
|
|
void on_tabWidget_currentChanged(int index);
|
2018-09-18 11:53:19 +02:00
|
|
|
|
void on_actionGenerate_code_triggered();
|
2016-12-26 16:06:55 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // MAINWINDOW_H
|