MLPlugin 1.0
Loading...
Searching...
No Matches
MLPlugin Class Reference

The MLPlugin class. More...

#include <MLPlugin.h>

Collaboration diagram for MLPlugin:

Public Member Functions

 MLPlugin (void *bases, void *plugin_path)
 MLPlugin constructor.
virtual void createWindow (QWidget *parent)
QString getPluginName ()
QString getPluginDescription ()
std::filesystem::path getPluginPath ()
std::shared_ptr< MLBookProc > getMLBookProc ()

Protected Attributes

Bases bases
std::filesystem::path plugin_path
QString plugin_name
QString plugin_description

Detailed Description

The MLPlugin class.

MLPlugin is base class for plugins creation. To create plugin inherit your plugin base class from MLPlugin and override createWindow() method. Also set plugin_name and plugin_description if needed. Your plugin base header file must include C function create (see example).

#ifndef EXAMPLEPLUGIN_H
#define EXAMPLEPLUGIN_H
#include <MLPlugin.h>
#include <QWidget>
class ExamplePlugin : public MLPlugin
{
public:
ExamplePlugin(void *bases, void *plugin_path);
void
createWindow(QWidget *parent) override;
};
extern "C"
{
#if defined(__linux)
create(void *bases, void *plugin_path)
{
return new ExamplePlugin(bases, plugin_path);
}
#elif defined(_WIN32)
__declspec(dllexport) MLPlugin *
create(void *bases, void *plugin_path)
{
return new ExamplePlugin(bases, plugin_path);
}
#endif
}
#endif // EXAMPLEPLUGIN_H
The MLPlugin class.
Definition MLPlugin.h:54
std::filesystem::path plugin_path
Definition MLPlugin.h:116
MLPlugin(void *bases, void *plugin_path)
MLPlugin constructor.
virtual void createWindow(QWidget *parent)
Bases bases
Definition MLPlugin.h:109
#include <Examplelugin.h>
#include <QApplication>
#include <QObject>
#include <QTranslator>
#include <QVBoxLayout>
#include <QLabel>
ExamplePlugin::ExamplePlugin(void *bases, void *plugin_path)
{
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for(const QString &locale : uiLanguages)
{
const QString baseName = "ExamplePlugin_" + QLocale(locale).name();
if(translator.load(":/i18n/" + baseName))
{
qApp->installTranslator(&translator);
break;
}
}
plugin_name = "ExamplePlugin";
plugin_description = QObject::tr("Example plugin");
}
void
ExamplePlugin::createWindow(QWidget *parent)
{
QWidget *window = new QWidget(parent);
window->setWindowFlag(Qt::Window);
window->setAttribute(Qt::WA_DeleteOnClose);
window->setWindowModality(Qt::WindowModal);
window->setWindowTitle(QObject::tr("Example plugin"));
QVBoxLayout *main_box = new QVBoxLayout;
window->setLayout(main_box);
QLabel *lab = new QLabel;
lab->setObjectName("Label");
QFont font = lab->font();
font.setBold(true);
lab->setFont(font);
lab->setText(QObject::tr("Example plugin"));
main_box->addWidget(lab, 0, Qt::AlignCenter);
window->show();
}

Constructor & Destructor Documentation

◆ MLPlugin()

MLPlugin::MLPlugin ( void * bases,
void * plugin_path )

MLPlugin constructor.

Parameters
basespointer to Bases object.
plugin_pathPointer to std::filesystem::path object.

Member Function Documentation

◆ createWindow()

virtual void MLPlugin::createWindow ( QWidget * parent)
virtual

This method will be called when user requests to show plugin window.

Parameters
parentPointer to parent window widget.

◆ getMLBookProc()

std::shared_ptr< MLBookProc > MLPlugin::getMLBookProc ( )

Returns smart pointer to MLBookProc object, set in internal bases object.

Returns
Smart pointer to MLBookProc object.

◆ getPluginDescription()

QString MLPlugin::getPluginDescription ( )

Returns plugin description set on plugin_description.

Returns
Value of plugin_description.

◆ getPluginName()

QString MLPlugin::getPluginName ( )

Returns plugin name set in plugin_name.

Returns
Value of plugin_name.

◆ getPluginPath()

std::filesystem::path MLPlugin::getPluginPath ( )

Returns plugin library file path.

Returns
Absolute path, set in plugin_path.

Member Data Documentation

◆ bases

Bases MLPlugin::bases
protected

Bases object.

Warning
Do not try to set or modify this object.

◆ plugin_description

QString MLPlugin::plugin_description
protected

Plugin description. You can set or modify this object on your need.

◆ plugin_name

QString MLPlugin::plugin_name
protected

Plugin name. You can set or modify this object on your need.

◆ plugin_path

std::filesystem::path MLPlugin::plugin_path
protected

Path to plugin library.

Warning
Do not try to set or modify this object.