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

The undo / redo command for ungrouping shapes. More...

#include <KoShapeUngroupCommand.h>

+ Inheritance diagram for KoShapeUngroupCommand:

Classes

struct  Private
 

Public Member Functions

 KoShapeUngroupCommand (KoShapeContainer *container, const QList< KoShape * > &shapes, const QList< KoShape * > &topLevelShapes=QList< KoShape * >(), KUndo2Command *parent=0)
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoShapeUngroupCommand ()
 
- 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 int id () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual bool mergeWith (const KUndo2Command *other)
 
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 ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

The undo / redo command for ungrouping shapes.

Definition at line 20 of file KoShapeUngroupCommand.h.

Constructor & Destructor Documentation

◆ KoShapeUngroupCommand()

KoShapeUngroupCommand::KoShapeUngroupCommand ( KoShapeContainer * container,
const QList< KoShape * > & shapes,
const QList< KoShape * > & topLevelShapes = QList<KoShape*>(),
KUndo2Command * parent = 0 )

Command to ungroup a set of shapes from one parent container.

Parameters
containerthe group to ungroup the shapes from.
shapesa list of all the shapes that should be ungrouped.
topLevelShapesa list of top level shapes.
parentthe parent command used for macro commands

Definition at line 37 of file KoShapeUngroupCommand.cpp.

39 : KUndo2Command(parent),
40 m_d(new Private(container, shapes, topLevelShapes))
41{
42 setText(kundo2_i18n("Ungroup shapes"));
43}
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
const QScopedPointer< Private > m_d
KUndo2MagicString kundo2_i18n(const char *text)

References kundo2_i18n(), and KUndo2Command::setText().

◆ ~KoShapeUngroupCommand()

KoShapeUngroupCommand::~KoShapeUngroupCommand ( )

Definition at line 45 of file KoShapeUngroupCommand.cpp.

46{
47}

Member Function Documentation

◆ redo()

void KoShapeUngroupCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 49 of file KoShapeUngroupCommand.cpp.

50{
51 using IndexedShape = KoShapeReorderCommand::IndexedShape;
52
53 KoShapeContainer *newParent = m_d->container->parent();
54
55 QList<IndexedShape> indexedSiblings;
56 QList<KoShape*> perspectiveSiblings;
57
58 if (newParent) {
59 perspectiveSiblings = newParent->shapes();
60 std::sort(perspectiveSiblings.begin(), perspectiveSiblings.end(), KoShape::compareShapeZIndex);
61 } else {
62 perspectiveSiblings = m_d->topLevelShapes;
63 }
64
65 Q_FOREACH (KoShape *shape, perspectiveSiblings) {
66 indexedSiblings.append(shape);
67 }
68
69 // find the place where the ungrouped shapes should be inserted
70 // (right on the top of their current container)
71 auto insertIt = std::upper_bound(indexedSiblings.begin(),
72 indexedSiblings.end(),
73 IndexedShape(m_d->container));
74
75 std::copy(m_d->shapes.begin(), m_d->shapes.end(),
76 std::inserter(indexedSiblings, insertIt));
77
78 indexedSiblings = KoShapeReorderCommand::homogenizeZIndexesLazy(indexedSiblings);
79
80 const QTransform ungroupTransform = m_d->container->absoluteTransformation();
81 for (auto it = m_d->shapes.begin(); it != m_d->shapes.end(); ++it) {
82 KoShape *shape = *it;
83 KIS_SAFE_ASSERT_RECOVER(shape->parent() == m_d->container) { continue; }
84
85 shape->setParent(newParent);
86 shape->applyAbsoluteTransformation(ungroupTransform);
87 }
88
89 if (!indexedSiblings.isEmpty()) {
90 m_d->shapesReorderCommand.reset(new KoShapeReorderCommand(indexedSiblings));
91 m_d->shapesReorderCommand->redo();
92 }
93}
QList< KoShape * > shapes() const
This command allows you to change the zIndex of a number of shapes.
static QList< KoShapeReorderCommand::IndexedShape > homogenizeZIndexesLazy(QList< IndexedShape > shapes)
void applyAbsoluteTransformation(const QTransform &matrix)
Definition KoShape.cpp:400
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
Definition KoShape.cpp:434
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
void setParent(KoShapeContainer *parent)
Definition KoShape.cpp:535
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References KoShape::applyAbsoluteTransformation(), KoShape::compareShapeZIndex(), KoShapeReorderCommand::homogenizeZIndexesLazy(), KIS_SAFE_ASSERT_RECOVER, m_d, KoShape::parent(), KoShape::setParent(), and KoShapeContainer::shapes().

◆ undo()

void KoShapeUngroupCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 95 of file KoShapeUngroupCommand.cpp.

96{
97 const QTransform groupTransform = m_d->container->absoluteTransformation().inverted();
98 for (auto it = m_d->shapes.begin(); it != m_d->shapes.end(); ++it) {
99 KoShape *shape = *it;
100
101 shape->setParent(m_d->container);
102 shape->applyAbsoluteTransformation(groupTransform);
103 }
104
105 if (m_d->shapesReorderCommand) {
106 m_d->shapesReorderCommand->undo();
107 m_d->shapesReorderCommand.reset();
108 }
109}

References KoShape::applyAbsoluteTransformation(), m_d, and KoShape::setParent().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KoShapeUngroupCommand::m_d
private

Definition at line 41 of file KoShapeUngroupCommand.h.


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