Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Expand/Collapse API to GroupLayer #4009

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

PalaBeaveR
Copy link

Related issue: #3997

Added a new scripting field in GroupLayer called expanded that controls the layer's expand state.

From what I'd been able to gather, in order to expand/collapse layers I would need access to LayerView(QTreeView) which controls layer expansion with setExpanded. It wasn't possible since those properties were privated so I added getters to access LayerDock, LayerView, QAbstractProxyModel.

Right now the expanded state is stored in GroupLayer and is not synced, however since Qt already stores that state itself, the scripting interface can be made to use that instead.

I also don't know if the same API is appropriate for ObjectGroup(as requested by #3997), but i have that code made in the same way as GroupLayer if it is needed.

I'm not sure if the new definitions in changelayer.h/undocommands.h are needed since i was just copying code from other places in the repo so it would be nice to have that clarified.

Group layers can now be expanded/collapsed from scripts
@bjorn
Copy link
Member

bjorn commented Jul 14, 2024

I think it would be better to allow the scripting API to interact directly with the UI. There is no need for this to go through an undo command. I also don't think we need to store that state on the GroupLayer object itself.

There already is QSet<int> expandedGroupLayers on the MapDocument, which actually exists only because it is saved in the session. But if the scripting API just talks to the view, updating that container should happen automatically.

Maybe it could just be some additional functions like tiled.mapEditor.layersView.setExpanded(layer, true), along with isExpanded.

@PalaBeaveR
Copy link
Author

PalaBeaveR commented Jul 14, 2024

Alright I've removed the state from GroupLayer and added setExpanded/isExpanded to tiled.mapEditor.layersView.
ObjectGroup and tiled.mapEditor.objectsView got the same treatment.

One thing I noticed is that for now changing group layer expanded state does not reflect in ObjectsView. This is what the code does right now, but we need to figure out how to go about it, because i assume it would be better to not sync them between trees, but need some input on that.

Also I got segfaults when passing the wrong layer to the setExpanded method and want to know whether this should be handled or not.

@bjorn bjorn self-assigned this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants