Skip to content
Snippets Groups Projects
Commit a9a60aa5 authored by Sacha Percot-Tétu's avatar Sacha Percot-Tétu
Browse files

Added class PluginService

A PluginService is a GenericInterface::Service which manage one Plugin.
parent a3ddac6f
No related branches found
No related tags found
No related merge requests found
#include "PluginService.h"
#include <GenericInterface.h>
#include <QMessageBox>
#include <QLibrary>
#include <string>
#include <typeinfo>
#include <sstream>
using namespace genericinterface;
using namespace std;
PluginService::PluginService(Plugin* plugin) : _plugin(plugin){
}
void PluginService::display(GenericInterface* gi)
{
_gi = gi;
_menu = gi->menu(_plugin->getName().c_str());
_menu->menuAction()->setVisible(true);
vector<Operation*> operations = _plugin->getOperations();
for(vector<Operation*>::iterator it = operations.begin(); it < operations.end(); ++it) {
OperationService* opService = new OperationService(*it, _menu);
_opServices.push_back(opService);
opService->display(gi);
opService->setEnabled(!(*it)->needCurrentImg());
}
}
void PluginService::connect(GenericInterface* gi)
{
for(vector<OperationService*>::iterator it = _opServices.begin(); it < _opServices.end(); ++it) {
(*it)->connect(gi);
}
//connexion des changements d'images
QObject::connect(_gi->windowService(), SIGNAL(subWindowActivated(QMdiSubWindow*)),
this, SLOT(checkActionsValid(QMdiSubWindow*)));
}
Plugin* PluginService::getPlugin() {
return _plugin;
}
PluginService::~PluginService() {
for(vector<OperationService*>::iterator it = _opServices.begin(); it < _opServices.end(); ++it) {
delete *it;
}
_opServices.clear();
if(_menu->isEmpty()) {
//_gi->removeAction(_menu->menuAction());
_menu->menuAction()->setVisible(false);
}
}
void PluginService::checkActionsValid(QMdiSubWindow* activeWindow) {
StandardImageWindow* window = (activeWindow) ? dynamic_cast<StandardImageWindow*>(activeWindow->widget()) : NULL;
for(vector<OperationService*>::iterator it = _opServices.begin(); it < _opServices.end(); ++it) {
if((*it)->getOperation()->needCurrentImg()) {
(*it)->setEnabled(window != NULL);
}
}
}
\ No newline at end of file
#ifndef PLUGINSERVICE_H
#define PLUGINSERVICE_H
#include <Service.h>
#include <Plugin.h>
#include "OperationService.h"
#include <Services/AlgorithmService.h>
#include <QToolBar>
#include <QMenu>
class PluginService : public QObject, public genericinterface::Service
{
Q_OBJECT
public:
PluginService(Plugin*);
void display(genericinterface::GenericInterface* gi);
void connect(genericinterface::GenericInterface* gi);
Plugin* getPlugin();
~PluginService();
public slots:
void checkActionsValid(QMdiSubWindow* activeWindow);
private:
Plugin* _plugin;
genericinterface::GenericInterface* _gi;
QMenu* _menu;
//std::vector<QAction*> _actions;
std::vector<OperationService*> _opServices;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment