Commit 49daf67b authored by Jan Möbius's avatar Jan Möbius

Merge branch 'feature_plugincommandlineoptions' into 'master'

Set plugin options via command line argument.

See merge request !120
parents f63fd963 24920cf0
......@@ -101,6 +101,16 @@ class BaseInterface {
*/
virtual void pluginsInitialized() {};
/** \brief Initialize Plugin step 2 alternative
*
* This slot is similar to the vanilla version without parameters but additionally passes plugin command line options
* as key-value pairs. For passing command line options, use e.g.:
* OpenFlipper -o key1=value1 -p key2=value2
* or
* OpenFlipper --pluginoptions key1=value1;key2=value2
*/
virtual void pluginsInitialized(QVector<QPair<QString, QString>> const& _pluginOptions) {};
/** @} */
......
......@@ -161,6 +161,13 @@ void disableExaminerLightHandling() {
bool examinerLightHandling() {
return internalLightHandling_;
}
/** \brief DONT USE DIRECTLY!!
*
* Plugin command line options
* The container is set by the command line parser once
* and it is passed to the respective pluginsInitialized(...) method
*/
static QVector<QPair<QString, QString>> pluginCommandLineOptions_;
int viewerId() {
return viewerId_;
......@@ -1262,4 +1269,14 @@ ObjectReferenceRange objectReferences(IteratorRestriction _restriction, DataType
return ObjectReferenceRange(_restriction, _dataType);
}
const QVector<QPair<QString, QString> > &pluginCommandLineOptions()
{
return pluginCommandLineOptions_;
}
void setPluginCommandLineOptions(const QVector<QPair<QString, QString> > &_pluginCommandLineOptions)
{
pluginCommandLineOptions_ = _pluginCommandLineOptions;
}
} // End namespace PluginFunctions
......@@ -158,6 +158,21 @@ void removeObjectFromMap(int _objectId);
/** @} */
//=======================================
// Object container functions
/** @name Internal container for plugin options set via command line arguments
* @{ */
//=======================================
/// Get command line plugin settings as key-value pairs
DLLEXPORT
QVector<QPair<QString, QString>> const& pluginCommandLineOptions();
/// Set the command line plugin settings ( DO NOT USE!! )
/// This method is usually only called by the command line parser
DLLEXPORT
void setPluginCommandLineOptions(QVector<QPair<QString, QString>> const& _pluginCommandLineOptions);
//=======================================
// SceneGraph Generator Map
/** @name Internal container for scenegraph widget generators
......
......@@ -404,6 +404,9 @@ signals:
/// Called after all plugins are loaded
void pluginsInitialized();
/// Called after all plugins are loaded and additionally passes command line plugin options
void pluginsInitialized(QVector<QPair<QString, QString>> const&);
/// Tell plugins that the visibility of an object has changed
void visibilityChanged(int _id);
......
......@@ -81,6 +81,7 @@
#include "OpenFlipper/BasePlugin/SecurityInterface.hh"
#include "OpenFlipper/BasePlugin/PluginConnectionInterface.hh"
#include "OpenFlipper/BasePlugin/MetadataInterface.hh"
#include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
#include <ACG/QtWidgets/QtFileDialog.hh>
......@@ -559,6 +560,8 @@ void Core::loadPlugins()
emit pluginsInitialized();
emit pluginsInitialized(PluginFunctions::pluginCommandLineOptions());
emit log(LOGOUT,tr("Loaded %n Plugin(s)","",int(plugins().size())) );
}
......@@ -1046,6 +1049,9 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic
if ( checkSlot( plugin , "pluginsInitialized()" ) )
connect(this,SIGNAL(pluginsInitialized()),plugin,SLOT(pluginsInitialized()), Qt::DirectConnection);
if ( checkSlot( plugin , "pluginsInitialized(QVector<QPair<QString,QString>>const&)" ) )
connect(this,SIGNAL(pluginsInitialized(QVector<QPair<QString,QString>>const&)),plugin,SLOT(pluginsInitialized(QVector<QPair<QString,QString>>const&)), Qt::DirectConnection);
if ( checkSignal(plugin,"setSlotDescription(QString,QString,QStringList,QStringList)") )
connect(plugin, SIGNAL(setSlotDescription(QString,QString,QStringList,QStringList)),
this, SLOT(slotSetSlotDescription(QString,QString,QStringList,QStringList)) );
......
......@@ -53,6 +53,7 @@
#include "OpenFlipper/Core/Core.hh"
#include "common/glew_wrappers.hh"
#include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
// Qt
#include <qgl.h>
......@@ -365,6 +366,10 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *err
QCommandLineOption profileOption("profile",QCoreApplication::translate("main","Request OpenGL context profile <profile> with profile set as compat or core"),QCoreApplication::translate("main","< compat | core >"));
parser.addOption(profileOption);
QCommandLineOption pluginOptionsOption(QStringList() << "o" << "pluginoptions",QCoreApplication::translate("main", "Pass options to plugins"), "key1=value1;key2=value2;...");
parser.addOption(pluginOptionsOption);
const QCommandLineOption helpOption = parser.addHelpOption();
const QCommandLineOption versionOption = parser.addVersionOption();
......@@ -454,6 +459,19 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *err
if(parser.isSet(coreProfileOption)) {
OpenFlipper::Options::coreProfile(true, true);
}
if(parser.isSet(pluginOptionsOption))
{
QStringList poptions = parser.value(pluginOptionsOption).split(";");
QVector<QPair<QString, QString>> pcloptions;
for(auto s : poptions)
{
auto kvp = s.split("=");
auto key = kvp[0];
auto value = kvp[1];
pcloptions.push_back({key, value});
}
PluginFunctions::setPluginCommandLineOptions(pcloptions);
}
return CommandLineOk;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment