Property Editor

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Property Editor

Postby luckyChris » Fri Aug 30, 2013 9:43 am

Hi,

adding a new property to a spline is done with a new item in the .ui file. This works fine, but when the line is drawn and afterwards selected, there is an other property edit window which shows only the original properties. How can I handle the need to edit the new property when the spline is selected?

Thanks for suggestions!

Chris
luckyChris
Newbie Member
 
Posts: 4
Joined: Mon Aug 26, 2013 7:06 pm

Re: Property Editor

Postby andrew » Fri Aug 30, 2013 10:21 am

New properties can only be added to an entity type in C++.
This only makes sense for properties that are available for all instances of an entity type. For example, one could add a read-only property 'Length' to all spline entities.

User defined custom properties can be added to any object / entity if XData is enabled using the command line switch -enable-xdata:

./qcad -enable-xdata


XData support is experimental and therefore disabled by default. Custom properties that are attached to an entity are persistent (that means they are saved and can be read from DXF / DWG files).

Setting a custom property:
entity.setCustomProperty("MyCustomProperty", 37.5);
var di = this.getDocumentInterface();
var operation = new RAddObjectsOperation(false);
operation.addObject(entity);
di.applyOperation(operation);


Getting a custom property:
// 0 is the default value if the custom property does not exist for that object / entity:
entity.getCustomProperty("MyCustomProperty", 0);
User avatar
andrew
Site Admin
 
Posts: 2364
Joined: Fri Mar 30, 2007 6:07 am

Re: Property Editor

Postby luckyChris » Fri Aug 30, 2013 11:09 am

thank you, Andrew for the fast response! This would help for the first version of my solution.

One basic question regarding the properties: in my .ui file there is the following definition to let the user enter a float value:
<item>
<widget class="RMathLineEdit" name="Speed">
<property name="speed" stdset="0">
<number>0</number>
</property>
</widget>
</item>

is RMathLineEdit the best class for doing that?

in my .js file I´ve tried to read the value, but it´s not successful:

var optionsToolBar = EAction.getOptionsToolBar();
var speedBox = optionsToolBar.findChild("Speed");
this.speed = parseFloat(speedBox.currentText);

can you please help me to get the value?
luckyChris
Newbie Member
 
Posts: 4
Joined: Mon Aug 26, 2013 7:06 pm

Re: Property Editor

Postby andrew » Fri Aug 30, 2013 11:34 am

RMathLineEdit is the best choice for entering numbers, yes:
<item>
<widget class="RMathLineEdit" name="Speed">
<property name="text">
<string notr="true">1</string> <!-- Initial default value is 1 -->
</property>
<property name="angle" stdset="0">
<bool>false</bool> <!-- Value is not an angle (don't convert from deg to rad) -->
</property>
</widget>
</item>


Try speedBox.getValue() to retrieve the value as number directly.

Some debugging hints:
// prints the value of a variable / object to stdout:
qDebug(variable);


Starts QCAD with the script debugger enabled (useful to catch syntax errors, undefined objects, etc). Not for production use (crashes / undefined behavior may occur):
qcad -enable-script-debugger


Note that there are many script tools available that do similar things to what you are likely trying to achieve (for example Draw/Line/LineParallel/LineParallel.js allows the user to input a distance which is processed in the script in even handler LineParallel.prototype.slotDistanceChanged (since the UI component is called 'Distance').
User avatar
andrew
Site Admin
 
Posts: 2364
Joined: Fri Mar 30, 2007 6:07 am

Re: Property Editor

Postby luckyChris » Fri Aug 30, 2013 1:14 pm

thank you for your tipps! very helpful for me!
luckyChris
Newbie Member
 
Posts: 4
Joined: Mon Aug 26, 2013 7:06 pm


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 1 guest

cron