Walls And Holes  1
tiletemplatechangecommand.h
Go to the documentation of this file.
1 #ifndef TILEMAPUNDOCOMMAND_H
2 #define TILEMAPUNDOCOMMAND_H
3 
4 
5 #include "tilemap.h"
6 
7 #include <QUndoCommand>
8 #include <QRegion>
9 #include <QObject>
10 
11 class TileTemplateChangeCommand : public QObject, public QUndoCommand
12 {
13 
14  Q_OBJECT
15 
16 public:
17 
29  static TileTemplateChangeCommand *make(TileMap *tileMap,
30  QRegion changedPoints,
31  TileTemplate *newTileTemplate,
32  const QString &text = "Changed templates for tiles.",
33  QUndoCommand *parent = nullptr,
34  int id = -1,
35  bool canMerge = false);
36 
37 
49  template< typename QPointIterable >
51  TileMap *tileMap,
52  QPointIterable changedPoints,
53  TileTemplate *newTileTemplate,
54  const QString &text = "Changed templates for tiles.",
55  QUndoCommand *parent = nullptr)
56  {
57  QRegion region;
58  for (const QPoint &pt : changedPoints)
59  region += QRect(pt.x(), pt.y(), 1, 1);
60  return make(tileMap, region, newTileTemplate, text, parent);
61  }
62 
63 
64  void undo() override;
65  void redo() override;
66 
67  int id() const override { return mId; }
68 
69  bool mergeWith(const QUndoCommand *other);
70 
71 private:
72 
74  QVector<QPoint> changedPositions,
75  QVector<TileTemplate *> oldTemplates,
76  TileTemplate *newTemplate,
77  const QString &text,
78  QUndoCommand *parent,
79  int id = -1,
80  bool canMerge = false);
81 
82  TileMap *mTileMap; // If mTileMap becomes invalid, the TileMap undo stack will be cleared.
83 
84  QVector<QPoint> mChangedTilePositions;
85  QVector<TileTemplate *> mOldTemplatePointers;
86  TileTemplate *mNewTemplatePointer;
87 
88  int mId;
89  bool mCanMerge;
90 };
91 
92 #endif // TILEMAPUNDOCOMMAND_H
int id() const override
Definition: tiletemplatechangecommand.h:67
static TileTemplateChangeCommand * make(TileMap *tileMap, QPointIterable changedPoints, TileTemplate *newTileTemplate, const QString &text="Changed templates for tiles.", QUndoCommand *parent=nullptr)
make Creates the TileTemplateChangeCommand. This will automatically crop the given region so that it ...
Definition: tiletemplatechangecommand.h:50
static TileTemplateChangeCommand * make(TileMap *tileMap, QRegion changedPoints, TileTemplate *newTileTemplate, const QString &text="Changed templates for tiles.", QUndoCommand *parent=nullptr, int id=-1, bool canMerge=false)
make Creates the TileTemplateChangeCommand. This will automatically crop the given region so that it ...
Definition: tiletemplatechangecommand.cpp:5
void undo() override
Definition: tiletemplatechangecommand.cpp:85
bool mergeWith(const QUndoCommand *other)
Definition: tiletemplatechangecommand.cpp:112
void redo() override
Definition: tiletemplatechangecommand.cpp:101
Definition: tiletemplate.h:13
Definition: tiletemplatechangecommand.h:11
Definition: tilemap.h:14