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

The undo / redo command for setting the shape background. More...

#include <KoShapeBackgroundCommand.h>

+ Inheritance diagram for KoShapeBackgroundCommand:

Public Member Functions

void addNewFill (QSharedPointer< KoShapeBackground > newFill)
 
void addOldFill (QSharedPointer< KoShapeBackground > oldFill)
 
int id () const override
 
 KoShapeBackgroundCommand (const QList< KoShape * > &shapes, const QList< QSharedPointer< KoShapeBackground > > &fills, KUndo2Command *parent=0)
 
 KoShapeBackgroundCommand (const QList< KoShape * > &shapes, QSharedPointer< KoShapeBackground > fill, KUndo2Command *parent=0)
 
 KoShapeBackgroundCommand (KoShape *shape, QSharedPointer< KoShapeBackground > fill, KUndo2Command *parent=0)
 
bool mergeWith (const KUndo2Command *command) override
 
 Private ()
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoShapeBackgroundCommand () override
 
 ~Private ()
 
- 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

QList< QSharedPointer< KoShapeBackground > > newFills
 
QList< QSharedPointer< KoShapeBackground > > oldFills
 
QList< KoShape * > shapes
 the shapes to set background for
 

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 setting the shape background.

Definition at line 17 of file KoShapeBackgroundCommand.cpp.

Constructor & Destructor Documentation

◆ ~Private()

KoShapeBackgroundCommand::~Private ( )
inline

Definition at line 22 of file KoShapeBackgroundCommand.cpp.

22 {
23 oldFills.clear();
24 newFills.clear();
25 }
QList< QSharedPointer< KoShapeBackground > > newFills
QList< QSharedPointer< KoShapeBackground > > oldFills

◆ KoShapeBackgroundCommand() [1/3]

KoShapeBackgroundCommand::KoShapeBackgroundCommand ( const QList< KoShape * > & shapes,
QSharedPointer< KoShapeBackground > fill,
KUndo2Command * parent = 0 )

Command to set a new shape background.

Parameters
shapesa set of all the shapes that should get the new background.
fillthe new shape background
parentthe parent command used for macro commands

Definition at line 42 of file KoShapeBackgroundCommand.cpp.

44 : KUndo2Command(parent)
45 , d(new Private())
46{
47 d->shapes = shapes;
48 Q_FOREACH (KoShape *shape, d->shapes) {
49 d->addOldFill(shape->background());
50 d->addNewFill(fill);
51 }
52
53 setText(kundo2_i18n("Set background"));
54}
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
QList< KoShape * > shapes
the shapes to set background for
virtual QSharedPointer< KoShapeBackground > background() const
Definition KoShape.cpp:926
KUndo2MagicString kundo2_i18n(const char *text)

References KoShape::background(), d, kundo2_i18n(), KUndo2Command::setText(), and shapes.

◆ KoShapeBackgroundCommand() [2/3]

KoShapeBackgroundCommand::KoShapeBackgroundCommand ( KoShape * shape,
QSharedPointer< KoShapeBackground > fill,
KUndo2Command * parent = 0 )

Command to set a new shape background.

Parameters
shapea single shape that should get the new background.
fillthe new shape background
parentthe parent command used for macro commands

Definition at line 56 of file KoShapeBackgroundCommand.cpp.

57 : KUndo2Command(parent)
58 , d(new Private())
59{
60 d->shapes.append(shape);
61 d->addOldFill(shape->background());
62 d->addNewFill(fill);
63
64 setText(kundo2_i18n("Set background"));
65}

References KoShape::background(), d, kundo2_i18n(), and KUndo2Command::setText().

◆ KoShapeBackgroundCommand() [3/3]

KoShapeBackgroundCommand::KoShapeBackgroundCommand ( const QList< KoShape * > & shapes,
const QList< QSharedPointer< KoShapeBackground > > & fills,
KUndo2Command * parent = 0 )

Command to set new shape backgrounds.

Parameters
shapesa set of all the shapes that should get a new background.
fillsthe new backgrounds, one for each shape
parentthe parent command used for macro commands

Definition at line 67 of file KoShapeBackgroundCommand.cpp.

68 : KUndo2Command(parent)
69 , d(new Private())
70{
71 d->shapes = shapes;
72 Q_FOREACH (KoShape *shape, d->shapes) {
73 d->addOldFill(shape->background());
74 }
75 foreach (QSharedPointer<KoShapeBackground> fill, fills) {
76 d->addNewFill(fill);
77 }
78
79 setText(kundo2_i18n("Set background"));
80}

References KoShape::background(), d, kundo2_i18n(), KUndo2Command::setText(), and shapes.

◆ ~KoShapeBackgroundCommand()

KoShapeBackgroundCommand::~KoShapeBackgroundCommand ( )
override

Definition at line 123 of file KoShapeBackgroundCommand.cpp.

124{
125 delete d;
126}

References d.

Member Function Documentation

◆ addNewFill()

void KoShapeBackgroundCommand::addNewFill ( QSharedPointer< KoShapeBackground > newFill)
inline

Definition at line 32 of file KoShapeBackgroundCommand.cpp.

33 {
34 newFills.append(newFill);
35 }

◆ addOldFill()

void KoShapeBackgroundCommand::addOldFill ( QSharedPointer< KoShapeBackground > oldFill)
inline

Definition at line 27 of file KoShapeBackgroundCommand.cpp.

28 {
29 oldFills.append(oldFill);
30 }

◆ id()

int KoShapeBackgroundCommand::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 104 of file KoShapeBackgroundCommand.cpp.

References KisCommandUtils::ChangeShapeBackgroundId.

◆ mergeWith()

bool KoShapeBackgroundCommand::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 109 of file KoShapeBackgroundCommand.cpp.

110{
111 const KoShapeBackgroundCommand *other = dynamic_cast<const KoShapeBackgroundCommand*>(command);
112
113 if (!other ||
114 other->d->shapes != d->shapes) {
115
116 return false;
117 }
118
119 d->newFills= other->d->newFills;
120 return true;
121}
The undo / redo command for setting the shape background.

References d.

◆ Private()

KoShapeBackgroundCommand::Private ( )
inline

Definition at line 20 of file KoShapeBackgroundCommand.cpp.

20 {
21 }

◆ redo()

void KoShapeBackgroundCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 82 of file KoShapeBackgroundCommand.cpp.

83{
85 QList<QSharedPointer<KoShapeBackground> >::iterator brushIt = d->newFills.begin();
86 Q_FOREACH (KoShape *shape, d->shapes) {
87 shape->setBackground(*brushIt);
88 shape->update();
89 ++brushIt;
90 }
91}
virtual void redo()
virtual void update() const
Definition KoShape.cpp:605
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918

References d, KUndo2Command::redo(), KoShape::setBackground(), and KoShape::update().

◆ undo()

void KoShapeBackgroundCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 93 of file KoShapeBackgroundCommand.cpp.

94{
96 QList<QSharedPointer<KoShapeBackground> >::iterator brushIt = d->oldFills.begin();
97 Q_FOREACH (KoShape *shape, d->shapes) {
98 shape->setBackground(*brushIt);
99 shape->update();
100 ++brushIt;
101 }
102}
virtual void undo()

References d, KoShape::setBackground(), KUndo2Command::undo(), and KoShape::update().

Member Data Documentation

◆ d

Private* const KoShapeBackgroundCommand::d
private

Definition at line 59 of file KoShapeBackgroundCommand.h.

◆ newFills

QList<QSharedPointer<KoShapeBackground> > KoShapeBackgroundCommand::newFills

Definition at line 39 of file KoShapeBackgroundCommand.cpp.

◆ oldFills

QList<QSharedPointer<KoShapeBackground> > KoShapeBackgroundCommand::oldFills

Definition at line 38 of file KoShapeBackgroundCommand.cpp.

◆ shapes

QList<KoShape*> KoShapeBackgroundCommand::shapes

the shapes to set background for

Definition at line 37 of file KoShapeBackgroundCommand.cpp.


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