Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeReorderCommand.cpp File Reference
#include "KoShapeReorderCommand.h"
#include "KoShape.h"
#include "KoShape_p.h"
#include "KoShapeManager.h"
#include "KoShapeContainer.h"
#include <klocalizedstring.h>
#include <FlakeDebug.h>
#include <limits.h>

Go to the source code of this file.

Classes

class  KoShapeReorderCommandPrivate
 

Functions

QDebug operator<< (QDebug dbg, const KoShapeReorderCommand::IndexedShape &indexedShape)
 
static void prepare (KoShape *s, QMap< KoShape *, QList< KoShape * > > &newOrder, KoShapeManager *manager, KoShapeReorderCommand::MoveShapeType move)
 

Function Documentation

◆ operator<<()

QDebug operator<< ( QDebug dbg,
const KoShapeReorderCommand::IndexedShape & indexedShape )

Definition at line 316 of file KoShapeReorderCommand.cpp.

317{
318 dbg.nospace() << "IndexedShape (" << indexedShape.shape << ", " << indexedShape.zIndex << ")";
319 return dbg.space();
320}

References KoShapeReorderCommand::IndexedShape::shape, and KoShapeReorderCommand::IndexedShape::zIndex.

◆ prepare()

static void prepare ( KoShape * s,
QMap< KoShape *, QList< KoShape * > > & newOrder,
KoShapeManager * manager,
KoShapeReorderCommand::MoveShapeType move )
static

Definition at line 96 of file KoShapeReorderCommand.cpp.

97{
99 QMap<KoShape*, QList<KoShape*> >::iterator it(newOrder.find(parent));
100 if (it == newOrder.end()) {
101 QList<KoShape*> children;
102 if (parent != 0) {
103 children = parent->shapes();
104 }
105 else {
106 // get all toplevel shapes
107 children = manager->topLevelShapes();
108 }
109 std::sort(children.begin(), children.end(), KoShape::compareShapeZIndex);
110 // the append and prepend are needed so that the raise/lower of all shapes works as expected.
111 children.append(0);
112 children.prepend(0);
113 it = newOrder.insert(parent, children);
114 }
115 QList<KoShape *> & shapes(newOrder[parent]);
116 int index = shapes.indexOf(s);
117 if (index != -1) {
118 shapes.removeAt(index);
119 switch (move) {
121 index = shapes.size();
122 break;
124 if (index < shapes.size()) {
125 ++index;
126 }
127 break;
129 if (index > 0) {
130 --index;
131 }
132 break;
134 index = 0;
135 break;
136 }
137 shapes.insert(index,s);
138 }
139}
QList< KoShape * > topLevelShapes() const
@ RaiseShape
raise the selected shape to the level that it is above the shape that is on top of it.
@ SendToBack
Lower the selected shape to be below all other shapes.
@ LowerShape
Lower the selected shape to the level that it is below the shape that is below it.
@ BringToFront
Raise the selected shape to be on top of all shapes.
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
Definition KoShape.cpp:434
KoShapeContainer * parent() const
Definition KoShape.cpp:1039
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References KoShapeReorderCommand::BringToFront, KoShape::compareShapeZIndex(), KoShapeReorderCommand::LowerShape, KoShape::parent(), KoShapeReorderCommand::RaiseShape, KoShapeReorderCommand::SendToBack, and KoShapeManager::topLevelShapes().