summaryrefslogtreecommitdiffstats
path: root/ksysv/ActionList.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit37333bf25ad9a4c538250f5af2f9f1d666362883 (patch)
treec45e8df5b9efbffe07eb3d9340df7811c7e16943 /ksysv/ActionList.cpp
downloadtdeadmin-37333bf25ad9a4c538250f5af2f9f1d666362883.tar.gz
tdeadmin-37333bf25ad9a4c538250f5af2f9f1d666362883.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeadmin@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksysv/ActionList.cpp')
-rw-r--r--ksysv/ActionList.cpp217
1 files changed, 217 insertions, 0 deletions
diff --git a/ksysv/ActionList.cpp b/ksysv/ActionList.cpp
new file mode 100644
index 0000000..a2e2de8
--- /dev/null
+++ b/ksysv/ActionList.cpp
@@ -0,0 +1,217 @@
+/***************************************************************************
+ begin : Sun Oct 3 1999
+ copyright : (C) 1999 by Peter Putzer
+ email : putzer@kde.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; version 2. *
+ * *
+ ***************************************************************************/
+
+#include <qapplication.h>
+#include "ksvdraglist.h"
+#include "ActionList.h"
+
+//////////////////////////////////
+// Action //
+//////////////////////////////////
+
+KSVAction::KSVAction()
+{
+}
+
+KSVAction::~KSVAction()
+{
+ // default - shouldn´t be used normally (pure virtual declaration)
+}
+
+SimpleAction::SimpleAction (KSVDragList* s, const KSVData* i)
+ : KSVAction(),
+ mSource (s),
+ mItem (new KSVData (*i))
+{
+}
+
+SimpleAction::~SimpleAction()
+{
+ delete mItem;
+}
+
+ChangeAction::ChangeAction (KSVDragList* s, const KSVData* oldS, const KSVData* newS)
+ : SimpleAction (s, oldS),
+ mNew (new KSVData (*newS))
+{
+ source()->addToRMList (*oldState());
+}
+
+ChangeAction::~ChangeAction()
+{
+ delete mNew;
+}
+
+void ChangeAction::redo ()
+{
+ source()->addToRMList(*oldState());
+ source()->match (*oldState())->copy (*newState());
+ source()->sort();
+}
+
+void ChangeAction::undo()
+{
+ source()->removeFromRMList(*oldState());
+ source()->match(*newState())->copy (*oldState());
+ source()->sort();
+}
+
+AddAction::AddAction (KSVDragList* s, const KSVData* i)
+ : SimpleAction(s, i)
+{
+}
+
+AddAction::~AddAction()
+{
+}
+
+void AddAction::redo ()
+{
+ new KSVItem (source(), *item());
+}
+
+void AddAction::undo()
+{
+ delete source()->match(*item());
+}
+
+RemoveAction::RemoveAction (KSVDragList* s, const KSVData* i)
+ : SimpleAction(s, i)
+{
+ source()->addToRMList (*item());
+}
+
+RemoveAction::~RemoveAction()
+{
+}
+
+void RemoveAction::redo()
+{
+ source()->addToRMList(*item());
+
+ delete source()->match (*item());
+}
+
+void RemoveAction::undo()
+{
+ source()->removeFromRMList(*item());
+
+ new KSVItem (source(), *item());
+}
+
+CompoundAction::CompoundAction (KSVAction** a, int nr)
+ : mActions (new KSVAction* [nr]),
+ mCount (nr)
+{
+ memcpy (mActions, a, sizeof(KSVAction*) * nr);
+}
+
+CompoundAction::~CompoundAction()
+{
+ for (int i=0; i < mCount; ++i)
+ {
+ delete mActions[i];
+ }
+
+ delete[] mActions;
+}
+
+void CompoundAction::redo ()
+{
+ for (int i=0; i < mCount; ++i)
+ {
+ mActions[i]->redo();
+ }
+}
+
+void CompoundAction::undo()
+{
+ for (int i=0; i < mCount; ++i)
+ {
+ mActions[i]->undo();
+ }
+}
+
+//////////////////////////////////
+// ActionList //
+//////////////////////////////////
+
+ActionList::ActionList (QObject* parent, const char* name)
+ : QObject(parent, name)
+{
+ setAutoDelete(false);
+}
+
+ActionList::~ActionList()
+{
+}
+
+void ActionList::undoLast()
+{
+ if (!count())
+ return;
+
+ KSVAction* a = QPtrStack<KSVAction>::pop();
+ a->undo();
+
+ emit undone();
+
+ if (!count())
+ emit empty();
+}
+
+void ActionList::undoAll()
+{
+ while (count())
+ undoLast();
+}
+
+void ActionList::redoLast()
+{
+ if (!count())
+ return;
+
+ KSVAction* a = QPtrStack<KSVAction>::pop();
+ a->redo();
+
+ emit undone();
+
+ if (!count())
+ emit empty();
+}
+
+void ActionList::redoAll()
+{
+ while (count())
+ redoLast();
+}
+
+void ActionList::push (KSVAction* a)
+{
+ QPtrStack<KSVAction>::push(a);
+
+ if (count() == 1)
+ emit filled();
+}
+
+void ActionList::clear()
+{
+ setAutoDelete (true);
+ QPtrStack<KSVAction>::clear();
+ setAutoDelete (false);
+
+ emit empty();
+}
+
+#include "ActionList.moc"