00001 #ifndef COMMANDS_H_13452674738
00002 #define COMMANDS_H_13452674738
00003
00004 #include <QUndoCommand>
00005 #include <QPointF>
00006 #include <QRect>
00007 #include <QMap>
00008 #include <QGraphicsItem>
00009 #include <QVector>
00010 #include <QList>
00011
00012 class Editor;
00013 class State;
00014 class Transition;
00015 class OneStateTransition;
00016 class TwoStatesTransition;
00017 class LabelX;
00018
00019 QString createCommandString(State *state, const QPointF &point);
00020
00021 class ShowGridFrameCommand : public QUndoCommand
00022 {
00023 public:
00024 ShowGridFrameCommand(Editor *editor, bool origGrid, bool origFrame,
00025 bool grid, bool frame);
00026
00027 void undo();
00028 void redo();
00029
00030 private:
00031 QString getMsg() const;
00032
00033 Editor *m_editor;
00034 bool m_origGrid, m_grid;
00035 bool m_origFrame, m_frame;
00036 };
00037
00038 class StateMoveCommand : public QUndoCommand
00039 {
00040 public:
00041 StateMoveCommand(State *state, const QPointF &oldPos, QUndoCommand *parent = 0);
00042
00043 void undo();
00044 void redo();
00045
00046 private:
00047 State *state;
00048 QPointF oldPos;
00049 QPointF newPos;
00050 };
00051
00052 class StateAddCommand : public QUndoCommand
00053 {
00054 public:
00055 StateAddCommand(Editor *editor, State *state, QUndoCommand *parent = 0);
00056 ~StateAddCommand();
00057
00058 void undo();
00059 void redo();
00060
00061 private:
00062 Editor *editor;
00063 State *state;
00064
00065 bool wasUndo;
00066 };
00067
00068 class StateDeleteCommand: public QUndoCommand
00069 {
00070 public:
00071 StateDeleteCommand(Editor *editor, State *state, QUndoCommand *parent = 0);
00072 ~StateDeleteCommand();
00073
00074 void undo();
00075 void redo();
00076
00077 private:
00078 Editor *editor;
00079 State *state;
00080 QList<Transition *> transitionList;
00081
00082 bool wasUndo;
00083 };
00084
00085 class StateEditCommand: public QUndoCommand
00086 {
00087 public:
00088 StateEditCommand(Editor *editor, State *state, QString label, QString name, bool db, bool dimmed,
00089 bool autoNammed, QUndoCommand *parent = 0);
00090
00091 void undo();
00092 void redo();
00093 private:
00094 Editor *editor;
00095 State *state;
00096
00097 QString label_old, label_new;
00098 QString name_old, name_new;
00099 bool db_old, db_new;
00100 bool dimmed_old, dimmed_new;
00101 bool an_old, an_new;
00102 };
00103
00104 class StateEditWithDelCommand: public QUndoCommand
00105 {
00106 public:
00107 StateEditWithDelCommand(Editor *editor, State *state_backup, State *state_new,
00108 QUndoCommand *parent = 0);
00109 ~StateEditWithDelCommand();
00110
00111 void undo();
00112 void redo();
00113
00114 void copyExtendedParameters(State* s1, State* const s2);
00115 private:
00116 Editor *editor;
00117 State *state_backup, *state_new;
00118 QList<Transition *> transitionList;
00119
00120 bool wasUndo;
00121 };
00122
00123 class StateEditExtendedCommand: public QUndoCommand
00124 {
00125 public:
00126 StateEditExtendedCommand(State *state, Qt::PenStyle lineS, float lineW, const QString &lineC,
00127 const QString &labelC, float labelS, Qt::BrushStyle fillS,
00128 const QString &fillC, Qt::PenStyle dimLineS, const QString &dimLineC,
00129 float dimLineCoef, const QString &dimLabelC, const QString &dimFillC,
00130 float lineDC, float lineDS, QUndoCommand *parent = 0);
00131
00132 void undo();
00133 void redo();
00134 private:
00135 State *state;
00136
00137 Qt::PenStyle lineStyle, lineStyle_old;
00138 float lineWidth, lineWidth_old;
00139 QString lineColor, lineColor_old;
00140 QString labelColor, labelColor_old;
00141 float labelScale, labelScale_old;
00142 Qt::BrushStyle fillStatus, fillStatus_old;
00143 QString fillColor, fillColor_old;
00144
00145
00146 Qt::PenStyle dimLineStyle, dimLineStyle_old;
00147 QString dimLineColor, dimLineColor_old;
00148 float dimLineCoef, dimLineCoef_old;
00149 QString dimLabelColor, dimLabelColor_old;
00150 QString dimFillColor, dimFillColor_old;
00151
00152
00153 float lineDoubleCoef, lineDoubleCoef_old;
00154 float lineDoubleSep, lineDoubleSep_old;
00155 };
00156
00157
00158
00159 class TransitionAddCommand: public QUndoCommand
00160 {
00161 public:
00162 TransitionAddCommand(Editor *editor, Transition *transition, QUndoCommand *parent = 0);
00163 ~TransitionAddCommand();
00164
00165 void undo();
00166 void redo();
00167 private:
00168 Editor *editor;
00169 Transition *transition;
00170
00171 bool wasUndo;
00172 };
00173
00174 class TransitionDeleteCommand: public QUndoCommand
00175 {
00176 public:
00177 TransitionDeleteCommand(Editor *editor, Transition *transition, QUndoCommand *parent = 0);
00178 ~TransitionDeleteCommand();
00179
00180 void undo();
00181 void redo();
00182
00183 private:
00184 Editor *editor;
00185 Transition *transition;
00186
00187 bool wasUndo;
00188 };
00189
00190 class OneStateTransitionEditCommand: public QUndoCommand
00191 {
00192 public:
00193 OneStateTransitionEditCommand
00194 (OneStateTransition *tr, QString label, float labelPos, int direction, bool dimmed,
00195 QUndoCommand *parent = 0);
00196
00197 void undo();
00198 void redo();
00199
00200 private:
00201 OneStateTransition *tr;
00202
00203 QString lab_old, lab_new;
00204 float labelPos_old, labelPos_new;
00205 int dir_old, dir_new;
00206 bool dimmed_old, dimmed_new;
00207 };
00208
00209 class TwoStatesTransitionEditCommand: public QUndoCommand
00210 {
00211 public:
00212 TwoStatesTransitionEditCommand
00213 (TwoStatesTransition *tr, QString label, float labelPos, bool dimmed,
00214 bool leftOriented = false, int arcAngle = 0,
00215 int arcAngleB = 0, float ncurv = 0, QUndoCommand *parent = 0);
00216
00217 void undo();
00218 void redo();
00219
00220 private:
00221 TwoStatesTransition *tr;
00222
00223 QString lab_old, lab_new;
00224 float labelPos_old, labelPos_new;
00225 bool dimmed_old, dimmed_new;
00226 bool lo_old, lo_new;
00227 int angle_old, angle_new;
00228 int angleB_old, angleB_new;
00229 float ncurv_old, ncurv_new;
00230 };
00231
00232 class TransitionEditWithDelCommand: public QUndoCommand
00233 {
00234 public:
00235 TransitionEditWithDelCommand(Editor *editor, Transition *tr_backup, Transition *tr_new,
00236 QUndoCommand *parent = 0);
00237 ~TransitionEditWithDelCommand();
00238
00239 void undo();
00240 void redo();
00241
00242 void copyExtendedParameters(Transition *tr1, Transition* const tr2);
00243 private:
00244 Editor *editor;
00245 Transition *tr_backup, *tr_new;
00246
00247 bool wasUndo;
00248 };
00249
00250 class TransitionEditExtendedCommand: public QUndoCommand
00251 {
00252 public:
00253 TransitionEditExtendedCommand(Transition *tr, Qt::PenStyle lineS, float lineW, const QString &lineC,
00254 const QString &labelC, float labelS, bool lineDoubleS, Qt::PenStyle dimLineS,
00255 const QString &dimLineC, float dimLineCoef, const QString &dimLabelC,
00256 float borderCoef, const QString &borderColor,
00257 float lineDC, float lineDS, QUndoCommand *parent = 0);
00258
00259 void undo();
00260 void redo();
00261 private:
00262 Transition *tr;
00263
00264 Qt::PenStyle lineStyle, lineStyle_old;
00265 float lineWidth, lineWidth_old;
00266 QString lineColor, lineColor_old;
00267 QString labelColor, labelColor_old;
00268 float labelScale, labelScale_old;
00269 bool lineDoubleStatus, lineDoubleStatus_old;
00270
00271
00272 Qt::PenStyle dimLineStyle, dimLineStyle_old;
00273 QString dimLineColor, dimLineColor_old;
00274 float dimLineCoef, dimLineCoef_old;
00275 QString dimLabelColor, dimLabelColor_old;
00276
00277
00278 float borderCoef, borderCoef_old;
00279 QString borderColor, borderColor_old;
00280
00281
00282 float lineDoubleCoef, lineDoubleCoef_old;
00283 float lineDoubleSep, lineDoubleSep_old;
00284 };
00285
00286 class NextLabelAddCommand: public QUndoCommand
00287 {
00288 public:
00289 NextLabelAddCommand(Editor *editor, LabelX *label, QUndoCommand *parent = 0);
00290 ~NextLabelAddCommand();
00291
00292 void undo();
00293 void redo();
00294
00295 protected:
00296 Editor* editor;
00297 LabelX* label;
00298 bool wasUndo;
00299 };
00300
00301 class NextLabelDeleteCommand: public QUndoCommand
00302 {
00303 public:
00304 NextLabelDeleteCommand(Editor *editor, LabelX *label, QUndoCommand *parent = 0);
00305 ~NextLabelDeleteCommand();
00306
00307 void undo();
00308 void redo();
00309
00310 protected:
00311 Editor* editor;
00312 LabelX* label;
00313 bool wasUndo;
00314 };
00315
00316 class NextLabelEditCommand: public QUndoCommand
00317 {
00318 public:
00319 NextLabelEditCommand(LabelX *label, const QString &labelText, float labelPos, bool isLeft, QUndoCommand *parent = 0);
00320
00321 void undo();
00322 void redo();
00323
00324 protected:
00325 LabelX* label;
00326 QString labelText_backup;
00327 float labelPos_backup;
00328 QString labelText_new;
00329 float labelPos_new;
00330 bool isLeft_backup;
00331 bool isLeft_new;
00332 };
00333
00334 class EditorChangeGridRectCommand: public QUndoCommand
00335 {
00336 public:
00337 EditorChangeGridRectCommand(Editor *editor, QRect gridRect ,int border, QUndoCommand *parent = 0);
00338
00339 void undo();
00340 void redo();
00341 private:
00342 Editor *editor;
00343 QRect gridRect_old, gridRect_new;
00344 int border_old, border_new;
00345 };
00346
00347 class StateStyleChangeCommand: public QUndoCommand
00348 {
00349 public:
00350 StateStyleChangeCommand(Editor *editor, int changeT, Qt::PenStyle lineS, float lineW,
00351 const QString &lineC, const QString &labelC, float labelS,
00352 Qt::BrushStyle fillS, const QString &fillC, Qt::PenStyle dimLineS,
00353 const QString &dimLineC, float dimLineCoef, const QString &dimLabelC,
00354 const QString &dimFillC, float lineDC, float lineDS,
00355 QUndoCommand *parent = 0);
00356
00357 void undo();
00358 void redo();
00359 private:
00360 Editor *editor;
00361 int changeType;
00362
00363 QList<State *> changedStates;
00364
00365
00366 QMap<State *, Qt::PenStyle> lineStyleMap;
00367 QMap<State *, float> lineWidthMap;
00368 QMap<State *, QString> lineColorMap;
00369 QMap<State *, QString> labelColorMap;
00370 QMap<State *, float> labelScaleMap;
00371 QMap<State *, Qt::BrushStyle> fillStatusMap;
00372 QMap<State *, QString> fillColorMap;
00373 QMap<State *, Qt::PenStyle> dimLineStyleMap;
00374 QMap<State *, QString> dimLineColorMap;
00375 QMap<State *, float> dimLineCoefMap;
00376 QMap<State *, QString> dimLabelColorMap;
00377 QMap<State *, QString> dimFillColorMap;
00378 QMap<State *, float> lineDoubleCoefMap;
00379 QMap<State *, float> lineDoubleSepMap;
00380
00381
00382 Qt::PenStyle lineStyle, lineStyle_old;
00383 float lineWidth, lineWidth_old;
00384 QString lineColor, lineColor_old;
00385 QString labelColor, labelColor_old;
00386 float labelScale, labelScale_old;
00387 Qt::BrushStyle fillStatus, fillStatus_old;
00388 QString fillColor, fillColor_old;
00389
00390
00391 Qt::PenStyle dimLineStyle, dimLineStyle_old;
00392 QString dimLineColor, dimLineColor_old;
00393 float dimLineCoef, dimLineCoef_old;
00394 QString dimLabelColor, dimLabelColor_old;
00395 QString dimFillColor, dimFillColor_old;
00396
00397
00398 float lineDoubleCoef, lineDoubleCoef_old;
00399 float lineDoubleSep, lineDoubleSep_old;
00400 };
00401
00402 class TransitionStyleChangeCommand: public QUndoCommand
00403 {
00404 public:
00405 TransitionStyleChangeCommand(Editor *editor, int ChangeT, Qt::PenStyle lineS, float lineW,
00406 const QString &lineC, const QString &labelC, float labelS, bool lineDoubleS,
00407 Qt::PenStyle dimLineS, const QString &dimLineC, float dimLineCoef,
00408 const QString &dimLabelC, float borderCoef, const QString &borderColor,
00409 float lineDC, float lineDS, QUndoCommand *parent = 0);
00410
00411 void undo();
00412 void redo();
00413 private:
00414 Editor *editor;
00415 int changeType;
00416
00417 QList<Transition *> changedTransitions;
00418
00419
00420 QMap<Transition *, Qt::PenStyle> lineStyleMap;
00421 QMap<Transition *, float> lineWidthMap;
00422 QMap<Transition *, QString> lineColorMap;
00423 QMap<Transition *, QString> labelColorMap;
00424 QMap<Transition *, float> labelScaleMap;
00425 QMap<Transition *, bool> lineDoubleStatusMap;
00426 QMap<Transition *, Qt::PenStyle> dimLineStyleMap;
00427 QMap<Transition *, QString> dimLineColorMap;
00428 QMap<Transition *, float> dimLineCoefMap;
00429 QMap<Transition *, QString> dimLabelColorMap;
00430 QMap<Transition *, float> lineBorderCoefMap;
00431 QMap<Transition *, QString> lineBorderColorMap;
00432 QMap<Transition *, float> lineDoubleCoefMap;
00433 QMap<Transition *, float> lineDoubleSepMap;
00434
00435
00436 Qt::PenStyle lineStyle, lineStyle_old;
00437 float lineWidth, lineWidth_old;
00438 QString lineColor, lineColor_old;
00439 QString labelColor, labelColor_old;
00440 float labelScale, labelScale_old;
00441 bool lineDoubleStatus, lineDoubleStatus_old;
00442
00443
00444 Qt::PenStyle dimLineStyle, dimLineStyle_old;
00445 QString dimLineColor, dimLineColor_old;
00446 float dimLineCoef, dimLineCoef_old;
00447 QString dimLabelColor, dimLabelColor_old;
00448
00449
00450 float borderCoef, borderCoef_old;
00451 QString borderColor, borderColor_old;
00452
00453
00454 float lineDoubleCoef, lineDoubleCoef_old;
00455 float lineDoubleSep, lineDoubleSep_old;
00456 };
00457
00458 template <typename T>
00459 class MoveItemsCommand : public QUndoCommand
00460 {
00461 public:
00462 MoveItemsCommand(const QList<T *> &items, const QVector<QPointF> &origPos)
00463 : m_itemList(items), m_origPositions(origPos), m_newPositions(origPos.size())
00464 {
00465 int i = 0;
00466 foreach(QGraphicsItem *item, items)
00467 {
00468 m_newPositions[i] = item->pos();
00469 ++i;
00470 }
00471 }
00472
00473 void undo()
00474 {
00475 QPointF pos;
00476 int i = 0;
00477 foreach(QGraphicsItem* item, m_itemList)
00478 {
00479 pos = m_origPositions[i];
00480 if (pos != item->pos())
00481 {
00482 item->setPos(pos.x(), pos.y());
00483 }
00484 ++i;
00485 }
00486 setText(QObject::tr("Move items"));
00487 }
00488
00489 void redo()
00490 {
00491 QPointF pos;
00492 int i = 0;
00493 foreach(QGraphicsItem* item, m_itemList)
00494 {
00495 pos = m_newPositions[i];
00496 if (pos != item->pos())
00497 {
00498 item->setPos(pos.x(), pos.y());
00499 }
00500 ++i;
00501 }
00502 setText(QObject::tr("Move items"));
00503 }
00504
00505 private:
00506 QList<T *> m_itemList;
00507 QVector<QPointF> m_origPositions, m_newPositions;
00508 };
00509
00510 template <typename T>
00511 MoveItemsCommand<T>* createMoveItemsCommand(const QList<T *> &items, const QVector<QPointF> &origPos)
00512 {
00513 return new MoveItemsCommand<T>(items, origPos);
00514 }
00515
00516
00517 class GeneratedGraphAddCommand : public QUndoCommand
00518 {
00519 public:
00520 GeneratedGraphAddCommand(Editor *editor, const QList<State *> &stateList, QRect gr_new,
00521 QUndoCommand *parent = 0);
00522
00523 ~GeneratedGraphAddCommand();
00524
00525 void undo();
00526 void redo();
00527 private:
00528 Editor *editor;
00529 QList<State *> stateList;
00530
00531 QRect gridRect_new, gridRect_old;
00532 bool wasUndo;
00533 };
00534
00535 class ItemsAddCommand : public QUndoCommand
00536 {
00537 public:
00538 ItemsAddCommand(Editor *editor, const QList<State *> &stateList, QRect gr_new,
00539 QUndoCommand *parent = 0);
00540
00541 ~ItemsAddCommand();
00542
00543 void undo();
00544 void redo();
00545
00546 protected:
00547 Editor *editor;
00548 QList<State *> stateList;
00549
00550 QRect gridRect_new, gridRect_old;
00551 bool wasUndo;
00552 };
00553
00554 class ItemsRemoveCommand : public QUndoCommand
00555 {
00556 public:
00557 ItemsRemoveCommand(Editor *editor, const QList<State *> &stateList,
00558 const QList<Transition *> &transitionList,
00559 QUndoCommand *parent = 0);
00560
00561 ~ItemsRemoveCommand();
00562
00563 void undo();
00564 void redo();
00565
00566 protected:
00567 Editor *editor;
00568 QList<State *> stateList;
00569 QList<Transition *> transitionList;
00570
00571 bool wasUndo;
00572 };
00573
00574 class StatesSetMarkedCommand : public QUndoCommand
00575 {
00576 public:
00577 StatesSetMarkedCommand(QList<State*> states, bool marked, QUndoCommand *parent = 0);
00578
00579 ~StatesSetMarkedCommand();
00580
00581 void undo();
00582 void redo();
00583
00584 protected:
00585 QList<State*> m_states;
00586 bool m_marked;
00587 };
00588
00589 #endif