|
VR-Engage
2.3
|
DtVreEntityRoleTreeModel provides a three-level tree model where:
The model consumes DtVreAssignmentTracker for assignment state and automatically refreshes when the tracker emits assignmentStateChanged().
#include <vreEntityRoleTreeModel.h>
Public Types | |
Sorting | |
| enum class | EntityOrderMode { ByName , ByAssignment , BySimEngine } |
Public Slots | |
| virtual void | refresh () |
Signals | |
| void | entitySelected (const DtUUID &entityUUID) |
| void | roleSelected (const DtUUID &entityUUID, const std::string &roleName) |
| void | branchDropCompleted (const DtUUID &entityUUID, const std::string &roleName) |
| void | droppedOnRole (const QModelIndex &roleIndex) |
Public Member Functions | |
| DtVreEntityRoleTreeModel (DtVreAssignmentTracker &tracker, QObject *parent=nullptr) | |
| virtual | ~DtVreEntityRoleTreeModel () override |
Entity Management | |
Methods for adding and removing entities from the tree. | |
| virtual void | addEntity (const DtUUID &entityUUID, const std::string &displayName, const std::vector< std::string > &availableRoles, const QIcon &entityIcon=QIcon(), int forceType=0) |
| virtual void | removeEntity (const DtUUID &entityUUID) |
| virtual void | clearEntities () |
| virtual void | setEntitySimEngine (const DtUUID &entityUUID, uint16_t siteId, uint16_t appId) |
| virtual void | moveEntityToForce (const DtUUID &entityUUID, int newRawForceType) |
| virtual void | setEntityAggregateChain (const DtUUID &entityUUID, const std::vector< DtUUID > &chainUUIDs, const std::vector< std::string > &chainNames, const std::vector< QIcon > &chainIcons, const std::vector< int > &chainForces) |
| virtual void | onEntityAggregateChanged (const DtUUID &entityUUID, const std::vector< DtUUID > &newChainUUIDs, const std::vector< std::string > &newChainNames, const std::vector< QIcon > &newChainIcons, const std::vector< int > &newChainForces) |
| virtual void | removeAggregateNode (const DtUUID &aggregateUUID) |
| virtual DtUUID | entityUUID (const QModelIndex &index) const |
| virtual std::string | roleName (const QModelIndex &index) const |
| virtual bool | isForceNode (const QModelIndex &index) const |
| virtual bool | isEntityNode (const QModelIndex &index) const |
| virtual bool | isRoleNode (const QModelIndex &index) const |
| virtual bool | isAggregateNode (const QModelIndex &index) const |
| virtual DtUUID | aggregateUUID (const QModelIndex &index) const |
Drop Resolution Helpers | |
| virtual QModelIndex | findFirstUnassignedRoleIndex (const QModelIndex &root) const |
Filtering | |
Methods for filtering the displayed entities. | |
| virtual void | setFilterPattern (const std::string &pattern) |
| virtual std::string | filterPattern () const |
| virtual void | setShowOnlyAssigned (bool showOnly) |
| virtual bool | showOnlyAssigned () const |
| virtual void | setShowOnlyUnassigned (bool showOnly) |
| virtual bool | showOnlyUnassigned () const |
One-shot User-initiated Sorting | |
applyEntityOrder() performs a single reorder of the tree and must be called only in response to an explicit user action (header button click). Assignment-state changes never trigger an automatic reorder. | |
| virtual void | applyEntityOrder (EntityOrderMode mode, Qt::SortOrder direction) |
| EntityOrderMode | entityOrderMode () const |
| Qt::SortOrder | entityOrderDirection () const |
QAbstractItemModel Interface | |
Standard Qt model interface implementation. | |
| virtual QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const override |
| virtual QModelIndex | parent (const QModelIndex &index) const override |
| virtual int | rowCount (const QModelIndex &parent=QModelIndex()) const override |
| virtual int | columnCount (const QModelIndex &parent=QModelIndex()) const override |
| virtual QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const override |
| virtual Qt::ItemFlags | flags (const QModelIndex &index) const override |
| virtual QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override |
| virtual Qt::DropActions | supportedDropActions () const override |
| virtual Qt::DropActions | supportedDragActions () const override |
| virtual QStringList | mimeTypes () const override |
| virtual QMimeData * | mimeData (const QModelIndexList &indexes) const override |
| virtual bool | canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override |
| virtual bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
Protected Member Functions | |
| virtual VreTreeNode * | nodeFromIndex (const QModelIndex &index) const |
| virtual QModelIndex | indexFromNode (VreTreeNode *node, int column=0) const |
| virtual bool | passesFilter (VreTreeNode *node) const |
| virtual int | visibleRowCount (VreTreeNode *parent) const |
| virtual VreTreeNode * | visibleChild (VreTreeNode *parent, int visibleRow) const |
| virtual VreTreeNode * | getOrCreateForceNode (int forceType) |
| virtual void | removeForceNodeIfEmpty (int bucketKey) |
| virtual void | removeAggregateNodeIfEmpty (const DtUUID &aggregateUUID) |
| virtual VreTreeNode * | getOrCreateAggregateChain (VreTreeNode *forceNode, const std::vector< DtUUID > &chainUUIDs, const std::vector< std::string > &chainNames, const std::vector< QIcon > &chainIcons, const std::vector< int > &chainForces) |
| bool | isEntityEffectivelyAssigned (VreTreeNode *node) const |
| bool | isRoleEffectivelyAssigned (VreTreeNode *node) const |
| bool | isForceEffectivelyAssigned (VreTreeNode *node) const |
| bool | isAggregateEffectivelyAssigned (VreTreeNode *node) const |
| void | sortChildren (VreTreeNode *parent) |
| void | resortAllLevels () |
Static Protected Member Functions | |
| static std::string | forceTypeLabel (int bucketKey) |
| static int | forceBucketKey (int rawForceType) |
| static void | assertGuiThread () |
Protected Attributes | |
| DtVreAssignmentTracker & | myTracker |
| std::vector< std::unique_ptr< VreTreeNode > > | myRootNodes |
| std::map< int, VreTreeNode * > | myForceIndex |
| std::map< DtUUID, VreTreeNode * > | myEntityIndex |
| std::map< DtUUID, VreTreeNode * > | myAggregateIndex |
| std::string | myFilterPattern |
| bool | myShowOnlyAssigned = false |
| bool | myShowOnlyUnassigned = false |
| EntityOrderMode | myEntityOrderMode = EntityOrderMode::ByName |
| Qt::SortOrder | myEntityOrderDirection = Qt::AscendingOrder |
Private Member Functions | |
| DtVreEntityRoleTreeModel (const DtVreEntityRoleTreeModel &)=delete | |
| DtVreEntityRoleTreeModel & | operator= (const DtVreEntityRoleTreeModel &)=delete |
|
strong |
Controls the primary sort key for applyEntityOrder()
| makVre::DtVreEntityRoleTreeModel::DtVreEntityRoleTreeModel | ( | DtVreAssignmentTracker & | tracker, |
| QObject * | parent = nullptr ) |
Constructor.
| tracker | Reference to the assignment tracker for state |
| parent | Optional parent QObject for Qt memory management |
References parent().
Referenced by DtVreEntityRoleTreeModel(), and operator=().
|
overridevirtual |
Destructor.
|
privatedelete |
Copy constructor (deleted)
References DtVreEntityRoleTreeModel().
|
virtual |
Adds an entity to the tree under the appropriate force group.
| entityUUID | The entity's unique identifier |
| displayName | The entity's display name (VR-Forces objectName when available, DIS marking text as a silent fallback) |
| availableRoles | List of role names available on this entity |
| entityIcon | Optional mil-symbol icon for the entity node (from DtVrfGuiSymbolMapper) |
| forceType | SISO force type (1=Friendly, 2=Opposing, 3=Neutral, other=Other) |
Creates a new entity node with child role nodes for each available role, placed under the force group node matching the given force type. Force group nodes are created automatically as needed. If the entity already exists, its roles and force group are updated.
References entityUUID().
|
virtual |
Removes an entity from the tree.
| entityUUID | The entity's unique identifier |
Removes the entity node and all its role children.
References entityUUID().
|
virtual |
Removes all entities from the tree.
|
virtual |
Updates the cached Sim Engine (siteId, applicationId) for an entity.
| entityUUID | The entity's unique identifier |
| siteId | SISO siteId reported by the simulator address |
| appId | SISO applicationId / host reported by the simulator address |
Caches the pair on the entity node and emits a column-2 dataChanged so views refresh the Sim Engine column. No-op if the entity is not in the tree. Safe to call even when column 2 is hidden — the cached value is still updated for an immediate render once the user reveals the column.
Must run on the GUI thread; the cache is consulted directly from data() during paint so updates from off-thread callbacks must be marshalled.
References entityUUID().
|
virtual |
Moves an existing entity to a different force bucket.
| entityUUID | The entity's unique identifier |
| newRawForceType | The new SISO force-type value |
If the entity exists and its current force bucket differs from the one implied by newRawForceType, the entity is removed from its current parent and re-inserted under the new force bucket (creating the new bucket if necessary, and removing the old bucket if it becomes empty). Issues the appropriate row-mutation signals so attached views update incrementally. No-op if the entity does not exist or already lives in the correct bucket.
assertGuiThread()). References entityUUID().
|
virtual |
Sets (or updates) the aggregate ancestry chain for an entity (Phase 8)
| entityUUID | Entity whose ancestry is being asserted |
| chainUUIDs | Aggregate ancestor UUIDs, ROOT-MOST FIRST. Empty vector means "no aggregate parents — place directly under force". |
| chainNames | Display names for each aggregate (parallel to chainUUIDs) |
| chainIcons | Pre-resolved aggregate icons (parallel to chainUUIDs); individual icons may be null |
| chainForces | SISO force-type per aggregate (parallel to chainUUIDs); used for symbol coloring on aggregate rows |
Inserts intermediate AggregateNode rows lazily, indexed by aggregate UUID. Reparents the entity if its current parent differs from the deepest aggregate in the supplied chain (or the force bucket when the chain is empty). Cleans up aggregate ancestors that become childless after the move. No-op if the entity is not yet known to the model — call addEntity() first.
Idempotent: calling repeatedly with the same chain emits no row events.
References entityUUID().
|
virtual |
Reparent an entity row when its aggregate membership changes (Phase 8)
| entityUUID | UUID of the affected entity |
| newChainUUIDs | Aggregate ancestor UUIDs, root-most first; an empty vector places the entity directly under its force group. |
| newChainNames | Display names for the aggregates, parallel to newChainUUIDs. |
| newChainIcons | Pre-resolved aggregate icons, parallel to newChainUUIDs; individual icons may be null. |
| newChainForces | SISO force types for the aggregates, parallel to newChainUUIDs, used for symbol coloring. |
Forwards the supplied ancestry chain to setEntityAggregateChain. No-op when the entity is unknown to the model.
References entityUUID().
|
virtual |
Removes an aggregate node from the tree (Phase 8)
| aggregateUUID | The aggregate's unique identifier |
Called when VR-Forces deletes the aggregate object. Children of the aggregate (entities and nested aggregates) are reparented one level up: either to the grand-parent aggregate or, if none, to the containing force node. Cleans up empty ancestor aggregates after the move. No-op if the UUID is not a known aggregate.
References aggregateUUID().
|
virtual |
Gets the entity UUID for a model index.
| index | The model index |
References index().
Referenced by addEntity(), branchDropCompleted(), entitySelected(), moveEntityToForce(), onEntityAggregateChanged(), removeEntity(), roleSelected(), setEntityAggregateChain(), and setEntitySimEngine().
|
virtual |
Gets the role name for a model index.
| index | The model index |
References index().
Referenced by branchDropCompleted(), and roleSelected().
|
virtual |
Checks if an index represents a force node.
| index | The model index |
References index().
|
virtual |
Checks if an index represents an entity node.
| index | The model index |
References index().
|
virtual |
Checks if an index represents a role node.
| index | The model index |
References index().
|
virtual |
Checks if an index represents an aggregate node (Phase 8)
| index | The model index |
References index().
|
virtual |
Returns the aggregate UUID for a model index (Phase 8)
| index | The model index |
References index().
Referenced by removeAggregateNode(), and removeAggregateNodeIfEmpty().
|
virtual |
Depth-first finds the first unassigned role under a non-role index.
Walks descendants of root in display order (using rowCount() + index()) and returns the QModelIndex of the first role row whose effective assignment state is "unassigned" (i.e., no committed or pending assignment). Honors the active sort order and the aggregates-first-then-entities ordering, because the walk uses the same row enumeration the view uses.
Used by dropMimeData() to resolve a drag onto a force, aggregate, or entity into the specific role that should receive the assignment.
| root | Index of a force, aggregate, or entity node (an invalid index walks the whole tree starting at root level). |
|
virtual |
Sets the filter pattern for entity names.
| pattern | Case-insensitive substring to filter by (empty shows all) |
Only entities whose display name contains the pattern will be shown. The filter is applied to entity nodes; role nodes follow their parent.
|
virtual |
Gets the current filter pattern.
|
virtual |
Sets whether to show only entities with assignments.
| showOnly | If true, hide entities with no assigned roles |
|
virtual |
Gets whether showing only assigned entities.
|
virtual |
Sets whether to show only entities with no assignments.
| showOnly | If true, hide entities that have at least one assigned role |
|
virtual |
Gets whether showing only unassigned entities.
|
virtual |
Reorders the tree by mode and direction (one-shot)
Sorts entity nodes within every force bucket and re-orders force buckets analogously using the same primary/secondary key logic. Roles within an entity are never reordered — they are always kept in .entity-file order.
The call is safe to invoke with the same parameters repeatedly; subsequent assignment-state changes do not reset the order — refresh() only repaints.
Emits layoutAboutToBeChanged / layoutChanged and updates all persistent model indexes correctly.
| mode | Primary sort key (ByName or ByAssignment) |
| direction | Qt::AscendingOrder or Qt::DescendingOrder |
| EntityOrderMode makVre::DtVreEntityRoleTreeModel::entityOrderMode | ( | ) | const |
Returns the mode passed to the last applyEntityOrder() call.
| Qt::SortOrder makVre::DtVreEntityRoleTreeModel::entityOrderDirection | ( | ) | const |
Returns the direction passed to the last applyEntityOrder() call.
|
overridevirtual |
Returns the model index for the given row, column, and parent.
| row | Row number |
| column | Column number |
| parent | Parent index |
References parent().
Referenced by aggregateUUID(), data(), entityUUID(), flags(), isAggregateNode(), isEntityNode(), isForceNode(), isRoleNode(), nodeFromIndex(), parent(), and roleName().
|
overridevirtual |
Returns the parent index for a given index.
| index | The child index |
References index().
Referenced by canDropMimeData(), columnCount(), dropMimeData(), DtVreEntityRoleTreeModel(), index(), rowCount(), sortChildren(), visibleChild(), and visibleRowCount().
|
overridevirtual |
Returns the number of rows under the given parent.
| parent | Parent index |
References parent().
|
overridevirtual |
Returns the number of columns.
| parent | Parent index (unused, constant column count) |
References parent().
|
overridevirtual |
Returns data for the given index and role.
| index | The model index |
| role | The data role |
References index().
Referenced by canDropMimeData(), and dropMimeData().
|
overridevirtual |
Returns item flags for the given index.
| index | The model index |
References index().
|
overridevirtual |
Returns header data for the given section.
| section | Section number |
| orientation | Header orientation |
| role | Data role |
|
overridevirtual |
Returns supported drop actions.
|
overridevirtual |
Returns supported drag actions.
|
overridevirtual |
Returns MIME types accepted for drop.
|
overridevirtual |
Creates MIME data for dragged role nodes.
| indexes | The indexes being dragged |
|
overridevirtual |
Checks whether dropped data can be accepted.
| data | The MIME data being dropped |
| action | The drop action |
| row | Target row (-1 when dropping on an item) |
| column | Target column (-1 when dropping on an item) |
| parent | Parent index (the item being dropped on) |
|
overridevirtual |
Handles dropped MIME data to create a pending assignment.
| data | The MIME data containing the station ID |
| action | The drop action |
| row | Target row (-1 when dropping on an item) |
| column | Target column (-1 when dropping on an item) |
| parent | Parent index (the role node being dropped on) |
|
virtualslot |
Refreshes the model from the tracker.
Called when the tracker's assignment state changes. Emits dataChanged() for all visible items to refresh assignment display.
|
signal |
Emitted when an entity is selected.
| entityUUID | The selected entity UUID |
References entityUUID().
|
signal |
Emitted when a role is selected.
| entityUUID | The entity UUID |
| roleName | The selected role name |
References entityUUID(), and roleName().
|
signal |
Emitted after a branch drop resolves to a specific role.
| entityUUID | The entity that received the assignment |
| roleName | The role that was assigned |
References entityUUID(), and roleName().
|
signal |
Emitted after dropMimeData() resolves to a specific role node.
Carries the QModelIndex of the role row that received the assignment (including direct drops on role rows). The widget connects this to a slot that expands ancestors and selects/scrolls to the role.
| roleIndex | Model index of the assigned role row (column 0) |
|
protectedvirtual |
Gets the tree node for a model index.
| index | The model index |
References index().
|
protectedvirtual |
Creates a model index for a tree node.
| node | The tree node |
| column | Column number |
|
protectedvirtual |
Checks if an entity passes the current filters.
| node | Entity node to check |
|
protectedvirtual |
Gets the visible row count for a parent.
| parent | Parent node (nullptr for root) |
References parent().
|
protectedvirtual |
Gets the nth visible child node.
| parent | Parent node (nullptr for root) |
| visibleRow | Visual row number |
References parent().
|
protectedvirtual |
Gets or creates the force group node for a given force type.
| forceType | SISO force type value |
|
staticprotected |
Returns the display label for a force-bucket key.
| bucketKey | The bucket key as produced by forceBucketKey() |
N is the raw non-standard force value
|
staticprotected |
Returns the bucket key used by myForceIndex for a raw force type.
| rawForceType | SISO force type value |
Because VR-Link's standard SISO force range is 0..3, returning the raw value for any value >3 cannot collide with a standard bucket.
|
protectedvirtual |
Removes a force node if it has no entity children.
| bucketKey | The bucket key whose node to check and possibly remove |
|
protectedvirtual |
Removes an aggregate node if it has no remaining children (Phase 8)
| aggregateUUID | The aggregate whose node to test and possibly remove |
Recurses upward: after removing a now-empty aggregate, checks the grand-parent aggregate as well, and so on. Force-bucket cleanup at the root is delegated to removeForceNodeIfEmpty().
References aggregateUUID().
|
protectedvirtual |
Get-or-create the deepest aggregate node along a chain (Phase 8)
| forceNode | Containing force bucket |
| chainUUIDs | Aggregate ancestor UUIDs, root-most first |
| chainNames | Display names parallel to chainUUIDs |
| chainIcons | Pre-resolved icons parallel to chainUUIDs |
| chainForces | SISO force-type per aggregate (parallel) |
chainUUIDs (the one the entity should be parented under), or forceNode itself if the chain is empty.Lazily inserts AggregateNode rows that don't yet exist anywhere in the model; existing aggregates encountered along the chain are reused via myAggregateIndex even if their current parent does not match forceNode (a separate fix-up reparent step is the caller's responsibility — see setEntityAggregateChain()).
|
staticprotected |
Asserts (in debug builds) that we are on the GUI thread.
Mutating model methods must run on the thread that owns the QApplication event loop. Listener callbacks that originate off the GUI thread should be marshalled through queued signal/slot connections before invoking any tree-mutation entry points.
|
protected |
Checks if an entity has any effective assignment (confirmed or pending)
| node | Entity node to check |
|
protected |
Checks if a role has any effective assignment (confirmed or pending)
| node | Role node to check |
|
protected |
Checks if any entity within a force has any effective assignment.
| node | Force node to check |
|
protected |
Checks if any descendant entity of an aggregate is effectively assigned.
| node | Aggregate node to check |
|
protected |
Sorts children of a parent node by assignment-first then alphabetical.
| parent | Force or entity node whose children to sort, or nullptr to sort the top-level force list (myRootNodes). |
Uses layoutAboutToBeChanged/layoutChanged to preserve expanded state and persistent indexes. Called from refresh() and addEntity().
References parent().
|
protected |
Re-sorts every level of the tree in-place.
Invokes sortChildren(nullptr), then sortChildren() for every force and entity node so that the [assigned-first, alphabetical] ordering stays in sync with the current tracker state. Used by refresh() to make ordering reactive to assignment changes.
|
privatedelete |
Assignment operator (deleted)
References DtVreEntityRoleTreeModel().
|
protected |
Reference to the assignment tracker.
|
protected |
Root nodes (force group nodes)
|
protected |
Map of force type to force node for fast lookup.
|
protected |
Map of entity UUID to entity node for fast lookup.
|
protected |
Map of aggregate UUID to aggregate node for fast lookup (Phase 8)
|
protected |
Current filter pattern (lowercase)
|
protected |
Whether to show only entities with assignments.
|
protected |
Whether to show only entities with no assignments.
|
protected |
Primary key for the last applyEntityOrder() call.
Remembered so the header sort button can toggle direction on successive clicks. Not used by refresh() — assignment changes never retrigger a sort.
|
protected |
Sort direction for the last applyEntityOrder() call.