DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DACommandsForGraphics.h
1#ifndef DACOMMANDSFORGRAPHICS_H
2#define DACOMMANDSFORGRAPHICS_H
3#include "DAGraphicsViewGlobal.h"
4#include <QUndoCommand>
5#include <QPointer>
6#include <QDateTime>
7class QGraphicsScene;
8class QGraphicsItem;
9class QGraphicsTextItem;
10class QTextDocument;
11
20namespace DA
21{
22class DAGraphicsScene;
23class DAGraphicsResizeableItem;
29class DAGRAPHICSVIEW_API DACommandsForGraphicsItemAdd : public QUndoCommand
30{
31public:
32 DACommandsForGraphicsItemAdd(QGraphicsItem* item, QGraphicsScene* scene, QUndoCommand* parent = nullptr);
34 void redo() override;
35 void undo() override;
36 virtual int id() const override
37 {
38 return CmdID_ItemAdd;
39 }
40
41private:
42 QGraphicsItem* mItem;
43 QGraphicsScene* mScene;
44 bool mNeedDelete;
45};
46
52class DAGRAPHICSVIEW_API DACommandsForGraphicsItemsAdd : public QUndoCommand
53{
54public:
55 DACommandsForGraphicsItemsAdd(const QList< QGraphicsItem* > its, QGraphicsScene* scene, QUndoCommand* parent = nullptr);
57 void redo() override;
58 void undo() override;
59 virtual int id() const override
60 {
61 return CmdID_ItemsAdd;
62 }
63
64private:
65 QList< QGraphicsItem* > mItems;
66 QGraphicsScene* mScene;
67 bool mNeedDelete;
68};
69
73class DAGRAPHICSVIEW_API DACommandsForGraphicsItemRemove : public QUndoCommand
74{
75public:
76 DACommandsForGraphicsItemRemove(QGraphicsItem* item, QGraphicsScene* scene, QUndoCommand* parent = nullptr);
78 void redo() override;
79 void undo() override;
80 virtual int id() const override
81 {
82 return CmdID_ItemRemove;
83 }
84
85private:
86 QGraphicsItem* mItem;
87 QGraphicsScene* mScene;
88 bool mNeedDelete;
89};
90
94class DAGRAPHICSVIEW_API DACommandsForGraphicsItemsRemove : public QUndoCommand
95{
96public:
97 DACommandsForGraphicsItemsRemove(const QList< QGraphicsItem* > its, QGraphicsScene* scene, QUndoCommand* parent = nullptr);
99 void redo() override;
100 void undo() override;
101 virtual int id() const override
102 {
103 return CmdID_ItemsRemove;
104 }
105
106private:
107 QList< QGraphicsItem* > mItems;
108 QGraphicsScene* mScene;
109 bool mNeedDelete;
110};
111
115class DAGRAPHICSVIEW_API DACommandsForGraphicsItemsMoved : public QUndoCommand
116{
117public:
118 DACommandsForGraphicsItemsMoved(const QList< QGraphicsItem* >& items,
119 const QList< QPointF >& starts,
120 const QList< QPointF >& ends,
121 bool skipfirst,
122 QUndoCommand* parent = nullptr);
123 void redo() override;
124 void undo() override;
125 int id() const override;
126 bool mergeWith(const QUndoCommand* command) override;
127 // 注意,此命令可能会合并,不应该在推入栈后再对此命令有任何操作,会出现空指针
128 const QList< QGraphicsItem* >& getItems() const;
129 // 注意,此命令可能会合并,不应该在推入栈后再对此命令有任何操作,会出现空指针
130 const QList< QPointF >& getStartsPos() const;
131 // 注意,此命令可能会合并,不应该在推入栈后再对此命令有任何操作,会出现空指针
132 const QList< QPointF >& getEndsPos() const;
133
134protected:
135 QList< QGraphicsItem* > mItems;
136 QList< QPointF > mStartsPos;
137 QList< QPointF > mEndsPos;
138 QDateTime mCmdDatetime;
139 bool mSkipFirst;
140};
141
145class DAGRAPHICSVIEW_API DACommandsForGraphicsItemMoved : public QUndoCommand
146{
147public:
148 DACommandsForGraphicsItemMoved(QGraphicsItem* item,
149 const QPointF& start,
150 const QPointF& end,
151 bool skipfirst,
152 QUndoCommand* parent = nullptr);
153 void redo() override;
154 void undo() override;
155 int id() const override;
156 bool mergeWith(const QUndoCommand* command) override;
157
158protected:
159 QGraphicsItem* mItem;
160 QPointF mStartPos;
161 QPointF mEndPos;
162 bool mSkipFirst;
163 QDateTime mDatetime;
164};
165
169class DAGRAPHICSVIEW_API DACommandsForGraphicsItemResized : public QUndoCommand
170{
171public:
173 const QPointF& oldpos,
174 const QSizeF& oldSize,
175 const QPointF& newpos,
176 const QSizeF& newSize,
177 bool skipfirst = true,
178 QUndoCommand* parent = nullptr);
180 const QSizeF& oldSize,
181 const QSizeF& newSize,
182 QUndoCommand* parent = nullptr);
183 void redo() override;
184 void undo() override;
185 int id() const override;
186 bool mergeWith(const QUndoCommand* command) override;
187
188private:
190 QPointF mOldpos;
191 QSizeF mOldSize;
192 QPointF mNewPosition;
193 QSizeF mNewSize;
194 bool mSkipfirst { false };
195 QDateTime mDatetime;
196};
197
201class DAGRAPHICSVIEW_API DACommandsForGraphicsItemResizeWidth : public QUndoCommand
202{
203public:
205 const qreal& oldWidth,
206 const qreal& newWidth,
207 QUndoCommand* parent = nullptr);
208 void redo() override;
209 void undo() override;
210 int id() const override;
211 bool mergeWith(const QUndoCommand* command) override;
212
213private:
215 qreal mOldWidth;
216 qreal mNewWidth;
217 qreal mHeight;
218 QDateTime mDatetime;
219};
220
224class DAGRAPHICSVIEW_API DACommandsForGraphicsItemResizeHeight : public QUndoCommand
225{
226public:
228 const qreal& oldHeight,
229 const qreal& newHeight,
230 QUndoCommand* parent = nullptr);
231 void redo() override;
232 void undo() override;
233 int id() const override;
234 bool mergeWith(const QUndoCommand* command) override;
235
236private:
238 qreal mOldHeight;
239 qreal mNewHeight;
240 qreal mWidth;
241 QDateTime mDatetime;
242};
243
249class DAGRAPHICSVIEW_API DACommandsForGraphicsItemRotation : public QUndoCommand
250{
251public:
253 const qreal& oldRotation,
254 const qreal& newRotation,
255 QUndoCommand* parent = nullptr);
256 void redo() override;
257 void undo() override;
258 int id() const override;
259 bool mergeWith(const QUndoCommand* command) override;
260
261private:
263 qreal mOldRotation;
264 qreal mNewRotation;
265 QDateTime mDatetime;
266};
267
271class DAGRAPHICSVIEW_API DACommandsForGraphicsItemGrouping : public QUndoCommand
272{
273public:
275 const QList< QGraphicsItem* >& groupingitems,
276 QUndoCommand* parent = nullptr);
278 void redo() override;
279 void undo() override;
280 // 这是一个清洗,要分组的item里面,如果存在item的parent在分组的item里,就驱除,这样不会分组嵌套,形成单一的层级
281 static QList< QGraphicsItem* > toSimple(const QList< QGraphicsItem* >& groupingitems);
282 QList< QGraphicsItem* > getWillGroupItems() const;
283 virtual int id() const override
284 {
285 return CmdID_ItemGrouping;
286 }
287
288private:
289 DAGraphicsScene* mScene;
290 QList< QGraphicsItem* > mWillGroupItems;
291 QGraphicsItemGroup* mGroupItem { nullptr };
292 bool mNeedDelete { false };
293};
294
300class DAGRAPHICSVIEW_API DACommandsForGraphicsItemUngrouping : public QUndoCommand
301{
302public:
303 DACommandsForGraphicsItemUngrouping(QGraphicsScene* sc, QGraphicsItemGroup* group, QUndoCommand* parent = nullptr);
305 void redo() override;
306 void undo() override;
307 virtual int id() const override
308 {
310 }
311
312private:
313 QGraphicsScene* mScene;
314 QList< QGraphicsItem* > mItems;
315 QGraphicsItemGroup* mGroupItem { nullptr };
316 bool mNeedDelete { false };
317};
318
322class DAGRAPHICSVIEW_API DACommandTextDocumentWrapper : public QUndoCommand
323{
324public:
325 DACommandTextDocumentWrapper(QTextDocument* doc, QUndoCommand* parent = nullptr);
327 virtual void redo() override;
328 virtual void undo() override;
329 virtual int id() const override
330 {
332 }
333
334private:
335 QPointer< QTextDocument > mDoc;
336};
337
343class DAGRAPHICSVIEW_API DACommandTextItemHtmlContentChanged : public QUndoCommand
344{
345public:
346 DACommandTextItemHtmlContentChanged(QGraphicsTextItem* item,
347 const QString& oldHtml,
348 const QString& newHtml,
349 QUndoCommand* parent = nullptr);
351 virtual void redo() override;
352 virtual void undo() override;
353 virtual int id() const override
354 {
356 }
357 // 合并
358 virtual bool mergeWith(const QUndoCommand* command) override;
359
360private:
361 QGraphicsTextItem* mItem;
362 QString mOldHtml;
363 QString mNewHtml;
364 bool mSkipFirst { true };
365 QDateTime mDate;
366};
367}
368#endif // DACOMMANDSFORGRAPHICS_H
改变GraphicsTextItem内容
Definition DACommandsForGraphics.h:323
QGraphicsTextItem的内容发生变化
Definition DACommandsForGraphics.h:344
添加item命令
Definition DACommandsForGraphics.h:30
分组命令
Definition DACommandsForGraphics.h:272
移动item命令,必须先确保item是movable的
Definition DACommandsForGraphics.h:146
移除item命令
Definition DACommandsForGraphics.h:74
改变高度
Definition DACommandsForGraphics.h:225
仅改变宽度
Definition DACommandsForGraphics.h:202
item改变尺寸
Definition DACommandsForGraphics.h:170
旋转
Definition DACommandsForGraphics.h:250
解除分组命令
Definition DACommandsForGraphics.h:301
添加item命令
Definition DACommandsForGraphics.h:53
移动item命令,必须先确保item是movable的
Definition DACommandsForGraphics.h:116
移除items命令
Definition DACommandsForGraphics.h:95
用于调整大小的item
Definition DAGraphicsResizeableItem.h:48
这是带着undostack的GraphicsScene 此QGraphicsScene支持:
Definition DAGraphicsScene.h:30
序列化类都是带异常的,使用中需要处理异常
Definition AppMainWindow.cpp:44
@ CmdID_ItemTextDocumentWrapper
Text Document Wrapper
Definition DAGraphicsViewGlobal.h:61
@ CmdID_ItemsAdd
items添加
Definition DAGraphicsViewGlobal.h:55
@ CmdID_ItemRemove
item移动
Definition DAGraphicsViewGlobal.h:48
@ CmdID_ItemGrouping
item Grouping
Definition DAGraphicsViewGlobal.h:58
@ CmdID_ItemsRemove
items删除
Definition DAGraphicsViewGlobal.h:56
@ CmdID_ItemAdd
item移动
Definition DAGraphicsViewGlobal.h:47
@ CmdID_ItemTextHtmlContentChanged
Text Document Wrapper
Definition DAGraphicsViewGlobal.h:62
@ CmdID_ItemUnGrouping
item Grouping
Definition DAGraphicsViewGlobal.h:59