VR-Engage  2.3
Loading...
Searching...
No Matches
makVre::DtVreEntityRoleTreeModel Class Reference

Detailed Description

DtVreEntityRoleTreeModel provides a three-level tree model where:

  • Level 0 nodes represent force groups (Friendly, Opposing, Neutral, Other)
  • Level 1 nodes represent entities within each force group (expandable)
  • Level 2 nodes represent roles on each entity

The model consumes DtVreAssignmentTracker for assignment state and automatically refreshes when the tracker emits assignmentStateChanged().

Custom Data Roles
The model provides custom data roles (VreTreeDataRole) for accessing assignment-specific information beyond standard Qt roles.
Filtering
The model supports filtering by entity display name (VR-Forces objectName, with DIS marking text as a silent fallback) through setFilterPattern(). Use setShowOnlyAssigned() to hide entities without any role assignments.
Example Usage
model->addEntity("uuid-1234", "Tank Alpha", {"driver", "gunner", "commander"}, QIcon(), 1);
QTreeView* view = new QTreeView(this);
view->setModel(model);
DtVreEntityRoleTreeModel(DtVreAssignmentTracker &tracker, QObject *parent=nullptr)
Constructor.
virtual void addEntity(const DtUUID &entityUUID, const std::string &displayName, const std::vector< std::string > &availableRoles, const QIcon &entityIcon=QIcon(), int forceType=0)
Adds an entity to the tree under the appropriate force group.

#include <vreEntityRoleTreeModel.h>

Inheritance diagram for makVre::DtVreEntityRoleTreeModel:
[legend]

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
 

Member Enumeration Documentation

◆ EntityOrderMode

Controls the primary sort key for applyEntityOrder()

Enumerator
ByName 

Primary key = entity name (alpha); secondary = has-any-assignment.

ByAssignment 

Primary key = has-any-assignment; secondary = entity name (alpha).

BySimEngine 

Primary key = numeric (siteId, applicationId) pair on entity rows. Force buckets fall back to alphabetical name ordering because force nodes have no sim-engine address. Entity rows whose address is not yet known sort last regardless of direction.

Constructor & Destructor Documentation

◆ DtVreEntityRoleTreeModel() [1/2]

makVre::DtVreEntityRoleTreeModel::DtVreEntityRoleTreeModel ( DtVreAssignmentTracker & tracker,
QObject * parent = nullptr )

Constructor.

Parameters
trackerReference to the assignment tracker for state
parentOptional parent QObject for Qt memory management

References parent().

Referenced by DtVreEntityRoleTreeModel(), and operator=().

◆ ~DtVreEntityRoleTreeModel()

virtual makVre::DtVreEntityRoleTreeModel::~DtVreEntityRoleTreeModel ( )
overridevirtual

Destructor.

◆ DtVreEntityRoleTreeModel() [2/2]

makVre::DtVreEntityRoleTreeModel::DtVreEntityRoleTreeModel ( const DtVreEntityRoleTreeModel & )
privatedelete

Copy constructor (deleted)

References DtVreEntityRoleTreeModel().

Member Function Documentation

◆ addEntity()

virtual void makVre::DtVreEntityRoleTreeModel::addEntity ( const DtUUID & entityUUID,
const std::string & displayName,
const std::vector< std::string > & availableRoles,
const QIcon & entityIcon = QIcon(),
int forceType = 0 )
virtual

Adds an entity to the tree under the appropriate force group.

Parameters
entityUUIDThe entity's unique identifier
displayNameThe entity's display name (VR-Forces objectName when available, DIS marking text as a silent fallback)
availableRolesList of role names available on this entity
entityIconOptional mil-symbol icon for the entity node (from DtVrfGuiSymbolMapper)
forceTypeSISO 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().

◆ removeEntity()

virtual void makVre::DtVreEntityRoleTreeModel::removeEntity ( const DtUUID & entityUUID)
virtual

Removes an entity from the tree.

Parameters
entityUUIDThe entity's unique identifier

Removes the entity node and all its role children.

References entityUUID().

◆ clearEntities()

virtual void makVre::DtVreEntityRoleTreeModel::clearEntities ( )
virtual

Removes all entities from the tree.

◆ setEntitySimEngine()

