Skip to content

Added Expand/Collapse API to GroupLayer- Contd#4379

Open
Oval17 wants to merge 5 commits intomapeditor:masterfrom
Oval17:3997_expand_collapse_layers_api
Open

Added Expand/Collapse API to GroupLayer- Contd#4379
Oval17 wants to merge 5 commits intomapeditor:masterfrom
Oval17:3997_expand_collapse_layers_api

Conversation

@Oval17
Copy link
Copy Markdown
Contributor

@Oval17 Oval17 commented Mar 2, 2026

Resolves : #3997
Continuation of PR : #4009

Addressed all the review comments :

Reverted grouplayer.h changess.

Reverted editablegrouplayer.h/cpp and editableobjectgroup.h/cpp , Removed the isExpanded/setExpanded properties and methods that were added directly to the layer object

Moved Q_INVOKABLE isExpanded/setExpanded out of the header files , In layerdock.h and objectsdock.h, the methods were defined inline. Moved the implementations to layerdock.cpp and objectsdock.cpp respectively.

Added null checks , The moved implementations now check for a null layer argument and call ScriptManager::instance().throwError(...) with a proper translated error message, matching the pattern used rest of pplaces.

@Oval17 Oval17 force-pushed the 3997_expand_collapse_layers_api branch 2 times, most recently from 302046e to 090240f Compare March 2, 2026 16:58
@Oval17
Copy link
Copy Markdown
Contributor Author

Oval17 commented Mar 2, 2026

Kindly review @bjorn @PalaBeaveR !
Thanks

Copy link
Copy Markdown
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This already looks like an improvement over #4009.

Please don't forget to update docs/scripting-doc/index.d.ts with the added API and add a line to the NEWS.md file (consider rebasing first, to avoid conflicts).

There's also still a potential crash (see comment) and I've suggested some further tweaks.

Q_INVOKABLE bool isExpanded(EditableGroupLayer *layer) const;
Q_INVOKABLE void setExpanded(EditableGroupLayer *layer, bool expanded);
bool isExpanded(GroupLayer *layer) const;
void setExpanded(GroupLayer *layer, bool expanded);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be a good idea to move these extra non-scripting functions into LayerView.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
Removed isExpanded(GroupLayer*) / setExpanded(GroupLayer*, bool) from LayerDock and added them to LayerView.

Q_INVOKABLE bool isExpanded(EditableObjectGroup *layer) const;
Q_INVOKABLE void setExpanded(EditableObjectGroup *layer, bool expanded);
bool isExpanded(ObjectGroup *layer) const;
void setExpanded(ObjectGroup *layer, bool expanded);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these non-script functions are better moved to ObjectsView.

Copy link
Copy Markdown
Contributor Author

@Oval17 Oval17 Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed isExpanded(ObjectGroup*) / setExpanded(ObjectGroup*, bool) declarations

@bjorn
Copy link
Copy Markdown
Member

bjorn commented Mar 19, 2026

ERROR: /home/runner/work/tiled/tiled/src/tiled/objectsdock.cpp: In member function ‘bool Tiled::ObjectsDock::isExpanded(Tiled::EditableObjectGroup*) const’:
/home/runner/work/tiled/tiled/src/tiled/objectsdock.cpp:158:46: error: ‘QCoreApplication’ has not been declared
  158 |         ScriptManager::instance().throwError(QCoreApplication::translate("Script Errors", "Invalid argument"));
      |                                              ^~~~~~~~~~~~~~~~

There is an #include <QCoreApplication> missing.

PalaBeaveR and others added 5 commits April 3, 2026 11:34
Group layers can now be expanded/collapsed from scripts
- Changed Q_INVOKABLE parameter types from EditableGroupLayer*/EditableObjectGroup*
  to EditableLayer*/EditableObjectGroup* using asGroupLayer() cast; non-group
  layers now return false/no-op instead of aborting with a type error
- Moved isExpanded/setExpanded(GroupLayer*) helpers from LayerDock to LayerView
  with mMapDocument null checks to fix potential crash when no map is open
- Moved isExpanded/setExpanded(ObjectGroup*) helpers from ObjectsDock to ObjectsView
- Fixed brace style for function definitions in objectsdock.cpp
- Added missing #include <QCoreApplication> to objectsdock.cpp
- Removed spurious #include "map.h" from changelayer.cpp
- Added LayersView and ObjectsView interfaces to scripting API (index.d.ts)
- Added changelog entry to NEWS.md
@Oval17 Oval17 force-pushed the 3997_expand_collapse_layers_api branch from 74a4f1c to 850a90b Compare April 3, 2026 06:04
@Oval17
Copy link
Copy Markdown
Contributor Author

Oval17 commented Apr 3, 2026

I have Implemented all the suggested Review Comments :
Also have updated docs/scripting-doc/index.d.ts with the added API and added a line to the NEWS.md file.
cc : @bjorn

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.

Expand/collapse layers API

3 participants