libs/flake
KoPathCombineCommand.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 "KoPathCombineCommand.h"
00022 #include "KoShapeControllerBase.h"
00023 #include "KoShapeContainer.h"
00024 #include <klocale.h>
00025
00026 class KoPathCombineCommand::Private
00027 {
00028 public:
00029 Private(KoShapeControllerBase *c, const QList<KoPathShape*> &p)
00030 : controller(c), paths(p)
00031 , combinedPath(0), combinedPathParent(0)
00032 , isCombined(false)
00033 {
00034 foreach( KoPathShape * path, paths )
00035 oldParents.append( path->parent() );
00036 }
00037 ~Private() {
00038 if (isCombined && controller) {
00039 foreach(KoPathShape* path, paths)
00040 delete path;
00041 } else
00042 delete combinedPath;
00043 }
00044
00045 KoShapeControllerBase *controller;
00046 QList<KoPathShape*> paths;
00047 QList<KoShapeContainer*> oldParents;
00048 KoPathShape *combinedPath;
00049 KoShapeContainer *combinedPathParent;
00050 bool isCombined;
00051 };
00052
00053 KoPathCombineCommand::KoPathCombineCommand(KoShapeControllerBase *controller,
00054 const QList<KoPathShape*> &paths, QUndoCommand *parent)
00055 : QUndoCommand(parent)
00056 , d(new Private(controller, paths))
00057 {
00058 setText(i18n("Combine paths"));
00059
00060 d->combinedPath = new KoPathShape();
00061 d->combinedPath->setBorder(d->paths.first()->border());
00062 d->combinedPath->setShapeId(d->paths.first()->shapeId());
00063
00064 foreach(KoPathShape* path, d->paths) {
00065 d->combinedPath->combine(path);
00066 if (! d->combinedPathParent && path->parent())
00067 d->combinedPathParent = path->parent();
00068 }
00069 }
00070
00071 KoPathCombineCommand::~KoPathCombineCommand()
00072 {
00073 delete d;
00074 }
00075
00076 void KoPathCombineCommand::redo()
00077 {
00078 QUndoCommand::redo();
00079
00080 if (! d->paths.size())
00081 return;
00082
00083 d->isCombined = true;
00084
00085 if (d->controller) {
00086 QList<KoShapeContainer*>::iterator parentIt = d->oldParents.begin();
00087 foreach(KoPathShape* p, d->paths) {
00088 d->controller->removeShape(p);
00089 if (*parentIt)
00090 (*parentIt)->removeChild(p);
00091 parentIt++;
00092
00093 }
00094 if (d->combinedPathParent)
00095 d->combinedPathParent->addChild(d->combinedPath);
00096 d->controller->addShape(d->combinedPath);
00097 }
00098 }
00099
00100 void KoPathCombineCommand::undo()
00101 {
00102 if (! d->paths.size())
00103 return;
00104
00105 d->isCombined = false;
00106
00107 if (d->controller) {
00108 d->controller->removeShape(d->combinedPath);
00109 if (d->combinedPath->parent())
00110 d->combinedPath->parent()->removeChild(d->combinedPath);
00111 QList<KoShapeContainer*>::iterator parentIt = d->oldParents.begin();
00112 foreach(KoPathShape* p, d->paths) {
00113 d->controller->addShape(p);
00114 p->setParent(*parentIt);
00115 parentIt++;
00116 }
00117 }
00118 QUndoCommand::undo();
00119 }
00120
|