Krita Source Code Documentation
Loading...
Searching...
No Matches
KoPathCombineCommand.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006, 2008 Jan Hambrecht <jaham@gmx.net>
3 * SPDX-FileCopyrightText: 2006, 2007 Thorsten Zachmann <zachmann@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
10#include "KoShapeContainer.h"
11#include "KoPathShape.h"
12#include <klocalizedstring.h>
13#include "kis_assert.h"
14#include <KoPathPointData.h>
15
16#include <QHash>
17
18class Q_DECL_HIDDEN KoPathCombineCommand::Private
19{
20public:
22 : controller(c), paths(p)
23 , combinedPath(0)
24 , combinedPathParent(0)
25 , isCombined(false)
26 {
27 foreach (KoPathShape * path, paths) {
28 oldParents.append(path->parent());
29 }
30 }
32 if (isCombined && controller) {
33 Q_FOREACH (KoPathShape* path, paths) {
34 delete path;
35 }
36 } else {
37 delete combinedPath;
38 }
39 }
40
46
47 QHash<KoPathShape*, int> shapeStartSegmentIndex;
48
50};
51
53 const QList<KoPathShape*> &paths, KUndo2Command *parent)
54 : KUndo2Command(kundo2_i18n("Combine paths"), parent)
55 , d(new Private(controller, paths))
56{
58
59 Q_FOREACH (KoPathShape* path, d->paths) {
60 if (!d->combinedPath) {
61 KoPathShape *clone = dynamic_cast<KoPathShape*>(path->cloneShape());
63
64 d->combinedPath = clone;
65 d->combinedPathParent = path->parent();
66 d->shapeStartSegmentIndex[path] = 0;
67 } else {
68 const int startSegmentIndex = d->combinedPath->combine(path);
69 d->shapeStartSegmentIndex[path] = startSegmentIndex;
70 }
71 }
72}
73
78
80{
82 if (d->paths.isEmpty()) return;
83
84 d->isCombined = true;
85
86 if (d->controller) {
87 Q_FOREACH (KoPathShape* p, d->paths) {
88 p->setParent(0);
89 }
90 d->combinedPath->setParent(d->combinedPathParent);
91 }
92}
93
95{
96 if (! d->paths.size())
97 return;
98
99 d->isCombined = false;
100
101 if (d->controller) {
102 d->combinedPath->setParent(0);
103
104 auto parentIt = d->oldParents.begin();
105 Q_FOREACH (KoPathShape* p, d->paths) {
106 p->setParent(*parentIt);
107 ++parentIt;
108 }
109 }
111}
112
114{
115 return d->combinedPath;
116}
117
119{
120 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(d->shapeStartSegmentIndex.contains(pd.pathShape), pd);
121
122 const int segmentOffset = d->shapeStartSegmentIndex[pd.pathShape];
123
124 KoPathPointIndex newIndex(segmentOffset + pd.pointIndex.first, pd.pointIndex.second);
125 return KoPathPointData(d->combinedPath, newIndex);
126}
127
const Params2D p
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
virtual void undo()
virtual void redo()
The undo / redo command for combining two or more paths into one.
QHash< KoPathShape *, int > shapeStartSegmentIndex
void redo() override
redo the command
QList< KoPathShape * > paths
KoPathCombineCommand(KoShapeControllerBase *controller, const QList< KoPathShape * > &paths, KUndo2Command *parent=0)
KoShapeContainer * combinedPathParent
KoPathPointData originalToCombined(KoPathPointData pd) const
QList< KoShapeContainer * > oldParents
void undo() override
revert the actions done in redo
KoShapeControllerBase * controller
Private(KoShapeControllerBase *c, const QList< KoPathShape * > &p)
Describe a KoPathPoint by a KoPathShape and its indices.
KoPathPointIndex pointIndex
position of the point in the path shape
KoPathShape * pathShape
path shape the path point belongs too
The position of a path point within a path shape.
Definition KoPathShape.h:63
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT_RECOVER_BREAK(cond)
Definition kis_assert.h:65
KUndo2MagicString kundo2_i18n(const char *text)