Commit 4dbf9d16 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'polishingAddObjectDocumentation' into 'master'

added more documentation on qt signals and the qt event queue which is

Closes OpenFlipper-Free#110

See merge request !31
parents 15593ff8 4d5e0a73
......@@ -63,7 +63,69 @@ void ExamplePlugin::exampleFunction() {
}
\endcode
Note, that the LoadSaveInterface::addEmptyObject signal is connected using a Qt::DirectConnection and immediately returns the ID of your new object.
Of course you have to add the includes for the ObjectTypes you want to use to your list of includes. A list of available
ObjectTypes can be found here: \ref datatypes
\section qt_signals Qt Signals
As mentioned above, new objects are created by emitting the LoadSaveInterface::addEmptyObject signal (more information on Qt signals http://doc.qt.io/qt-5/signalsandslots.html). In addition to that another signal is emitted, to inform other plugins about the new object. This signal is connected with a Qt::QueuedConnection which means, that it will be pushed to the Event-Queue of Qt. This allows other plugins to process the new object, e.g. create and add textures for it.
However, after the line "emit addEmptyObject(DATA_PLANE, newObjectId);" from the above example, there may be plugins that have not yet processed this information, which may cause problems if they change properties you want to set. To avoid such problems you can inject a new signal to the Event-Queue, because the Event-Queue is processed in order.
Example: YourPlugin.hh:
\code
signals:
[...]
// LoadSaveInterface
void addEmptyObject( DataType _type, int& _id);
//use this signal to make sure addEmptyObject was processed.
void doStuff(IdList);
[...]
slots:
[...]
void slotDoStuff(IdList _ist);
[...]
\endcode
YourPlugin.cc:
\code
void YourPlugin::pluginsInitialized()
{
[...]
connect(this, SIGNAL(doStuff(IdList)), this, SLOT(slotDoStuff(IdList)), Qt::QueuedConnection);
}
[...]
void YourPlugin::slotDoStuff(IdList _list)
{
// You can use whatever plugin you want with your object now
// All others have finished processing addEmptyObject
RPC::callFunctionValue<int>("datacontrol","groupObjects", _list, QString("test_group"));
}
void YourPlugin::createLotsOfObjects()
{
//create lots of empty objects by emitting
// addEmptyObject or calling the porimitive generator e.g.
IdList ids;
ids.push_back( RPC::callFunctionValue<int>("primitivesgenerator","addCube",Vector(1.0f),4.0d));
ids.push_back( RPC::callFunctionValue<int>("primitivesgenerator","addCube",Vector(2.0f),4.0d));
// Now use your own signal to make sure the previous signal was consumed by all plugins
// since the connection for this signal is Qt::QueuedConnection,
// it will be inserted at the end of the event queue. and events are processed in order
emit doStuff(ids);
}
\endcode
*/
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