diff --git a/lib/abstractimageoperation.h b/lib/abstractimageoperation.h --- a/lib/abstractimageoperation.h +++ b/lib/abstractimageoperation.h @@ -58,6 +58,8 @@ void applyToDocument(Document::Ptr); Document::Ptr document() const; + void finishUndoJob(); + protected: virtual void redo() = 0; virtual void undo() diff --git a/lib/abstractimageoperation.cpp b/lib/abstractimageoperation.cpp --- a/lib/abstractimageoperation.cpp +++ b/lib/abstractimageoperation.cpp @@ -23,6 +23,7 @@ // Qt #include +#include // KDE #include @@ -90,6 +91,7 @@ ImageOperationCommand* command = new ImageOperationCommand(this); command->setText(d->mText); document()->undoStack()->push(command); + document()->imageOperationCompleted(); } else { deleteLater(); } @@ -100,6 +102,13 @@ finish(job->error() == KJob::NoError); } +void AbstractImageOperation::finishUndoJob() +{ + // Give QUndoStack time to update in case the undo is executed immediately + // (e.g. undo crop just sets the previous image) + QTimer::singleShot(0, document().data(), &Document::imageOperationCompleted); +} + void AbstractImageOperation::setText(const QString& text) { d->mText = text; diff --git a/lib/crop/cropimageoperation.cpp b/lib/crop/cropimageoperation.cpp --- a/lib/crop/cropimageoperation.cpp +++ b/lib/crop/cropimageoperation.cpp @@ -89,6 +89,7 @@ return; } document()->editor()->setImage(d->mOriginalImage); + finishUndoJob(); } } // namespace diff --git a/lib/document/document.h b/lib/document/document.h --- a/lib/document/document.h +++ b/lib/document/document.h @@ -197,6 +197,8 @@ void enqueueJob(DocumentJob*); + void imageOperationCompleted(); + /** * Returns true if there are queued tasks for this document. */ @@ -220,7 +222,6 @@ void emitMetaInfoLoaded(); void emitLoaded(); void emitLoadingFailed(); - void slotUndoIndexChanged(); void slotSaveResult(KJob*); void slotJobFinished(KJob*); diff --git a/lib/document/document.cpp b/lib/document/document.cpp --- a/lib/document/document.cpp +++ b/lib/document/document.cpp @@ -154,7 +154,6 @@ d->mImpl = 0; d->mUrl = url; d->mKeepRawData = false; - connect(&d->mUndoStack, SIGNAL(indexChanged(int)), SLOT(slotUndoIndexChanged())); reload(); } @@ -483,7 +482,7 @@ return &d->mUndoStack; } -void Document::slotUndoIndexChanged() +void Document::imageOperationCompleted() { if (d->mUndoStack.isClean()) { // If user just undid all his changes this does not really correspond diff --git a/lib/redeyereduction/redeyereductionimageoperation.cpp b/lib/redeyereduction/redeyereductionimageoperation.cpp --- a/lib/redeyereduction/redeyereductionimageoperation.cpp +++ b/lib/redeyereduction/redeyereductionimageoperation.cpp @@ -104,6 +104,7 @@ painter.drawImage(rect.topLeft(), d->mOriginalImage); } document()->editor()->setImage(img); + finishUndoJob(); } /** diff --git a/lib/resize/resizeimageoperation.cpp b/lib/resize/resizeimageoperation.cpp --- a/lib/resize/resizeimageoperation.cpp +++ b/lib/resize/resizeimageoperation.cpp @@ -89,6 +89,7 @@ return; } document()->editor()->setImage(d->mOriginalImage); + finishUndoJob(); } } // namespace diff --git a/lib/thumbnailview/thumbnailview.cpp b/lib/thumbnailview/thumbnailview.cpp --- a/lib/thumbnailview/thumbnailview.cpp +++ b/lib/thumbnailview/thumbnailview.cpp @@ -876,7 +876,7 @@ return; } - if (d->mDocumentInfoProvider && d->mDocumentInfoProvider->isModified(url)) { + if (d->mDocumentInfoProvider) { d->updateThumbnailForModifiedDocument(it->mIndex); } else { const KFileItem item = fileItemForIndex(it->mIndex); diff --git a/lib/transformimageoperation.cpp b/lib/transformimageoperation.cpp --- a/lib/transformimageoperation.cpp +++ b/lib/transformimageoperation.cpp @@ -101,7 +101,10 @@ orientation = d->mOrientation; break; } - document()->enqueueJob(new TransformJob(orientation)); + + TransformJob* job = new TransformJob(orientation); + connect(job, &TransformJob::result, this, &AbstractImageOperation::finishUndoJob); + document()->enqueueJob(job); } } // namespace diff --git a/tests/auto/documenttest.cpp b/tests/auto/documenttest.cpp --- a/tests/auto/documenttest.cpp +++ b/tests/auto/documenttest.cpp @@ -671,9 +671,11 @@ QCOMPARE(modifiedSpy.count(), 2); doc->undoStack()->undo(); + QTest::qWait(100); QCOMPARE(modifiedSpy.count(), 3); doc->undoStack()->undo(); + QTest::qWait(100); QCOMPARE(savedSpy.count(), 1); }