libs/flake
KoShapeUngroupCommand.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KoShapeUngroupCommand.h"
00022 #include "KoShapeContainer.h"
00023
00024 #include <klocale.h>
00025
00026 KoShapeUngroupCommand::KoShapeUngroupCommand(KoShapeContainer *container, const QList<KoShape *> &shapes,
00027 const QList<KoShape*> &topLevelShapes, QUndoCommand *parent)
00028 : KoShapeGroupCommand(parent)
00029 {
00030 QList<KoShape*> orderdShapes(shapes);
00031 qSort(orderdShapes.begin(), orderdShapes.end(), KoShape::compareShapeZIndex);
00032 m_shapes = orderdShapes;
00033 m_container = container;
00034
00035 QList<KoShape*> ancestors = m_container->parent()? m_container->parent()->childShapes(): topLevelShapes;
00036 qSort(ancestors.begin(), ancestors.end(), KoShape::compareShapeZIndex);
00037 QList<KoShape*>::const_iterator it(qFind(ancestors, m_container));
00038
00039 Q_ASSERT(it != ancestors.constEnd());
00040 for ( ; it != ancestors.constEnd(); ++it ) {
00041 m_oldAncestorsZIndex.append(QPair<KoShape*, int>(*it, (*it)->zIndex()));
00042 }
00043
00044 int zIndex = m_container->zIndex();
00045 foreach(KoShape *shape, m_shapes) {
00046 m_clipped.append(m_container->childClipped(shape));
00047 m_oldParents.append(m_container->parent());
00048 m_oldClipped.append(m_container->childClipped(shape));
00049
00050 m_oldZIndex.append(zIndex++);
00051 }
00052
00053 setText(i18n("Ungroup shapes"));
00054 }
00055
00056 void KoShapeUngroupCommand::redo()
00057 {
00058 KoShapeGroupCommand::undo();
00059 int zIndex = m_container->zIndex() + m_oldZIndex.count() - 1;
00060 for (QList<QPair<KoShape*, int> >::const_iterator it( m_oldAncestorsZIndex.constBegin()); it != m_oldAncestorsZIndex.constEnd(); ++it) {
00061 it->first->setZIndex(zIndex++);
00062 }
00063 }
00064
00065 void KoShapeUngroupCommand::undo()
00066 {
00067 KoShapeGroupCommand::redo();
00068 for (QList<QPair<KoShape*, int> >::const_iterator it( m_oldAncestorsZIndex.constBegin()); it != m_oldAncestorsZIndex.constEnd(); ++it) {
00069 it->first->setZIndex(it->second);
00070 }
00071 }
|