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

fix: no more empty groups in generated svgs #1235

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/libs/vformat/svg_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,24 @@ QDomDocument SvgGenerator::mergeSvgDoms()
*/
void SvgGenerator::removeEmptyGroups(QDomElement &mainGroup)
{
QDomNodeList groups = mainGroup.elementsByTagName("g");
for (int i = 0; i < groups.size(); ++i) {
QDomElement group = groups.at(i).toElement();
if (group.childNodes().isEmpty()) {
if (mainGroup.removeChild(group).isNull()) {
qDebug() << "Error : could not remove empty group";
bool svgCleaned = false;

//We must remove the empty groups one by one until no more empty group is found.
//Since removing a group modifies the QDomNodeList indexation, we start over
//the search from the beginning each time a group is removed.
while(!svgCleaned)
{
svgCleaned = true;
QDomNodeList groups = mainGroup.elementsByTagName("g");

for (int i = 0; i < groups.size(); ++i) {
QDomElement group = groups.at(i).toElement();
if (group.childNodes().isEmpty()) {
if (mainGroup.removeChild(group).isNull()) {
qDebug() << "Error : could not remove empty group";
}
svgCleaned = false;
break;
}
}
}
Expand Down
Loading