virtual void makVre::DtVreEntityRoleTreeModel::setEntitySimEngine ( const DtUUID & entityUUID,
uint16_t siteId,
uint16_t appId )
virtual

Updates the cached Sim Engine (siteId, applicationId) for an entity.

Parameters
entityUUIDThe entity's unique identifier
siteIdSISO siteId reported by the simulator address
appIdSISO 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().

◆ moveEntityToForce()

virtual void makVre::DtVreEntityRoleTreeModel::moveEntityToForce ( const DtUUID & entityUUID,
int newRawForceType )
virtual

Moves an existing entity to a different force bucket.

Parameters
entityUUIDThe entity's unique identifier
newRawForceTypeThe 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.

Note
Must be invoked on the GUI thread; in debug builds a thread-id assertion fires otherwise (see assertGuiThread()).

References entityUUID().

◆ setEntityAggregateChain()

virtual void makVre::DtVreEntityRoleTreeModel::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

Sets (or updates) the aggregate ancestry chain for an entity (Phase 8)

Parameters
entityUUIDEntity whose ancestry is being asserted
chainUUIDsAggregate ancestor UUIDs, ROOT-MOST FIRST. Empty vector means "no aggregate parents — place directly under force".
chainNamesDisplay names for each aggregate (parallel to chainUUIDs)
chainIconsPre-resolved aggregate icons (parallel to chainUUIDs); individual icons may be null
chainForcesSISO 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().

◆ onEntityAggregateChanged()

virtual void makVre::DtVreEntityRoleTreeModel::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

Reparent an entity row when its aggregate membership changes (Phase 8)

Parameters
entityUUIDUUID of the affected entity
newChainUUIDsAggregate ancestor UUIDs, root-most first; an empty vector places the entity directly under its force group.
newChainNamesDisplay names for the aggregates, parallel to newChainUUIDs.
newChainIconsPre-resolved aggregate icons, parallel to newChainUUIDs; individual icons may be null.
newChainForcesSISO 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().

◆ removeAggregateNode()

virtual void makVre::DtVreEntityRoleTreeModel::removeAggregateNode ( const DtUUID & aggregateUUID)
virtual

Removes an aggregate node from the tree (Phase 8)

Parameters
aggregateUUIDThe 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().

◆ entityUUID()

virtual DtUUID makVre::DtVreEntityRoleTreeModel::entityUUID ( const QModelIndex & index) const
virtual

Gets the entity UUID for a model index.

Parameters
indexThe model index
Returns
Entity UUID or null UUID if invalid index

References index().

Referenced by addEntity(), branchDropCompleted(), entitySelected(), moveEntityToForce(), onEntityAggregateChanged(), removeEntity(), roleSelected(), setEntityAggregateChain(), and setEntitySimEngine().

◆ roleName()

virtual std::string makVre::DtVreEntityRoleTreeModel::roleName ( const QModelIndex & index) const
virtual

Gets the role name for a model index.

Parameters
indexThe model index
Returns
Role name or empty string if not a role node

References index().

Referenced by branchDropCompleted(), and roleSelected().

◆ isForceNode()

virtual bool makVre::DtVreEntityRoleTreeModel::isForceNode ( const QModelIndex & index) const
virtual

Checks if an index represents a force node.

Parameters
indexThe model index
Returns
True if the index is a force (level 0) node

References index().

◆ isEntityNode()

virtual bool makVre::DtVreEntityRoleTreeModel::isEntityNode ( const QModelIndex & index) const
virtual

Checks if an index represents an entity node.

Parameters
indexThe model index
Returns
True if the index is an entity (level 1) node

References index().

◆ isRoleNode()

virtual bool makVre::DtVreEntityRoleTreeModel::isRoleNode ( const QModelIndex & index) const
virtual

Checks if an index represents a role node.

Parameters
indexThe model index
Returns
True if the index is a role (level 2) node

References index().

◆ isAggregateNode()

virtual bool makVre::DtVreEntityRoleTreeModel::isAggregateNode ( const QModelIndex & index) const
virtual

Checks if an index represents an aggregate node (Phase 8)

Parameters
indexThe model index
Returns
True if the index is an aggregate node

References index().

◆ aggregateUUID()

virtual DtUUID makVre::DtVreEntityRoleTreeModel::aggregateUUID ( const QModelIndex & index) const
virtual

