1 #ifndef MERKATOR_COMMAND_H_
2 #define MERKATOR_COMMAND_H_
3 
4 #include <QList>
5 #include <QtXml>
6 
7 #define KEY_UNDEF_VALUE "%%%%%"
8 #define TAG_UNDEF_VALUE "%%%%%"
9 
10 class Document;
11 class Layer;
12 class Feature;
13 class DirtyList;
14 class CommandList;
15 
16 class QAction;
17 class QListWidget;
18 class QProgressDialog;
19 
20 class Command
21 {
22     public:
23         Command(Feature* aF);
24         virtual ~Command(void) = 0;
25 
26         virtual void undo();
27         virtual void redo();
28         virtual bool buildDirtyList(DirtyList& theList) = 0;
29         virtual bool buildUndoList(QListWidget* theList);
30 
31         void setId(const QString& id);
32         const QString& id() const;
33         virtual bool toXML(QXmlStreamWriter& stream) const;
34         static void fromXML(Document* d, QXmlStreamReader& stream, Command* C);
35 
36         virtual QString getDescription();
37         virtual void setDescription(QString desc);
38         virtual Feature* getFeature();
39         virtual void setFeature(Feature* feat);
40 
41         int incDirtyLevel(Layer* aLayer, Feature* F);
42         int decDirtyLevel(Layer* aLayer, Feature* F);
43         int getDirtyLevel();
44 
45     protected:
46         mutable QString Id;
47         QString description;
48         Feature* mainFeature;
49         int commandDirtyLevel;
50         QString oldCreated;
51         bool isUndone;
52         bool wasUploaded;
53 };
54 
55 class CommandList : public Command
56 {
57     public:
58         CommandList();
59         CommandList(QString aDesc, Feature* aFeat=NULL);
60         virtual ~CommandList();
61 
62         virtual void undo();
63         virtual void redo();
64         bool empty() const;
65         int size();
66         void add(Command* aCommand);
67         virtual bool buildDirtyList(DirtyList& theList);
68         void setReversed(bool val);
69 
70         virtual bool toXML(QXmlStreamWriter& stream) const;
71         static CommandList* fromXML(Document* d, QXmlStreamReader& stream);
72 
73     private:
74         QList<Command*> Subs;
75         int Size;
76         bool isReversed;
77 };
78 
79 class CommandHistory
80 {
81     public:
82         CommandHistory();
83         virtual ~CommandHistory();
84 
85         void cleanup();
86         void undo();
87         void redo();
88         void add(Command* aCommand);
89         void setActions(QAction* anUndo, QAction* aRedo, QAction* anUploadAction);
90         void updateActions();
91         int buildDirtyList(DirtyList& theList);
92         int buildUndoList(QListWidget* theList);
93         int index() const;
94         int size() const;
95 
96         virtual bool toXML(QXmlStreamWriter& stream, QProgressDialog * progress) const;
97         static CommandHistory* fromXML(Document* d, QXmlStreamReader& stream, QProgressDialog * progress);
98 
99     private:
100         QList<Command*> Subs;
101         int Index;
102         int Size;
103         QAction* UndoAction;
104         QAction* RedoAction;
105         QAction* UploadAction;
106 };
107 
108 #endif
109 
110 
111