Skip to content

Commit

Permalink
fix: no more empty groups in generated svgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Onetchou authored and DSCaskey committed Dec 30, 2024
1 parent b08abd8 commit c19fe53
Showing 1 changed file with 18 additions and 6 deletions.
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

0 comments on commit c19fe53

Please sign in to comment.