Returns the aggregate UUID for a model index (Phase 8)

Parameters
indexThe model index
Returns
Aggregate UUID, or null UUID if the index is not an aggregate row

References index().

Referenced by removeAggregateNode(), and removeAggregateNodeIfEmpty().

◆ findFirstUnassignedRoleIndex()

virtual QModelIndex makVre::DtVreEntityRoleTreeModel::findFirstUnassignedRoleIndex ( const QModelIndex & root) const
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.

Parameters
rootIndex of a force, aggregate, or entity node (an invalid index walks the whole tree starting at root level).
Returns
Index of the chosen role row (column 0), or an invalid index if the subtree contains no unassigned role.

◆ setFilterPattern()

virtual void makVre::DtVreEntityRoleTreeModel::setFilterPattern ( const std::string & pattern)
virtual

Sets the filter pattern for entity names.

Parameters
patternCase-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.

◆ filterPattern()

virtual std::string makVre::DtVreEntityRoleTreeModel::filterPattern ( ) const
virtual

Gets the current filter pattern.

Returns
The current filter pattern

◆ setShowOnlyAssigned()

virtual void makVre::DtVreEntityRoleTreeModel::setShowOnlyAssigned ( bool showOnly)
virtual

Sets whether to show only entities with assignments.

Parameters
showOnlyIf true, hide entities with no assigned roles

◆ showOnlyAssigned()

virtual bool makVre::DtVreEntityRoleTreeModel::showOnlyAssigned ( ) const
virtual

Gets whether showing only assigned entities.

Returns
True if filtering to only show assigned entities

◆ setShowOnlyUnassigned()

virtual void makVre::DtVreEntityRoleTreeModel::setShowOnlyUnassigned ( bool showOnly)
virtual

Sets whether to show only entities with no assignments.

Parameters
showOnlyIf true, hide entities that have at least one assigned role

◆ showOnlyUnassigned()

virtual bool makVre::DtVreEntityRoleTreeModel::showOnlyUnassigned ( ) const
virtual

Gets whether showing only unassigned entities.

Returns
True if filtering to only show fully unassigned entities

◆ applyEntityOrder()

virtual void makVre::DtVreEntityRoleTreeModel::applyEntityOrder ( EntityOrderMode mode,
Qt::SortOrder direction )
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.

Parameters
modePrimary sort key (ByName or ByAssignment)
directionQt::AscendingOrder or Qt::DescendingOrder

◆ entityOrderMode()

EntityOrderMode makVre::DtVreEntityRoleTreeModel::entityOrderMode ( ) const

Returns the mode passed to the last applyEntityOrder() call.

Returns
Current entity order mode

◆ entityOrderDirection()

Qt::SortOrder makVre::DtVreEntityRoleTreeModel::entityOrderDirection ( ) const

Returns the direction passed to the last applyEntityOrder() call.

Returns
Current entity sort direction

◆ index()

virtual QModelIndex makVre::DtVreEntityRoleTreeModel::index ( int row,
int column,
const QModelIndex & parent = QModelIndex() ) const
overridevirtual

Returns the model index for the given row, column, and parent.

Parameters
rowRow number
columnColumn number
parentParent index
Returns
Model index for the specified cell

References parent().

Referenced by aggregateUUID(), data(), entityUUID(), flags(), isAggregateNode(), isEntityNode(), isForceNode(), isRoleNode(), nodeFromIndex(), parent(), and roleName().

◆ parent()

virtual QModelIndex makVre::DtVreEntityRoleTreeModel::parent ( const QModelIndex & index) const
overridevirtual

Returns the parent index for a given index.

Parameters
indexThe child index
Returns
Parent index or invalid index for root items

References index().

Referenced by canDropMimeData(), columnCount(), dropMimeData(), DtVreEntityRoleTreeModel(), index(), rowCount(), sortChildren(), visibleChild(), and visibleRowCount().

◆ rowCount()

virtual int makVre::DtVreEntityRoleTreeModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
overridevirtual

Returns the number of rows under the given parent.

Parameters
parentParent index
Returns
Number of child rows

References parent().

◆ columnCount()

