Add new property in property editor for RTextEntity

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Add new property in property editor for RTextEntity

Post by sarlaa » Thu Nov 16, 2017 8:03 pm

Hi, I'm new to QCAD, and I'm wondering how can I extend RTextEntity properties ? I want to add visibility property, so I can show/hide a text.
Thanks in advance

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Add new property in property editor for RTextEntity

Post by andrew » Thu Nov 16, 2017 8:24 pm

The visibility of an entity would typically be controlled by its layer (preferred).

Text entities don't have a visibility flag. Adding such a feature would require adding this information to DXF/DWG when saving (as a custom property).

As an alternative, you could use block attributes instead of text labels.

Create a block with a single attribute definition:
Screen Shot 2017-11-16 at 19.19.27.png
Screen Shot 2017-11-16 at 19.19.27.png (202.81 KiB) Viewed 13816 times
Insert an instance of that block for each text label in the drawing. This creates a single block attribute for every instance of the block:
Screen Shot 2017-11-16 at 19.20.16.png
Screen Shot 2017-11-16 at 19.20.16.png (225.8 KiB) Viewed 13816 times
Block attributes (unlike text entities) do have a visibility property:
Screen Shot 2017-11-16 at 19.20.28.png
Screen Shot 2017-11-16 at 19.20.28.png (202.06 KiB) Viewed 13816 times

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: Add new property in property editor for RTextEntity

Post by sarlaa » Fri Nov 17, 2017 6:11 pm

Thanks Andrew for your reply. I understand the approch to use block because they have visibility property.
but still i need to know how it is possible to exted class such RLineEntity
because my goal is :
to be able with a custom tool line to develop, to draw a line that automaticaly draw with it dimention of line as text
and that tool line have a custom property further : visibility, that allow showig or hiding line dimension

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Add new property in property editor for RTextEntity

Post by andrew » Mon Nov 20, 2017 10:55 am

You would have to work with custom properties and maybe a transaction listener to react to property changes.

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: Add new property in property editor for RTextEntity

Post by sarlaa » Mon Nov 20, 2017 12:36 pm

Thanks for your reply, working with custom properties shows perfecty the property in the editor roperty.
As you said now for tracking property changes, do you have an exemple using RTransactionListener ?
Thanks in advance !

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Add new property in property editor for RTextEntity

Post by andrew » Mon Nov 20, 2017 12:40 pm

Yes, a transaction listener example (as C++ plugin) is available at:
https://github.com/qcad/qcad/tree/maste ... onlistener

And the JS equivalent:
https://github.com/qcad/qcad/tree/maste ... onListener

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: Add new property in property editor for RTextEntity

Post by sarlaa » Mon Nov 20, 2017 2:11 pm

I saw the JS transaction listener example, and the given Ids of objects affected.
For the example transaction listener is applied on RMainWindowQt(appWin) is there a possibility to apply it on REntityLine ?
Otherwise I can't figure out how can I detect change made on custom property of REntityLine. Could you give me your instructions ?

A question related to the given Id objects affected, I try to query the entity by Id as : var entity = doc.queryEntity(objId);
but that gives me a pointer to the entity. How can I get the entity ?

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Add new property in property editor for RTextEntity

Post by andrew » Mon Nov 20, 2017 5:06 pm

sarlaa wrote:For the example transaction listener is applied on RMainWindowQt(appWin) is there a possibility to apply it on REntityLine ?
No. Your transaction listener is global and will always be triggered, for every change in every document. To find out what has changed you need to look into the RTransaction object.
sarlaa wrote:Otherwise I can't figure out how can I detect change made on custom property of REntityLine. Could you give me your instructions ?
I've updated the example:
https://github.com/qcad/qcad/blob/maste ... istener.js
sarlaa wrote:A question related to the given Id objects affected, I try to query the entity by Id as : var entity = doc.queryEntity(objId);
but that gives me a pointer to the entity. How can I get the entity ?
The entity pointer can be used just like the entity to retrieve data or change data. To pass a pointer to a function that expects an entity, you can use .data() to dereference. E.g.:

Code: Select all

entity2.copyAttributesFrom(entity1.data());

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: Add new property in property editor for RTextEntity

Post by sarlaa » Mon Nov 20, 2017 6:21 pm

Again thanks Andrew for your reply, that was very helpful.

Now that I have all these pieces, if you may I have just one a further question, assuming that I have the object RLineEntity and the object RTextEntity (line dimension), is there a way to set the text dimension as an attribute of RLineEntity object by JS ? And reach after the attribute of dimension base on the object RLineEntity ?

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Add new property in property editor for RTextEntity

Post by andrew » Tue Nov 21, 2017 10:51 am

I'm not sure I understood this question correctly.

If you mean to reference an entity from another entity, the recommended way to do su is through the entity's handle (entity.getHandle()). Handles are persistent and don't change during the lifetime of an object. The dimension entity might have a handle of "0xa1" and the line entity might refer to the dimension entity through a custom property "dimension" with value "0xa1".

You can query objects by handle using

Code: Select all

document.queryObjectByHandle(handle);

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: Add new property in property editor for RTextEntity

Post by sarlaa » Mon Dec 04, 2017 12:54 pm

Hi Andrew,

Doing as you described, i'll need to hide the custom property. Is there a way to do that ?

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Add new property in property editor for RTextEntity

Post by andrew » Mon Dec 04, 2017 1:36 pm

No, there is currently no easy way to hide custom properties.

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: Add new property in property editor for RTextEntity

Post by sarlaa » Mon Dec 04, 2017 3:30 pm

Okay.

I have 3 questions more please :

1- Can I hide the button : Add Custom Property, from property editor custom section ?
2- I tried to change text translation in PropertyEditor_fr.ts file, but I don't see my changes (I have Qcad in french), have I to do something more ?
3- How can I at the start of qcad launch the listener : https://github.com/qcad/qcad/tree/maste ... onListener

Thanks in advance.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Add new property in property editor for RTextEntity

Post by andrew » Mon Dec 04, 2017 11:03 pm

sarlaa wrote:1- Can I hide the button : Add Custom Property, from property editor custom section ?
You could install an RPropertyListener and look up and hide the button every time the property editor layout is rebuilt:

Code: Select all

var appWin = RMainWindowQt.getMainWindow();
var dock = appWin.findChild("PropertyEditorDock");
var button = dock.findChild("AddCustomProperty");
button.hide();
sarlaa wrote:2- I tried to change text translation in PropertyEditor_fr.ts file, but I don't see my changes (I have Qcad in french), have I to do something more ?
Yes, you'd need to release the translations using lrelease (comes with Qt) to create a qm file. ts files are translation sources.
sarlaa wrote:3- How can I at the start of qcad launch the listener : https://github.com/qcad/qcad/tree/maste ... onListener
Everything in init is called on start up. So you can simply place all code you want to run on start up into ExTransactionListener.init:

Code: Select all

ExTransactionListener.init = function(basePath) {
    ...
    var adapter = new RTransactionListenerAdapter();
    var appWin = EAction.getMainWindow();
    appWin.addTransactionListener(adapter);
    ...
};

sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

Re: Add new property in property editor for RTextEntity

Post by sarlaa » Tue Dec 05, 2017 12:47 pm

Thanks very much Andrew, with your orientation all is working !

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”