SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
LayerTreeModel Class Reference

QAbstractItemModel that mirrors the layer stack of a MapCanvas, grouped by category. More...

#include <layertreepanel.h>

Inheritance diagram for LayerTreeModel:
Collaboration diagram for LayerTreeModel:

Public Member Functions

 LayerTreeModel (MapCanvas *canvas=nullptr, QObject *parent=nullptr)
 
 ~LayerTreeModel () override
 
void setCanvas (MapCanvas *canvas)
 Rebind to a different MapCanvas (called on MDI tab switch). Pass nullptr to detach (empty tree).
 
MapCanvascanvas () const
 
QModelIndex index (int row, int column, const QModelIndex &parent={}) const override
 
QModelIndex parent (const QModelIndex &child) const override
 
int rowCount (const QModelIndex &parent={}) const override
 
int columnCount (const QModelIndex &parent={}) const override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
Qt::DropActions supportedDropActions () const override
 
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
 
QMimeData * mimeData (const QModelIndexList &indexes) const override
 
QStringList mimeTypes () const override
 
OpenSWMMVisLayerlayerForIndex (const QModelIndex &index) const
 Returns the OpenSWMMVisLayer for a layer-row index, or nullptr for category rows / invalid indices.
 
bool isCategoryIndex (const QModelIndex &index) const
 True if index is a category header row (no associated layer).
 
bool isKindIndex (const QModelIndex &index) const
 
OpenSWMMVisLayerkindParentLayer (const QModelIndex &index) const
 
int kindOrdinal (const QModelIndex &index) const
 
bool isSublayerIndex (const QModelIndex &index) const
 
OpenSWMMVisLayersublayerParentLayer (const QModelIndex &index) const
 
OpenSWMM::Render::ISublayersublayerForIndex (const QModelIndex &index) const
 
bool reorderCategory (int categoryId, int dstTreeRow)
 Slice LTR-2026-09-19 — moves the category group categoryId (an openswmmvis::ui::CategoryId currently shown in the tree) to tree row dstTreeRow, then batch-reorders the canvas layer stack so paint order follows (an undoable ReorderLayersCommand) and records the new group order on the canvas (MapCanvas::setLayerGroupOrder, persisted per project).
 
int categoryIdForIndex (const QModelIndex &index) const
 
QModelIndex indexForCategory (int categoryId) const
 
QModelIndex indexForLayer (OpenSWMMVisLayer *layer) const
 
QModelIndex indexForSublayer (OpenSWMMVisLayer *layer, OpenSWMM::Render::ISublayer *sublayer) const
 
void notifyHostSubOrderChanged ()
 Slice GUI-2026-05-30 §2 / §3 — notify the model that the sublayer or kind paint-order on a host layer has changed externally (context-menu Move Up / Down or drop). Rebuilds the cached sub-row storage and emits a model reset so the view re-renders in the new order.
 

Detailed Description

QAbstractItemModel that mirrors the layer stack of a MapCanvas, grouped by category.

Two-level tree:

     Root
     ├── Category (e.g. "SWMM Model")
     │   └── Layer
     ├── Category (e.g. "Vectors")
     │   ├── Layer
     │   └── Layer
     └── …

     Categories are derived from each layer's `OpenSWMMVisLayerType`. A
     category is shown only if it contains at least one layer. Within a
     category, layers appear in canvas-stack order (top-of-stack first).

     Columns: [0] visibility checkbox + layer/category name + icon ·
              [1] opacity (layer rows only).

     The model reacts to layerAdded / layerRemoved / layerOrderChanged
     signals from the canvas so it stays in sync automatically.

     Reordering (Slice LTR-2026-09-19): category rows, layer rows and
     sublayer rows are all draggable. A layer can only be dropped
     inside its own category (its type decides the category, so a
     cross-category drop is refused with the forbidden cursor); a
     sublayer only inside its host layer. Every drop changes the
     canvas paint order (or the host's sublayer paint order) and is
     undoable; the canvas keeps the stack grouped by category so the
     tree is always an exact picture of the drawing order.

Constructor & Destructor Documentation

◆ LayerTreeModel()

LayerTreeModel::LayerTreeModel ( MapCanvas canvas = nullptr,
QObject *  parent = nullptr 
)
explicit
Here is the call graph for this function:

◆ ~LayerTreeModel()

LayerTreeModel::~LayerTreeModel ( )
overridedefault

Member Function Documentation

◆ canDropMimeData()

bool LayerTreeModel::canDropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
) const
override
Here is the call graph for this function:

◆ canvas()

MapCanvas * LayerTreeModel::canvas ( ) const

Bound canvas, or nullptr once it is unbound or destroyed. Out-of-line so QPointer<MapCanvas>::data() is not instantiated against the forward declaration.

Here is the caller graph for this function:

◆ categoryIdForIndex()