virtual int makVre::DtVreEntityRoleTreeModel::columnCount ( const QModelIndex & parent = QModelIndex()) const
overridevirtual

Returns the number of columns.

Parameters
parentParent index (unused, constant column count)
Returns
Always returns 3 (entity-role column, assignment column, Sim Engine column)

References parent().

◆ data()

virtual QVariant makVre::DtVreEntityRoleTreeModel::data ( const QModelIndex & index,
int role = Qt::DisplayRole ) const
overridevirtual

Returns data for the given index and role.

Parameters
indexThe model index
roleThe data role
Returns
Requested data as QVariant

References index().

Referenced by canDropMimeData(), and dropMimeData().

◆ flags()

virtual Qt::ItemFlags makVre::DtVreEntityRoleTreeModel::flags ( const QModelIndex & index) const
overridevirtual

Returns item flags for the given index.

Parameters
indexThe model index
Returns
Item flags (e.g., selectable, enabled)

References index().

◆ headerData()

virtual QVariant makVre::DtVreEntityRoleTreeModel::headerData ( int section,
Qt::Orientation orientation,
int role = Qt::DisplayRole ) const
overridevirtual

Returns header data for the given section.

Parameters
sectionSection number
orientationHeader orientation
roleData role
Returns
Header data as QVariant

◆ supportedDropActions()

virtual Qt::DropActions makVre::DtVreEntityRoleTreeModel::supportedDropActions ( ) const
overridevirtual

Returns supported drop actions.

Returns
Drop actions supported by this model (CopyAction for assignment)

◆ supportedDragActions()

virtual Qt::DropActions makVre::DtVreEntityRoleTreeModel::supportedDragActions ( ) const
overridevirtual

Returns supported drag actions.

Returns
CopyAction for dragging role assignments

◆ mimeTypes()

virtual QStringList makVre::DtVreEntityRoleTreeModel::mimeTypes ( ) const
overridevirtual

Returns MIME types accepted for drop.

Returns
List of MIME types (station ID and role-assignment formats)

◆ mimeData()

virtual QMimeData * makVre::DtVreEntityRoleTreeModel::mimeData ( const QModelIndexList & indexes) const
overridevirtual

Creates MIME data for dragged role nodes.

Parameters
indexesThe indexes being dragged
Returns
MIME data containing entity UUID and role name, or nullptr

◆ canDropMimeData()

virtual bool makVre::DtVreEntityRoleTreeModel::canDropMimeData ( const QMimeData * data,
Qt::DropAction action,
int row,
int column,
const QModelIndex & parent ) const
overridevirtual

Checks whether dropped data can be accepted.

Parameters
dataThe MIME data being dropped
actionThe drop action
rowTarget row (-1 when dropping on an item)
columnTarget column (-1 when dropping on an item)
parentParent index (the item being dropped on)
Returns
True if the drop can be accepted (only role nodes accept drops)

References data(), and parent().

◆ dropMimeData()

virtual bool makVre::DtVreEntityRoleTreeModel::dropMimeData ( const QMimeData * data,
Qt::DropAction action,
int row,
int column,
const QModelIndex & parent )
overridevirtual

Handles dropped MIME data to create a pending assignment.

Parameters
dataThe MIME data containing the station ID
actionThe drop action
rowTarget row (-1 when dropping on an item)
columnTarget column (-1 when dropping on an item)
parentParent index (the role node being dropped on)
Returns
True if the drop was handled successfully

References data(), and parent().

◆ refresh

virtual void makVre::DtVreEntityRoleTreeModel::refresh ( )
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.

◆ entitySelected

void makVre::DtVreEntityRoleTreeModel::entitySelected ( const DtUUID & entityUUID)
signal

Emitted when an entity is selected.

Parameters
entityUUIDThe selected entity UUID

References entityUUID().

◆ roleSelected

void makVre::DtVreEntityRoleTreeModel::roleSelected ( const DtUUID & entityUUID,
const std::string & roleName )
signal

Emitted when a role is selected.

Parameters
entityUUIDThe entity UUID
roleNameThe selected role name

References entityUUID(), and roleName().

◆ branchDropCompleted

void makVre::DtVreEntityRoleTreeModel::branchDropCompleted ( const DtUUID & entityUUID,
const std::string & roleName )
signal

Emitted after a branch drop resolves to a specific role.

