#ifndef IPLUGIN_H #define IPLUGIN_H #include #include #include #include #include #include #include #include #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(m_ui); bool filled = true; if (form != nullptr) { filled = form->fillData(); } return filled ? m_ui : nullptr; } QList dasboardWidgets() { return m_dashboardWidgets; } virtual QWidget *settingsUi() { return m_settingsUi; } virtual QString settingsTabLabel() { return pluginName(); } template Service *service() { return (Service*)m_service; } virtual bool showIcon() { return true; } virtual QTranslator* translator() { return nullptr; } virtual QIcon pluginIcon() { return {}; } QMap 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"; } } return m_translator; } QTranslator* m_translator{nullptr}; QWidget *m_ui {nullptr}; QWidget *m_settingsUi {nullptr}; IService *m_service {nullptr}; QMap m_translations; QList m_dashboardWidgets; }; #define PluginInterface_iid "cz.itsolved.prodejna.IPlugin" Q_DECLARE_INTERFACE(IPlugin, PluginInterface_iid) #endif // IPLUGIN_H