Changing entity properties

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

Changing entity properties

Postby andrew » Thu Aug 08, 2013 1:52 pm

From a QCAD developer:

How can I set / change properties and custom properties of existing entities?
User avatar
andrew
Site Admin
 
Posts: 2592
Joined: Fri Mar 30, 2007 6:07 am

Re: Changing entity properties

Postby andrew » Thu Aug 08, 2013 2:02 pm

You can change properties through an operation in the same way as you would change the geometry of an entity.

Note that operations live on a higher level than transactions. An operation triggers a transaction underneath and in addition keeps the views up to date. Operations can also be previewed. Whenever a document has views attached to it, use operations. If a document is being modified without views, a transaction may be used instead.

// create new operation:
RModifyObjectsOperation* op = new RModifyObjectsOperation();

// fetch existing entity:
QSharedPointer<REntity> entity = document->queryEntity(entityId);

// TODO: check if entity is NULL

// change entity:
// set / change custom property:
entity->setProperty(RPropertyTypeId("MyProperty"), 37.5);

// set fixed property:
entity->setProperty(REntity::PropertyColor, RColor("blue"));
// which is the same as:
entity->setColor(RColor("blue"));

// set layer ID:
entity->setLayerId(...);

// add modified entity to operation:
op->addObject(entity);

// apply operation to document (trigger transaction) and update views, etc.
// document interface takes ownership of the operation (deletes it when done)
documentInterface->applyOperation(op);


The same in ECMAScript:
// create new operation:
var op = new RModifyObjectsOperation();

// fetch existing entity:
var entity = document.queryEntity(entityId);

// TODO: check if entity is undefined

// change entity:
// set / change custom property:
entity.setProperty(new RPropertyTypeId("MyProperty"), 37.5);

// set fixed property:
entity.setProperty(REntity.PropertyColor, new RColor("blue"));
// which is the same as:
entity.setColor(new RColor("blue"));

// set layer ID:
entity.setLayerId(...);

// add modified entity to operation:
op.addObject(entity);

// apply operation to document (trigger transaction) and update views, etc:
documentInterface.applyOperation(op);
User avatar
andrew
Site Admin
 
Posts: 2592
Joined: Fri Mar 30, 2007 6:07 am


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 1 guest