Discussion Forums: help

Monitor Forum | Start New Thread Start New Thread


RE: How to get the list of all parameters of an action ? [ reply ]
By: Claire SERY on 2015-11-12 12:03
Thank you Mahnu for tour answer.

I think I can get what I want using qObject::dynamicPropertyNames() that returns the name of properties. So, I can get my Camitk::Property by its name, and then I see its description.

I think it is enought for what I want to do (always for the catalogue and the XML file for the wizard).

Thank you !


RE: How to get the list of all parameters of an action ? [ reply ]
By: Emmanuel Promayon on 2015-11-10 19:25
Hello Claire,

For the first question: the idea behind properties is that it is managed by the Qt MetaObject of the Action (which is a well designed concept), and a camitk::Property just add an encapsulation that could be used to defined value range, precision... etc...

About the second question:
- for an Action, a Property defines a "parameter" of the action
- the getProperty(..) method is declared as Q_INVOKABLE, which allows for the tricky encapsulation described above (if it is Q_INVOKABLE, it means one can check if this method exists, if this method exists, we know that we can access to specific things such as the value range, precision etc...). It builds a very light way of doing nice things.

Therefore getProperty is needed to see if a specific camitk::Property is available, and addParameters is needed to encapsulate the camitk::Propetry around the Qt Property.

I suggest you check the ObjectController API documentation (there is a bit more about the used mechanism).

Now back to your initial question: to list the parameters of an action, you can get a good example in the ObjectControllerPrivate::addDynamicProperties(..) method. This source code loops over a QObject (and Action is a QObject somehow) and check whether it has the getProperty method (thanks to the Q_INVOKABLE keyword and Qt MetaObject mechanism). Doing something similar you will be able to get all the parameters of any action!

Concerning your suggestion of giving access to parameterMap: yet again this might be a very good idea if you have a specific use-case. At least I would strongly recommend:
a) to only give a read-only access (return a const Property)
b) to double check any possible underlying side effect: it touches the heart of the Core API and might give unwanted access to the Property mechanisms (e.g. any external code would be able to change the precision or value range of an action parameter outside the designed and well controlled zone of the Action constructor itself, that might lead to mayhem created by an innocent programmer!)

Again, let me know if that rambling makes any sens.

Best regards,

How to get the list of all parameters of an action ? [ reply ]
By: Claire SERY on 2015-11-10 18:28
When I have an Camitk::Action, I want to know the list of all its parameters (camitk::Property).

I can only access to the property by its name. But how to do if I don't know its name ?

As there is a private QMap in the Action containing the Property, I suggest to create methods to access to this map...

Thank you for your answer !


PS: In the same way, why is there a method:
Property* getProperty(QString name);
bool addParameter(Property*);
whereas both methods use Property...

Powered By FusionForge