Krita Source Code Documentation
Loading...
Searching...
No Matches
KoMultiPathPointMergeCommand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8#include <KoPathPointData.h>
9
12#include <KoSelection.h>
13
14#include "kis_assert.h"
15
16
18{
19 Private(const KoPathPointData &_pointData1, const KoPathPointData &_pointData2, KoShapeControllerBase *_controller, KoSelection *_selection)
20 : pointData1(_pointData1),
21 pointData2(_pointData2),
22 controller(_controller),
23 selection(_selection)
24 {
25 }
26
31
32
33 QScopedPointer<KoPathCombineCommand> combineCommand;
34 QScopedPointer<KUndo2Command> mergeCommand;
35};
36
38 : KUndo2Command(kundo2_i18n("Merge points"), parent),
39 m_d(new Private(pointData1, pointData2, controller, selection))
40{
41}
42
46
51
53{
54 // Create shapes during the first call only.
55 if (!m_d->mergeCommand && !m_d->combineCommand)
56 {
57 if (m_d->pointData1.pathShape != m_d->pointData2.pathShape) {
59
60 QList<KoPathShape*> shapes = { m_d->pointData1.pathShape, m_d->pointData2.pathShape };
61 m_d->combineCommand.reset(new KoPathCombineCommand(m_d->controller, shapes));
62
63 KoPathPointData newPD1 = m_d->combineCommand->originalToCombined(m_d->pointData1);
64 KoPathPointData newPD2 = m_d->combineCommand->originalToCombined(m_d->pointData2);
65
66 m_d->mergeCommand.reset(createMergeCommand(newPD1, newPD2));
67 }
68 else {
69 m_d->mergeCommand.reset(createMergeCommand(m_d->pointData1, m_d->pointData2));
70 }
71 }
72
73 KoShape *mergedShape = 0;
74 if (m_d->mergeCommand)
75 {
76 m_d->mergeCommand->redo();
77 mergedShape = m_d->pointData1.pathShape;
78 }
79
80 if (m_d->combineCommand)
81 {
82 m_d->combineCommand->redo();
83 mergedShape = m_d->combineCommand->combinedPath();
84 }
85
86 if (m_d->selection) {
87 m_d->selection->select(mergedShape);
88 }
89
91}
92
94{
95 return m_d->combineCommand ? m_d->combineCommand->combinedPath() : 0;
96}
97
99{
101
102 if (m_d->mergeCommand) {
103 m_d->mergeCommand->undo();
104 }
105
106 if (m_d->combineCommand) {
107 m_d->combineCommand->undo();
108 }
109
110 if (m_d->selection) {
111 m_d->selection->select(m_d->pointData1.pathShape);
112 if (m_d->pointData1.pathShape != m_d->pointData2.pathShape) {
113 m_d->selection->select(m_d->pointData2.pathShape);
114 }
115 }
116}
117
virtual void undo()
virtual void redo()
The undo / redo command for combining two or more paths into one.
Describe a KoPathPoint by a KoPathShape and its indices.
The undo / redo command for merging two subpath end points.
The position of a path point within a path shape.
Definition KoPathShape.h:63
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
KUndo2MagicString kundo2_i18n(const char *text)
const QScopedPointer< Private > m_d
virtual KUndo2Command * createMergeCommand(const KoPathPointData &pointData1, const KoPathPointData &pointData2)
QScopedPointer< KoPathCombineCommand > combineCommand
KoMultiPathPointMergeCommand(const KoPathPointData &pointData1, const KoPathPointData &pointData2, KoShapeControllerBase *controller, KoSelection *selection, KUndo2Command *parent=0)
QScopedPointer< KUndo2Command > mergeCommand
Private(const KoPathPointData &_pointData1, const KoPathPointData &_pointData2, KoShapeControllerBase *_controller, KoSelection *_selection)