VR-Engage  2.3
Loading...
Searching...
No Matches
vreEntityRoleTreeModel.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreEntityRoleTreeModel.h
7//! \ingroup vreManager
8//! \brief Tree model for entity/role hierarchy display
9//!
10//! This file defines the DtVreEntityRoleTreeModel class, which provides a
11//! Qt tree model for displaying entities and their available roles. The model
12//! consumes DtVreAssignmentTracker for assignment state.
13
14#pragma once
15
16#include "vreManager/export.h"
17
18#include <QAbstractItemModel>
19#include <QIcon>
20
21#include <vrfutil/uuid.h>
22
23#include <map>
24#include <memory>
25#include <string>
26#include <vector>
27
28class QMimeData;
29
30
31namespace makVre
32{
33
35
36
37//! \brief Node type for the (possibly four-level+) hierarchy
38//!
39//! Phase 8: AggregateNode rows may appear between a ForceNode and the
40//! EntityNode rows it contains, mirroring VR-Forces aggregate composition.
41//! Aggregates may also nest, so the tree depth is no longer bounded.
43{
44 ForceNode, //!< Top-level force grouping node (friendly, opposing, etc.)
45 AggregateNode, //!< Optional intermediate aggregate node (may nest)
46 EntityNode, //!< Entity row (parent may be a ForceNode or an AggregateNode)
47 RoleNode //!< Leaf-level role node
48};
49
50
51//! \brief Standard SISO/VR-Link force category buckets
52//!
53//! Mirrors VR-Link's \c DtForceType enumeration (\c disEnums.h):
54//! 0 = Other, 1 = Friendly, 2 = Opposing, 3 = Neutral.
55//!
56//! Any raw force-type value that falls outside this set is grouped under its
57//! own \c "Other:N" sub-bucket — see forceCategoryFromRaw() and
58//! DtVreEntityRoleTreeModel::forceTypeLabel().
59enum class ForceCategory
60{
61 Other, //!< Raw value 0 (DtForceOther) — the canonical SISO "Other" bucket
62 Friendly, //!< Raw value 1 (DtForceFriendly)
63 Opposing, //!< Raw value 2 (DtForceOpposing)
64 Neutral, //!< Raw value 3 (DtForceNeutral)
65 OtherRaw //!< Non-standard raw value (>3) — bucketed as "Other:N" per Len
66};
67
68
69//! \brief Maps a raw SISO force-type value to a ForceCategory
70//! \param rawForceType The integer force-type value as reported by VR-Link
71//! \return The matching ForceCategory; \c OtherRaw for any value outside 0..3
72//!
73//! Standard VR-Link force types (\c DtForceOther/Friendly/Opposing/Neutral)
74//! map to their named category. All other raw values map to \c OtherRaw and
75//! are sub-bucketed by the raw numeric value at the model level (one
76//! "Other:N" tree node per distinct non-standard value).
78
79
80//! \brief Custom data roles for entity/role tree items
81//!
82//! These roles extend Qt's standard roles to provide assignment-specific
83//! data for delegates and other consumers.
85{
86 //! \brief QString: Entity UUID
87 EntityUUIDRole = Qt::UserRole + 1,
88
89 //! \brief QString: Role name (empty for entity and force nodes)
91
92 //! \brief bool: True if this is a force node (level 0)
94
95 //! \brief bool: True if this is an entity node (level 1)
97
98 //! \brief bool: True if this is a role node (level 2)
100
101 //! \brief bool: True if role has confirmed or pending assignment
103
104 //! \brief bool: True if has pending assignment
106
107 //! \brief bool: True if pending assignment creates conflict
109
110 //! \brief int: Number of roles with assignments on entity
112
113 //! \brief int: Total number of roles on entity
115
116 //! \brief QString: Badge text like "(2/3)" for entity nodes
118
119 //! \brief QString: Comma-separated station names assigned to role
121
122 //! \brief bool: True if station is in spectator mode
124
125 //! \brief QVariantList: Per-station parts for rich rendering.
126 //! Each entry is a QVariantMap with keys:
127 //! "name" -> QString (station display name)
128 //! "spectator" -> bool (true if in spectator mode)
129 //! "pending" -> bool (true if pending assignment)
131
132 //! \brief uint: Numeric composite key (siteId<<16 | applicationId) for the
133 //! Sim Engine column (column 2) on entity rows. Returns an invalid
134 //! QVariant when the address is not yet known, so unknown entries can
135 //! be sorted to the bottom by a comparator that treats invalid as
136 //! "greater than" all known keys. Force/role rows return invalid.
137 //!
138 //! Provided in addition to Qt::DisplayRole so that proxy comparators can
139 //! sort numerically without re-parsing the "site:app" display string.
141
142 //! \brief bool: True if this is an aggregate node (Phase 8)
144
145 //! \brief QString: Aggregate UUID (empty for non-aggregate rows)
147};
148
149
150//! \brief Internal tree node for force/entity/role hierarchy
151//!
152//! Represents a force node (level 0), entity node (level 1), or role node (level 2).
153//! Used internally by DtVreEntityRoleTreeModel to build the tree structure.
155{
156 //! \brief Node type in the hierarchy
158
159 //! \brief Entity UUID (for entity and role nodes; null UUID for force nodes)
161
162 //! \brief Aggregate UUID (Phase 8 — valid only for AggregateNode rows)
164
165 //! \brief Role name (empty for entity and force nodes)
166 std::string myRoleName;
167
168 //! \brief Display name (force label, entity objectName / marking-text fallback, or role name)
169 std::string myDisplayName;
170
171 //! \brief Force type value (force nodes only; SISO force ID)
172 int myForceType = 0;
173
174 //! \brief Available roles for this entity (entity nodes only)
175 std::vector<std::string> myAvailableRoles;
176
177 //! \brief Parent node (nullptr for root force nodes)
179
180 //! \brief Child nodes (entity nodes for force nodes, role nodes for entity nodes)
181 std::vector<std::unique_ptr<VreTreeNode>> myChildren;
182
183 //! \brief Index of this node within parent's children
184 int myRow = 0;
185
186 //! \brief Entity type icon (entity nodes only; null for force and role nodes)
188
189 //! \brief Cached assigned-role count for this node (-1 = invalid / not yet cached)
190 //!
191 //! Used by entity and force nodes to avoid recomputing assignment aggregates on
192 //! every data() call. Invalidated by refresh() on every assignment-state change.
193 mutable int myCachedAssignedCount = -1;
194
195 //! \brief Cached total-role count for this node (-1 = invalid / not yet cached)
196 //!
197 //! Parallel to myCachedAssignedCount. For entity nodes the total equals the
198 //! number of available roles, which is stable between assignment events;
199 //! for force nodes it is the sum across child entities.
200 mutable int myCachedTotalCount = -1;
201
202 //! \brief Cached SISO siteId for the Sim Engine column (entity nodes only)
203 uint16_t mySimEngineSite = 0;
204
205 //! \brief Cached SISO applicationId / host for the Sim Engine column (entity nodes only)
206 uint16_t mySimEngineApp = 0;
207
208 //! \brief True if the cached (site, app) pair has been populated for this entity
209 //!
210 //! Force / role nodes always leave this false. Entity rows whose simulator
211 //! address has not yet been observed also leave this false; the model treats
212 //! them as "unknown" — the Sim Engine column displays an empty cell and the
213 //! BySimEngine sort drops them to the bottom regardless of direction.
214 bool mySimEngineKnown = false;
215
216 //! \brief Pre-formatted "site:app" string for Qt::DisplayRole on column 2
217 //!
218 //! Empty when mySimEngineKnown is false. Cached so the model never blocks
219 //! on a live reflected-entity lookup during paint.
220 std::string mySimEngineCached;
221};
222
223
224//! \brief Tree model for entity/role hierarchy display
225//!
226//! DtVreEntityRoleTreeModel provides a three-level tree model where:
227//! - Level 0 nodes represent force groups (Friendly, Opposing, Neutral, Other)
228//! - Level 1 nodes represent entities within each force group (expandable)
229//! - Level 2 nodes represent roles on each entity
230//!
231//! The model consumes DtVreAssignmentTracker for assignment state and
232//! automatically refreshes when the tracker emits assignmentStateChanged().
233//!
234//! \par Custom Data Roles
235//! The model provides custom data roles (VreTreeDataRole) for accessing
236//! assignment-specific information beyond standard Qt roles.
237//!
238//! \par Filtering
239//! The model supports filtering by entity display name (VR-Forces objectName,
240//! with DIS marking text as a silent fallback) through
241//! setFilterPattern(). Use setShowOnlyAssigned() to hide entities
242//! without any role assignments.
243//!
244//! \par Example Usage
245//! \code
246//! DtVreEntityRoleTreeModel* model = new DtVreEntityRoleTreeModel(tracker, this);
247//! model->addEntity("uuid-1234", "Tank Alpha", {"driver", "gunner", "commander"}, QIcon(), 1);
248//!
249//! QTreeView* view = new QTreeView(this);
250//! view->setModel(model);
251//! \endcode
252class VREMANAGER_DLL DtVreEntityRoleTreeModel : public QAbstractItemModel
253{
254 Q_OBJECT
255
256public:
257 // -------------------------------------------------------------------------
258 //! @name Sorting
259 //! @{
260 // -------------------------------------------------------------------------
261
262 //! \brief Controls the primary sort key for applyEntityOrder()
264 {
265 //! Primary key = entity name (alpha); secondary = has-any-assignment.
267
268 //! Primary key = has-any-assignment; secondary = entity name (alpha).
270
271 //! Primary key = numeric (siteId, applicationId) pair on entity rows.
272 //! Force buckets fall back to alphabetical name ordering because force
273 //! nodes have no sim-engine address. Entity rows whose address is not
274 //! yet known sort last regardless of direction.
276 };
277
278 //! @}
279
280 //! \brief Constructor
281 //! \param tracker Reference to the assignment tracker for state
282 //! \param parent Optional parent QObject for Qt memory management
284
285 //! \brief Destructor
286 virtual ~DtVreEntityRoleTreeModel() override;
287
288 // -------------------------------------------------------------------------
289 //! @name Entity Management
290 //! Methods for adding and removing entities from the tree.
291 //! @{
292 // -------------------------------------------------------------------------
293
294 //! \brief Adds an entity to the tree under the appropriate force group
295 //! \param entityUUID The entity's unique identifier
296 //! \param displayName The entity's display name (VR-Forces objectName when
297 //! available, DIS marking text as a silent fallback)
298 //! \param availableRoles List of role names available on this entity
299 //! \param entityIcon Optional mil-symbol icon for the entity node (from DtVrfGuiSymbolMapper)
300 //! \param forceType SISO force type (1=Friendly, 2=Opposing, 3=Neutral, other=Other)
301 //!
302 //! Creates a new entity node with child role nodes for each available role,
303 //! placed under the force group node matching the given force type.
304 //! Force group nodes are created automatically as needed.
305 //! If the entity already exists, its roles and force group are updated.
306 virtual void addEntity(const DtUUID& entityUUID, const std::string& displayName,
307 const std::vector<std::string>& availableRoles,
308 const QIcon& entityIcon = QIcon(), int forceType = 0);
309
310 //! \brief Removes an entity from the tree
311 //! \param entityUUID The entity's unique identifier
312 //!
313 //! Removes the entity node and all its role children.
314 virtual void removeEntity(const DtUUID& entityUUID);
315
316 //! \brief Removes all entities from the tree
317 virtual void clearEntities();
318
319 //! \brief Updates the cached Sim Engine (siteId, applicationId) for an entity
320 //! \param entityUUID The entity's unique identifier
321 //! \param siteId SISO siteId reported by the simulator address
322 //! \param appId SISO applicationId / host reported by the simulator address
323 //!
324 //! Caches the pair on the entity node and emits a column-2 dataChanged so
325 //! views refresh the Sim Engine column. No-op if the entity is not in the
326 //! tree. Safe to call even when column 2 is hidden — the cached value is
327 //! still updated for an immediate render once the user reveals the column.
328 //!
329 //! Must run on the GUI thread; the cache is consulted directly from data()
330 //! during paint so updates from off-thread callbacks must be marshalled.
331 virtual void setEntitySimEngine(const DtUUID& entityUUID,
332 uint16_t siteId, uint16_t appId);
333
334 //! \brief Moves an existing entity to a different force bucket
335 //! \param entityUUID The entity's unique identifier
336 //! \param newRawForceType The new SISO force-type value
337 //!
338 //! If the entity exists and its current force bucket differs from the one
339 //! implied by \c newRawForceType, the entity is removed from its current
340 //! parent and re-inserted under the new force bucket (creating the new
341 //! bucket if necessary, and removing the old bucket if it becomes empty).
342 //! Issues the appropriate row-mutation signals so attached views update
343 //! incrementally. No-op if the entity does not exist or already lives in
344 //! the correct bucket.
345 //!
346 //! \note Must be invoked on the GUI thread; in debug builds a thread-id
347 //! assertion fires otherwise (see \c assertGuiThread()).
348 virtual void moveEntityToForce(const DtUUID& entityUUID, int newRawForceType);
349
350 //! \brief Sets (or updates) the aggregate ancestry chain for an entity (Phase 8)
351 //! \param entityUUID Entity whose ancestry is being asserted
352 //! \param chainUUIDs Aggregate ancestor UUIDs, ROOT-MOST FIRST. Empty vector
353 //! means "no aggregate parents — place directly under force".
354 //! \param chainNames Display names for each aggregate (parallel to \c chainUUIDs)
355 //! \param chainIcons Pre-resolved aggregate icons (parallel to \c chainUUIDs);
356 //! individual icons may be null
357 //! \param chainForces SISO force-type per aggregate (parallel to \c chainUUIDs);
358 //! used for symbol coloring on aggregate rows
359 //!
360 //! Inserts intermediate AggregateNode rows lazily, indexed by aggregate UUID.
361 //! Reparents the entity if its current parent differs from the deepest
362 //! aggregate in the supplied chain (or the force bucket when the chain is
363 //! empty). Cleans up aggregate ancestors that become childless after the
364 //! move. No-op if the entity is not yet known to the model — call
365 //! \c addEntity() first.
366 //!
367 //! Idempotent: calling repeatedly with the same chain emits no row events.
368 virtual void setEntityAggregateChain(const DtUUID& entityUUID,
369 const std::vector<DtUUID>& chainUUIDs,
370 const std::vector<std::string>& chainNames,
371 const std::vector<QIcon>& chainIcons,
372 const std::vector<int>& chainForces);
373
374 //! \brief Reparent an entity row when its aggregate membership changes (Phase 8)
375 //! \param entityUUID UUID of the affected entity
376 //! \param newChainUUIDs Aggregate ancestor UUIDs, root-most first; an empty vector places
377 //! the entity directly under its force group.
378 //! \param newChainNames Display names for the aggregates, parallel to newChainUUIDs.
379 //! \param newChainIcons Pre-resolved aggregate icons, parallel to newChainUUIDs; individual icons may be null.
380 //! \param newChainForces SISO force types for the aggregates, parallel to newChainUUIDs,
381 //! used for symbol coloring.
382 //!
383 //! Forwards the supplied ancestry chain to \c setEntityAggregateChain.
384 //! No-op when the entity is unknown to the model.
385 virtual void onEntityAggregateChanged(const DtUUID& entityUUID,
386 const std::vector<DtUUID>& newChainUUIDs,
387 const std::vector<std::string>& newChainNames,
388 const std::vector<QIcon>& newChainIcons,
389 const std::vector<int>& newChainForces);
390
391 //! \brief Removes an aggregate node from the tree (Phase 8)
392 //! \param aggregateUUID The aggregate's unique identifier
393 //!
394 //! Called when VR-Forces deletes the aggregate object. Children of the
395 //! aggregate (entities and nested aggregates) are reparented one level up:
396 //! either to the grand-parent aggregate or, if none, to the containing
397 //! force node. Cleans up empty ancestor aggregates after the move. No-op
398 //! if the UUID is not a known aggregate.
399 virtual void removeAggregateNode(const DtUUID& aggregateUUID);
400
401 //! \brief Gets the entity UUID for a model index
402 //! \param index The model index
403 //! \return Entity UUID or null UUID if invalid index
404 virtual DtUUID entityUUID(const QModelIndex& index) const;
405
406 //! \brief Gets the role name for a model index
407 //! \param index The model index
408 //! \return Role name or empty string if not a role node
409 virtual std::string roleName(const QModelIndex& index) const;
410
411 //! \brief Checks if an index represents a force node
412 //! \param index The model index
413 //! \return True if the index is a force (level 0) node
414 virtual bool isForceNode(const QModelIndex& index) const;
415
416 //! \brief Checks if an index represents an entity node
417 //! \param index The model index
418 //! \return True if the index is an entity (level 1) node
419 virtual bool isEntityNode(const QModelIndex& index) const;
420
421 //! \brief Checks if an index represents a role node
422 //! \param index The model index
423 //! \return True if the index is a role (level 2) node
424 virtual bool isRoleNode(const QModelIndex& index) const;
425
426 //! \brief Checks if an index represents an aggregate node (Phase 8)
427 //! \param index The model index
428 //! \return True if the index is an aggregate node
429 virtual bool isAggregateNode(const QModelIndex& index) const;
430
431 //! \brief Returns the aggregate UUID for a model index (Phase 8)
432 //! \param index The model index
433 //! \return Aggregate UUID, or null UUID if the index is not an aggregate row
434 virtual DtUUID aggregateUUID(const QModelIndex& index) const;
435
436 //! @}
437
438 // -------------------------------------------------------------------------
439 //! @name Drop Resolution Helpers
440 //! @{
441 // -------------------------------------------------------------------------
442
443 //! \brief Depth-first finds the first unassigned role under a non-role index.
444 //!
445 //! Walks descendants of \p root in **display order** (using rowCount() +
446 //! index()) and returns the QModelIndex of the first role row whose
447 //! effective assignment state is "unassigned" (i.e., no committed or
448 //! pending assignment). Honors the active sort order and the
449 //! aggregates-first-then-entities ordering, because the walk uses the
450 //! same row enumeration the view uses.
451 //!
452 //! Used by dropMimeData() to resolve a drag onto a force, aggregate, or
453 //! entity into the specific role that should receive the assignment.
454 //!
455 //! \param root Index of a force, aggregate, or entity node (an invalid
456 //! index walks the whole tree starting at root level).
457 //! \return Index of the chosen role row (column 0), or an invalid index
458 //! if the subtree contains no unassigned role.
459 virtual QModelIndex findFirstUnassignedRoleIndex(const QModelIndex& root) const;
460
461 //! @}
462
463 // -------------------------------------------------------------------------
464 //! @name Filtering
465 //! Methods for filtering the displayed entities.
466 //! @{
467 // -------------------------------------------------------------------------
468
469 //! \brief Sets the filter pattern for entity names
470 //! \param pattern Case-insensitive substring to filter by (empty shows all)
471 //!
472 //! Only entities whose display name contains the pattern will be shown.
473 //! The filter is applied to entity nodes; role nodes follow their parent.
474 virtual void setFilterPattern(const std::string& pattern);
475
476 //! \brief Gets the current filter pattern
477 //! \return The current filter pattern
478 virtual std::string filterPattern() const;
479
480 //! \brief Sets whether to show only entities with assignments
481 //! \param showOnly If true, hide entities with no assigned roles
482 virtual void setShowOnlyAssigned(bool showOnly);
483
484 //! \brief Gets whether showing only assigned entities
485 //! \return True if filtering to only show assigned entities
486 virtual bool showOnlyAssigned() const;
487
488 //! \brief Sets whether to show only entities with no assignments
489 //! \param showOnly If true, hide entities that have at least one assigned role
490 virtual void setShowOnlyUnassigned(bool showOnly);
491
492 //! \brief Gets whether showing only unassigned entities
493 //! \return True if filtering to only show fully unassigned entities
494 virtual bool showOnlyUnassigned() const;
495
496 //! @}
497
498 // -------------------------------------------------------------------------
499 //! @name One-shot User-initiated Sorting
500 //! applyEntityOrder() performs a single reorder of the tree and must be
501 //! called only in response to an explicit user action (header button click).
502 //! Assignment-state changes never trigger an automatic reorder.
503 //! @{
504 // -------------------------------------------------------------------------
505
506 //! \brief Reorders the tree by \a mode and \a direction (one-shot)
507 //!
508 //! Sorts entity nodes within every force bucket and re-orders force buckets
509 //! analogously using the same primary/secondary key logic. Roles within an
510 //! entity are \b never reordered — they are always kept in .entity-file order.
511 //!
512 //! The call is safe to invoke with the same parameters repeatedly; subsequent
513 //! assignment-state changes do \b not reset the order — refresh() only
514 //! repaints.
515 //!
516 //! Emits layoutAboutToBeChanged / layoutChanged and updates all persistent
517 //! model indexes correctly.
518 //!
519 //! \param mode Primary sort key (ByName or ByAssignment)
520 //! \param direction Qt::AscendingOrder or Qt::DescendingOrder
521 virtual void applyEntityOrder(EntityOrderMode mode, Qt::SortOrder direction);
522
523 //! \brief Returns the mode passed to the last applyEntityOrder() call
524 //! \return Current entity order mode
526
527 //! \brief Returns the direction passed to the last applyEntityOrder() call
528 //! \return Current entity sort direction
529 Qt::SortOrder entityOrderDirection() const;
530
531 //! @}
532
533 // -------------------------------------------------------------------------
534 //! @name QAbstractItemModel Interface
535 //! Standard Qt model interface implementation.
536 //! @{
537 // -------------------------------------------------------------------------
538
539 //! \brief Returns the model index for the given row, column, and parent
540 //! \param row Row number
541 //! \param column Column number
542 //! \param parent Parent index
543 //! \return Model index for the specified cell
544 virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
545
546 //! \brief Returns the parent index for a given index
547 //! \param index The child index
548 //! \return Parent index or invalid index for root items
549 virtual QModelIndex parent(const QModelIndex& index) const override;
550
551 //! \brief Returns the number of rows under the given parent
552 //! \param parent Parent index
553 //! \return Number of child rows
554 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
555
556 //! \brief Returns the number of columns
557 //! \param parent Parent index (unused, constant column count)
558 //! \return Always returns 3 (entity-role column, assignment column, Sim Engine column)
559 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
560
561 //! \brief Returns data for the given index and role
562 //! \param index The model index
563 //! \param role The data role
564 //! \return Requested data as QVariant
565 virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
566
567 //! \brief Returns item flags for the given index
568 //! \param index The model index
569 //! \return Item flags (e.g., selectable, enabled)
570 virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
571
572 //! \brief Returns header data for the given section
573 //! \param section Section number
574 //! \param orientation Header orientation
575 //! \param role Data role
576 //! \return Header data as QVariant
577 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
578
579 //! \brief Returns supported drop actions
580 //! \return Drop actions supported by this model (CopyAction for assignment)
581 virtual Qt::DropActions supportedDropActions() const override;
582
583 //! \brief Returns supported drag actions
584 //! \return CopyAction for dragging role assignments
585 virtual Qt::DropActions supportedDragActions() const override;
586
587 //! \brief Returns MIME types accepted for drop
588 //! \return List of MIME types (station ID and role-assignment formats)
589 virtual QStringList mimeTypes() const override;
590
591 //! \brief Creates MIME data for dragged role nodes
592 //! \param indexes The indexes being dragged
593 //! \return MIME data containing entity UUID and role name, or nullptr
594 virtual QMimeData* mimeData(const QModelIndexList& indexes) const override;
595
596 //! \brief Checks whether dropped data can be accepted
597 //! \param data The MIME data being dropped
598 //! \param action The drop action
599 //! \param row Target row (-1 when dropping on an item)
600 //! \param column Target column (-1 when dropping on an item)
601 //! \param parent Parent index (the item being dropped on)
602 //! \return True if the drop can be accepted (only role nodes accept drops)
603 virtual bool canDropMimeData(const QMimeData* data, Qt::DropAction action,
604 int row, int column, const QModelIndex& parent) const override;
605
606 //! \brief Handles dropped MIME data to create a pending assignment
607 //! \param data The MIME data containing the station ID
608 //! \param action The drop action
609 //! \param row Target row (-1 when dropping on an item)
610 //! \param column Target column (-1 when dropping on an item)
611 //! \param parent Parent index (the role node being dropped on)
612 //! \return True if the drop was handled successfully
613 virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action,
614 int row, int column, const QModelIndex& parent) override;
615
616 //! @}
617
618public slots:
619 //! \brief Refreshes the model from the tracker
620 //!
621 //! Called when the tracker's assignment state changes. Emits
622 //! dataChanged() for all visible items to refresh assignment display.
623 virtual void refresh();
624
625signals:
626 //! \brief Emitted when an entity is selected
627 //! \param entityUUID The selected entity UUID
628 void entitySelected(const DtUUID& entityUUID);
629
630 //! \brief Emitted when a role is selected
631 //! \param entityUUID The entity UUID
632 //! \param roleName The selected role name
633 void roleSelected(const DtUUID& entityUUID, const std::string& roleName);
634
635 //! \brief Emitted after a branch drop resolves to a specific role
636 //! \param entityUUID The entity that received the assignment
637 //! \param roleName The role that was assigned
638 void branchDropCompleted(const DtUUID& entityUUID, const std::string& roleName);
639
640 //! \brief Emitted after dropMimeData() resolves to a specific role node.
641 //!
642 //! Carries the QModelIndex of the role row that received the assignment
643 //! (including direct drops on role rows). The widget connects this to a
644 //! slot that expands ancestors and selects/scrolls to the role.
645 //! \param roleIndex Model index of the assigned role row (column 0)
646 void droppedOnRole(const QModelIndex& roleIndex);
647
648protected:
649 //! \brief Reference to the assignment tracker
651
652 //! \brief Root nodes (force group nodes)
653 std::vector<std::unique_ptr<VreTreeNode>> myRootNodes;
654
655 //! \brief Map of force type to force node for fast lookup
656 std::map<int, VreTreeNode*> myForceIndex;
657
658 //! \brief Map of entity UUID to entity node for fast lookup
659 std::map<DtUUID, VreTreeNode*> myEntityIndex;
660
661 //! \brief Map of aggregate UUID to aggregate node for fast lookup (Phase 8)
662 std::map<DtUUID, VreTreeNode*> myAggregateIndex;
663
664 //! \brief Current filter pattern (lowercase)
665 std::string myFilterPattern;
666
667 //! \brief Whether to show only entities with assignments
668 bool myShowOnlyAssigned = false;
669
670 //! \brief Whether to show only entities with no assignments
672
673 //! \brief Primary key for the last applyEntityOrder() call
674 //!
675 //! Remembered so the header sort button can toggle direction on successive
676 //! clicks. Not used by refresh() — assignment changes never retrigger a sort.
678
679 //! \brief Sort direction for the last applyEntityOrder() call
680 Qt::SortOrder myEntityOrderDirection = Qt::AscendingOrder;
681
682 //! \brief Gets the tree node for a model index
683 //! \param index The model index
684 //! \return Pointer to tree node or nullptr if invalid
685 virtual VreTreeNode* nodeFromIndex(const QModelIndex& index) const;
686
687 //! \brief Creates a model index for a tree node
688 //! \param node The tree node
689 //! \param column Column number
690 //! \return Model index for the node
691 virtual QModelIndex indexFromNode(VreTreeNode* node, int column = 0) const;
692
693 //! \brief Checks if an entity passes the current filters
694 //! \param node Entity node to check
695 //! \return True if the entity should be visible
696 virtual bool passesFilter(VreTreeNode* node) const;
697
698 //! \brief Gets the visible row count for a parent
699 //! \param parent Parent node (nullptr for root)
700 //! \return Number of visible children
701 virtual int visibleRowCount(VreTreeNode* parent) const;
702
703 //! \brief Gets the nth visible child node
704 //! \param parent Parent node (nullptr for root)
705 //! \param visibleRow Visual row number
706 //! \return Pointer to the visible child node
707 virtual VreTreeNode* visibleChild(VreTreeNode* parent, int visibleRow) const;
708
709 //! \brief Gets or creates the force group node for a given force type
710 //! \param forceType SISO force type value
711 //! \return Pointer to the force group node
712 virtual VreTreeNode* getOrCreateForceNode(int forceType);
713
714 //! \brief Returns the display label for a force-bucket key
715 //! \param bucketKey The bucket key as produced by forceBucketKey()
716 //! \return Display name: "Friendly", "Opposing", "Neutral", "Other", or
717 //! "Other:N" where \c N is the raw non-standard force value
718 static std::string forceTypeLabel(int bucketKey);
719
720 //! \brief Returns the bucket key used by \c myForceIndex for a raw force type
721 //! \param rawForceType SISO force type value
722 //! \return Bucket key. Standard SISO values 0..3 map to themselves
723 //! (Other/Friendly/Opposing/Neutral). Non-standard values (>3) are
724 //! returned as-is so each distinct non-standard value gets its own
725 //! "Other:N" sub-bucket.
726 //!
727 //! Because VR-Link's standard SISO force range is 0..3, returning the raw
728 //! value for any value >3 cannot collide with a standard bucket.
729 static int forceBucketKey(int rawForceType);
730
731 //! \brief Removes a force node if it has no entity children
732 //! \param bucketKey The bucket key whose node to check and possibly remove
733 virtual void removeForceNodeIfEmpty(int bucketKey);
734
735 //! \brief Removes an aggregate node if it has no remaining children (Phase 8)
736 //! \param aggregateUUID The aggregate whose node to test and possibly remove
737 //!
738 //! Recurses upward: after removing a now-empty aggregate, checks the
739 //! grand-parent aggregate as well, and so on. Force-bucket cleanup at the
740 //! root is delegated to \c removeForceNodeIfEmpty().
741 virtual void removeAggregateNodeIfEmpty(const DtUUID& aggregateUUID);
742
743 //! \brief Get-or-create the deepest aggregate node along a chain (Phase 8)
744 //! \param forceNode Containing force bucket
745 //! \param chainUUIDs Aggregate ancestor UUIDs, root-most first
746 //! \param chainNames Display names parallel to \c chainUUIDs
747 //! \param chainIcons Pre-resolved icons parallel to \c chainUUIDs
748 //! \param chainForces SISO force-type per aggregate (parallel)
749 //! \return Pointer to the deepest aggregate node in \c chainUUIDs (the one
750 //! the entity should be parented under), or \c forceNode itself if
751 //! the chain is empty.
752 //!
753 //! Lazily inserts AggregateNode rows that don't yet exist anywhere in the
754 //! model; existing aggregates encountered along the chain are reused via
755 //! \c myAggregateIndex even if their current parent does not match
756 //! \c forceNode (a separate fix-up reparent step is the caller's
757 //! responsibility — see setEntityAggregateChain()).
759 VreTreeNode* forceNode,
760 const std::vector<DtUUID>& chainUUIDs,
761 const std::vector<std::string>& chainNames,
762 const std::vector<QIcon>& chainIcons,
763 const std::vector<int>& chainForces);
764
765 //! \brief Asserts (in debug builds) that we are on the GUI thread
766 //!
767 //! Mutating model methods must run on the thread that owns the QApplication
768 //! event loop. Listener callbacks that originate off the GUI thread should
769 //! be marshalled through queued signal/slot connections before invoking
770 //! any tree-mutation entry points.
771 static void assertGuiThread();
772
773 //! \brief Checks if an entity has any effective assignment (confirmed or pending)
774 //! \param node Entity node to check
775 //! \return True if any role on this entity has an assignment
777
778 //! \brief Checks if a role has any effective assignment (confirmed or pending)
779 //! \param node Role node to check
780 //! \return True if this role has at least one assigned station
782
783 //! \brief Checks if any entity within a force has any effective assignment
784 //! \param node Force node to check
785 //! \return True if any entity under this force has at least one assigned role
787
788 //! \brief Checks if any descendant entity of an aggregate is effectively assigned
789 //! \param node Aggregate node to check
790 //! \return True if any nested entity under this aggregate has at least one
791 //! assigned role. Recurses through sub-aggregates.
793
794 //! \brief Sorts children of a parent node by assignment-first then alphabetical
795 //! \param parent Force or entity node whose children to sort, or nullptr
796 //! to sort the top-level force list (\c myRootNodes).
797 //!
798 //! Uses layoutAboutToBeChanged/layoutChanged to preserve expanded state
799 //! and persistent indexes. Called from refresh() and addEntity().
801
802 //! \brief Re-sorts every level of the tree in-place
803 //!
804 //! Invokes sortChildren(nullptr), then sortChildren() for every force and
805 //! entity node so that the [assigned-first, alphabetical] ordering stays in
806 //! sync with the current tracker state. Used by refresh() to make ordering
807 //! reactive to assignment changes.
809
810private:
811 //! \brief Copy constructor (deleted)
813
814 //! \brief Assignment operator (deleted)
816};
817
818} // namespace makVre
Centralized tracking of confirmed and pending station assignments.
Definition vreAssignmentTracker.h:187
static void assertGuiThread()
Asserts (in debug builds) that we are on the GUI thread.
virtual QModelIndex parent(const QModelIndex &index) const override
Returns the parent index for a given index.
bool myShowOnlyAssigned
Whether to show only entities with assignments.
Definition vreEntityRoleTreeModel.h:668
EntityOrderMode entityOrderMode() const
Returns the mode passed to the last applyEntityOrder() call.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns.
virtual QModelIndex findFirstUnassignedRoleIndex(const QModelIndex &root) const
Depth-first finds the first unassigned role under a non-role index.
virtual void refresh()
Refreshes the model from the tracker.
virtual Qt::DropActions supportedDropActions() const override
Returns supported drop actions.
bool isAggregateEffectivelyAssigned(VreTreeNode *node) const
Checks if any descendant entity of an aggregate is effectively assigned.
void resortAllLevels()
Re-sorts every level of the tree in-place.
void roleSelected(const DtUUID &entityUUID, const std::string &roleName)
Emitted when a role is selected.
virtual void removeAggregateNodeIfEmpty(const DtUUID &aggregateUUID)
Removes an aggregate node if it has no remaining children (Phase 8)
virtual std::string filterPattern() const
Gets the current filter pattern.
virtual bool isAggregateNode(const QModelIndex &index) const
Checks if an index represents an aggregate node (Phase 8)
std::string myFilterPattern
Current filter pattern (lowercase)
Definition vreEntityRoleTreeModel.h:665
virtual QStringList mimeTypes() const override
Returns MIME types accepted for drop.
virtual bool isEntityNode(const QModelIndex &index) const
Checks if an index represents an entity node.
EntityOrderMode
Controls the primary sort key for applyEntityOrder()
Definition vreEntityRoleTreeModel.h:264
@ BySimEngine
Primary key = numeric (siteId, applicationId) pair on entity rows. Force buckets fall back to alphabe...
Definition vreEntityRoleTreeModel.h:275
@ ByName
Primary key = entity name (alpha); secondary = has-any-assignment.
Definition vreEntityRoleTreeModel.h:266
@ ByAssignment
Primary key = has-any-assignment; secondary = entity name (alpha).
Definition vreEntityRoleTreeModel.h:269
virtual ~DtVreEntityRoleTreeModel() override
Destructor.
Qt::SortOrder entityOrderDirection() const
Returns the direction passed to the last applyEntityOrder() call.
virtual bool isForceNode(const QModelIndex &index) const
Checks if an index represents a force node.
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)
Get-or-create the deepest aggregate node along a chain (Phase 8)
virtual bool showOnlyAssigned() const
Gets whether showing only assigned entities.
void entitySelected(const DtUUID &entityUUID)
Emitted when an entity is selected.
virtual bool passesFilter(VreTreeNode *node) const
Checks if an entity passes the current filters.
void branchDropCompleted(const DtUUID &entityUUID, const std::string &roleName)
Emitted after a branch drop resolves to a specific role.
virtual DtUUID aggregateUUID(const QModelIndex &index) const
Returns the aggregate UUID for a model index (Phase 8)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
void sortChildren(VreTreeNode *parent)
Sorts children of a parent node by assignment-first then alphabetical.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns data for the given index and role.
virtual void removeEntity(const DtUUID &entityUUID)
Removes an entity from the tree.
DtVreEntityRoleTreeModel(DtVreAssignmentTracker &tracker, QObject *parent=nullptr)
Constructor.
void droppedOnRole(const QModelIndex &roleIndex)
Emitted after dropMimeData() resolves to a specific role node.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Handles dropped MIME data to create a pending assignment.
bool isRoleEffectivelyAssigned(VreTreeNode *node) const
Checks if a role has any effective assignment (confirmed or pending)
virtual VreTreeNode * nodeFromIndex(const QModelIndex &index) const
Gets the tree node for a model index.
virtual void removeForceNodeIfEmpty(int bucketKey)
Removes a force node if it has no entity children.
virtual int visibleRowCount(VreTreeNode *parent) const
Gets the visible row count for a parent.
std::map< DtUUID, VreTreeNode * > myEntityIndex
Map of entity UUID to entity node for fast lookup.
Definition vreEntityRoleTreeModel.h:659
virtual QModelIndex indexFromNode(VreTreeNode *node, int column=0) const
Creates a model index for a tree node.
virtual DtUUID entityUUID(const QModelIndex &index) const
Gets the entity UUID for a model index.
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.
virtual void setEntitySimEngine(const DtUUID &entityUUID, uint16_t siteId, uint16_t appId)
Updates the cached Sim Engine (siteId, applicationId) for an entity.
bool myShowOnlyUnassigned
Whether to show only entities with no assignments.
Definition vreEntityRoleTreeModel.h:671
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
Checks whether dropped data can be accepted.
virtual void setShowOnlyUnassigned(bool showOnly)
Sets whether to show only entities with no assignments.
DtVreEntityRoleTreeModel(const DtVreEntityRoleTreeModel &)=delete
Copy constructor (deleted)
bool isEntityEffectivelyAssigned(VreTreeNode *node) const
Checks if an entity has any effective assignment (confirmed or pending)
virtual VreTreeNode * visibleChild(VreTreeNode *parent, int visibleRow) const
Gets the nth visible child node.
std::map< int, VreTreeNode * > myForceIndex
Map of force type to force node for fast lookup.
Definition vreEntityRoleTreeModel.h:656
virtual bool showOnlyUnassigned() const
Gets whether showing only unassigned entities.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the model index for the given row, column, and parent.
virtual void setFilterPattern(const std::string &pattern)
Sets the filter pattern for entity names.
virtual void clearEntities()
Removes all entities from the tree.
EntityOrderMode myEntityOrderMode
Primary key for the last applyEntityOrder() call.
Definition vreEntityRoleTreeModel.h:677
virtual void moveEntityToForce(const DtUUID &entityUUID, int newRawForceType)
Moves an existing entity to a different force bucket.
virtual void removeAggregateNode(const DtUUID &aggregateUUID)
Removes an aggregate node from the tree (Phase 8)
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)
Reparent an entity row when its aggregate membership changes (Phase 8)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns header data for the given section.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const override
Creates MIME data for dragged role nodes.
virtual VreTreeNode * getOrCreateForceNode(int forceType)
Gets or creates the force group node for a given force type.
std::map< DtUUID, VreTreeNode * > myAggregateIndex
Map of aggregate UUID to aggregate node for fast lookup (Phase 8)
Definition vreEntityRoleTreeModel.h:662
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
Returns item flags for the given index.
virtual bool isRoleNode(const QModelIndex &index) const
Checks if an index represents a role node.
virtual Qt::DropActions supportedDragActions() const override
Returns supported drag actions.
static std::string forceTypeLabel(int bucketKey)
Returns the display label for a force-bucket key.
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)
Sets (or updates) the aggregate ancestry chain for an entity (Phase 8)
bool isForceEffectivelyAssigned(VreTreeNode *node) const
Checks if any entity within a force has any effective assignment.
Qt::SortOrder myEntityOrderDirection
Sort direction for the last applyEntityOrder() call.
Definition vreEntityRoleTreeModel.h:680
virtual void applyEntityOrder(EntityOrderMode mode, Qt::SortOrder direction)
Reorders the tree by mode and direction (one-shot)
static int forceBucketKey(int rawForceType)
Returns the bucket key used by myForceIndex for a raw force type.
std::vector< std::unique_ptr< VreTreeNode > > myRootNodes
Root nodes (force group nodes)
Definition vreEntityRoleTreeModel.h:653
DtVreAssignmentTracker & myTracker
Reference to the assignment tracker.
Definition vreEntityRoleTreeModel.h:650
virtual void setShowOnlyAssigned(bool showOnly)
Sets whether to show only entities with assignments.
virtual std::string roleName(const QModelIndex &index) const
Gets the role name for a model index.
DtVreEntityRoleTreeModel & operator=(const DtVreEntityRoleTreeModel &)=delete
Assignment operator (deleted)
Export macros for the VREngage Manager library.
#define VREMANAGER_DLL
Platform-specific export/import macro for VREngage Manager library.
Definition export.h:28
!
Definition glsVreMessageUtil.h:50
ForceCategory
Standard SISO/VR-Link force category buckets.
Definition vreEntityRoleTreeModel.h:60
@ Friendly
Raw value 1 (DtForceFriendly)
Definition vreEntityRoleTreeModel.h:62
@ Opposing
Raw value 2 (DtForceOpposing)
Definition vreEntityRoleTreeModel.h:63
@ OtherRaw
Non-standard raw value (>3) — bucketed as "Other:N" per Len.
Definition vreEntityRoleTreeModel.h:65
@ Other
Raw value 0 (DtForceOther) — the canonical SISO "Other" bucket.
Definition vreEntityRoleTreeModel.h:61
@ Neutral
Raw value 3 (DtForceNeutral)
Definition vreEntityRoleTreeModel.h:64
VreTreeDataRole
Custom data roles for entity/role tree items.
Definition vreEntityRoleTreeModel.h:85
@ AssignedRoleCountRole
int: Number of roles with assignments on entity
Definition vreEntityRoleTreeModel.h:111
@ IsAggregateNodeRole
bool: True if this is an aggregate node (Phase 8)
Definition vreEntityRoleTreeModel.h:143
@ IsRoleNodeRole
bool: True if this is a role node (level 2)
Definition vreEntityRoleTreeModel.h:99
@ IsForceNodeRole
bool: True if this is a force node (level 0)
Definition vreEntityRoleTreeModel.h:93
@ AggregateUUIDRole
QString: Aggregate UUID (empty for non-aggregate rows)
Definition vreEntityRoleTreeModel.h:146
@ HasConflictRole
bool: True if pending assignment creates conflict
Definition vreEntityRoleTreeModel.h:108
@ IsSpectatorRole
bool: True if station is in spectator mode
Definition vreEntityRoleTreeModel.h:123
@ AssignedStationNamesRole
QString: Comma-separated station names assigned to role.
Definition vreEntityRoleTreeModel.h:120
@ TotalRoleCountRole
int: Total number of roles on entity
Definition vreEntityRoleTreeModel.h:114
@ IsAssignedRole
bool: True if role has confirmed or pending assignment
Definition vreEntityRoleTreeModel.h:102
@ RoleNameRole
QString: Role name (empty for entity and force nodes)
Definition vreEntityRoleTreeModel.h:90
@ AssignmentBadgeTextRole
QString: Badge text like "(2/3)" for entity nodes.
Definition vreEntityRoleTreeModel.h:117
@ IsPendingRole
bool: True if has pending assignment
Definition vreEntityRoleTreeModel.h:105
@ SimEngineSortKeyRole
uint: Numeric composite key (siteId<<16 | applicationId) for the Sim Engine column (column 2) on enti...
Definition vreEntityRoleTreeModel.h:140
@ EntityUUIDRole
QString: Entity UUID.
Definition vreEntityRoleTreeModel.h:87
@ IsEntityNodeRole
bool: True if this is an entity node (level 1)
Definition vreEntityRoleTreeModel.h:96
@ AssignedStationPartsRole
QVariantList: Per-station parts for rich rendering. Each entry is a QVariantMap with keys: "name" -> ...
Definition vreEntityRoleTreeModel.h:130
VREMANAGER_DLL ForceCategory forceCategoryFromRaw(int rawForceType)
Maps a raw SISO force-type value to a ForceCategory.
VreNodeType
Node type for the (possibly four-level+) hierarchy.
Definition vreEntityRoleTreeModel.h:43
@ AggregateNode
Optional intermediate aggregate node (may nest)
Definition vreEntityRoleTreeModel.h:45
@ RoleNode
Leaf-level role node.
Definition vreEntityRoleTreeModel.h:47
@ EntityNode
Entity row (parent may be a ForceNode or an AggregateNode)
Definition vreEntityRoleTreeModel.h:46
@ ForceNode
Top-level force grouping node (friendly, opposing, etc.)
Definition vreEntityRoleTreeModel.h:44
Internal tree node for force/entity/role hierarchy.
Definition vreEntityRoleTreeModel.h:155
int myCachedAssignedCount
Cached assigned-role count for this node (-1 = invalid / not yet cached)
Definition vreEntityRoleTreeModel.h:193
bool mySimEngineKnown
True if the cached (site, app) pair has been populated for this entity.
Definition vreEntityRoleTreeModel.h:214
VreTreeNode * myParent
Parent node (nullptr for root force nodes)
Definition vreEntityRoleTreeModel.h:178
uint16_t mySimEngineSite
Cached SISO siteId for the Sim Engine column (entity nodes only)
Definition vreEntityRoleTreeModel.h:203
uint16_t mySimEngineApp
Cached SISO applicationId / host for the Sim Engine column (entity nodes only)
Definition vreEntityRoleTreeModel.h:206
DtUUID myEntityUUID
Entity UUID (for entity and role nodes; null UUID for force nodes)
Definition vreEntityRoleTreeModel.h:160
int myCachedTotalCount
Cached total-role count for this node (-1 = invalid / not yet cached)
Definition vreEntityRoleTreeModel.h:200
std::string mySimEngineCached
Pre-formatted "site:app" string for Qt::DisplayRole on column 2.
Definition vreEntityRoleTreeModel.h:220
std::string myDisplayName
Display name (force label, entity objectName / marking-text fallback, or role name)
Definition vreEntityRoleTreeModel.h:169
VreNodeType myNodeType
Node type in the hierarchy.
Definition vreEntityRoleTreeModel.h:157
std::vector< std::unique_ptr< VreTreeNode > > myChildren
Child nodes (entity nodes for force nodes, role nodes for entity nodes)
Definition vreEntityRoleTreeModel.h:181
std::vector< std::string > myAvailableRoles
Available roles for this entity (entity nodes only)
Definition vreEntityRoleTreeModel.h:175
int myRow
Index of this node within parent's children.
Definition vreEntityRoleTreeModel.h:184
int myForceType
Force type value (force nodes only; SISO force ID)
Definition vreEntityRoleTreeModel.h:172
QIcon myEntityIcon
Entity type icon (entity nodes only; null for force and role nodes)
Definition vreEntityRoleTreeModel.h:187
std::string myRoleName
Role name (empty for entity and force nodes)
Definition vreEntityRoleTreeModel.h:166
DtUUID myAggregateUUID
Aggregate UUID (Phase 8 — valid only for AggregateNode rows)
Definition vreEntityRoleTreeModel.h:163