Page 1 of 1

Property Editor

Posted: Fri Aug 30, 2013 9:43 am
by luckyChris
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

Re: Property Editor

Posted: Fri Aug 30, 2013 10:21 am
by andrew
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);

Re: Property Editor

Posted: Fri Aug 30, 2013 11:09 am
by luckyChris
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?

Re: Property Editor

Posted: Fri Aug 30, 2013 11:34 am
by andrew
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').

Re: Property Editor

Posted: Fri Aug 30, 2013 1:14 pm
by luckyChris
thank you for your tipps! very helpful for me!