Parameters
entityUUIDThe entity that received the assignment
roleNameThe role that was assigned

References entityUUID(), and roleName().

◆ droppedOnRole

void makVre::DtVreEntityRoleTreeModel::droppedOnRole ( const QModelIndex & roleIndex)
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.

Parameters
roleIndexModel index of the assigned role row (column 0)

◆ nodeFromIndex()

virtual VreTreeNode * makVre::DtVreEntityRoleTreeModel::nodeFromIndex ( const QModelIndex & index) const
protectedvirtual

Gets the tree node for a model index.

Parameters
indexThe model index
Returns
Pointer to tree node or nullptr if invalid

References index().

◆ indexFromNode()

virtual QModelIndex makVre::DtVreEntityRoleTreeModel::indexFromNode ( VreTreeNode * node,
int column = 0 ) const
protectedvirtual

Creates a model index for a tree node.

Parameters
nodeThe tree node
columnColumn number
Returns
Model index for the node

◆ passesFilter()

virtual bool makVre::DtVreEntityRoleTreeModel::passesFilter ( VreTreeNode * node) const
protectedvirtual

Checks if an entity passes the current filters.

Parameters
nodeEntity node to check
Returns
True if the entity should be visible

◆ visibleRowCount()

virtual int makVre::DtVreEntityRoleTreeModel::visibleRowCount ( VreTreeNode * parent) const
protectedvirtual

Gets the visible row count for a parent.

Parameters
parentParent node (nullptr for root)
Returns
Number of visible children

References parent().

◆ visibleChild()

virtual VreTreeNode * makVre::DtVreEntityRoleTreeModel::visibleChild ( VreTreeNode * parent,
int visibleRow ) const
protectedvirtual

Gets the nth visible child node.

Parameters
parentParent node (nullptr for root)
visibleRowVisual row number
Returns
Pointer to the visible child node

References parent().

◆ getOrCreateForceNode()

virtual VreTreeNode * makVre::DtVreEntityRoleTreeModel::getOrCreateForceNode ( int forceType)
protectedvirtual

Gets or creates the force group node for a given force type.

Parameters
forceTypeSISO force type value
Returns
Pointer to the force group node

◆ forceTypeLabel()

static std::string makVre::DtVreEntityRoleTreeModel::forceTypeLabel ( int bucketKey)
staticprotected

Returns the display label for a force-bucket key.

Parameters
bucketKeyThe bucket key as produced by forceBucketKey()
Returns
Display name: "Friendly", "Opposing", "Neutral", "Other", or "Other:N" where N is the raw non-standard force value

◆ forceBucketKey()

static int makVre::DtVreEntityRoleTreeModel::forceBucketKey ( int rawForceType)
staticprotected

Returns the bucket key used by myForceIndex for a raw force type.

Parameters
rawForceTypeSISO force type value
Returns
Bucket key. Standard SISO values 0..3 map to themselves (Other/Friendly/Opposing/Neutral). Non-standard values (>3) are returned as-is so each distinct non-standard value gets its own "Other:N" sub-bucket.

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.

◆ removeForceNodeIfEmpty()

virtual void makVre::DtVreEntityRoleTreeModel::removeForceNodeIfEmpty ( int bucketKey)
protectedvirtual

Removes a force node if it has no entity children.

Parameters
bucketKeyThe bucket key whose node to check and possibly remove

◆ removeAggregateNodeIfEmpty()

virtual void makVre::DtVreEntityRoleTreeModel::removeAggregateNodeIfEmpty ( const DtUUID & aggregateUUID)
protectedvirtual

Removes an aggregate node if it has no remaining children (Phase 8)

Parameters
aggregateUUIDThe 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().

◆ getOrCreateAggregateChain()

virtual VreTreeNode * makVre::DtVreEntityRoleTreeModel::getOrCreateAggregateChain ( VreTreeNode * forceNode,
const std::vector< DtUUID > & chainUUIDs,
const std::vector< std::string > & chainNames,
const std::vector< QIcon > & chainIcons,
const std::vector< int > & chainForces )
protectedvirtual

Get-or-create the deepest aggregate node along a chain (Phase 8)

