Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Fix an assert when modifying Mesh Gradient on a shape

Dmitry Kazakov0842ec2b208f
diff --git a/libs/command/kis_command_utils.cpp b/libs/command/kis_command_utils.cpp
index b92523ccba..44394ce8f0 100644
--- a/libs/command/kis_command_utils.cpp
+++ b/libs/command/kis_command_utils.cpp
@@ -197,4 +197,17 @@ namespace KisCommandUtils
KUndo2Command::undo();
}
+ void redoAndMergeIntoAccumulatingCommand(KUndo2Command *cmd, QScopedPointer<KUndo2Command> &accumulatingCommand)
+ {
+ cmd->redo();
+ if (accumulatingCommand) {
+ const bool isMerged = accumulatingCommand->mergeWith(cmd);
+ KIS_SAFE_ASSERT_RECOVER_NOOP(isMerged);
+ delete cmd;
+ } else {
+ accumulatingCommand.reset(cmd);
+ }
+ }
+
+
}
diff --git a/libs/command/kis_command_utils.h b/libs/command/kis_command_utils.h
index 719fc0ae74..53c9c02802 100644
--- a/libs/command/kis_command_utils.h
+++ b/libs/command/kis_command_utils.h
@@ -130,6 +130,15 @@ namespace KisCommandUtils
private:
QVector<KUndo2Command*> m_commands;
};
+
+ /**
+ * A simple function to merge down commands in iterative actions, like the
+ * ones we use in shape manipulations. The function takes ownership of \p cmd
+ * and either merges it into \p accumulatingCommand (if exists) or just
+ * sets the accumulating command to that command
+ */
+ KRITACOMMAND_EXPORT
+ void redoAndMergeIntoAccumulatingCommand(KUndo2Command *cmd, QScopedPointer<KUndo2Command> &accumulatingCommand);
}
#endif /* __KIS_COMMAND_UTILS_H */
diff --git a/libs/flake/tools/KoPathControlPointMoveStrategy.cpp b/libs/flake/tools/KoPathControlPointMoveStrategy.cpp
index 9e3cf199e3..b251c57adc 100644
--- a/libs/flake/tools/KoPathControlPointMoveStrategy.cpp
+++ b/libs/flake/tools/KoPathControlPointMoveStrategy.cpp
@@ -39,14 +39,9 @@ void KoPathControlPointMoveStrategy::handleMouseMove(const QPointF &mouseLocatio
m_move += move;
- KoPathControlPointMoveCommand *cmd = new KoPathControlPointMoveCommand(m_pointData, move, m_pointType);
-
- cmd->redo();
- if (m_intermediateCommand) {
- m_intermediateCommand->mergeWith(cmd);
- } else {
- m_intermediateCommand.reset(cmd);
- }
+ KisCommandUtils::redoAndMergeIntoAccumulatingCommand(
+ new KoPathControlPointMoveCommand(m_pointData, move, m_pointType),
+ m_intermediateCommand);
}
void KoPathControlPointMoveStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
diff --git a/libs/flake/tools/KoPathPointMoveStrategy.cpp b/libs/flake/tools/KoPathPointMoveStrategy.cpp
index 5e3b16c4a5..447b5e1998 100644
--- a/libs/flake/tools/KoPathPointMoveStrategy.cpp
+++ b/libs/flake/tools/KoPathPointMoveStrategy.cpp
@@ -44,14 +44,10 @@ void KoPathPointMoveStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::
if (! selection)
return;
- KoPathPointMoveCommand *cmd = new KoPathPointMoveCommand(selection->selectedPointsData(), move - m_move);
+ KisCommandUtils::redoAndMergeIntoAccumulatingCommand(
+ new KoPathPointMoveCommand(selection->selectedPointsData(), move - m_move),
+ m_intermediateCommand);
- cmd->redo();
- if (m_intermediateCommand) {
- m_intermediateCommand->mergeWith(cmd);
- } else {
- m_intermediateCommand.reset(cmd);
- }
m_move = move;
}
diff --git a/plugins/tools/defaulttool/defaulttool/ShapeGradientEditStrategy.cpp b/plugins/tools/defaulttool/defaulttool/ShapeGradientEditStrategy.cpp
index 825159442b..e9891c8538 100644
--- a/plugins/tools/defaulttool/defaulttool/ShapeGradientEditStrategy.cpp
+++ b/plugins/tools/defaulttool/defaulttool/ShapeGradientEditStrategy.cpp
@@ -14,6 +14,7 @@
#include "kis_assert.h"
#include "SelectionDecorator.h"
#include <kundo2command.h>
+#include <kis_command_utils.h>
#include <KoSnapGuide.h>
#include <KisSnapPointStrategy.h>
@@ -69,20 +70,17 @@ void ShapeGradientEditStrategy::handleMouseMove(const QPointF &mouseLocation, Qt
const QPointF snappedPosition = tool()->canvas()->snapGuide()->snap(mouseLocation, m_d->initialOffset, modifiers);
const QPointF diff = snappedPosition - m_d->previous;
m_d->previous = snappedPosition;
- KUndo2Command *cmd = m_d->gradientHandles.moveGradientHandle(m_d->handleType, diff);
- cmd->redo();
- if (cmd) {
- if (m_d->intermediateCommand) {
- m_d->intermediateCommand->mergeWith(cmd);
- } else {
- m_d->intermediateCommand.reset(cmd);
- }
- }
+
+ KisCommandUtils::redoAndMergeIntoAccumulatingCommand(
+ m_d->gradientHandles.moveGradientHandle(m_d->handleType, diff),
+ m_d->intermediateCommand);
}
KUndo2Command *ShapeGradientEditStrategy::createCommand()
{
- return m_d->intermediateCommand.take();
+ return m_d->intermediateCommand ?
+ new KisCommandUtils::SkipFirstRedoWrapper(m_d->intermediateCommand.take()) :
+ nullptr;
}
void ShapeGradientEditStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)
diff --git a/plugins/tools/defaulttool/defaulttool/ShapeMeshGradientEditStrategy.cpp b/plugins/tools/defaulttool/defaulttool/ShapeMeshGradientEditStrategy.cpp
index d067fb35fd..751ba6ea3e 100644
--- a/plugins/tools/defaulttool/defaulttool/ShapeMeshGradientEditStrategy.cpp
+++ b/plugins/tools/defaulttool/defaulttool/ShapeMeshGradientEditStrategy.cpp
@@ -8,6 +8,8 @@
#include <KoToolBase.h>
#include <KoCanvasBase.h>
+#include <kundo2command.h>
+#include <kis_command_utils.h>
struct ShapeMeshGradientEditStrategy::Private {
Private(const QPointF& start, KoShape *shape, KoFlake::FillVariant fillVariant)
@@ -20,6 +22,7 @@ struct ShapeMeshGradientEditStrategy::Private {
QPointF start;
KoShapeMeshGradientHandles::Handle startHandle;
KoShapeMeshGradientHandles handles;
+ QScopedPointer<KUndo2Command> intermediateCommand;
};
ShapeMeshGradientEditStrategy::ShapeMeshGradientEditStrategy(KoToolBase *tool,
@@ -41,12 +44,18 @@ void ShapeMeshGradientEditStrategy::handleMouseMove(const QPointF &mouseLocation
Qt::KeyboardModifiers modifiers)
{
Q_UNUSED(modifiers);
- tool()->canvas()->addCommand(m_d->handles.moveGradientHandle(m_d->startHandle, mouseLocation));
+
+
+ KisCommandUtils::redoAndMergeIntoAccumulatingCommand(
+ m_d->handles.moveGradientHandle(m_d->startHandle, mouseLocation),
+ m_d->intermediateCommand);
}
KUndo2Command* ShapeMeshGradientEditStrategy::createCommand()
{
- return nullptr;
+ return m_d->intermediateCommand ?
+ new KisCommandUtils::SkipFirstRedoWrapper(m_d->intermediateCommand.take()) :
+ nullptr;
}
void ShapeMeshGradientEditStrategy::finishInteraction(Qt::KeyboardModifiers modifiers)