Skip to content

Commit

Permalink
Layers view: restore expanded group layers after reload
Browse files Browse the repository at this point in the history
Since they get collapsed due to the model reset.

todo: unduplicate code
  • Loading branch information
bjorn committed May 2, 2024
1 parent 6b91864 commit a3f9b8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tiled/layerdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ void LayerView::setMapDocument(MapDocument *mapDocument)
auto layerModel = mMapDocument->layerModel();
mProxyModel->setSourceModel(layerModel);

connect(mMapDocument, &MapDocument::changed,
this, &LayerView::changeEvent);
connect(mMapDocument, &MapDocument::currentLayerChanged,
this, &LayerView::currentLayerChanged);
connect(mMapDocument, &MapDocument::selectedLayersChanged,
Expand Down Expand Up @@ -377,6 +379,26 @@ void LayerView::indexPressed(const QModelIndex &proxyIndex)
mMapDocument->setCurrentObject(layer);
}

void LayerView::changeEvent(const ChangeEvent &event)
{
switch (event.type) {
case ChangeEvent::DocumentReloaded: {
// Restore expanded layers
const LayerModel *layerModel = mMapDocument->layerModel();
for (const int layerId : std::as_const(mMapDocument->expandedGroupLayers)) {
if (Layer *layer = mMapDocument->map()->findLayerById(layerId)) {
const QModelIndex sourceIndex = layerModel->index(layer);
const QModelIndex index = mProxyModel->mapFromSource(sourceIndex);
setExpanded(index, true);
}
}
break;
}
default:
break;
}
}

void LayerView::currentLayerChanged(Layer *layer)
{
const LayerModel *layerModel = mMapDocument->layerModel();
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/layerdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class LayerView : public QTreeView

void currentRowChanged(const QModelIndex &proxyIndex);
void indexPressed(const QModelIndex &proxyIndex);

void changeEvent(const ChangeEvent &event);
void currentLayerChanged(Layer *layer);
void selectedLayersChanged();
void layerRemoved(Layer *layer);
Expand Down

0 comments on commit a3f9b8a

Please sign in to comment.