From 37333bf25ad9a4c538250f5af2f9f1d666362883 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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 --- ksysv/ActionList.cpp | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 ksysv/ActionList.cpp (limited to 'ksysv/ActionList.cpp') 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 +#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::pop(); + a->undo(); + + emit undone(); + + if (!count()) + emit empty(); +} + +void ActionList::undoAll() +{ + while (count()) + undoLast(); +} + +void ActionList::redoLast() +{ + if (!count()) + return; + + KSVAction* a = QPtrStack::pop(); + a->redo(); + + emit undone(); + + if (!count()) + emit empty(); +} + +void ActionList::redoAll() +{ + while (count()) + redoLast(); +} + +void ActionList::push (KSVAction* a) +{ + QPtrStack::push(a); + + if (count() == 1) + emit filled(); +} + +void ActionList::clear() +{ + setAutoDelete (true); + QPtrStack::clear(); + setAutoDelete (false); + + emit empty(); +} + +#include "ActionList.moc" -- cgit v1.2.1