You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
2.8 KiB
C++
118 lines
2.8 KiB
C++
#ifndef IPLUGIN_H
|
|
#define IPLUGIN_H
|
|
|
|
#include <QString>
|
|
#include <QWidget>
|
|
#include <QtPlugin>
|
|
#include <QJsonObject>
|
|
#include <QStringList>
|
|
#include <QIcon>
|
|
#include <QTranslator>
|
|
#include <QMessageBox>
|
|
|
|
#include "service.h"
|
|
#include "igridform.h"
|
|
#include "reporting/report.h"
|
|
|
|
class IPlugin
|
|
{
|
|
|
|
public:
|
|
IPlugin() = default;
|
|
|
|
virtual ~IPlugin() {
|
|
delete m_service;
|
|
delete m_translator;
|
|
|
|
if (m_ui != nullptr && m_ui->parent() == nullptr)
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
if (m_settingsUi != nullptr && m_settingsUi->parent() == nullptr)
|
|
{
|
|
delete m_settingsUi;
|
|
}
|
|
}
|
|
|
|
virtual QString pluginName() = 0;
|
|
virtual QString pluginId() = 0;
|
|
virtual QString pluginDescription() = 0;
|
|
virtual int schemaVersion() = 0;
|
|
virtual QStringList schemas() = 0;
|
|
virtual QStringList dependsOn() = 0;
|
|
virtual ReportList reports() = 0;
|
|
|
|
virtual void init(const QJsonObject &metaData) = 0;
|
|
|
|
virtual QWidget *ui() {
|
|
PermissionEvaluator permEv;
|
|
if (!permEv.hasPermission(pluginId(), PERM_READ))
|
|
{
|
|
QMessageBox::critical(m_ui, QObject::tr("Permission denied"), QObject::tr("You don't have permission to open this plugin."));
|
|
return nullptr;
|
|
}
|
|
|
|
IGridForm *form = qobject_cast<IGridForm*>(m_ui);
|
|
bool filled = true;
|
|
|
|
if (form != nullptr)
|
|
{
|
|
filled = form->fillData();
|
|
}
|
|
|
|
return filled ? m_ui : nullptr;
|
|
}
|
|
|
|
QList<QFrame*> dasboardWidgets() {
|
|
return m_dashboardWidgets;
|
|
}
|
|
|
|
virtual QWidget *settingsUi() {
|
|
return m_settingsUi;
|
|
}
|
|
|
|
virtual QString settingsTabLabel() {
|
|
return pluginName();
|
|
}
|
|
|
|
template<class T>
|
|
Service<T> *service() {
|
|
return (Service<T>*)m_service;
|
|
}
|
|
|
|
virtual bool showIcon() { return true; }
|
|
virtual QTranslator* translator() { return nullptr; }
|
|
virtual QIcon pluginIcon() { return {}; }
|
|
QMap<QString, QString> translations() { return m_translations; }
|
|
|
|
virtual bool hasNumberSeries() { return false; }
|
|
virtual QString numberSeriesPrefix() { return ""; }
|
|
|
|
protected:
|
|
QTranslator* translatorFrom(const QString& fileName) {
|
|
if (!m_translator) {
|
|
m_translator = new QTranslator();
|
|
|
|
if (!m_translator->load(fileName + QLocale::system().name())) {
|
|
qDebug() << "Cannot load translation " << QLocale::system().name();
|
|
}
|
|
}
|
|
|
|
return m_translator;
|
|
}
|
|
|
|
QTranslator* m_translator{nullptr};
|
|
QWidget *m_ui {nullptr};
|
|
QWidget *m_settingsUi {nullptr};
|
|
IService *m_service {nullptr};
|
|
QMap<QString, QString> m_translations;
|
|
QList<QFrame*> m_dashboardWidgets;
|
|
};
|
|
|
|
#define PluginInterface_iid "cz.itsolved.prodejna.IPlugin"
|
|
|
|
Q_DECLARE_INTERFACE(IPlugin, PluginInterface_iid)
|
|
|
|
#endif // IPLUGIN_H
|