Parameters
forceNodeContaining force bucket
chainUUIDsAggregate ancestor UUIDs, root-most first
chainNamesDisplay names parallel to chainUUIDs
chainIconsPre-resolved icons parallel to chainUUIDs
chainForcesSISO force-type per aggregate (parallel)
Returns
Pointer to the deepest aggregate node in 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()).

◆ assertGuiThread()

static void makVre::DtVreEntityRoleTreeModel::assertGuiThread ( )
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.

◆ isEntityEffectivelyAssigned()

bool makVre::DtVreEntityRoleTreeModel::isEntityEffectivelyAssigned ( VreTreeNode * node) const
protected

Checks if an entity has any effective assignment (confirmed or pending)

Parameters
nodeEntity node to check
Returns
True if any role on this entity has an assignment

◆ isRoleEffectivelyAssigned()

bool makVre::DtVreEntityRoleTreeModel::isRoleEffectivelyAssigned ( VreTreeNode * node) const
protected

Checks if a role has any effective assignment (confirmed or pending)

Parameters
nodeRole node to check
Returns
True if this role has at least one assigned station

◆ isForceEffectivelyAssigned()

bool makVre::DtVreEntityRoleTreeModel::isForceEffectivelyAssigned ( VreTreeNode * node) const
protected

Checks if any entity within a force has any effective assignment.

Parameters
nodeForce node to check
Returns
True if any entity under this force has at least one assigned role

◆ isAggregateEffectivelyAssigned()

bool makVre::DtVreEntityRoleTreeModel::isAggregateEffectivelyAssigned ( VreTreeNode * node) const
protected

Checks if any descendant entity of an aggregate is effectively assigned.

Parameters
nodeAggregate node to check
Returns
True if any nested entity under this aggregate has at least one assigned role. Recurses through sub-aggregates.

◆ sortChildren()

void makVre::DtVreEntityRoleTreeModel::sortChildren ( VreTreeNode * parent)
protected

Sorts children of a parent node by assignment-first then alphabetical.

Parameters
parentForce 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().

◆ resortAllLevels()

void makVre::DtVreEntityRoleTreeModel::resortAllLevels ( )
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.

◆ operator=()

DtVreEntityRoleTreeModel & makVre::DtVreEntityRoleTreeModel::operator= ( const DtVreEntityRoleTreeModel & )
privatedelete

Assignment operator (deleted)

References DtVreEntityRoleTreeModel().

Member Data Documentation

◆ myTracker

DtVreAssignmentTracker& makVre::DtVreEntityRoleTreeModel::myTracker
protected

Reference to the assignment tracker.

◆ myRootNodes

std::vector<std::unique_ptr<VreTreeNode> > makVre::DtVreEntityRoleTreeModel::myRootNodes
protected

Root nodes (force group nodes)

◆ myForceIndex

std::map<int, VreTreeNode*> makVre::DtVreEntityRoleTreeModel::myForceIndex
protected

Map of force type to force node for fast lookup.

◆ myEntityIndex

std::map<DtUUID, VreTreeNode*> makVre::DtVreEntityRoleTreeModel::myEntityIndex
protected

Map of entity UUID to entity node for fast lookup.

◆ myAggregateIndex

std::map<DtUUID, VreTreeNode*> makVre::DtVreEntityRoleTreeModel::myAggregateIndex
protected

Map of aggregate UUID to aggregate node for fast lookup (Phase 8)

◆ myFilterPattern

std::string makVre::DtVreEntityRoleTreeModel::myFilterPattern
protected

Current filter pattern (lowercase)

◆ myShowOnlyAssigned

bool makVre::DtVreEntityRoleTreeModel::myShowOnlyAssigned = false
protected

Whether to show only entities with assignments.

◆ myShowOnlyUnassigned

bool makVre::DtVreEntityRoleTreeModel::myShowOnlyUnassigned = false
protected

Whether to show only entities with no assignments.

◆ myEntityOrderMode

EntityOrderMode makVre::DtVreEntityRoleTreeModel::myEntityOrderMode = EntityOrderMode::ByName
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.

◆ myEntityOrderDirection

Qt::SortOrder makVre::DtVreEntityRoleTreeModel::myEntityOrderDirection = Qt::AscendingOrder
protected

Sort direction for the last applyEntityOrder() call.


The documentation for this class was generated from the following file: