7 #include "guiQt/Plugin.hpp" 9 #include <fwCore/base.hpp> 11 #include <fwGuiQt/App.hpp> 12 #include <fwGuiQt/WorkerQt.hpp> 14 #include <fwRuntime/operations.hpp> 15 #include <fwRuntime/profile/Profile.hpp> 16 #include <fwRuntime/utils/GenericExecutableFactoryRegistrar.hpp> 18 #include <fwServices/macros.hpp> 19 #include <fwServices/registry/ActiveWorkers.hpp> 24 #include <QStyleFactory> 25 #include <QTextStream> 33 static ::fwRuntime::utils::GenericExecutableFactoryRegistrar<Plugin> registrar(
"::guiQt::Plugin");
45 ::fwRuntime::profile::Profile::sptr profile = ::fwRuntime::profile::getCurrentProfile();
46 SLM_ASSERT(
"Profile is not initialized", profile);
47 int& argc = profile->getRawArgCount();
48 char** argv = profile->getRawParams();
50 m_workerQt = ::fwGuiQt::getQtWorker(argc, argv);
54 m_workerQt->post( std::bind( &Plugin::loadStyleSheet,
this ) );
56 ::fwRuntime::profile::getCurrentProfile()->setRunCallback(std::bind(&Plugin::run,
this));
74 ::fwRuntime::profile::getCurrentProfile()->setup();
79 int Plugin::run() noexcept
81 m_workerQt->post( std::bind( &setup ) );
82 m_workerQt->getFuture().wait();
84 ::fwRuntime::profile::getCurrentProfile()->cleanup();
85 int result = ::boost::any_cast<
int>(m_workerQt->getFuture().get());
95 void Plugin::loadStyleSheet()
97 if( this->
getBundle()->hasParameter(
"resource") )
99 const std::string resourceFile = this->
getBundle()->getParameterValue(
"resource");
102 const bool resourceLoaded = QResource::registerResource(path.string().c_str());
103 SLM_ASSERT(
"Cannot load resources '"+resourceFile+
"'.", resourceLoaded);
106 if( this->
getBundle()->hasParameter(
"style") )
108 const std::string style = this->
getBundle()->getParameterValue(
"style");
109 qApp->setStyle(QStyleFactory::create(QString::fromStdString(style)));
112 if( this->
getBundle()->hasParameter(
"stylesheet") )
114 const std::string stylesheetFile = this->
getBundle()->getParameterValue(
"stylesheet");
117 QFile data(QString::fromStdString(path.string()));
119 if(data.open(QFile::ReadOnly))
121 QTextStream styleIn(&data);
122 style = styleIn.readAll();
124 qApp->setStyleSheet(style);
GUIQT_API void start()
Notifies the plugin about its start.
static FWSERVICES_API void setDefaultWorker(::fwThread::Worker::sptr worker)
Register the default active worker.
GUIQT_API ~Plugin() noexcept
destructor
static FWSERVICES_API ActiveWorkers::sptr getDefault()
Returns an instance of ActiveWorkers.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWRUNTIME_API std::shared_ptr< Bundle > getBundle() const noexcept override
Retrieves the bundle the executable originates from.
FWRUNTIME_API::boost::filesystem::path getBundleResourceFilePath(const std::string &bundleIdentifier, const ::boost::filesystem::path &path) noexcept
Retrieve a filesystem valid path for a path relative to the bundle having the specified identifier...
The namespace guiQt contains the basic services to build the application IHM with Qt...
GUIQT_API void stop() noexcept
Notifies the plugin about its stop.