Discussion:
[Interest] Qt3D QAbstractItemModel to watch QEntity's
Philip Schuchardt
2018-11-12 21:09:09 UTC
Permalink
I want to create a QAbstractItemModel to watches Entity that have a custom
component. The custom component would have information (a list key value
pairs) for the QAbstractItemModel to change visibility of Entity's via a
QLayer. The QAbstractItemModel would be attached to a ListView to allow
users to enable and disable visibility. I'm having trouble figuring out how
to access signals and slots for add/remove entity and component events. I'm
think about writing a custom aspect since it get's add/remove/property
updates. The custom aspect probably won't do any real work, ie no jobs, and
just produce scene updates to another component that manages
QAbstractItemModel in the frontend. I think it's possible, but Qt3D uses
QNode::id() for scene events. I would then need to covert the QNode:id() to
a QNode. It looks like there's no public API to ask the private QScene to
convert QNode::id() to a QNode*. I would have to linear search from the
root entry to all the leaf nodes to find QNode::id() for QNode*. This seems
a bit silly.

How bad is it to use private API on Q3DCore::QScene::lookupNode() function
and QNode's private data to get QScene through Q_D()?

or

Is there a public version to convert id to QNode?

or

Is this monitoring approach a bad idea? I just need a list of QEntrity's
and corresponding QComponent's and signals and slots for when they're being
added, removed, or updated for QAbstractItemModel implementation.

Thanks
Philip
Philip Schuchardt
2018-11-13 14:48:18 UTC
Permalink
Yea, it would be really useful to have more add/remove signals. I think
having a way to see if QNode are added/removed to another QNode. There's
currently no way to see if the QNode tree has been modified structurally at
the moment. Aspects can see these changes, via QSceneChanges, but other
that that, it's all private.

I file a bug for converting QNodeId to QNode*: QTBUG-71767
Hi,
void QComponent::addedToEntity(QEntity *entity);
void QComponent::removedFromEntity(QEntity *entity);
That would be up to you to write a table you would update based on these
signals to keep track of which entities reference which components.
There's no public way of knowing when a component is added or removed
from a QEntity though that would be something trivial to add for 5.13 if
that can make your life easier.
There's no public API to get a QNode* form a QNodeId. Using the private
API QScene::lookupNode would indeed be an option but keep in mind it
could be removed, renamed ... in future versions (though unlikely). That
might be the quickest option to get you started.
Aspects don't get access to the frontend QNode, they only communicate
with QSceneChanges with ids. Usually aspect create a backend
representation of the QNode with only the data they care about and with
the changes and ids, these backend representations are kept in sync with
the frontend.
You could indeed have an aspect but would have to create backend
representations for QEntity and your custom QComponent I suppose, which
sounds like quite a bit of work for what you want to do.
Hopefully this may be of some help,
Paul
--
KDAB (France) S.A.S., a KDAB Group company
Tel: France +33 (0)4 90 84 08 53, http://www.kdab.fr
KDAB - The Qt, C++ and OpenGL Experts
Loading...