Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeMoveCommand Class Reference

The undo / redo command for shape moving. More...

#include <KoShapeMoveCommand.h>

+ Inheritance diagram for KoShapeMoveCommand:

Public Member Functions

int id () const override
 
 KoShapeMoveCommand (const QList< KoShape * > &shapes, const QPointF &offset, KUndo2Command *parent=0)
 
 KoShapeMoveCommand (const QList< KoShape * > &shapes, QList< QPointF > &previousPositions, QList< QPointF > &newPositions, KoFlake::AnchorPosition anchor=KoFlake::Center, KUndo2Command *parent=0)
 
bool mergeWith (const KUndo2Command *command) override
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoShapeMoveCommand () override
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
virtual bool canAnnihilateWith (const KUndo2Command *other) const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Public Attributes

KoFlake::AnchorPosition anchor
 
QList< QPointF > newPositions
 
QList< QPointF > previousPositions
 
QList< KoShape * > shapes
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

The undo / redo command for shape moving.

Definition at line 15 of file KoShapeMoveCommand.cpp.

Constructor & Destructor Documentation

◆ KoShapeMoveCommand() [1/2]

KoShapeMoveCommand::KoShapeMoveCommand ( const QList< KoShape * > & shapes,
QList< QPointF > & previousPositions,
QList< QPointF > & newPositions,
KoFlake::AnchorPosition anchor = KoFlake::Center,
KUndo2Command * parent = 0 )

Constructor.

Parameters
shapesthe set of objects that are moved.
previousPositionsthe known set of previous positions for each of the objects. this list naturally must have the same amount of items as the shapes set.
newPositionsthe new positions for the shapes. this list naturally must have the same amount of items as the shapes set.
parentthe parent command used for macro commands

Definition at line 23 of file KoShapeMoveCommand.cpp.

24 : KUndo2Command(kundo2_i18n("Move shapes"), parent),
25 d(new Private())
26{
27 d->shapes = shapes;
28 d->previousPositions = previousPositions;
29 d->newPositions = newPositions;
30 d->anchor = anchor;
31 Q_ASSERT(d->shapes.count() == d->previousPositions.count());
32 Q_ASSERT(d->shapes.count() == d->newPositions.count());
33}
KUndo2Command(KUndo2Command *parent=0)
QList< KoShape * > shapes
KoFlake::AnchorPosition anchor
QList< QPointF > newPositions
QList< QPointF > previousPositions
KUndo2MagicString kundo2_i18n(const char *text)

References anchor, d, newPositions, previousPositions, and shapes.

◆ KoShapeMoveCommand() [2/2]

KoShapeMoveCommand::KoShapeMoveCommand ( const QList< KoShape * > & shapes,
const QPointF & offset,
KUndo2Command * parent = 0 )

Definition at line 35 of file KoShapeMoveCommand.cpp.

36 : KUndo2Command(kundo2_i18n("Move shapes"), parent),
37 d(new Private())
38{
39 d->shapes = shapes;
40 d->anchor = KoFlake::Center;
41
42 Q_FOREACH (KoShape *shape, d->shapes) {
43 const QPointF pos = shape->absolutePosition();
44
45 d->previousPositions << pos;
46 d->newPositions << pos + offset;
47 }
48}
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
Definition KoShape.cpp:653
@ Center
Definition KoFlake.h:90

References KoShape::absolutePosition(), KoFlake::Center, d, and shapes.

◆ ~KoShapeMoveCommand()

KoShapeMoveCommand::~KoShapeMoveCommand ( )
override

Definition at line 50 of file KoShapeMoveCommand.cpp.

51{
52 delete d;
53}

References d.

Member Function Documentation

◆ id()

int KoShapeMoveCommand::id ( ) const
overridevirtual

Returns the ID of this command.

A command ID is used in command compression. It must be an integer unique to this command's class, or -1 if the command doesn't support compression.

If the command supports compression this function must be overridden in the derived class to return the correct ID. The base implementation returns -1.

KUndo2QStack::push() will only try to merge two commands if they have the same ID, and the ID is not -1.

See also
mergeWith(), KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 80 of file KoShapeMoveCommand.cpp.

References KisCommandUtils::MoveShapeId.

◆ mergeWith()

bool KoShapeMoveCommand::mergeWith ( const KUndo2Command * command)
overridevirtual

Attempts to merge this command with command. Returns true on success; otherwise returns false.

If this function returns true, calling this command's redo() must have the same effect as redoing both this command and command. Similarly, calling this command's undo() must have the same effect as undoing command and this command.

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 85 of file KoShapeMoveCommand.cpp.

86{
87 const KoShapeMoveCommand *other = dynamic_cast<const KoShapeMoveCommand*>(command);
88 KIS_ASSERT(other);
89
90 if (other->d->shapes != d->shapes ||
91 other->d->anchor != d->anchor) {
92
93 return false;
94 }
95
96 d->newPositions = other->d->newPositions;
97 return true;
98}
The undo / redo command for shape moving.
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References d, and KIS_ASSERT.

◆ redo()

void KoShapeMoveCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 55 of file KoShapeMoveCommand.cpp.

56{
58
59 for (int i = 0; i < d->shapes.count(); i++) {
60 KoShape *shape = d->shapes.at(i);
61
62 const QRectF oldDirtyRect = shape->boundingRect();
63 shape->setAbsolutePosition(d->newPositions.at(i), d->anchor);
64 shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
65 }
66}
virtual void redo()
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
Definition KoShape.cpp:668

References KoShape::boundingRect(), d, KUndo2Command::redo(), KoShape::setAbsolutePosition(), and KoShape::updateAbsolute().

◆ undo()

void KoShapeMoveCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 68 of file KoShapeMoveCommand.cpp.

69{
71 for (int i = 0; i < d->shapes.count(); i++) {
72 KoShape *shape = d->shapes.at(i);
73
74 const QRectF oldDirtyRect = shape->boundingRect();
75 shape->setAbsolutePosition(d->previousPositions.at(i), d->anchor);
76 shape->updateAbsolute(oldDirtyRect | shape->boundingRect());
77 }
78}
virtual void undo()

References KoShape::boundingRect(), d, KoShape::setAbsolutePosition(), KUndo2Command::undo(), and KoShape::updateAbsolute().

Member Data Documentation

◆ anchor

KoFlake::AnchorPosition KoShapeMoveCommand::anchor

Definition at line 20 of file KoShapeMoveCommand.cpp.

◆ d

Private* const KoShapeMoveCommand::d
private

Definition at line 49 of file KoShapeMoveCommand.h.

◆ newPositions

QList<QPointF> KoShapeMoveCommand::newPositions

Definition at line 19 of file KoShapeMoveCommand.cpp.

◆ previousPositions

QList<QPointF> KoShapeMoveCommand::previousPositions

Definition at line 19 of file KoShapeMoveCommand.cpp.

◆ shapes

QList<KoShape*> KoShapeMoveCommand::shapes

Definition at line 18 of file KoShapeMoveCommand.cpp.


The documentation for this class was generated from the following files: