Commit 52533ef6 authored by Tusooa Zhu's avatar Tusooa Zhu 🔼

Change edit guides cmd to post-exec & auto-upload to doc

KisChangeGuidesCommand is now post-exec, which means the first redo
will be ignored. The command will not be created during dragging.
Instead, only when the mouse/pen/finger is released will the command
be created. The commands will not be merged.

Any set* function of KisGuidesManager will upload
the config to KisDocument.
parent 3723b4c0
......@@ -27,7 +27,7 @@
struct KisChangeGuidesCommand::Private
{
Private(KisDocument *_doc, KisChangeGuidesCommand *q) : doc(_doc), q(q) {}
Private(KisDocument *_doc, KisChangeGuidesCommand *q) : doc(_doc), q(q), firstRedo(true) {}
bool sameOrOnlyMovedOneGuideBetween(const KisGuidesConfig &first, const KisGuidesConfig &second);
enum Status {
......@@ -46,6 +46,8 @@ struct KisChangeGuidesCommand::Private
KisGuidesConfig oldGuides;
KisGuidesConfig newGuides;
bool firstRedo;
};
bool KisChangeGuidesCommand::Private::sameOrOnlyMovedOneGuideBetween(const KisGuidesConfig &first, const KisGuidesConfig &second)
......@@ -131,6 +133,10 @@ void KisChangeGuidesCommand::undo()
void KisChangeGuidesCommand::redo()
{
if (m_d->firstRedo) {
m_d->firstRedo = false;
return;
}
m_d->switchTo(m_d->newGuides);
}
......@@ -139,24 +145,3 @@ int KisChangeGuidesCommand::id() const
return 1863;
}
bool KisChangeGuidesCommand::mergeWith(const KUndo2Command *command)
{
bool result = false;
const KisChangeGuidesCommand *rhs =
dynamic_cast<const KisChangeGuidesCommand*>(command);
if (rhs) {
// we want to only merge consecutive movements, or creation then movement, or movement then deletion
// there should not be any changes not on the stack (see kis_guides_manager.cpp)
// nor any addition/removal of guides
// nor the movement of other guides
if (m_d->newGuides == rhs->m_d->oldGuides &&
m_d->sameOrOnlyMovedOneGuideBetween(m_d->oldGuides, rhs->m_d->newGuides)) {
m_d->newGuides = rhs->m_d->newGuides;
result = true;
}
}
return result;
}
......@@ -38,7 +38,6 @@ public:
void redo() override;
int id() const override;
bool mergeWith(const KUndo2Command *command) override;
private:
struct Private;
......
......@@ -49,13 +49,13 @@ struct KisGuidesManager::Private
currentGuide(invalidGuide),
cursorSwitched(false),
dragStartGuidePos(0),
updateDocumentCompressor(40, KisSignalCompressor::FIRST_ACTIVE),
shouldSetModified(false) {}
KisGuidesManager *q;
KisGuidesDecoration *decoration;
KisGuidesConfig guidesConfig;
KisGuidesConfig oldGuidesConfig;
KisSnapConfig snapConfig;
QPointer<KisView> view;
......@@ -96,7 +96,6 @@ struct KisGuidesManager::Private
KisSignalAutoConnectionsStore viewConnections;
KisSignalCompressor updateDocumentCompressor;
bool shouldSetModified;
};
......@@ -104,7 +103,6 @@ KisGuidesManager::KisGuidesManager(QObject *parent)
: QObject(parent),
m_d(new Private(this))
{
connect(&m_d->updateDocumentCompressor, SIGNAL(timeout()), SLOT(slotUploadConfigToDocument()));
}
KisGuidesManager::~KisGuidesManager()
......@@ -114,7 +112,8 @@ KisGuidesManager::~KisGuidesManager()
void KisGuidesManager::setGuidesConfig(const KisGuidesConfig &config)
{
if (config == m_d->guidesConfig) return;
setGuidesConfigImpl(config, true);
setGuidesConfigImpl(config, !config.hasSamePositionAs(m_d->guidesConfig));
slotUploadConfigToDocument();
}
void KisGuidesManager::slotDocumentRequestedConfig(const KisGuidesConfig &config)
......@@ -134,9 +133,10 @@ void KisGuidesManager::slotUploadConfigToDocument()
if (m_d->shouldSetModified && m_d->needsUndoCommand()) {
KUndo2Command *cmd = new KisChangeGuidesCommand(doc, value);
doc->addCommand(cmd);
} else {
doc->setGuidesConfig(value);
}
// we've made KisChangeGuidesCommand post-exec, so in all situations
// we will replace the whole config
doc->setGuidesConfig(value);
value.saveStaticData();
}
......@@ -154,7 +154,6 @@ void KisGuidesManager::setGuidesConfigImpl(const KisGuidesConfig &value, bool em
}
m_d->shouldSetModified |= emitModified;
m_d->updateDocumentCompressor.start();
const bool shouldFilterEvent =
value.showGuides() && !value.lockGuides() && value.hasGuides();
......@@ -263,6 +262,7 @@ void KisGuidesManager::setShowGuides(bool value)
{
m_d->guidesConfig.setShowGuides(value);
setGuidesConfigImpl(m_d->guidesConfig);
slotUploadConfigToDocument();
}
bool KisGuidesManager::lockGuides() const
......@@ -274,6 +274,7 @@ void KisGuidesManager::setLockGuides(bool value)
{
m_d->guidesConfig.setLockGuides(value);
setGuidesConfigImpl(m_d->guidesConfig);
slotUploadConfigToDocument();
}
bool KisGuidesManager::snapToGuides() const
......@@ -285,6 +286,7 @@ void KisGuidesManager::setSnapToGuides(bool value)
{
m_d->guidesConfig.setSnapToGuides(value);
setGuidesConfigImpl(m_d->guidesConfig);
slotUploadConfigToDocument();
}
bool KisGuidesManager::rulersMultiple2() const
......@@ -296,6 +298,7 @@ void KisGuidesManager::setRulersMultiple2(bool value)
{
m_d->guidesConfig.setRulersMultiple2(value);
setGuidesConfigImpl(m_d->guidesConfig);
slotUploadConfigToDocument();
}
KoUnit::Type KisGuidesManager::unitType() const
......@@ -307,6 +310,7 @@ void KisGuidesManager::setUnitType(const KoUnit::Type type)
{
m_d->guidesConfig.setUnitType(type);
setGuidesConfigImpl(m_d->guidesConfig, false);
slotUploadConfigToDocument();
}
void KisGuidesManager::setup(KisActionManager *actionManager)
......@@ -360,10 +364,7 @@ void KisGuidesManager::setView(QPointer<KisView> view)
snapGuide->overrideSnapStrategy(KoSnapGuide::GuideLineSnapping, 0);
snapGuide->enableSnapStrategy(KoSnapGuide::GuideLineSnapping, false);
if (m_d->updateDocumentCompressor.isActive()) {
m_d->updateDocumentCompressor.stop();
slotUploadConfigToDocument();
}
slotUploadConfigToDocument();
m_d->decoration = 0;
m_d->viewConnections.clear();
......@@ -503,6 +504,7 @@ void KisGuidesManager::Private::initDragStart(const GuideHandle &guide,
qreal guideValue,
bool snapToStart)
{
oldGuidesConfig = guidesConfig;
currentGuide = guide;
dragStartDoc = dragStart;
dragStartGuidePos = guideValue;
......@@ -582,6 +584,8 @@ bool KisGuidesManager::Private::mouseReleaseHandler(const QPointF &docPos)
updateSnappingStatus(guidesConfig);
}
q->slotUploadConfigToDocument();
return updateCursor(docPos) | result;
}
......
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