QSapecNG
 All Classes Functions Enumerations Properties
undoredocommand.h
00001 /*
00002     QSapecNG - Qt based SapecNG GUI front-end
00003     Copyright (C) 2009, Michele Caini
00004 
00005     This program is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef UNDOREDO_H
00021 #define UNDOREDO_H
00022 
00023 
00024 #include "gui/editor/schematicscene.h"
00025 
00026 #include <QtGui/QUndoCommand>
00027 
00028 #include <QtCore/QPointF>
00029 #include <QtCore/QLineF>
00030 
00031 #include <QtCore/QVariant>
00032 #include <QtCore/QList>
00033 
00034 
00035 class QGraphicsScene;
00036 class QGraphicsItem;
00037 
00038 
00039 namespace qsapecng
00040 {
00041 
00042 
00043 class Wire;
00044 class Item;
00045 
00046 
00047 class AddItems: public QUndoCommand
00048 {
00049 
00050 public:
00051   AddItems(
00052       SchematicScene* scene,
00053       QList<QGraphicsItem*> items,
00054       QUndoCommand* parent = 0
00055     );
00056   AddItems(
00057       SchematicScene* scene,
00058       QGraphicsItem* item,
00059       QUndoCommand* parent = 0
00060     );
00061   AddItems(
00062       SchematicScene* scene,
00063       QList<QGraphicsItem*> items,
00064       const QList<QPointF>& pos,
00065       QUndoCommand* parent = 0
00066     );
00067   AddItems(
00068       SchematicScene* scene,
00069       QGraphicsItem* item,
00070       const QPointF& pos,
00071       QUndoCommand* parent = 0
00072     );
00073   ~AddItems();
00074 
00075   virtual void undo();
00076   virtual void redo();
00077 
00078 private:
00079   SchematicScene* scene_;
00080   QList<QPointF> pos_;
00081   QList<QGraphicsItem*> items_;
00082 
00083 };
00084 
00085 
00086 class AddSupportedItem: public QUndoCommand
00087 {
00088 
00089 public:
00090   AddSupportedItem(
00091       SchematicScene* scene,
00092       SchematicScene::SupportedItemType type,
00093       const QPointF& pos,
00094       QUndoCommand* parent = 0
00095     );
00096   ~AddSupportedItem();
00097 
00098   virtual void undo();
00099   virtual void redo();
00100 
00101   Item* item() const;
00102 
00103 private:
00104   SchematicScene* scene_;
00105   QPointF pos_;
00106   Item* item_;
00107 
00108 };
00109 
00110 
00111 class AddUserDefItem: public QUndoCommand
00112 {
00113 
00114 public:
00115   AddUserDefItem(
00116       SchematicScene* scene,
00117       QByteArray md5,
00118       int size,
00119       std::string info,
00120       const QPointF& pos,
00121       QUndoCommand* parent = 0
00122     );
00123   ~AddUserDefItem();
00124 
00125   virtual void undo();
00126   virtual void redo();
00127 
00128   Item* item() const;
00129 
00130 private:
00131   SchematicScene* scene_;
00132   QPointF pos_;
00133   Item* item_;
00134 
00135 };
00136 
00137 
00138 class AddWire: public QUndoCommand
00139 {
00140 
00141 public:
00142   AddWire(
00143       SchematicScene* scene,
00144       const QPointF& pos,
00145       const QLineF& wire,
00146       bool connectedJunctions,
00147       QUndoCommand* parent = 0
00148     );
00149   ~AddWire();
00150 
00151   virtual void undo();
00152   virtual void redo();
00153 
00154 private:
00155   SchematicScene* scene_;
00156   QPointF pos_;
00157   Item* wire_;
00158 
00159 };
00160 
00161 
00162 class JoinWires: public QUndoCommand
00163 {
00164 
00165 public:
00166   JoinWires(
00167       Wire* w1,
00168       Wire* w2,
00169       QUndoCommand* parent = 0
00170     );
00171   ~JoinWires();
00172 
00173   virtual void undo();
00174   virtual void redo();
00175 
00176 private:
00177   SchematicScene* scene_;
00178   Item* wire_;
00179   Item* w1_;
00180   Item* w2_;
00181 
00182 };
00183 
00184 
00185 class RemoveItems: public QUndoCommand
00186 {
00187 
00188 public:
00189   RemoveItems(
00190       SchematicScene* scene,
00191       QList<QGraphicsItem*> items,
00192       QUndoCommand* parent = 0
00193     );
00194   RemoveItems(
00195       SchematicScene* scene,
00196       QGraphicsItem* item,
00197       QUndoCommand* parent = 0
00198     );
00199 
00200   virtual void undo();
00201   virtual void redo();
00202 
00203 private:
00204   SchematicScene* scene_;
00205   QList<QGraphicsItem*> items_;
00206 
00207 };
00208 
00209 
00210 class RotateItems: public QUndoCommand
00211 {
00212 
00213 public:
00214   RotateItems(
00215       QList<QGraphicsItem*> items,
00216       QUndoCommand* parent = 0
00217   );
00218   RotateItems(
00219       QGraphicsItem* item,
00220       QUndoCommand* parent = 0
00221   );
00222 
00223   virtual void undo();
00224   virtual void redo();
00225 
00226 private:
00227   QList<QGraphicsItem*> items_;
00228 
00229 };
00230 
00231 
00232 class MirrorItems: public QUndoCommand
00233 {
00234 
00235 public:
00236   MirrorItems(
00237       QList<QGraphicsItem*> items,
00238       QUndoCommand* parent = 0
00239     );
00240   MirrorItems(
00241       QGraphicsItem* item,
00242       QUndoCommand* parent = 0
00243     );
00244 
00245   virtual void undo();
00246   virtual void redo();
00247 
00248 private:
00249   QList<QGraphicsItem*> items_;
00250 
00251 };
00252 
00253 
00254 class BringToFrontItem: public QUndoCommand
00255 {
00256 
00257 public:
00258   BringToFrontItem(
00259       QGraphicsItem* item,
00260       QUndoCommand* parent = 0
00261     );
00262 
00263   enum { ID = 23 };
00264 
00265   virtual void undo();
00266   virtual void redo();
00267 
00268   inline int id() const { return ID; }
00269   bool mergeWith(const QUndoCommand* command);
00270 
00271 private:
00272   QGraphicsItem* item_;
00273   qreal oldZValue_;
00274   qreal zValue_;
00275 
00276 };
00277 
00278 
00279 class SendToBackItem: public QUndoCommand
00280 {
00281 
00282 public:
00283   SendToBackItem(QGraphicsItem* item, QUndoCommand* parent = 0);
00284 
00285   enum { ID = 29 };
00286 
00287   virtual void undo();
00288   virtual void redo();
00289 
00290   inline int id() const { return ID; }
00291   bool mergeWith(const QUndoCommand* command);
00292 
00293 private:
00294   QGraphicsItem* item_;
00295   qreal oldZValue_;
00296   qreal zValue_;
00297 
00298 };
00299 
00300 
00301 class MoveItems: public QUndoCommand
00302 {
00303 
00304 public:
00305   MoveItems(
00306     SchematicScene* scene,
00307     QList<QGraphicsItem*> items,
00308     const QPointF& offset,
00309     QUndoCommand* parent = 0
00310   );
00311   MoveItems(
00312     SchematicScene* scene,
00313     QGraphicsItem* item,
00314     const QPointF& offset,
00315     QUndoCommand* parent = 0
00316   );
00317 
00318   enum { ID = 7 };
00319 
00320   virtual void undo();
00321   virtual void redo();
00322 
00323   inline int id() const { return ID; }
00324   bool mergeWith(const QUndoCommand* command);
00325 
00326 private:
00327   SchematicScene* scene_;
00328   QList<QGraphicsItem*> items_;
00329   QList<QPointF> oldPos_;
00330   QPointF offset_;
00331 
00332 };
00333 
00334 
00335 }
00336 
00337 
00338 #endif // UNDOREDO_H
 All Classes Functions Enumerations Properties