Made step to remove ASyncWindow in favour of usage of Future and FutureWatcher.
This should allow concurrency in the plugins to be independent from their container. Contains also some work on the system for registering plugins.
This commit is contained in:
parent
a54a063c13
commit
15bee33076
25 changed files with 327 additions and 52 deletions
|
|
@ -12,8 +12,9 @@ template <class T>
|
||||||
class ControllableTask
|
class ControllableTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Result = T;
|
||||||
virtual ~ControllableTask() {}
|
virtual ~ControllableTask() {}
|
||||||
virtual T run(TaskControl& control) = 0;
|
virtual Result run(TaskControl& control) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTROLLABLETASK_H
|
#endif // CONTROLLABLETASK_H
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,16 @@
|
||||||
|
|
||||||
#include <QFutureInterface>
|
#include <QFutureInterface>
|
||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
|
#include <QThreadPool>
|
||||||
#include "ControllableTask.h"
|
#include "ControllableTask.h"
|
||||||
|
#include "TaskControl.h"
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class RunControllableTask : public QFutureInterface<T> , public QRunnable
|
class RunControllableTask : public QFutureInterface<T> , public QRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RunControllableTask(ControllableTask<T>* tsk) : task(tsk) { }
|
RunControllableTask(ControllableTask<T>* tsk) : task(tsk) { }
|
||||||
virtial ~RunControllableTask() { delete task; }
|
virtual ~RunControllableTask() { delete task; }
|
||||||
|
|
||||||
QFuture<T> start()
|
QFuture<T> start()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@
|
||||||
|
|
||||||
#include <QFutureInterfaceBase>
|
#include <QFutureInterfaceBase>
|
||||||
|
|
||||||
class TaskControl
|
class TaskControl {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TaskControl(QFutureInterfaceBase *f) : fu(f) { }
|
TaskControl(QFutureInterfaceBase *f) : fu(f) { }
|
||||||
bool shouldRun() const { return !fu->isCanceled(); }
|
bool shouldRun() const { return !fu->isCanceled(); }
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
#include "ControllableTask.h"
|
#include "ControllableTask.h"
|
||||||
#include "RunControllableTask.h"
|
#include "RunControllableTask.h"
|
||||||
|
#include <QFuture>
|
||||||
/**
|
/**
|
||||||
* @brief The TaskExecutor class
|
* @brief The TaskExecutor class
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define CODEGENERATOR_H
|
#define CODEGENERATOR_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "PluginContentWidget.h"
|
#include "plugin_support/PluginContentWidget.h"
|
||||||
#include "Pgsql_declare.h"
|
#include "Pgsql_declare.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "ScopeGuard.h"
|
#include "ScopeGuard.h"
|
||||||
|
|
||||||
CrudModel::CrudModel(ASyncWindow *async_window)
|
CrudModel::CrudModel(QObject *parent)
|
||||||
: m_asyncWindow(async_window)
|
: QAbstractTableModel(parent)
|
||||||
, m_dbConn(*getGlobalAsioIoService())
|
, m_dbConn(*getGlobalAsioIoService())
|
||||||
{
|
{
|
||||||
qDebug("CrudModel created");
|
qDebug("CrudModel created");
|
||||||
|
|
@ -172,7 +172,8 @@ void CrudModel::loadData()
|
||||||
if (res.valid()) {
|
if (res.valid()) {
|
||||||
auto dbres = res.get();
|
auto dbres = res.get();
|
||||||
if (dbres && *dbres) {
|
if (dbres && *dbres) {
|
||||||
m_asyncWindow->QueueTask([this, dbres]() { loadIntoModel(dbres); });
|
/// \todo Use ControllableTask instead with QFUtureWatcher
|
||||||
|
// m_asyncWindow->QueueTask([this, dbres]() { loadIntoModel(dbres); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
class PgConstraint;
|
class PgConstraint;
|
||||||
class OpenDatabase;
|
class OpenDatabase;
|
||||||
class ASyncWindow;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The CrudModel class
|
* @brief The CrudModel class
|
||||||
|
|
@ -55,7 +54,7 @@ class ASyncWindow;
|
||||||
class CrudModel: public QAbstractTableModel {
|
class CrudModel: public QAbstractTableModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CrudModel(ASyncWindow *async_win);
|
explicit CrudModel(QObject *parent = nullptr);
|
||||||
~CrudModel() override;
|
~CrudModel() override;
|
||||||
|
|
||||||
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
||||||
|
|
@ -231,8 +230,6 @@ private:
|
||||||
};
|
};
|
||||||
using RowMappingVector = std::vector<RowMapping>;
|
using RowMappingVector = std::vector<RowMapping>;
|
||||||
|
|
||||||
|
|
||||||
ASyncWindow * m_asyncWindow;
|
|
||||||
std::shared_ptr<OpenDatabase> m_database;
|
std::shared_ptr<OpenDatabase> m_database;
|
||||||
std::optional<PgClass> m_table;
|
std::optional<PgClass> m_table;
|
||||||
std::optional<PgConstraint> m_primaryKey;
|
std::optional<PgConstraint> m_primaryKey;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "catalog/PgClass.h"
|
#include "catalog/PgClass.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "PluginContentWidget.h"
|
#include "plugin_support/PluginContentWidget.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ class CrudTab : public PluginContentWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CrudTab(IPluginContentWidgetContext *context, DatabaseWindow *parent = 0);
|
explicit CrudTab(IPluginContentWidgetContext *context, DatabaseWindow *parent = nullptr);
|
||||||
~CrudTab() override;
|
~CrudTab() override;
|
||||||
|
|
||||||
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
#include "QueryTab.h"
|
#include "QueryTab.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "PluginContentWidget.h"
|
#include "plugin_support/PluginContentWidget.h"
|
||||||
#include "CodeGenerator.h"
|
#include "CodeGenerator.h"
|
||||||
#include "MasterController.h"
|
#include "MasterController.h"
|
||||||
#include "CrudTab.h"
|
#include "CrudTab.h"
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include "ScopeGuard.h"
|
#include "ScopeGuard.h"
|
||||||
#include "EditTableWidget.h"
|
#include "EditTableWidget.h"
|
||||||
#include "IPluginContentWidgetContext.h"
|
#include "IPluginContentWidgetContext.h"
|
||||||
|
#include "TaskExecutor.h"
|
||||||
|
|
||||||
namespace pg = Pgsql;
|
namespace pg = Pgsql;
|
||||||
|
|
||||||
|
|
@ -49,9 +50,9 @@ namespace DatabaseWindow_details {
|
||||||
return m_window->getDatabase();
|
return m_window->getDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueueTask(TSQueue::t_Callable c) override
|
void QueueTask(TSQueue::t_Callable ) override
|
||||||
{
|
{
|
||||||
m_window->QueueTask(c);
|
// m_window->QueueTask(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showStatusMessage(const QString &msg) override
|
void showStatusMessage(const QString &msg) override
|
||||||
|
|
@ -67,18 +68,20 @@ using namespace DatabaseWindow_details;
|
||||||
|
|
||||||
|
|
||||||
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
DatabaseWindow::DatabaseWindow(MasterController *master, QWidget *parent)
|
||||||
: ASyncWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
, m_context(new DatabaseWindowContentContext(this))
|
, m_context(new DatabaseWindowContentContext(this))
|
||||||
, m_masterController(master)
|
, m_masterController(master)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->tabWidget->setDocumentMode(true);
|
ui->tabWidget->setDocumentMode(true);
|
||||||
|
|
||||||
|
connect(&loadWatcher, &QFutureWatcher<LoadCatalog::Result>::finished,
|
||||||
|
this, &DatabaseWindow::catalogLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseWindow::~DatabaseWindow()
|
DatabaseWindow::~DatabaseWindow()
|
||||||
{
|
{
|
||||||
loader.reset();
|
|
||||||
delete m_context;
|
delete m_context;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
@ -128,10 +131,9 @@ void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
||||||
title += m_config.name().c_str();
|
title += m_config.name().c_str();
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
|
|
||||||
loader = std::make_shared<QLoad>(m_config, [this](QRunnable *) {
|
auto f = TaskExecutor::run(new LoadCatalog(m_config));
|
||||||
QueueTask([this] () { catalogLoaded(); });
|
loadWatcher.setFuture(f);
|
||||||
} );
|
|
||||||
WorkManager::getWorkManager()->addRunnable(loader.get());
|
|
||||||
} catch (std::runtime_error &ex) {
|
} catch (std::runtime_error &ex) {
|
||||||
QMessageBox::critical(this, "Error reading database",
|
QMessageBox::critical(this, "Error reading database",
|
||||||
QString::fromUtf8(ex.what()));
|
QString::fromUtf8(ex.what()));
|
||||||
|
|
@ -143,8 +145,8 @@ void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
||||||
void DatabaseWindow::catalogLoaded()
|
void DatabaseWindow::catalogLoaded()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
SCOPE_EXIT { loader.reset(); };
|
//SCOPE_EXIT { loadFuture = {}; };
|
||||||
m_database = loader->GetResult();
|
m_database = loadWatcher.future().result();
|
||||||
|
|
||||||
auto tt = new TablesPage(this);
|
auto tt = new TablesPage(this);
|
||||||
tt->setCatalog(m_database->catalog());
|
tt->setCatalog(m_database->catalog());
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,24 @@
|
||||||
#include "ConnectionConfig.h"
|
#include "ConnectionConfig.h"
|
||||||
#include "OpenDatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include "ASyncWindow.h"
|
//#include "ASyncWindow.h"
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QRunnable>
|
#include <QRunnable>
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include "Pgsql_Connection.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include "QueuedBackgroundTask.h"
|
//#include "QueuedBackgroundTask.h"
|
||||||
|
#include "ControllableTask.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QFuture>
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
@ -42,7 +46,7 @@ namespace DatabaseWindow_details {
|
||||||
/** This is the class for windows that handle tasks for a specific database/catalog
|
/** This is the class for windows that handle tasks for a specific database/catalog
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DatabaseWindow : public ASyncWindow {
|
class DatabaseWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DatabaseWindow(MasterController *master, QWidget *parent);
|
explicit DatabaseWindow(MasterController *master, QWidget *parent);
|
||||||
|
|
@ -68,33 +72,50 @@ private:
|
||||||
MasterController *m_masterController;
|
MasterController *m_masterController;
|
||||||
PluginContentWidget *m_previousPage = nullptr; ///< tracks which pages buttons were previously being displayed
|
PluginContentWidget *m_previousPage = nullptr; ///< tracks which pages buttons were previously being displayed
|
||||||
|
|
||||||
class QLoad : public QueuedBackgroundTask {
|
// 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> {
|
||||||
public:
|
public:
|
||||||
explicit QLoad(ConnectionConfig config, CompletionFunction on_completion)
|
LoadCatalog(ConnectionConfig config)
|
||||||
: QueuedBackgroundTask(on_completion)
|
: m_config(config)
|
||||||
, m_config(config)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
OpenDatabase::OpenDatabaseSPtr GetResult()
|
OpenDatabase::OpenDatabaseSPtr run(TaskControl& ) override
|
||||||
{
|
|
||||||
if (hasException()) rethrow();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
|
|
||||||
OpenDatabase::OpenDatabaseSPtr result;
|
|
||||||
virtual void doRun()
|
|
||||||
{
|
{
|
||||||
auto res = OpenDatabase::createOpenDatabase(m_config);
|
auto res = OpenDatabase::createOpenDatabase(m_config);
|
||||||
result = res.get();
|
return res.get();
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
ConnectionConfig m_config;
|
ConnectionConfig m_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<QLoad> loader;
|
QFutureWatcher<LoadCatalog::Result> loadWatcher;
|
||||||
|
|
||||||
|
|
||||||
QueryTab *GetActiveQueryTab();
|
QueryTab *GetActiveQueryTab();
|
||||||
|
|
||||||
|
|
@ -103,7 +124,6 @@ private:
|
||||||
QueryTab *newSqlPage();
|
QueryTab *newSqlPage();
|
||||||
void newCreateTablePage();
|
void newCreateTablePage();
|
||||||
|
|
||||||
void catalogLoaded();
|
|
||||||
|
|
||||||
/// Called when a newly created page is added to the QTabWidget
|
/// Called when a newly created page is added to the QTabWidget
|
||||||
void addPage(PluginContentWidget* page, QString caption);
|
void addPage(PluginContentWidget* page, QString caption);
|
||||||
|
|
@ -115,6 +135,8 @@ private:
|
||||||
//class PageData
|
//class PageData
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
|
void catalogLoaded();
|
||||||
|
|
||||||
void on_actionLoad_SQL_triggered();
|
void on_actionLoad_SQL_triggered();
|
||||||
void on_actionSave_SQL_triggered();
|
void on_actionSave_SQL_triggered();
|
||||||
void on_actionExport_data_triggered();
|
void on_actionExport_data_triggered();
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include "GlobalIoService.h"
|
#include "GlobalIoService.h"
|
||||||
#include "UserConfiguration.h"
|
#include "UserConfiguration.h"
|
||||||
#include "IPluginContentWidgetContext.h"
|
#include "IPluginContentWidgetContext.h"
|
||||||
|
#include "plugin_support/PluginRegister.h"
|
||||||
|
|
||||||
QueryTab::QueryTab(IPluginContentWidgetContext *context_, QWidget *parent)
|
QueryTab::QueryTab(IPluginContentWidgetContext *context_, QWidget *parent)
|
||||||
: PluginContentWidget(context_, parent)
|
: PluginContentWidget(context_, parent)
|
||||||
|
|
@ -58,7 +59,8 @@ QueryTab::QueryTab(IPluginContentWidgetContext *context_, QWidget *parent)
|
||||||
|
|
||||||
QueryTab::~QueryTab()
|
QueryTab::~QueryTab()
|
||||||
{
|
{
|
||||||
m_dbConnection.closeConnection();
|
// m_dbConnection.blockSignals(true);
|
||||||
|
// m_dbConnection.closeConnection();
|
||||||
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
@ -667,3 +669,33 @@ std::vector<QAction*> QueryTab::getToolbarActions()
|
||||||
}
|
}
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QueryToolModule::init()
|
||||||
|
{
|
||||||
|
auto action_new = new QAction(QIcon(":/icons/new_query_tab.png"), tr("New"), this);
|
||||||
|
connect(action_new, &QAction::triggered, this, &QueryToolModule::new_triggered);
|
||||||
|
|
||||||
|
registerAction(action_new, MenuLocation({"File/New"}), ToolbarLocation("File", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
void QueryToolModule::new_triggered()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<PluginModule> createModule()
|
||||||
|
{
|
||||||
|
auto module = std::make_shared<QueryToolModule>("Query tool", "pglab.querytool");
|
||||||
|
module->init();
|
||||||
|
|
||||||
|
PluginRegister::getInstance()->registerModule(module);
|
||||||
|
return std::move(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::weak_ptr<PluginModule> register_variable = createModule();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@
|
||||||
#include "tuplesresultwidget.h"
|
#include "tuplesresultwidget.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "PluginContentWidget.h"
|
#include "plugin_support/PluginContentWidget.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "plugin_support/PluginModule.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class QueryTab;
|
class QueryTab;
|
||||||
|
|
@ -110,4 +111,14 @@ private slots:
|
||||||
void startConnect();
|
void startConnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class QueryToolModule: public PluginModule {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
using PluginModule::PluginModule;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
private slots:
|
||||||
|
void new_triggered();
|
||||||
|
};
|
||||||
|
|
||||||
#endif // QUERYTAB_H
|
#endif // QUERYTAB_H
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,12 @@ PropertyProxyModel.cpp \
|
||||||
SequencesPage.cpp \
|
SequencesPage.cpp \
|
||||||
DatabaseWindow.cpp \
|
DatabaseWindow.cpp \
|
||||||
PgLabTableView.cpp \
|
PgLabTableView.cpp \
|
||||||
PluginContentWidget.cpp
|
plugin_support/PluginModule.cpp \
|
||||||
|
plugin_support/MenuPath.cpp \
|
||||||
|
plugin_support/MenuLocation.cpp \
|
||||||
|
plugin_support/ToolbarLocation.cpp \
|
||||||
|
plugin_support/PluginRegister.cpp \
|
||||||
|
plugin_support/PluginContentWidget.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
QueryResultModel.h \
|
QueryResultModel.h \
|
||||||
|
|
@ -146,8 +151,13 @@ CustomDataRole.h \
|
||||||
SequencesPage.h \
|
SequencesPage.h \
|
||||||
DatabaseWindow.h \
|
DatabaseWindow.h \
|
||||||
PgLabTableView.h \
|
PgLabTableView.h \
|
||||||
PluginContentWidget.h \
|
IPluginContentWidgetContext.h \
|
||||||
IPluginContentWidgetContext.h
|
plugin_support/PluginModule.h \
|
||||||
|
plugin_support/MenuPath.h \
|
||||||
|
plugin_support/MenuLocation.h \
|
||||||
|
plugin_support/ToolbarLocation.h \
|
||||||
|
plugin_support/PluginRegister.h \
|
||||||
|
plugin_support/PluginContentWidget.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
ConnectionManagerWindow.ui \
|
ConnectionManagerWindow.ui \
|
||||||
|
|
|
||||||
8
pglab/plugin_support/MenuLocation.cpp
Normal file
8
pglab/plugin_support/MenuLocation.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "MenuLocation.h"
|
||||||
|
|
||||||
|
MenuLocation::MenuLocation() = default;
|
||||||
|
|
||||||
|
MenuLocation::MenuLocation(MenuPath path, int position)
|
||||||
|
: m_path(std::move(path))
|
||||||
|
, m_position(position)
|
||||||
|
{}
|
||||||
17
pglab/plugin_support/MenuLocation.h
Normal file
17
pglab/plugin_support/MenuLocation.h
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef MENULOCATION_H
|
||||||
|
#define MENULOCATION_H
|
||||||
|
|
||||||
|
#include "plugin_support/MenuPath.h"
|
||||||
|
|
||||||
|
class MenuLocation {
|
||||||
|
public:
|
||||||
|
MenuLocation();
|
||||||
|
MenuLocation(MenuPath path, int position = -1);
|
||||||
|
|
||||||
|
bool isEmpty() const;
|
||||||
|
private:
|
||||||
|
MenuPath m_path;
|
||||||
|
int m_position = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MENULOCATION_H
|
||||||
10
pglab/plugin_support/MenuPath.cpp
Normal file
10
pglab/plugin_support/MenuPath.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include "MenuPath.h"
|
||||||
|
|
||||||
|
MenuPath::MenuPath() = default;
|
||||||
|
|
||||||
|
MenuPath::MenuPath(QString menu_path)
|
||||||
|
: m_menuPath(std::move(menu_path))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
21
pglab/plugin_support/MenuPath.h
Normal file
21
pglab/plugin_support/MenuPath.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef MENUPATH_H
|
||||||
|
#define MENUPATH_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <boost/container/small_vector.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
class MenuPath {
|
||||||
|
public:
|
||||||
|
MenuPath();
|
||||||
|
MenuPath(QString menu_path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_menuPath;
|
||||||
|
/// Contains the elements of the path, in general
|
||||||
|
/// more then 3 levels is a bad idea but small_vector can grow when required.
|
||||||
|
// boost::container::small_vector<int, 3> m_menuItemSeperators;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MENUPATH_H
|
||||||
19
pglab/plugin_support/PluginModule.cpp
Normal file
19
pglab/plugin_support/PluginModule.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "plugin_support/PluginModule.h"
|
||||||
|
|
||||||
|
PluginModule::PluginModule(QString name, QString ident)
|
||||||
|
: m_name(std::move(name))
|
||||||
|
, m_ident(std::move(ident))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginModule::setDisplayCategory(QString category)
|
||||||
|
{
|
||||||
|
m_displayCategory = std::move(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PluginModule::registerAction(QAction *action, MenuLocation menu_location, ToolbarLocation toolbar_location)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
31
pglab/plugin_support/PluginModule.h
Normal file
31
pglab/plugin_support/PluginModule.h
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef PLUGIN_SUPPORTPLUGINMODULE_H
|
||||||
|
#define PLUGIN_SUPPORTPLUGINMODULE_H
|
||||||
|
|
||||||
|
#include "plugin_support/MenuLocation.h"
|
||||||
|
#include "plugin_support/ToolbarLocation.h"
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class QAction;
|
||||||
|
|
||||||
|
|
||||||
|
class PluginModule: public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
PluginModule(QString name, QString ident);
|
||||||
|
|
||||||
|
const QString& name() const { return m_name; }
|
||||||
|
const QString& identifier() const { return m_ident; }
|
||||||
|
const QString& displayCategory() const { return m_displayCategory; }
|
||||||
|
|
||||||
|
void setDisplayCategory(QString category);
|
||||||
|
void registerAction(QAction *action, MenuLocation menu_location, ToolbarLocation toolbar_location);
|
||||||
|
private:
|
||||||
|
/// Name shown to end users
|
||||||
|
QString m_name;
|
||||||
|
/// Unique identifier
|
||||||
|
QString m_ident;
|
||||||
|
QString m_displayCategory;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PLUGIN_SUPPORTPLUGINMODULE_H
|
||||||
29
pglab/plugin_support/PluginRegister.cpp
Normal file
29
pglab/plugin_support/PluginRegister.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#include "PluginRegister.h"
|
||||||
|
#include "plugin_support/PluginModule.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
|
PluginRegister* PluginRegister::s_pluginRegister;
|
||||||
|
|
||||||
|
PluginRegister* PluginRegister::getInstance()
|
||||||
|
{
|
||||||
|
static std::mutex m;
|
||||||
|
// check if set without locking first (in most cases it will be set and it will never be unset) so locking the mutex everytime
|
||||||
|
// is a waist of time.
|
||||||
|
if (!s_pluginRegister) {
|
||||||
|
// not set then lock
|
||||||
|
std::lock_guard<std::mutex> guard(m);
|
||||||
|
// recheck in case someone else just set it
|
||||||
|
if (!s_pluginRegister) {
|
||||||
|
s_pluginRegister = new PluginRegister;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s_pluginRegister;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginRegister::PluginRegister() = default;
|
||||||
|
|
||||||
|
void PluginRegister::registerModule(PluginModuleSPtr module)
|
||||||
|
{
|
||||||
|
qDebug() << "Register called for " << module->identifier();
|
||||||
|
}
|
||||||
30
pglab/plugin_support/PluginRegister.h
Normal file
30
pglab/plugin_support/PluginRegister.h
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef PLUGINREGISTER_H
|
||||||
|
#define PLUGINREGISTER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class QAction;
|
||||||
|
class PluginModule;
|
||||||
|
|
||||||
|
class PluginRegister {
|
||||||
|
public:
|
||||||
|
using PluginModuleSPtr = std::shared_ptr<PluginModule>;
|
||||||
|
using ModuleMap = std::map<QString, PluginModuleSPtr>;
|
||||||
|
|
||||||
|
static PluginRegister* getInstance();
|
||||||
|
|
||||||
|
PluginRegister();
|
||||||
|
void registerModule(PluginModuleSPtr module);
|
||||||
|
const ModuleMap& modules() const { return m_moduleMap; }
|
||||||
|
private:
|
||||||
|
|
||||||
|
ModuleMap m_moduleMap;
|
||||||
|
|
||||||
|
static PluginRegister* s_pluginRegister;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PLUGINREGISTER_H
|
||||||
14
pglab/plugin_support/ToolbarLocation.cpp
Normal file
14
pglab/plugin_support/ToolbarLocation.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "ToolbarLocation.h"
|
||||||
|
|
||||||
|
ToolbarLocation::ToolbarLocation() = default;
|
||||||
|
|
||||||
|
ToolbarLocation::ToolbarLocation(QString toolbar, QString group, int position)
|
||||||
|
: m_toolbar(std::move(toolbar))
|
||||||
|
, m_group(std::move(group))
|
||||||
|
, m_position(position)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool ToolbarLocation::isEmpty() const
|
||||||
|
{
|
||||||
|
return m_toolbar.isEmpty();
|
||||||
|
}
|
||||||
19
pglab/plugin_support/ToolbarLocation.h
Normal file
19
pglab/plugin_support/ToolbarLocation.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef TOOLBARLOCATION_H
|
||||||
|
#define TOOLBARLOCATION_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class ToolbarLocation {
|
||||||
|
public:
|
||||||
|
ToolbarLocation();
|
||||||
|
ToolbarLocation(QString toolbar, QString group, int position = -1);
|
||||||
|
|
||||||
|
bool isEmpty() const;
|
||||||
|
private:
|
||||||
|
QString m_toolbar;
|
||||||
|
QString m_group;
|
||||||
|
int m_position = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TOOLBARLOCATION_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue