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:
eelke 2018-12-30 15:46:15 +01:00
parent a54a063c13
commit 15bee33076
25 changed files with 327 additions and 52 deletions

View 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)
{}

View 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

View file

@ -0,0 +1,10 @@
#include "MenuPath.h"
MenuPath::MenuPath() = default;
MenuPath::MenuPath(QString menu_path)
: m_menuPath(std::move(menu_path))
{
}

View 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

View file

@ -0,0 +1,18 @@
#include "PluginContentWidget.h"
PluginContentWidget::PluginContentWidget(IPluginContentWidgetContext *context, QWidget* parent)
: QWidget(parent)
, m_context(context)
{
}
std::vector<QAction*> PluginContentWidget::getToolbarActions()
{
return std::vector<QAction*>();
}
bool PluginContentWidget::canClose()
{
return true;
}

View file

@ -0,0 +1,33 @@
#ifndef PGLPAGE_H
#define PGLPAGE_H
#include <QWidget>
#include <vector>
class IPluginContentWidgetContext;
/// 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, QWidget* parent = nullptr);
/// Returns the toolbar buttons for this page
virtual std::vector<QAction*> getToolbarActions();
virtual bool canClose();
protected:
IPluginContentWidgetContext *context() { return m_context; }
private:
IPluginContentWidgetContext *m_context;
};
#endif // PGLPAGE_H

View 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)
{
}

View 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

View 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();
}

View 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

View 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();
}

View 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