[pim/kmail] src: inherit from UndoInfoBase
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 3b1964a498ae304c9ba5a10e9df52b060808fe0b by Laurent Montel.
Committed on 23/07/2026 at 05:58.
Pushed by mlaurent into branch 'master'.
inherit from UndoInfoBase
M +4 -4 src/kmcommands.cpp
M +7 -6 src/undostack.cpp
M +8 -8 src/undostack.h
https://invent.kde.org/pim/kmail/-/commit/3b1964a498ae304c9ba5a10e9df52b060808fe0b
diff --git a/src/kmcommands.cpp b/src/kmcommands.cpp
index 9e27e1470..3ca7ed39f 100644
--- a/src/kmcommands.cpp
+++ b/src/kmcommands.cpp
@@ -1523,9 +1523,9 @@ KMCommand::Result KMMoveCommand::execute()
}
if (parent.id() != item.storageCollectionId()) {
parent = Akonadi::Collection(item.storageCollectionId());
- undoId = kmkernel->undoStack()->newUndoAction(parent, mDestFolder);
+ undoId = kmkernel->undoStack()->newUndoMoveAction(parent, mDestFolder);
}
- kmkernel->undoStack()->addMsgToAction(undoId, item);
+ kmkernel->undoStack()->addMsgToMoveAction(undoId, item);
}
} else {
auto job = new Akonadi::ItemDeleteJob(retrievedList, this);
@@ -1649,9 +1649,9 @@ KMCommand::Result KMTrashMsgCommand::execute()
}
if (parent.id() != item.storageCollectionId()) {
parent = Akonadi::Collection(item.storageCollectionId());
- undoId = kmkernel->undoStack()->newUndoAction(parent, trash);
+ undoId = kmkernel->undoStack()->newUndoMoveAction(parent, trash);
}
- kmkernel->undoStack()->addMsgToAction(undoId, item);
+ kmkernel->undoStack()->addMsgToMoveAction(undoId, item);
}
} else {
auto job = new Akonadi::ItemDeleteJob(*trashIt, this);
diff --git a/src/undostack.cpp b/src/undostack.cpp
index 4e773ed37..4041f1b62 100644
--- a/src/undostack.cpp
+++ b/src/undostack.cpp
@@ -38,14 +38,14 @@ void UndoStack::clear()
QString UndoStack::undoInfo() const
{
if (!mStack.isEmpty()) {
- UndoInfoMoveItems *info = mStack.first();
+ UndoInfoBase *info = mStack.first();
return info->undoInfo();
} else {
return {};
}
}
-int UndoStack::newUndoAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder)
+int UndoStack::newUndoMoveAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder)
{
auto info = new UndoInfoMoveItems;
info->id = ++mLastId;
@@ -61,10 +61,10 @@ int UndoStack::newUndoAction(const Akonadi::Collection &srcFolder, const Akonadi
return info->id;
}
-void UndoStack::addMsgToAction(int undoId, const Akonadi::Item &item)
+void UndoStack::addMsgToMoveAction(int undoId, const Akonadi::Item &item)
{
if (!mCachedInfo || mCachedInfo->id != undoId) {
- QList<UndoInfoMoveItems *>::const_iterator itr = mStack.constBegin();
+ QList<UndoInfoBase *>::const_iterator itr = mStack.constBegin();
while (itr != mStack.constEnd()) {
if ((*itr)->id == undoId) {
mCachedInfo = (*itr);
@@ -75,7 +75,8 @@ void UndoStack::addMsgToAction(int undoId, const Akonadi::Item &item)
}
Q_ASSERT(mCachedInfo);
- mCachedInfo->items.append(item);
+ UndoInfoMoveItems *moveItems = dynamic_cast<UndoInfoMoveItems *>(mCachedInfo);
+ moveItems->items.append(item);
}
bool UndoStack::isEmpty() const
@@ -86,7 +87,7 @@ bool UndoStack::isEmpty() const
void UndoStack::undo()
{
if (!mStack.isEmpty()) {
- UndoInfoMoveItems *info = mStack.takeFirst();
+ UndoInfoBase *info = mStack.takeFirst();
info->undo();
Q_EMIT undoStackChanged();
} else {
diff --git a/src/undostack.h b/src/undostack.h
index 29e4cb5c0..69adaa69b 100644
--- a/src/undostack.h
+++ b/src/undostack.h
@@ -26,19 +26,19 @@ public:
virtual ~UndoInfoBase() { };
virtual void undo() = 0;
[[nodiscard]] virtual QString undoInfo() const = 0;
+ int id = -1;
};
/** A class for storing Undo information. */
-class UndoInfoMoveItems : public QObject
+class UndoInfoMoveItems : public QObject, public UndoInfoBase
{
Q_OBJECT
public:
UndoInfoMoveItems();
~UndoInfoMoveItems() override;
- [[nodiscard]] QString undoInfo() const;
+ [[nodiscard]] QString undoInfo() const override;
- void undo();
- int id = -1;
+ void undo() override;
Akonadi::Item::List items;
Akonadi::Collection srcFolder;
Akonadi::Collection destFolder;
@@ -56,8 +56,8 @@ public:
explicit UndoStack(int size);
~UndoStack() override;
- [[nodiscard]] int newUndoAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder);
- void addMsgToAction(int undoId, const Akonadi::Item &item);
+ [[nodiscard]] int newUndoMoveAction(const Akonadi::Collection &srcFolder, const Akonadi::Collection &destFolder);
+ void addMsgToMoveAction(int undoId, const Akonadi::Item &item);
[[nodiscard]] bool isEmpty() const;
void undo();
@@ -68,9 +68,9 @@ Q_SIGNALS:
private:
KMAIL_NO_EXPORT void clear();
- QList<UndoInfoMoveItems *> mStack;
+ QList<UndoInfoBase *> mStack;
const int mSize = 0;
int mLastId = 0;
- UndoInfoMoveItems *mCachedInfo = nullptr;
+ UndoInfoBase *mCachedInfo = nullptr;
};
}