-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditManager.h
52 lines (40 loc) · 1.27 KB
/
EditManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef EDITMANAGER_H
#define EDITMANAGER_H
#include "Shape.h"
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QPointF>
#include <memory>
#include <list>
#include <stack>
#include <unordered_map>
#include "ICommand.h"
using std::stack;
using std::list;
using std::shared_ptr;
using std::weak_ptr;
using std::unordered_map;
class EditManager
{
public:
EditManager(QGraphicsScene* scene);
void undo();
void redo();
// Actions
void createShape(Shape::Type type, const QPointF &pos, const QPointF &size, const QColor& color);
void deleteShape(QGraphicsItem* item);
void moveShape(QGraphicsItem* item, const QPointF& newPos);
void resizeShape(QGraphicsItem* item, const QPointF& newSize);
void changeShapeColor(QGraphicsItem* item, const QColor& color);
// Manage QGraphicsItems' pointers
void addGraphicsItem(QGraphicsItem *graphicsItem, shared_ptr<Shape> shape);
void removeGraphicsItem(QGraphicsItem* graphicsItem);
shared_ptr<Shape> getShape(QGraphicsItem* graphicsItem);
QGraphicsScene* m_scene;
private:
void resetRedoStack();
stack<shared_ptr<ICommand>> m_undoStack;
stack<shared_ptr<ICommand>> m_redoStack;
unordered_map<QGraphicsItem*, shared_ptr<Shape>> m_graphicsItems;
};
#endif // EDITMANAGER_H