Commit fe691e04 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Remove all explicit setModified calls

The modified state must be controlled by the undo stack. Therefore,
this signal is now emitted by KisUndoStore.

In cases where undo history is not implemented, like in compositions
docker, one should use KisImage::setModifiedWithoutUndo(). This method
marks image as modified until the next save operation. And this mark
cannot be overridden by the undo stack.
parent f703e306
......@@ -7,6 +7,7 @@
#ifndef KIS_UNDO_STORE_H_
#define KIS_UNDO_STORE_H_
#include <QObject>
#include <QString>
#include <QVector>
......@@ -42,8 +43,9 @@ class KUndo2MagicString;
* KisDocument::createUndoStore() is just a factory method, the document
* doesn't store the undo store itself.
*/
class KRITACOMMAND_EXPORT KisUndoStore
class KRITACOMMAND_EXPORT KisUndoStore : public QObject
{
Q_OBJECT
public:
KisUndoStore();
virtual ~KisUndoStore();
......@@ -60,6 +62,9 @@ public:
virtual void endMacro() = 0;
virtual void purgeRedoState() = 0;
Q_SIGNALS:
void historyStateChanged();
private:
Q_DISABLE_COPY(KisUndoStore)
};
......
......@@ -16,6 +16,7 @@
KisSurrogateUndoStore::KisSurrogateUndoStore()
: m_undoStack(new KUndo2Stack)
{
connect(m_undoStack, SIGNAL(indexChanged(int)), this, SIGNAL(historyStateChanged()));
}
KisSurrogateUndoStore::~KisSurrogateUndoStore()
......@@ -98,6 +99,8 @@ void KisDumbUndoStore::undoLastCommand()
/**
* Ermm.. Do we actually have one? We are dumb! ;)
*/
emit historyStateChanged();
}
void KisDumbUndoStore::addCommand(KUndo2Command *command)
......@@ -107,6 +110,8 @@ void KisDumbUndoStore::addCommand(KUndo2Command *command)
*/
command->redo();
delete command;
emit historyStateChanged();
}
void KisDumbUndoStore::beginMacro(const KUndo2MagicString& macroName)
......@@ -122,6 +127,8 @@ void KisDumbUndoStore::endMacro()
/**
* Roger that! :)
*/
emit historyStateChanged();
}
void KisDumbUndoStore::purgeRedoState()
......
......@@ -197,8 +197,6 @@ void KisNodePropertyListCommand::setNodePropertiesAutoUndo(KisNodeSP node, KisIm
QScopedPointer<KUndo2Command> cmd(new KisNodePropertyListCommand(node, proplist));
image->setModified();
if (undo) {
image->undoAdapter()->addCommand(cmd.take());
}
......@@ -225,6 +223,9 @@ void KisNodePropertyListCommand::setNodePropertiesAutoUndo(KisNodeSP node, KisIm
void initStrokeCallback() override {
m_cmd->redo();
// NOTE: we don't emit imageModified signal here because this
// branch is only taken for the stasis changes, that do not
// change actual image representation.
}
private:
......
......@@ -171,6 +171,7 @@ public:
}
connect(q, SIGNAL(sigImageModified()), KisMemoryStatisticsServer::instance(), SLOT(notifyImageChanged()));
connect(undoStore.data(), SIGNAL(historyStateChanged()), &signalRouter, SLOT(emitImageModifiedNotification()));
}
~KisImagePrivate() {
......@@ -1525,12 +1526,6 @@ void KisImage::flattenLayer(KisLayerSP layer)
KisLayerUtils::flattenLayer(this, layer);
}
void KisImage::setModified()
{
m_d->signalRouter.emitNotification(ModifiedSignal);
}
void KisImage::setModifiedWithoutUndo()
{
m_d->signalRouter.emitNotification(ModifiedWithoutUndoSignal);
......
......@@ -442,18 +442,15 @@ public:
*/
KisUndoStore* undoStore();
/**
* Tell the image it's modified; this emits the sigImageModified
* signal. This happens when the image needs to be saved
*/
void setModified();
/**
* Tell the image it's modified without creation of an undo command.
* It may happen when e.g. layer visibility has changed.
*
* This function emits both, sigImageModified() and
* sigImageModifiedWithoutUndo()
*
* For normal modifications with undo information the signal
* emission is triggered by the undo stack
*/
void setModifiedWithoutUndo();
......
......@@ -60,6 +60,11 @@ KisImageSignalRouter::~KisImageSignalRouter()
{
}
void KisImageSignalRouter::emitImageModifiedNotification()
{
emitNotification(ModifiedSignal);
}
void KisImageSignalRouter::emitNotifications(KisImageSignalVector notifications)
{
Q_FOREACH (const KisImageSignalType &type, notifications) {
......
......@@ -33,6 +33,9 @@ public:
void emitNotifyBatchUpdateStarted();
void emitNotifyBatchUpdateEnded();
public Q_SLOTS:
void emitImageModifiedNotification();
private Q_SLOTS:
void slotNotification(KisImageSignalType type);
......
......@@ -38,10 +38,6 @@ void KisLegacyUndoAdapter::addCommand(KUndo2Command *command)
m_image->barrierLock();
undoStore()->addCommand(command);
m_image->unlock();
/// Sometimes legacy commands forget to emit sigImageModified() signal,
/// it causes dockers to be updated in correctly. Let's help them.
m_image->setModified();
}
}
......@@ -63,9 +59,5 @@ void KisLegacyUndoAdapter::endMacro()
m_image->unlock();
}
undoStore()->endMacro();
/// Sometimes legacy commands forget to emit sigImageModified() signal,
/// it causes dockers to be updated in correctly. Let's help them.
m_image->setModified();
}
......@@ -44,6 +44,8 @@ void KisMacroBasedUndoStore::addCommand(KUndo2Command *cmd)
*/
cmd->redo();
m_d->command->addCommand(toQShared(cmd));
emit historyStateChanged();
}
void KisMacroBasedUndoStore::beginMacro(const KUndo2MagicString& macroName)
......
......@@ -218,7 +218,7 @@ bool Document::setBackgroundColor(const QColor &color)
KoColor background = KoColor(color, d->document->image()->colorSpace());
d->document->image()->setDefaultProjectionColor(background);
d->document->image()->setModified();
d->document->image()->setModifiedWithoutUndo();
d->document->image()->initialRefreshGraph();
return true;
......
......@@ -959,7 +959,7 @@ void LayerModel::updateActiveLayerWithNewFilterConfig()
}
d->newConfig = 0;
d->activeNode->setDirty(d->activeNode->extent());
d->image->setModified();
d->image->setModifiedWithoutUndo();
QTimer::singleShot(100, this, SIGNAL(activeFilterConfigChanged()));
}
......@@ -573,7 +573,6 @@ void KisStrokeSelectionActionFactory::run(KisViewManager *view, const StrokeSele
KUndo2Command *cmd = view->canvasBase()->shapeController()->addShapeDirect(shape, 0);
KisProcessingApplicator::runSingleCommandStroke(view->image(), cmd);
}
image->setModified();
}
void KisStrokeBrushSelectionActionFactory::run(KisViewManager *view, const StrokeSelectionOptions& params)
......@@ -611,6 +610,5 @@ void KisStrokeBrushSelectionActionFactory::run(KisViewManager *view, const Strok
helper.setFGColorOverride(color);
helper.setSelectionOverride(0);
helper.paintPainterPath(outline);
image->setModified();
}
}
......@@ -17,6 +17,7 @@
KisDocumentUndoStore::KisDocumentUndoStore(KisDocument *doc)
: m_doc(doc)
{
connect(doc->undoStack(), SIGNAL(indexChanged(int)), this, SIGNAL(historyStateChanged()));
}
const KUndo2Command* KisDocumentUndoStore::presentCommand()
......
......@@ -343,13 +343,6 @@ QCursor KisTool::cursor() const
return d->cursor;
}
void KisTool::notifyModified() const
{
if (image()) {
image()->setModified();
}
}
KoPatternSP KisTool::currentPattern()
{
return d->currentPattern;
......
......@@ -261,9 +261,6 @@ protected:
KisImageWSP image() const;
QCursor cursor() const;
/// Call this to set the document modified
void notifyModified() const;
KisImageWSP currentImage();
KoPatternSP currentPattern();
KoAbstractGradientSP currentGradient();
......
......@@ -238,7 +238,6 @@ void KisToolFreehand::endPrimaryAction(KoPointerEvent *event)
static_cast<KisCanvas2*>(canvas())->paintingAssistantsDecoration()->endStroke();
}
notifyModified();
KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2 *>(canvas());
if (canvas2) {
canvas2->viewManager()->enableControls();
......
......@@ -197,7 +197,7 @@ void CompositionDockerDock::saveClicked()
saveNameEdit->clear();
updateModel();
compositionView->setCurrentIndex(m_model->index(image->compositions().count()-1, 0));
image->setModified();
image->setModifiedWithoutUndo();
}
void CompositionDockerDock::moveCompositionUp()
......@@ -402,7 +402,7 @@ void CompositionDockerDock::updateComposition()
if (m_canvas && m_canvas->viewManager() && m_canvas->viewManager()->image() && index.isValid()) {
KisLayerCompositionSP composition = m_model->compositionFromIndex(index);
composition->store();
m_canvas->image()->setModified();
m_canvas->image()->setModifiedWithoutUndo();
}
}
......@@ -418,7 +418,7 @@ void CompositionDockerDock::renameComposition()
composition->name(), &ok);
if (ok && !name.isEmpty()) {
composition->setName(name);
m_canvas->image()->setModified();
m_canvas->image()->setModifiedWithoutUndo();
}
}
}
......
......@@ -225,7 +225,6 @@ void LayerSplit::slotLayerSplit()
}
undo->endMacro();
image->setModified();
}
QApplication::restoreOverrideCursor();
......
......@@ -216,7 +216,6 @@ void KisChannelSeparator::separate(KoUpdater * progressUpdater, enumSepAlphaOpti
}
adapter.endMacro();
image->setModified();
}
progressUpdater->setProgress(100);
......
......@@ -136,7 +136,6 @@ void WaveletDecompose::slotWaveletDecompose()
undo->endMacro();
updater->setProgress(100);
image->unlock();
image->setModified();
}
QApplication::restoreOverrideCursor();
......
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