Commit 3a0e576e authored by Jan Möbius's avatar Jan Möbius

Merge branch 'featureQueuedCrossPluginConnect' into 'master'

Feature queued cross plugin connect

Closes OpenFlipper-Free#109

See merge request !20
parents 326249f6 747f4ba9
/** \page pluginConnectionInterfacePage Plugin Connection Interface
\n
\image html PluginConnectionInterface.png
\n
The PluginConnectionInterface allows to connect signals and slots across different OpenFlipper plugins.
Usually you should implement the BaseInterface::pluginsInitialized() function from BaseInterface. In this function you can setup
your connections. Don't try to setup your connections earlier as the plugins you try to connect may not exist yet.
\n
<b> WARNING! Never connect SIGNALS and SLOTS which are already defined in other Interfaces!! WARNING! </b>
\n
This might result in endless loops and breaks OpenFlippers control loops. You have to keep track
of your connections yourself. If you call slots which call updatedOject which in turn call your original
slot you get a loop and OpenFlipper is not responsible for your endless loops! Be careful!
The following code shows a simple example to connect signals and slots. For the signal and slot definition
you have to use the common QT macros SIGNAL and SLOT.
\code
void ExamplePlugin::pluginsInitialized()
{
// Use the QT macros to generate the signatures
emit crossPluginConnect(pluginA,SIGNAL(signalA(QString)),pluginB,SLOT(slotB(QString)));
}
\endcode
The next example shows how to use a queued connection between two plugins:
\n
ExamplePlugin.hh:
\code
class ExamplePlugin: public QObject, BaseInterface, PluginConnectionInterface, [...]
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(PluginConnectionInterface)
[...]
signals:
void crossPluginConnectQueued( QString, const char*, QString, const char*);
/// example signal which can be used to group objects in datacontrol
void void dataControlGroupObjects(IdList, QString);
[...]
void exampleFunction();
}
\endcode
ExamplePlugin.cc:
\code
[...]
void ExamplePlugin::pluginsInitialized()
{
[...]
emit crossPluginConnectQueued("exampleplugin",SIGNAL(dataControlGroupObjects(IdList, QString)),"datacontrol",SLOT(groupObjects(IdList, QString)));
}
void ExamplePlugin::exampleFunction()
{
//do whatever you want, especially use the signals you want, but don't create loops
// e.g. emit a bazillion addEmptObject signals
[...]
// finally group them by emitting the connected signal
emit dataControlGroupObjects(ids, "fancy group name");
}
\endcode
To use the PluginConnectionInterface:
<ul>
<li> include PluginConnectionInterface.hh in your plugins header file
<li> derive your plugin from the class PluginConnectionInterface
<li> add Q_INTERFACES(PluginConnectionInterface) to your plugin class
<li> And add the signals or slots you want to use to your plugin class (You don't need to implement all of them)
</ul>
*/
......@@ -80,13 +80,24 @@ class PluginConnectionInterface {
/** \brief connect signals and slots of plugins across plugins
*
* Connect a signal of one plugin to another plugin by its scripting name.
* _pluginName1 is the scripting name of the plugin containing the signal ( Use script editor to check that name)
* _signal is the signal name. Use it like with regular connect ( <tt>SIGNAL(...)</tt> ) macro
* _pluginName2 is the scripting name of the plugin containing a slot
* _slot is the slot name. Use it like with regular connect ( <tt>SLOT(...)</tt> ) macro
* \param _pluginName1 is the scripting name of the plugin containing the signal ( Use script editor to check that name)
* \param _signal is the signal name. Use it like with regular connect ( <tt>SIGNAL(...)</tt> ) macro
* \param _pluginName2 is the scripting name of the plugin containing a slot
* \param _slot is the slot name. Use it like with regular connect ( <tt>SLOT(...)</tt> ) macro
*
*/
virtual void crossPluginConnect( QString /*_pluginName1*/, const char* /*_signal*/, QString /*_pluginName2*/, const char* /*_slot*/) {};
virtual void crossPluginConnect( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) = 0;
/** \brief connect signals and slots of plugins across plugins using Qt::QueuedConnection
*
* Connect a signal of one plugin to another plugin by its scripting name.
* \param _pluginName1 is the scripting name of the plugin containing the signal ( Use script editor to check that name)
* \param _signal is the signal name. Use it like with regular connect ( <tt>SIGNAL(...)</tt> ) macro
* \param _pluginName2 is the scripting name of the plugin containing a slot
* \param _slot is the slot name. Use it like with regular connect ( <tt>SLOT(...)</tt> ) macro
*
*/
virtual void crossPluginConnectQueued( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) = 0;
public :
......@@ -96,43 +107,6 @@ class PluginConnectionInterface {
};
/** \page pluginConnectionInterfacePage Plugin Connection Interface
\n
\image html PluginConnectionInterface.png
\n
The PluginConnectionInterface allows to connect signals and slots across different OpenFlipper plugins.
Usually you should implement the BaseInterface::pluginsInitialized() function from BaseInterface. In this function you can setup
your connections. Don't try to setup your connections earlier as the plugins you try to connect may not exist yet.
\n
<b> WARNING! Never connect SIGNALS and SLOTS which are already defined in other Interfaces!! WARNING! </b>
\n
This might result in endless loops and breaks OpenFlippers control loops. You have to keep track
of your connections yourself. If you call slots which call updatedOject which in turn call your original
slot you get a loop and OpenFlipper is not responsible for your endless loops! Be careful!
The following code shows a simple example to connect signals and slots. For the signal and slot definition
you have to use the common QT macros SIGNAL and SLOT.
\code
void ExamplePlugin::pluginsInitialized()
{
// Use the QT macros to generate the signatures
emit crossPluginConnect(pluginA,SIGNAL(signalA(QString)),pluginB,SLOT(slotB(QString)));
}
\endcode
To use the ScriptInterface:
<ul>
<li> include PluginConnectionInterface.hh in your plugins header file
<li> derive your plugin from the class PluginConnectionInterface
<li> add Q_INTERFACES(PluginConnectionInterface) to your plugin class
<li> And add the signals or slots you want to use to your plugin class (You don't need to implement all of them)
</ul>
*/
Q_DECLARE_INTERFACE(PluginConnectionInterface,"OpenFlipper.PluginConnectionInterface/1.0")
......
......@@ -636,6 +636,9 @@ signals:
/// Called to create inter plugin connections
void slotCrossPluginConnect( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot);
/// Called to create inter plugin connections
void slotCrossPluginConnectQueued( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot);
/// called to switch the renderer for a specific viewer
void slotSetRenderer(unsigned int _viewer, QString _rendererName);
......
......@@ -433,10 +433,13 @@ void Core::deletedObject(int /*_objectId*/) {
//========================================================================================
// === Cross Plugin connections ============================
//========================================================================================
void Core::slotCrossPluginConnect( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) {
/// Helper function to avoid code duplication
void connectPlugins( Core* c, const std::vector<PluginInfo>& plugins_, QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot, bool _queued)
{
QObject* plugin1 = 0;
QObject* plugin2 = 0;
for ( int i = 0 ; i < (int)plugins_.size(); ++i ) {
if ( plugins_[i].rpcName == _pluginName1 ) {
plugin1 = plugins_[i].plugin;
......@@ -447,17 +450,28 @@ void Core::slotCrossPluginConnect( QString _pluginName1, const char* _signal, QS
}
if ( plugin1 == 0 ) {
emit log(LOGERR,tr("Cross Plugin Interconnection failed because plugin %1 was not found!").arg(_pluginName1));
emit c->log(LOGERR,QObject::tr("Cross Plugin Interconnection failed because plugin %1 was not found!").arg(_pluginName1));
return;
}
if ( plugin2 == 0 ) {
emit log(LOGERR,tr("Cross Plugin Interconnection failed because plugin %1 was not found!").arg(_pluginName2));
emit c->log(LOGERR,QObject::tr("Cross Plugin Interconnection failed because plugin %1 was not found!").arg(_pluginName2));
return;
}
// now connect them
connect(plugin1,_signal,plugin2,_slot);
if(_queued)
QObject::connect(plugin1,_signal,plugin2,_slot, Qt::QueuedConnection);
else
QObject::connect(plugin1,_signal,plugin2,_slot);
}
void Core::slotCrossPluginConnect( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) {
connectPlugins(this, plugins_, _pluginName1, _signal, _pluginName2, _slot, false);
}
void Core::slotCrossPluginConnectQueued( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) {
connectPlugins(this, plugins_, _pluginName1, _signal, _pluginName2, _slot, true);
}
//========================================================================================
......
......@@ -1997,6 +1997,11 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic
connect(plugin , SIGNAL( crossPluginConnect(QString,const char*,QString,const char*) ),
this , SLOT( slotCrossPluginConnect(QString,const char*,QString,const char*) ));
}
if ( checkSignal(plugin,"crossPluginConnectQueued(QString,const char*,QString,const char*)" ) ) {
connect(plugin , SIGNAL( crossPluginConnectQueued(QString,const char*,QString,const char*) ),
this , SLOT( slotCrossPluginConnectQueued(QString,const char*,QString,const char*) ));
}
}
//Check if the plugin supports RenderInterface
......
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