Extended the plugin system to allow for dynamic runtime bindings between modules.
As a test implementation, this allows the TablesPage to open a CrudTab for a table/view without the need for TablesPage, CrudTab and DatabaseWindow to know anything about each other.
This commit is contained in:
parent
f996703937
commit
b0cd47ef46
17 changed files with 209 additions and 55 deletions
|
|
@ -1,16 +1,23 @@
|
|||
#ifndef PLUGIN_SUPPORTPLUGINMODULE_H
|
||||
#define PLUGIN_SUPPORTPLUGINMODULE_H
|
||||
|
||||
#include "plugin_support/MenuLocation.h"
|
||||
#include "plugin_support/ToolbarLocation.h"
|
||||
#include "MenuLocation.h"
|
||||
#include "ToolbarLocation.h"
|
||||
#include "ModuleActionParameters.h"
|
||||
#include "PluginRegister.h"
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
class QAction;
|
||||
|
||||
class IPluginContentWidgetContext;
|
||||
|
||||
class PluginModule: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using ModuleAction = std::function<void(IPluginContentWidgetContext*, const ModuleActionParameters &)>;
|
||||
using ModuleActionMap = std::map<QString, ModuleAction>;
|
||||
|
||||
PluginModule(QString name, QString ident);
|
||||
|
||||
const QString& name() const { return m_name; }
|
||||
|
|
@ -19,13 +26,32 @@ public:
|
|||
|
||||
void setDisplayCategory(QString category);
|
||||
void registerAction(QAction *action, MenuLocation menu_location, ToolbarLocation toolbar_location);
|
||||
|
||||
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;
|
||||
private:
|
||||
/// Name shown to end users
|
||||
QString m_name;
|
||||
/// Unique identifier
|
||||
QString m_ident;
|
||||
QString m_displayCategory;
|
||||
|
||||
ModuleActionMap m_moduleActions;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<PluginModule> createPluginModule(QString name, QString ident)
|
||||
{
|
||||
auto module = std::make_shared<T>(std::move(name), std::move(ident));
|
||||
module->init();
|
||||
|
||||
PluginRegister::getInstance()->registerModule(module);
|
||||
return std::move(module);
|
||||
}
|
||||
|
||||
|
||||
#endif // PLUGIN_SUPPORTPLUGINMODULE_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue