summaryrefslogtreecommitdiffabout
path: root/kaddressbook/undo.h
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kaddressbook/undo.h
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kaddressbook/undo.h') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/undo.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/kaddressbook/undo.h b/kaddressbook/undo.h
new file mode 100644
index 0000000..843bc26
--- a/dev/null
+++ b/kaddressbook/undo.h
@@ -0,0 +1,95 @@
1/*
2 This file is part of KAddressBook.
3 Copyright (C) 1999 Don Sanders <sanders@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#ifndef UNDO_H
25#define UNDO_H
26
27#include <qobject.h>
28#include <qptrstack.h>
29#include <qstring.h>
30
31class Command
32{
33public:
34 Command() {}
35 virtual ~Command() {};
36 virtual QString name() = 0;
37 virtual void redo() = 0; // egcs requires these methods to have
38 virtual void undo() = 0; // implementations (Seems like a bug)
39 // pure virtual may not work
40};
41
42/** The Undo and Redo stacks now no longer inherit directly from a stack.
43* They now contain a stack internally and inherit from StackBase, which
44* has a signal for when the stack is modified. This is need to keep
45* the edit menu and toolbar up to date.
46*
47* Really this is a simple observable stack.
48*/
49class StackBase : public QObject
50{
51 Q_OBJECT
52
53 public:
54 StackBase() : QObject() {}
55
56 void push(Command *c);
57 bool isEmpty();
58 Command *top();
59 void clear();
60
61 signals:
62 void changed();
63
64 protected:
65 /** Protect the pop method so users must call undo/redo to properly
66 * use the stack, however the subclasses need it to modify the stack.
67 */
68 Command *pop();
69
70 QPtrStack<Command> mCommandStack;
71};
72
73class UndoStack : public StackBase
74{
75public:
76 static UndoStack *instance();
77 void undo();
78
79protected:
80 UndoStack();
81 static UndoStack* instance_;
82};
83
84class RedoStack : public StackBase
85{
86public:
87 static RedoStack *instance();
88 void redo();
89
90protected:
91 RedoStack();
92 static RedoStack* instance_;
93};
94
95#endif