Remove all of plugin_support
This commit is contained in:
parent
09ef4cdf6b
commit
b0fa02455c
25 changed files with 46 additions and 1007 deletions
|
|
@ -5,9 +5,9 @@
|
|||
#include "UserConfiguration.h"
|
||||
#include <QTextStream>
|
||||
|
||||
CodeGenerator::CodeGenerator(IPluginContentWidgetContext *context, PluginModule *module, QWidget *parent) :
|
||||
PluginContentWidget(context, module, parent),
|
||||
ui(new Ui::CodeGenerator)
|
||||
CodeGenerator::CodeGenerator(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::CodeGenerator)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#define CODEGENERATOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "plugin_support/PluginContentWidget.h"
|
||||
#include "Pgsql_declare.h"
|
||||
|
||||
namespace Ui {
|
||||
|
|
@ -11,12 +10,10 @@ class CodeGenerator;
|
|||
|
||||
class PgDatabaseCatalog;
|
||||
|
||||
class CodeGenerator : public PluginContentWidget
|
||||
{
|
||||
class CodeGenerator : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CodeGenerator(IPluginContentWidgetContext *context, PluginModule *module, QWidget *parent = nullptr);
|
||||
CodeGenerator(QWidget *parent = nullptr);
|
||||
~CodeGenerator();
|
||||
|
||||
void Init(std::shared_ptr<PgDatabaseCatalog> catalog, QString query, std::shared_ptr<const Pgsql::Result> dbres);
|
||||
|
|
|
|||
|
|
@ -12,16 +12,16 @@
|
|||
#include <QMessageBox>
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include "plugin_support/PluginRegister.h"
|
||||
#include "plugin_support/IPluginContentWidgetContext.h"
|
||||
|
||||
|
||||
CrudTab::CrudTab(IPluginContentWidgetContext *context, PluginModule *module, QWidget *parent)
|
||||
: PluginContentWidget(context, module, parent)
|
||||
CrudTab::CrudTab(std::shared_ptr<OpenDatabase> open_database, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::CrudTab)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_db = open_database;
|
||||
|
||||
SetTableViewDefault(ui->tableView);
|
||||
|
||||
auto delegate = new PgLabItemDelegate(ui->tableView);
|
||||
|
|
@ -48,7 +48,6 @@ CrudTab::~CrudTab()
|
|||
|
||||
void CrudTab::setConfig(Oid oid) //std::shared_ptr<OpenDatabase> db, const PgClass &table)
|
||||
{
|
||||
m_db = context()->getObject<OpenDatabase>(); // getDatabase();;
|
||||
m_table = *m_db->catalog()->classes()->getByKey(oid);
|
||||
m_crudModel->setConfig(m_db, *m_table);
|
||||
}
|
||||
|
|
@ -117,33 +116,33 @@ void CrudTab::initActions()
|
|||
}
|
||||
}
|
||||
|
||||
QList<QAction *> CrudTab::actions()
|
||||
{
|
||||
return { m_refreshAction };
|
||||
}
|
||||
//QList<QAction *> CrudTab::actions()
|
||||
//{
|
||||
// return { m_refreshAction };
|
||||
//}
|
||||
|
||||
|
||||
void CrudPageModule::init()
|
||||
{
|
||||
registerModuleAction("open",
|
||||
[this] (IPluginContentWidgetContext* context,
|
||||
const ModuleActionParameters ¶ms)
|
||||
{
|
||||
moduleAction_open(context, params);
|
||||
});
|
||||
}
|
||||
//void CrudPageModule::init()
|
||||
//{
|
||||
// registerModuleAction("open",
|
||||
// [this] (IPluginContentWidgetContext* context,
|
||||
// const ModuleActionParameters ¶ms)
|
||||
// {
|
||||
// moduleAction_open(context, params);
|
||||
// });
|
||||
//}
|
||||
|
||||
void CrudPageModule::moduleAction_open(
|
||||
IPluginContentWidgetContext* context,
|
||||
const ModuleActionParameters ¶ms
|
||||
)
|
||||
{
|
||||
// create new widget for specified table
|
||||
// hand widget to context for display
|
||||
CrudTab *ct = new CrudTab(context, this);
|
||||
context->addContentWidget(ct); // maybe CrudTab should do this
|
||||
ct->setConfig(params.at("oid").toUInt());
|
||||
//void CrudPageModule::moduleAction_open(
|
||||
// IPluginContentWidgetContext* context,
|
||||
// const ModuleActionParameters ¶ms
|
||||
// )
|
||||
//{
|
||||
// // create new widget for specified table
|
||||
// // hand widget to context for display
|
||||
// CrudTab *ct = new CrudTab(context, this);
|
||||
// context->addContentWidget(ct); // maybe CrudTab should do this
|
||||
// ct->setConfig(params.at("oid").toUInt());
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
REGISTER_PLUGIN_MODULE_CAT(CrudPageModule, "CRUD tool", "pglab.crudpage", "database")
|
||||
//REGISTER_PLUGIN_MODULE_CAT(CrudPageModule, "CRUD tool", "pglab.crudpage", "database")
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
#include "catalog/PgClass.h"
|
||||
#include <QWidget>
|
||||
#include "plugin_support/PluginContentWidget.h"
|
||||
#include "plugin_support/PluginModule.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
|
|
@ -15,13 +13,10 @@ namespace Ui {
|
|||
class OpenDatabase;
|
||||
class CrudModel;
|
||||
|
||||
class CrudTab : public PluginContentWidget
|
||||
{
|
||||
class CrudTab : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CrudTab(IPluginContentWidgetContext *context, PluginModule *module,
|
||||
QWidget *parent = nullptr);
|
||||
explicit CrudTab(std::shared_ptr<OpenDatabase> open_database, QWidget *parent = nullptr);
|
||||
~CrudTab() override;
|
||||
|
||||
void setConfig(Oid oid);
|
||||
|
|
@ -38,25 +33,25 @@ private:
|
|||
|
||||
void initActions();
|
||||
|
||||
virtual QList<QAction *> actions() override;
|
||||
// virtual QList<QAction *> actions() override;
|
||||
|
||||
private slots:
|
||||
void on_actionRemove_rows_triggered();
|
||||
void headerCustomContextMenu(const QPoint &pos);
|
||||
};
|
||||
|
||||
class CrudPageModule: public PluginModule {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using PluginModule::PluginModule;
|
||||
//class CrudPageModule: public PluginModule {
|
||||
// Q_OBJECT
|
||||
//public:
|
||||
// using PluginModule::PluginModule;
|
||||
|
||||
void init();
|
||||
private slots:
|
||||
// void init();
|
||||
//private slots:
|
||||
|
||||
private:
|
||||
//private:
|
||||
|
||||
void moduleAction_open(IPluginContentWidgetContext* context, const ModuleActionParameters ¶ms);
|
||||
};
|
||||
// void moduleAction_open(IPluginContentWidgetContext* context, const ModuleActionParameters ¶ms);
|
||||
//};
|
||||
|
||||
|
||||
#endif // CRUDTAB_H
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
#include "util.h"
|
||||
#include "GlobalIoService.h"
|
||||
#include "UserConfiguration.h"
|
||||
#include "plugin_support/IPluginContentWidgetContext.h"
|
||||
|
||||
|
||||
QueryTool::QueryTool(std::shared_ptr<OpenDatabase> open_database, QWidget *parent)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#endif
|
||||
#include <memory>
|
||||
#include "GlobalIoService.h"
|
||||
#include "plugin_support/PluginRegister.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
@ -30,8 +29,6 @@ int main(int argc, char *argv[])
|
|||
QCoreApplication::setOrganizationDomain("eelkeklein.nl");
|
||||
QCoreApplication::setApplicationName("pglab");
|
||||
|
||||
PluginRegister::getInstance()->initModules();
|
||||
|
||||
std::thread asio_service_thread;
|
||||
int result = -1;
|
||||
{
|
||||
|
|
|
|||
|
|
@ -75,16 +75,8 @@ PropertyProxyModel.cpp \
|
|||
SequenceModel.cpp \
|
||||
DatabaseWindow.cpp \
|
||||
PgLabTableView.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 \
|
||||
plugin_support/PluginContentWidgetContextBase.cpp \
|
||||
QueryTool.cpp \
|
||||
CatalogInspector.cpp \
|
||||
plugin_support/StaticAction.cpp \
|
||||
widgets/CatalogIndexPage.cpp \
|
||||
widgets/CatalogPageBase.cpp \
|
||||
widgets/CatalogConstraintPage.cpp \
|
||||
|
|
@ -148,18 +140,8 @@ CustomDataRole.h \
|
|||
SequenceModel.h \
|
||||
DatabaseWindow.h \
|
||||
PgLabTableView.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 \
|
||||
plugin_support/ModuleActionParameters.h \
|
||||
plugin_support/IPluginContentWidgetContext.h \
|
||||
plugin_support/PluginContentWidgetContextBase.h \
|
||||
QueryTool.h \
|
||||
CatalogInspector.h \
|
||||
plugin_support/StaticAction.h \
|
||||
widgets/CatalogIndexPage.h \
|
||||
widgets/CatalogPageBase.h \
|
||||
widgets/CatalogConstraintPage.h \
|
||||
|
|
|
|||
|
|
@ -1,98 +0,0 @@
|
|||
#ifndef IPLUGINCONTENTWIDGETCONTEXT_H
|
||||
#define IPLUGINCONTENTWIDGETCONTEXT_H
|
||||
|
||||
#include <QString>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <typeindex>
|
||||
#include "plugin_support/ModuleActionParameters.h"
|
||||
|
||||
class OpenDatabase;
|
||||
class PluginModule;
|
||||
class PluginContentWidget;
|
||||
|
||||
|
||||
/** This class serves to isolate the plugin from the actual construct in which it is
|
||||
* used.
|
||||
*
|
||||
* It provides interface for operating on the context without needing to many details.
|
||||
* Actual default implementation is in PluginContentWidgetContextBase.
|
||||
*
|
||||
* objectRegistry implementation is from Igor Tandetnik answer to the following question
|
||||
* https://stackoverflow.com/questions/35413745/using-shared-ptr-with-a-generic-registry-or-shared-object-storage-or-not
|
||||
*/
|
||||
class IPluginContentWidgetContext {
|
||||
public:
|
||||
|
||||
virtual ~IPluginContentWidgetContext() = default;
|
||||
/** Tells the context what to use as a caption for this content widget.
|
||||
*
|
||||
* Depending on the context the caption might not be visible or used as the caption
|
||||
* of a window or tab.
|
||||
*/
|
||||
virtual void setCaption(PluginContentWidget *content, const QString &caption, const QString &hint = {}) = 0;
|
||||
/** Tells the context what icon to use.
|
||||
*
|
||||
* In general the icon is used in a similar place as the caption.
|
||||
* \param iconname Assumed to be the name of an iconresource. The system will look for different
|
||||
* sizes under :/icons/<size>/iconname
|
||||
*/
|
||||
virtual void setIcon(PluginContentWidget *content, const QString &iconname) = 0;
|
||||
|
||||
virtual void showStatusMessage(const QString &msg) = 0;
|
||||
|
||||
virtual void moduleAction(
|
||||
const QString &module_identifier,
|
||||
QString module_action,
|
||||
const ModuleActionParameters &action_params
|
||||
) = 0;
|
||||
|
||||
virtual void addContentWidget(PluginContentWidget *widget) = 0;
|
||||
virtual void removeContentWidget(PluginContentWidget *widget) = 0;
|
||||
|
||||
/** Return a widget you can use as a parent
|
||||
*/
|
||||
virtual QWidget* container() = 0;
|
||||
|
||||
template<typename T, class...Args>
|
||||
bool addObjects(Args&&...args);
|
||||
template<typename T>
|
||||
bool registerObject(std::shared_ptr<T> object);
|
||||
template<typename T>
|
||||
std::shared_ptr<T> getObject() const;
|
||||
|
||||
private:
|
||||
std::map<std::type_index, std::shared_ptr<void> > m_objectRegistry;
|
||||
|
||||
};
|
||||
|
||||
template<typename T, class...Args>
|
||||
bool IPluginContentWidgetContext::addObjects(Args&&...args)
|
||||
{
|
||||
std::type_index key(typeid(T));
|
||||
if (!m_objectRegistry.count(key)) {
|
||||
auto p = std::make_shared<T>(std::forward<Args>(args)...);
|
||||
m_objectRegistry[key] = p;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool IPluginContentWidgetContext::registerObject(std::shared_ptr<T> object)
|
||||
{
|
||||
return m_objectRegistry.emplace(std::type_index(typeid(T)), object).second;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::shared_ptr<T> IPluginContentWidgetContext::getObject() const
|
||||
{
|
||||
auto it = m_objectRegistry.find(typeid(T));
|
||||
if (it == m_objectRegistry.end()) {
|
||||
return {};
|
||||
}
|
||||
return std::static_pointer_cast<T>(it->second);
|
||||
}
|
||||
|
||||
|
||||
#endif // IPLUGINCONTENTWIDGETCONTEXT_H
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#include "MenuLocation.h"
|
||||
|
||||
MenuLocation::MenuLocation() = default;
|
||||
|
||||
MenuLocation::MenuLocation(MenuPath path, int position)
|
||||
: m_path(std::move(path))
|
||||
, m_position(position)
|
||||
{}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#ifndef MENULOCATION_H
|
||||
#define MENULOCATION_H
|
||||
|
||||
#include "plugin_support/MenuPath.h"
|
||||
#include <QString>
|
||||
|
||||
///
|
||||
class MenuLocation {
|
||||
public:
|
||||
|
||||
MenuLocation();
|
||||
MenuLocation(MenuPath path, int position = -1);
|
||||
|
||||
bool isEmpty() const;
|
||||
private:
|
||||
MenuPath m_path;
|
||||
int m_position = -1;
|
||||
};
|
||||
|
||||
#endif // MENULOCATION_H
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#include "MenuPath.h"
|
||||
|
||||
MenuPath::MenuPath() = default;
|
||||
|
||||
//MenuPath::MenuPath(QString menu_path)
|
||||
// : m_menuPath(std::move(menu_path))
|
||||
//{
|
||||
//}
|
||||
|
||||
MenuPath::MenuPath(QString menu_path)
|
||||
{
|
||||
auto parts = menu_path.splitRef('/');
|
||||
for (auto&& elem : parts) {
|
||||
m_elems.emplace_back(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
#ifndef MENUPATH_H
|
||||
#define MENUPATH_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
|
||||
|
||||
/// For a menu path we use a string very similar to a file path. Width however the addition of semicolons
|
||||
/// for specifying groups. So the following path
|
||||
///
|
||||
/// /File:Save
|
||||
///
|
||||
/// Specifies the File menu and the group Save within that menu while
|
||||
///
|
||||
/// /File/Export
|
||||
///
|
||||
/// Would specify the export sub menu of the file menu
|
||||
///
|
||||
class MenuPath {
|
||||
public:
|
||||
MenuPath();
|
||||
MenuPath(QString menu_path);
|
||||
|
||||
|
||||
private:
|
||||
class Elem {
|
||||
public:
|
||||
QStringRef menu;
|
||||
QStringRef group;
|
||||
|
||||
explicit Elem(QStringRef s)
|
||||
{
|
||||
auto p = s.split(':');
|
||||
menu = p[0];
|
||||
if (p.size() > 1) {
|
||||
group = p[1];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<Elem> m_elems;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // MENUPATH_H
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#ifndef MODULEACTIONPARAMETERS_H
|
||||
#define MODULEACTIONPARAMETERS_H
|
||||
|
||||
#include <map>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
using ModuleActionParameters = std::map<QString, QVariant>;
|
||||
|
||||
#endif // MODULEACTIONPARAMETERS_H
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#include "PluginContentWidget.h"
|
||||
|
||||
PluginContentWidget::PluginContentWidget(IPluginContentWidgetContext *context,
|
||||
PluginModule *module, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_context(context)
|
||||
, m_pluginModule(module)
|
||||
{}
|
||||
|
||||
bool PluginContentWidget::canClose()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<QAction *> PluginContentWidget::actions()
|
||||
{ return QList<QAction*>(); }
|
||||
|
||||
PluginModule *PluginContentWidget::pluginModule()
|
||||
{ return m_pluginModule; }
|
||||
|
||||
IPluginContentWidgetContext *PluginContentWidget::context()
|
||||
{ return m_context; }
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#ifndef PGLPAGE_H
|
||||
#define PGLPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <vector>
|
||||
|
||||
class IPluginContentWidgetContext;
|
||||
class PluginModule;
|
||||
|
||||
/// Provides a pluggable system for toolbar buttons and menu actions
|
||||
///
|
||||
/// We will need several kind of actions
|
||||
/// - create actions, these will create a new document or load from file , always available in menu
|
||||
/// - save actions available when on tab
|
||||
/// - edit actions
|
||||
/// - custom menu?
|
||||
///
|
||||
/// Can we use same groupings for toolbars and menu's
|
||||
/// How about additional toolbars?
|
||||
///
|
||||
class PluginContentWidget: public QWidget{
|
||||
public:
|
||||
PluginContentWidget(IPluginContentWidgetContext *context, PluginModule *module, QWidget* parent = nullptr);
|
||||
/// Returns the toolbar buttons for this page
|
||||
virtual bool canClose();
|
||||
|
||||
virtual QList<QAction *> actions();
|
||||
|
||||
PluginModule *pluginModule();
|
||||
IPluginContentWidgetContext *context();
|
||||
protected:
|
||||
|
||||
private:
|
||||
IPluginContentWidgetContext *m_context = nullptr;
|
||||
PluginModule *m_pluginModule = nullptr;
|
||||
};
|
||||
|
||||
#endif // PGLPAGE_H
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
#include "PluginContentWidgetContextBase.h"
|
||||
#include "PluginContentWidget.h"
|
||||
#include "PluginModule.h"
|
||||
#include "PluginRegister.h"
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QMenuBar>
|
||||
#include <QToolBar>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
LWidgetData::LWidgetData(PluginModule *module, PluginContentWidget *widget)
|
||||
: m_module(module)
|
||||
, m_widget(widget)
|
||||
{}
|
||||
|
||||
void LWidgetData::init()
|
||||
{
|
||||
}
|
||||
|
||||
void LWidgetData::addToMenu(QMenuBar *menubar)
|
||||
{
|
||||
auto&& menu = menubar->actions().first()->menu();
|
||||
|
||||
auto ti = std::type_index(typeid(*m_widget));
|
||||
auto&& actions = m_module->actionsForContext(ti);
|
||||
m_menuActions.reserve(actions.size());
|
||||
for (auto&& actiondef : actions) {
|
||||
auto ac = actiondef->createAction(m_widget);
|
||||
menu->addAction(ac);
|
||||
m_menuActions.push_back(ac);
|
||||
}
|
||||
}
|
||||
|
||||
void LWidgetData::removeFromMenu(QMenuBar *menubar)
|
||||
{
|
||||
for (auto&& action : m_menuActions) {
|
||||
delete action;
|
||||
}
|
||||
m_menuActions.clear();
|
||||
}
|
||||
|
||||
|
||||
PluginContentWidgetContextBase::PluginContentWidgetContextBase() = default;
|
||||
|
||||
void PluginContentWidgetContextBase::moduleAction(
|
||||
const QString &module_identifier,
|
||||
QString module_action,
|
||||
const ModuleActionParameters &action_params
|
||||
)
|
||||
{
|
||||
auto reg = PluginRegister::getInstance();
|
||||
auto mod = reg->findModule(module_identifier);
|
||||
if (mod) {
|
||||
auto action = mod->findModuleAction(module_action);
|
||||
if (action) {
|
||||
qDebug() << QString("module %1 action %2 called ").arg(module_identifier, module_action);
|
||||
(*action)(this, action_params);
|
||||
}
|
||||
else
|
||||
qWarning() << QString("module %1 has no action %2").arg(module_identifier, module_action);
|
||||
}
|
||||
else
|
||||
qWarning() << QString("module not found %1").arg(module_identifier);
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::addContentWidget(PluginContentWidget *widget)
|
||||
{
|
||||
auto res = m_widgetLst.emplace(widget, LWidgetData{widget->pluginModule(), widget});
|
||||
if (!res.second)
|
||||
throw std::runtime_error("Unexpected conflicting key on insertiong PluginContentWidgetContextBase::addContentWidget");
|
||||
|
||||
res.first->second.init();
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::removeContentWidget(PluginContentWidget *widget)
|
||||
{
|
||||
auto res = m_widgetLst.find(widget);
|
||||
if (res == m_widgetLst.end())
|
||||
return;
|
||||
|
||||
m_widgetLst.erase(res);
|
||||
}
|
||||
|
||||
|
||||
void PluginContentWidgetContextBase::addWidgetActionsToToolbar(PluginContentWidget *widget, QToolBar *toolbar)
|
||||
{
|
||||
auto && actions = widget->actions();
|
||||
toolbar->addActions(actions);
|
||||
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::removeWidgetActionsFromToolbar(PluginContentWidget *widget, QToolBar *toolbar)
|
||||
{
|
||||
auto && actions = widget->actions();
|
||||
for (auto && ac : actions)
|
||||
toolbar->removeAction(ac);
|
||||
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::addContextActionsToMenu(PluginContentWidget *widget, QMenuBar *menubar)
|
||||
{
|
||||
auto res = m_widgetLst.find(widget);
|
||||
if (res == m_widgetLst.end())
|
||||
return;
|
||||
res->second.addToMenu(menubar);
|
||||
}
|
||||
|
||||
void PluginContentWidgetContextBase::removeContextActionsFromMenu(PluginContentWidget *widget, QMenuBar *menubar)
|
||||
{
|
||||
auto res = m_widgetLst.find(widget);
|
||||
if (res == m_widgetLst.end())
|
||||
return;
|
||||
res->second.removeFromMenu(menubar);
|
||||
}
|
||||
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
#ifndef PLUGINCONTENTWIDGETCONTEXTBASE_H
|
||||
#define PLUGINCONTENTWIDGETCONTEXTBASE_H
|
||||
|
||||
#include "plugin_support/IPluginContentWidgetContext.h"
|
||||
#include <QList>
|
||||
#include <typeindex>
|
||||
|
||||
class LContextAction;
|
||||
class QToolBar;
|
||||
class QAction;
|
||||
class QMenuBar;
|
||||
|
||||
/// Maintains the list of actions added to a toolbar for a specific widget
|
||||
/// it facilitates the removal of all those actions.
|
||||
class WidgetToolbarActionList {
|
||||
public:
|
||||
QToolBar *m_toolBar;
|
||||
std::vector<QAction*> m_actions;
|
||||
void removeAll()
|
||||
{
|
||||
// for (auto && a : m_actions)
|
||||
// m_toolBar->removeAction(a);
|
||||
}
|
||||
};
|
||||
|
||||
class WidgetToolbarManager {
|
||||
public:
|
||||
void addAction(QAction *action, QString section);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
class LWidgetData {
|
||||
public:
|
||||
LWidgetData(PluginModule *module, PluginContentWidget *widget);
|
||||
PluginModule* module() { return m_module; }
|
||||
PluginContentWidget *widget() { return m_widget; }
|
||||
void init();
|
||||
|
||||
void addToMenu(QMenuBar* menubar);
|
||||
void removeFromMenu(QMenuBar* menubar);
|
||||
private:
|
||||
PluginModule *m_module;
|
||||
PluginContentWidget *m_widget;
|
||||
WidgetToolbarManager m_toolbarManager;
|
||||
|
||||
std::vector<QAction*> m_menuActions; ///< List of actions we put in the menu
|
||||
};
|
||||
|
||||
/// Provides base implementation of IPluginContentWidgetContext
|
||||
class PluginContentWidgetContextBase : public IPluginContentWidgetContext
|
||||
{
|
||||
public:
|
||||
PluginContentWidgetContextBase();
|
||||
|
||||
void moduleAction(
|
||||
const QString &module_identifier,
|
||||
QString module_action,
|
||||
const ModuleActionParameters &action_params
|
||||
) override;
|
||||
|
||||
void addContentWidget(PluginContentWidget *widget) override;
|
||||
void removeContentWidget(PluginContentWidget *widget) override;
|
||||
|
||||
void addWidgetActionsToToolbar(PluginContentWidget *widget, QToolBar *toolbar);
|
||||
void removeWidgetActionsFromToolbar(PluginContentWidget *widget, QToolBar *toolbar);
|
||||
|
||||
void addContextActionsToMenu(PluginContentWidget *widget, QMenuBar *menubar);
|
||||
void removeContextActionsFromMenu(PluginContentWidget *widget, QMenuBar *menubar);
|
||||
private:
|
||||
|
||||
using WidgetLst = std::map<PluginContentWidget*, LWidgetData>;
|
||||
|
||||
WidgetLst m_widgetLst; /// Keeps track of which widget belongs to which module
|
||||
};
|
||||
|
||||
#endif // PLUGINCONTENTWIDGETCONTEXTBASE_H
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
#include "plugin_support/PluginModule.h"
|
||||
#include "PluginContentWidget.h"
|
||||
#include <QDebug>
|
||||
#include <typeinfo>
|
||||
#include <typeindex>
|
||||
|
||||
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::registerStaticAction(StaticAction action)
|
||||
{
|
||||
m_menuActions.emplace_back(std::move(action));
|
||||
}
|
||||
|
||||
const PluginModule::StaticActionList& PluginModule::staticActions() const
|
||||
{
|
||||
return m_menuActions;
|
||||
}
|
||||
|
||||
void PluginModule::registerModuleAction(QString module_action, ModuleAction action)
|
||||
{
|
||||
m_moduleActions.emplace(
|
||||
std::move(module_action),
|
||||
std::move(action)
|
||||
);
|
||||
}
|
||||
|
||||
const PluginModule::ModuleAction* PluginModule::findModuleAction(const QString &module_action) const
|
||||
{
|
||||
auto res = m_moduleActions.find(module_action);
|
||||
if (res == m_moduleActions.end())
|
||||
return nullptr;
|
||||
return &res->second;
|
||||
}
|
||||
|
||||
void PluginModule::registerContextAction(std::shared_ptr<ContextBaseAction> action)
|
||||
{
|
||||
auto find_result_iter = m_contextMap.find(action->contextTypeIndex());
|
||||
if (find_result_iter != m_contextMap.end())
|
||||
find_result_iter->second.push_back(action);
|
||||
else
|
||||
m_contextMap.emplace(action->contextTypeIndex(), ContextActionContainer({ action }));
|
||||
}
|
||||
|
||||
const PluginModule::ContextActionContainer &PluginModule::actionsForContext(std::type_index ti)
|
||||
{
|
||||
static const ContextActionContainer empty_result;
|
||||
|
||||
auto find_result_iter = m_contextMap.find(ti);
|
||||
if (find_result_iter != m_contextMap.end())
|
||||
return find_result_iter->second;
|
||||
|
||||
return empty_result;
|
||||
}
|
||||
|
||||
const PluginModule::ContextActionContainer& PluginModule::actionsForContext(PluginContentWidget *widget)
|
||||
{
|
||||
return actionsForContext(std::type_index(typeid(*widget)));
|
||||
}
|
||||
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
#ifndef PLUGIN_SUPPORTPLUGINMODULE_H
|
||||
#define PLUGIN_SUPPORTPLUGINMODULE_H
|
||||
|
||||
#include "ModuleActionParameters.h"
|
||||
#include "StaticAction.h"
|
||||
#include "PluginRegister.h"
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <typeindex>
|
||||
|
||||
class QAction;
|
||||
class IPluginContentWidgetContext;
|
||||
class PluginContentWidget;
|
||||
|
||||
/** Defines available actions for the application framework.
|
||||
*
|
||||
* There are static and context actions.
|
||||
* There can be multiple contexts which are seperated by there typeid/type_index.
|
||||
*/
|
||||
class PluginModule: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using StaticActionList = std::vector<StaticAction>;
|
||||
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
||||
using ModuleActionMap = std::map<QString, ModuleAction>;
|
||||
|
||||
using ContextActionContainer = std::vector<std::shared_ptr<ContextBaseAction>>;
|
||||
|
||||
PluginModule(QString name, QString ident);
|
||||
|
||||
virtual void init() {}
|
||||
|
||||
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);
|
||||
|
||||
/// registers an action that should always be accessible from the menu
|
||||
void registerStaticAction(StaticAction action);
|
||||
const StaticActionList& staticActions() const;
|
||||
|
||||
/// "API" action that other modules can trigger by name without being linked to
|
||||
/// this module. Allows for loose coupling.
|
||||
void registerModuleAction(QString module_action, ModuleAction action);
|
||||
|
||||
/// Searches for and returns a pointer to the requested module action.
|
||||
/// When the action is not found nullptr is returned.
|
||||
const ModuleAction* findModuleAction(const QString &module_action) const;
|
||||
|
||||
void registerContextAction(std::shared_ptr<ContextBaseAction> action);
|
||||
|
||||
std::set<std::type_index> contextTypeIndexes();
|
||||
const ContextActionContainer& actionsForContext(std::type_index ti);
|
||||
const ContextActionContainer& actionsForContext(PluginContentWidget *widget);
|
||||
|
||||
private:
|
||||
using ContextMap = std::unordered_map<std::type_index, ContextActionContainer>;
|
||||
|
||||
/// Name shown to end users
|
||||
QString m_name;
|
||||
/// Unique identifier
|
||||
QString m_ident;
|
||||
QString m_displayCategory;
|
||||
|
||||
StaticActionList m_menuActions;
|
||||
ModuleActionMap m_moduleActions;
|
||||
ContextMap m_contextMap;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident, QString category={})
|
||||
{
|
||||
auto module = std::make_shared<T>(std::move(name), std::move(ident));
|
||||
module->setDisplayCategory(category);
|
||||
|
||||
PluginRegister::getInstance()->registerModule(module);
|
||||
return std::move(module);
|
||||
}
|
||||
|
||||
#define REGISTER_PLUGIN_MODULE(module, name, ident) \
|
||||
namespace {\
|
||||
std::weak_ptr<PluginModule> register_variable = createPluginModule<module>\
|
||||
(name, ident);}
|
||||
|
||||
#define REGISTER_PLUGIN_MODULE_CAT(module, name, ident, category) \
|
||||
namespace {\
|
||||
std::weak_ptr<PluginModule> register_variable = createPluginModule<module>\
|
||||
(name, ident, category);}
|
||||
|
||||
|
||||
#endif // PLUGIN_SUPPORTPLUGINMODULE_H
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
#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::initModules()
|
||||
{
|
||||
for (auto && mod : m_moduleMap) {
|
||||
mod.second->init();
|
||||
}
|
||||
}
|
||||
|
||||
void PluginRegister::registerModule(PluginModuleSPtr module)
|
||||
{
|
||||
qDebug() << "registerModule " << module->identifier();
|
||||
m_moduleMap.emplace(module->identifier(), module);
|
||||
}
|
||||
|
||||
const PluginModule* PluginRegister::findModule(const QString &module_ident) const
|
||||
{
|
||||
auto res = m_moduleMap.find(module_ident);
|
||||
if (res == m_moduleMap.end())
|
||||
return nullptr;
|
||||
return res->second.get();
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#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);
|
||||
|
||||
void initModules();
|
||||
const ModuleMap& modules() const{ return m_moduleMap; }
|
||||
|
||||
const PluginModule* findModule(const QString &module_ident) const;
|
||||
private:
|
||||
|
||||
ModuleMap m_moduleMap;
|
||||
|
||||
static PluginRegister* s_pluginRegister;
|
||||
};
|
||||
|
||||
|
||||
#endif // PLUGINREGISTER_H
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
#include "StaticAction.h"
|
||||
|
||||
BaseAction::BaseAction(const QString &text)
|
||||
: m_text(text)
|
||||
{}
|
||||
|
||||
const QIcon& BaseAction::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
const MenuLocation& BaseAction::menuLocation() const
|
||||
{
|
||||
return m_menuLocation;
|
||||
}
|
||||
|
||||
void BaseAction::setIcon(QIcon icon)
|
||||
{
|
||||
m_icon = std::move(icon);
|
||||
}
|
||||
|
||||
void BaseAction::setMenuLocation(MenuLocation menu_location)
|
||||
{
|
||||
m_menuLocation = std::move(menu_location);
|
||||
}
|
||||
|
||||
void BaseAction::setToolbarLocation(ToolbarLocation toolbar_location)
|
||||
{
|
||||
m_toolbarLocation = toolbar_location;
|
||||
}
|
||||
|
||||
void BaseAction::setShortcut(QKeySequence shortcut)
|
||||
{
|
||||
m_shortcut = std::move(shortcut);
|
||||
}
|
||||
|
||||
void BaseAction::setText(QString text)
|
||||
{
|
||||
m_text = std::move(text);
|
||||
}
|
||||
|
||||
void BaseAction::setToolTip(QString tooltip)
|
||||
{
|
||||
m_toolTip = std::move(tooltip);
|
||||
}
|
||||
|
||||
const QKeySequence& BaseAction::shortcut() const
|
||||
{
|
||||
return m_shortcut;
|
||||
}
|
||||
|
||||
const QString& BaseAction::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
const QString& BaseAction::toolTip() const
|
||||
{
|
||||
return m_toolTip;
|
||||
}
|
||||
|
||||
StaticAction::StaticAction(QString text, Func func)
|
||||
: BaseAction(std::move(text))
|
||||
, m_func(std::move(func))
|
||||
{}
|
||||
|
||||
void StaticAction::perform(IPluginContentWidgetContext *context) const
|
||||
{
|
||||
if (m_func)
|
||||
m_func(context);
|
||||
}
|
||||
|
||||
|
||||
ContextBaseAction::~ContextBaseAction()
|
||||
{}
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
#ifndef MENUACTION_H
|
||||
#define MENUACTION_H
|
||||
|
||||
#include "MenuLocation.h"
|
||||
#include "ToolbarLocation.h"
|
||||
#include "plugin_support/PluginContentWidget.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QIcon>
|
||||
#include <QKeySequence>
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
#include <typeindex>
|
||||
|
||||
class IPluginContentWidgetContext;
|
||||
|
||||
class BaseAction {
|
||||
public:
|
||||
explicit BaseAction(const QString &text);
|
||||
|
||||
const QIcon& icon() const;
|
||||
const MenuLocation& menuLocation() const;
|
||||
void setIcon(QIcon icon);
|
||||
void setMenuLocation(MenuLocation menu_location);
|
||||
void setToolbarLocation(ToolbarLocation toolbar_location);
|
||||
void setShortcut(QKeySequence shortcut);
|
||||
void setText(QString text);
|
||||
void setToolTip(QString tooltip);
|
||||
const QKeySequence& shortcut() const;
|
||||
const QString& text() const;
|
||||
const QString& toolTip() const;
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
QString m_toolTip;
|
||||
QIcon m_icon;
|
||||
QKeySequence m_shortcut;
|
||||
MenuLocation m_menuLocation;
|
||||
ToolbarLocation m_toolbarLocation;
|
||||
|
||||
};
|
||||
/** An action for in a menu or toolbar that does not pertain to a specific
|
||||
* widget. It often will create a widget for instance a New or Open action.
|
||||
* It does need a context.
|
||||
*
|
||||
*/
|
||||
class StaticAction: public BaseAction {
|
||||
public:
|
||||
using Func = std::function<void(IPluginContentWidgetContext *context)>;
|
||||
|
||||
StaticAction(QString text, Func func);
|
||||
|
||||
|
||||
void perform(IPluginContentWidgetContext *context) const;
|
||||
private:
|
||||
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
|
||||
class ContextBaseAction: public BaseAction {
|
||||
public:
|
||||
using BaseAction::BaseAction;
|
||||
virtual ~ContextBaseAction();
|
||||
|
||||
virtual std::type_index contextTypeIndex() const = 0;
|
||||
|
||||
virtual QAction* createAction(PluginContentWidget *widget)
|
||||
{
|
||||
auto action = new QAction(widget);
|
||||
action->setText(text());
|
||||
setupConnectionForAction(action, widget);
|
||||
return action;
|
||||
}
|
||||
|
||||
virtual void setupConnectionForAction(QAction *action, PluginContentWidget *context) = 0;
|
||||
};
|
||||
|
||||
class QAction;
|
||||
|
||||
/** Defines an action that can be performed within a certain context.
|
||||
* For instance the save action for a query can only be called when a query is loaded.
|
||||
*
|
||||
* Note Func should be something that QAction::triggered can connect to. If not you
|
||||
* could get quite a vague error.
|
||||
*/
|
||||
template <typename Context, typename Func>
|
||||
class ContextAction: public ContextBaseAction {
|
||||
public:
|
||||
//using Func = void (Context::*)(bool);
|
||||
|
||||
ContextAction(QString text, Func func)
|
||||
: ContextBaseAction(text)
|
||||
, m_func(func)
|
||||
{}
|
||||
|
||||
std::type_index contextTypeIndex() const override
|
||||
{
|
||||
return std::type_index(typeid(Context));
|
||||
}
|
||||
|
||||
// Mostly a helper for the code that creates the QAction
|
||||
// without the helper that would need template code to.
|
||||
virtual void setupConnectionForAction(QAction *action, PluginContentWidget *context) override
|
||||
{
|
||||
QObject::connect(action, &QAction::triggered, dynamic_cast<Context*>(context), m_func);
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Context, typename Func>
|
||||
auto makeContextAction(QString text, Func func)
|
||||
{
|
||||
return std::make_shared<ContextAction<Context, Func>>(text, func);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // MENUACTION_H
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#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();
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
#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