Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 62b1c189 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Cleanup: Reuse FlipFlopCommand in layer utils and processing applicator

parent e99b21ab
......@@ -435,29 +435,13 @@ namespace KisLayerUtils {
}
SwitchFrameCommand::SwitchFrameCommand(KisImageSP image, int time, bool finalize, SharedStorageSP storage)
: m_image(image),
: FlipFlopCommand(finalize),
m_image(image),
m_newTime(time),
m_finalize(finalize),
m_storage(storage) {}
SwitchFrameCommand::~SwitchFrameCommand() {}
void SwitchFrameCommand::redo() {
if (!m_finalize) {
init();
} else {
end();
}
}
void SwitchFrameCommand::undo() {
if (m_finalize) {
init();
} else {
end();
}
}
void SwitchFrameCommand::init() {
KisImageAnimationInterface *interface = m_image->animationInterface();
const int currentTime = interface->currentTime();
......
......@@ -22,6 +22,7 @@
#include "kundo2command.h"
#include "kis_types.h"
#include "kritaimage_export.h"
#include "kis_command_utils.h"
namespace KisMetaData
{
......@@ -51,7 +52,7 @@ namespace KisLayerUtils
void updateFrameJobs(FrameJobs *jobs, KisNodeSP node);
void updateFrameJobsRecursive(FrameJobs *jobs, KisNodeSP rootNode);
struct SwitchFrameCommand : public KUndo2Command {
struct SwitchFrameCommand : public KisCommandUtils::FlipFlopCommand {
struct SharedStorage {
/**
* For some reason the absence of a destructor in the SharedStorage
......@@ -66,8 +67,6 @@ namespace KisLayerUtils
public:
SwitchFrameCommand(KisImageSP image, int time, bool finalize, SharedStorageSP storage);
~SwitchFrameCommand();
void redo();
void undo();
private:
void init();
......@@ -76,7 +75,6 @@ namespace KisLayerUtils
private:
KisImageWSP m_image;
int m_newTime;
bool m_finalize;
SharedStorageSP m_storage;
};
......
......@@ -25,58 +25,46 @@
#include "commands_new/kis_processing_command.h"
#include "kis_stroke_strategy_undo_command_based.h"
#include "kis_layer_utils.h"
#include "kis_command_utils.h"
class DisableUIUpdatesCommand : public KUndo2Command
class DisableUIUpdatesCommand : public KisCommandUtils::FlipFlopCommand
{
public:
DisableUIUpdatesCommand(KisImageWSP image,
bool finalUpdate)
: m_image(image),
m_finalUpdate(finalUpdate)
: FlipFlopCommand(finalUpdate),
m_image(image)
{
}
void redo() {
if(m_finalUpdate) m_image->enableUIUpdates();
else m_image->disableUIUpdates();
void init() {
m_image->disableUIUpdates();
}
void undo() {
if(!m_finalUpdate) m_image->enableUIUpdates();
else m_image->disableUIUpdates();
void end() {
m_image->enableUIUpdates();
}
private:
KisImageWSP m_image;
bool m_finalUpdate;
};
class UpdateCommand : public KUndo2Command
class UpdateCommand : public KisCommandUtils::FlipFlopCommand
{
public:
UpdateCommand(KisImageWSP image, KisNodeSP node,
KisProcessingApplicator::ProcessingFlags flags,
bool finalUpdate)
: m_image(image),
: FlipFlopCommand(finalUpdate),
m_image(image),
m_node(node),
m_flags(flags),
m_finalUpdate(finalUpdate)
m_flags(flags)
{
}
void redo() {
if(!m_finalUpdate) initialize();
else finalize();
}
void undo() {
if(m_finalUpdate) initialize();
else finalize();
}
private:
void initialize() {
void init() {
/**
* We disable all non-centralized updates here. Everything
* should be done by this command's explicit updates.
......@@ -88,7 +76,7 @@ private:
m_image->disableDirtyRequests();
}
void finalize() {
void end() {
m_image->enableDirtyRequests();
if(m_flags.testFlag(KisProcessingApplicator::RECURSIVE)) {
......@@ -130,25 +118,22 @@ private:
bool m_finalUpdate;
};
class EmitImageSignalsCommand : public KUndo2Command
class EmitImageSignalsCommand : public KisCommandUtils::FlipFlopCommand
{
public:
EmitImageSignalsCommand(KisImageWSP image,
KisImageSignalVector emitSignals,
bool finalUpdate)
: m_image(image),
m_emitSignals(emitSignals),
m_finalUpdate(finalUpdate)
: FlipFlopCommand(finalUpdate),
m_image(image),
m_emitSignals(emitSignals)
{
}
void redo() {
if(m_finalUpdate) doUpdate(m_emitSignals);
}
void undo() {
if(!m_finalUpdate) {
void end() {
if (isFinalizing()) {
doUpdate(m_emitSignals);
} else {
KisImageSignalVector reverseSignals;
KisImageSignalVector::iterator i = m_emitSignals.end();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment