File indexing completed on 2024-05-12 15:59:05

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #include "GroupShape.h"
0007 #include <KoShapeGroup.h>
0008 
0009 GroupShape::GroupShape(QObject *parent) : Shape(new KoShapeGroup(), parent)
0010 {
0011 }
0012 
0013 GroupShape::GroupShape(KoShapeGroup *shape, QObject *parent) :
0014     Shape(shape, parent)
0015 {
0016 
0017 }
0018 
0019 GroupShape::~GroupShape()
0020 {
0021 
0022 }
0023 
0024 QString GroupShape::type() const
0025 {
0026     //Has no default KoID
0027     return "groupshape";
0028 }
0029 
0030 QList<Shape *> GroupShape::children()
0031 {
0032     KoShapeGroup * group = dynamic_cast<KoShapeGroup*>(this->shape());
0033     QList <Shape*> shapes;
0034     if (group) {
0035         QList<KoShape*> originalShapes = group->shapes();
0036         std::sort(originalShapes.begin(), originalShapes.end(), KoShape::compareShapeZIndex);
0037         for(int i=0; i<group->shapeCount(); i++) {
0038             if (dynamic_cast<KoShapeGroup*>(originalShapes.at(i))) {
0039                 shapes << new GroupShape(dynamic_cast<KoShapeGroup*>(originalShapes.at(i)));
0040             } else {
0041                 shapes << new Shape(originalShapes.at(i));
0042             }
0043         }
0044     }
0045     return shapes;
0046 }