int LayerTreeModel::categoryIdForIndex ( const QModelIndex &  index) const

CategoryId of a category row; -1 for any other row / invalid index.

◆ columnCount()

int LayerTreeModel::columnCount ( const QModelIndex &  parent = {}) const
override

◆ data()

QVariant LayerTreeModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dropMimeData()

bool LayerTreeModel::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
override
Here is the call graph for this function:

◆ flags()

Qt::ItemFlags LayerTreeModel::flags ( const QModelIndex &  index) const
override

◆ headerData()

QVariant LayerTreeModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
override

◆ index()

QModelIndex LayerTreeModel::index ( int  row,
int  column,
const QModelIndex &  parent = {} 
) const
override

◆ indexForCategory()

QModelIndex LayerTreeModel::indexForCategory ( int  categoryId) const

◆ indexForLayer()

QModelIndex LayerTreeModel::indexForLayer ( OpenSWMMVisLayer layer) const

◆ indexForSublayer()

QModelIndex LayerTreeModel::indexForSublayer ( OpenSWMMVisLayer layer,
OpenSWMM::Render::ISublayer sublayer 
) const

◆ isCategoryIndex()

bool LayerTreeModel::isCategoryIndex ( const QModelIndex &  index) const

True if index is a category header row (no associated layer).

◆ isKindIndex()

bool LayerTreeModel::isKindIndex ( const QModelIndex &  index) const

True if index is a kind-row (3rd-level sub-row under a SWMMModelLayer).

Here is the caller graph for this function:

◆ isSublayerIndex()

bool LayerTreeModel::isSublayerIndex ( const QModelIndex &  index) const

True if index is a sublayer-row (3rd-level sub-row under an ISublayerHost).

Here is the caller graph for this function:

◆ kindOrdinal()

int LayerTreeModel::kindOrdinal ( const QModelIndex &  index) const

Kind ordinal (0..10, matches SWMMModelLayer::Category) for a kind-row index; -1 for any other row type.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kindParentLayer()

OpenSWMMVisLayer * LayerTreeModel::kindParentLayer ( const QModelIndex &  index) const

Parent layer for a kind-row index; nullptr for any other row type.

Here is the call graph for this function:

◆ layerForIndex()

OpenSWMMVisLayer * LayerTreeModel::layerForIndex ( const QModelIndex &  index) const

Returns the OpenSWMMVisLayer for a layer-row index, or nullptr for category rows / invalid indices.

Here is the caller graph for this function:

◆ mimeData()

QMimeData * LayerTreeModel::mimeData ( const QModelIndexList &  indexes) const
override
Here is the call graph for this function:

◆ mimeTypes()

QStringList LayerTreeModel::mimeTypes ( ) const
override

◆ notifyHostSubOrderChanged()

void LayerTreeModel::notifyHostSubOrderChanged ( )

Slice GUI-2026-05-30 §2 / §3 — notify the model that the sublayer or kind paint-order on a host layer has changed externally (context-menu Move Up / Down or drop). Rebuilds the cached sub-row storage and emits a model reset so the view re-renders in the new order.

◆ parent()

QModelIndex LayerTreeModel::parent ( const QModelIndex &  child) const
override

◆ reorderCategory()

bool LayerTreeModel::reorderCategory ( int  categoryId,
int  dstTreeRow 
)

Slice LTR-2026-09-19 — moves the category group categoryId (an openswmmvis::ui::CategoryId currently shown in the tree) to tree row dstTreeRow, then batch-reorders the canvas layer stack so paint order follows (an undoable ReorderLayersCommand) and records the new group order on the canvas (MapCanvas::setLayerGroupOrder, persisted per project).

Tree row 0 = top of tree = highest canvas z-order. Rows are positions among the NON-EMPTY categories the tree displays; dstTreeRow is the row the group occupies after the move. Returns false (no-op) when the id is not shown, the row is out of range, or the move is a no-op.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rowCount()

int LayerTreeModel::rowCount ( const QModelIndex &  parent = {}) const
override

◆ setCanvas()

void LayerTreeModel::setCanvas ( MapCanvas canvas)

Rebind to a different MapCanvas (called on MDI tab switch). Pass nullptr to detach (empty tree).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setData()

bool LayerTreeModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
override
Here is the call graph for this function:

◆ sublayerForIndex()

OpenSWMM::Render::ISublayer * LayerTreeModel::sublayerForIndex ( const QModelIndex &  index) const

The ISublayer pointer for a sublayer-row index; nullptr otherwise.

Here is the call graph for this function:

◆ sublayerParentLayer()

OpenSWMMVisLayer * LayerTreeModel::sublayerParentLayer ( const QModelIndex &  index) const

Parent layer for a sublayer-row index; nullptr for any other row type.

Here is the call graph for this function:

◆ supportedDropActions()

Qt::DropActions LayerTreeModel::supportedDropActions ( ) const
override

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