Commit 96b0e478 authored by Laurent Montel's avatar Laurent Montel 😁

Allow to load other plugins in customtoolswidget

parent 888c6322
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.10.41")
set(PIM_VERSION "5.10.42")
project(pimcommon VERSION ${PIM_VERSION})
......
......@@ -296,6 +296,7 @@ ecm_generate_headers(PimCommon_Camelcasecustomtools_HEADERS
CustomToolsWidgetng
CustomToolsPlugin
CustomToolsViewInterface
CustomToolsPluginManager
REQUIRED_HEADERS PimCommon_customtools_HEADERS
PREFIX PimCommon
RELATIVE customtools
......
......@@ -34,7 +34,7 @@ CustomToolsWidgetNgTest::~CustomToolsWidgetNgTest()
void CustomToolsWidgetNgTest::shouldHaveDefaultValue()
{
PimCommon::CustomToolsWidgetNg widget(new KActionCollection(this));
PimCommon::CustomToolsWidgetNg widget;
widget.show();
QStackedWidget *stackWidget = widget.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
......
......@@ -26,6 +26,7 @@ public:
CustomToolsPluginPrivate()
{
}
bool enabled = false;
};
CustomToolsPlugin::CustomToolsPlugin(QObject *parent)
......@@ -38,3 +39,29 @@ CustomToolsPlugin::~CustomToolsPlugin()
{
delete d;
}
bool CustomToolsPlugin::hasConfigureDialog() const
{
return false;
}
void CustomToolsPlugin::showConfigureDialog(QWidget *parent)
{
Q_UNUSED(parent);
}
QString CustomToolsPlugin::description() const
{
return {};
}
void CustomToolsPlugin::setIsEnabled(bool enabled)
{
d->enabled = enabled;
}
bool CustomToolsPlugin::isEnabled() const
{
return d->enabled;
}
......@@ -34,7 +34,17 @@ public:
~CustomToolsPlugin();
virtual PimCommon::CustomToolsViewInterface *createView(KActionCollection *ac, CustomToolsWidgetNg *parent = nullptr) = 0;
virtual QString customToolName() const = 0;
Q_REQUIRED_RESULT virtual QString customToolName() const = 0;
Q_REQUIRED_RESULT virtual bool hasConfigureDialog() const;
virtual void showConfigureDialog(QWidget *parent);
void emitConfigChanged();
Q_REQUIRED_RESULT virtual QString description() const;
void setIsEnabled(bool enabled);
Q_REQUIRED_RESULT bool isEnabled() const;
private:
CustomToolsPluginPrivate *const d;
......
......@@ -20,11 +20,11 @@
#define CUSTOMTOOLSPLUGINMANAGER_H
#include <QObject>
#include "pimcommon_private_export.h"
#include "pimcommon_export.h"
namespace PimCommon {
class CustomToolsPlugin;
class CustomToolsPluginManagerPrivate;
class PIMCOMMON_TESTS_EXPORT CustomToolsPluginManager : public QObject
class PIMCOMMON_EXPORT CustomToolsPluginManager : public QObject
{
Q_OBJECT
public:
......
......@@ -39,7 +39,7 @@ public:
QList<PimCommon::CustomToolsViewInterface *> mListInterfaceView;
};
CustomToolsWidgetNg::CustomToolsWidgetNg(KActionCollection *ac, QWidget *parent)
CustomToolsWidgetNg::CustomToolsWidgetNg(QWidget *parent)
: QWidget(parent)
, d(new PimCommon::CustomToolsWidgetNgPrivate)
{
......@@ -47,7 +47,6 @@ CustomToolsWidgetNg::CustomToolsWidgetNg(KActionCollection *ac, QWidget *parent)
d->mStackedWidget = new QStackedWidget;
d->mStackedWidget->setObjectName(QStringLiteral("stackedwidget"));
lay->addWidget(d->mStackedWidget);
initializeView(ac);
hide();
}
......@@ -56,9 +55,8 @@ CustomToolsWidgetNg::~CustomToolsWidgetNg()
delete d;
}
void CustomToolsWidgetNg::initializeView(KActionCollection *ac)
void CustomToolsWidgetNg::initializeView(KActionCollection *ac, const QVector<CustomToolsPlugin *> &localPluginsList)
{
const QVector<CustomToolsPlugin *> localPluginsList = PimCommon::CustomToolsPluginManager::self()->pluginsList();
for (CustomToolsPlugin *plugin : localPluginsList) {
PimCommon::CustomToolsViewInterface *localCreateView = plugin->createView(ac, this);
d->mListInterfaceView.append(localCreateView);
......
......@@ -25,14 +25,16 @@ class KToggleAction;
class KActionCollection;
namespace PimCommon {
class CustomToolsWidgetNgPrivate;
class CustomToolsPlugin;
class PIMCOMMON_EXPORT CustomToolsWidgetNg : public QWidget
{
Q_OBJECT
public:
explicit CustomToolsWidgetNg(KActionCollection *ac, QWidget *parent = nullptr);
explicit CustomToolsWidgetNg(QWidget *parent = nullptr);
~CustomToolsWidgetNg();
Q_REQUIRED_RESULT QList<KToggleAction *> actionList() const;
void initializeView(KActionCollection *ac, const QVector<CustomToolsPlugin *> &localPluginsList);
void setText(const QString &text);
......@@ -45,7 +47,6 @@ Q_SIGNALS:
void toolActivated();
private:
void initializeView(KActionCollection *ac);
CustomToolsWidgetNgPrivate *const d;
};
}
......
......@@ -36,7 +36,8 @@ CustomToolWidgetNgTest::CustomToolWidgetNgTest(QWidget *parent)
QToolBar *menu = new QToolBar(this);
lay->addWidget(menu);
mCustomTools = new PimCommon::CustomToolsWidgetNg(new KActionCollection(this), this);
mCustomTools = new PimCommon::CustomToolsWidgetNg(this);
mCustomTools->initializeView(new KActionCollection(this), PimCommon::CustomToolsPluginManager::self()->pluginsList());
const QList<KToggleAction *> lst = mCustomTools->actionList();
for (KToggleAction *act : lst) {
menu->addAction(act);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment