libs/flake
KoShapeBorderCommand.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 "KoShapeBorderCommand.h"
00022 #include "KoShape.h"
00023 #include "KoShapeBorderModel.h"
00024
00025 #include <klocale.h>
00026
00027 class KoShapeBorderCommand::Private
00028 {
00029 public:
00030 Private() {}
00031 ~Private()
00032 {
00033 foreach(KoShapeBorderModel* border, oldBorders) {
00034 if (border && ! border->removeUser())
00035 delete border;
00036 }
00037 }
00038
00039 void addOldBorder( KoShapeBorderModel * oldBorder )
00040 {
00041 if (oldBorder)
00042 oldBorder->addUser();
00043 oldBorders.append(oldBorder);
00044 }
00045
00046 void addNewBorder( KoShapeBorderModel * newBorder )
00047 {
00048 if (newBorder)
00049 newBorder->addUser();
00050 newBorders.append(newBorder);
00051 }
00052
00053 QList<KoShape*> shapes;
00054 QList<KoShapeBorderModel*> oldBorders;
00055 QList<KoShapeBorderModel*> newBorders;
00056 };
00057
00058 KoShapeBorderCommand::KoShapeBorderCommand(const QList<KoShape*> &shapes, KoShapeBorderModel *border, QUndoCommand *parent)
00059 : QUndoCommand(parent)
00060 , d(new Private())
00061 {
00062 d->shapes = shapes;
00063
00064
00065 foreach(KoShape *shape, d->shapes) {
00066 d->addOldBorder(shape->border());
00067 d->addNewBorder(border);
00068 }
00069
00070 setText(i18n("Set border"));
00071 }
00072
00073 KoShapeBorderCommand::KoShapeBorderCommand(const QList<KoShape*> &shapes,
00074 const QList<KoShapeBorderModel*> &borders,
00075 QUndoCommand *parent)
00076 : QUndoCommand(parent)
00077 , d(new Private())
00078 {
00079 Q_ASSERT(shapes.count() == borders.count());
00080
00081 d->shapes = shapes;
00082
00083
00084 foreach(KoShape *shape, shapes)
00085 d->addOldBorder(shape->border());
00086 foreach(KoShapeBorderModel * border, borders )
00087 d->addNewBorder(border);
00088
00089 setText(i18n("Set border"));
00090 }
00091
00092 KoShapeBorderCommand::KoShapeBorderCommand(KoShape* shape, KoShapeBorderModel *border, QUndoCommand *parent)
00093 : QUndoCommand(parent)
00094 , d(new Private())
00095 {
00096 d->shapes.append(shape);
00097 d->addNewBorder(border);
00098 d->addOldBorder(shape->border());
00099
00100 setText(i18n("Set border"));
00101 }
00102
00103 KoShapeBorderCommand::~KoShapeBorderCommand()
00104 {
00105 delete d;
00106 }
00107
00108 void KoShapeBorderCommand::redo()
00109 {
00110 QUndoCommand::redo();
00111 QList<KoShapeBorderModel*>::iterator borderIt = d->newBorders.begin();
00112 foreach(KoShape *shape, d->shapes) {
00113 shape->update();
00114 shape->setBorder(*borderIt);
00115 shape->update();
00116 ++borderIt;
00117 }
00118 }
00119
00120 void KoShapeBorderCommand::undo()
00121 {
00122 QUndoCommand::undo();
00123 QList<KoShapeBorderModel*>::iterator borderIt = d->oldBorders.begin();
00124 foreach(KoShape *shape, d->shapes) {
00125 shape->update();
00126 shape->setBorder(*borderIt);
00127 shape->update();
00128 ++borderIt;
00129 }
00130 }
|