• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

C:/CVUT/diplomka/Automata_editor/sources/commands.cpp

Go to the documentation of this file.
00001 #include "constants.h"
00002 
00003 #include "commands.h"
00004 #include "editor.h"
00005 #include "state.h"
00006 #include "transition.h"
00007 #include "oneStateTransition.h"
00008 #include "twoStatesTransition.h"
00009 #include "label.h"
00010 
00011 #include <QGraphicsScene>
00012 #include <QGraphicsItem>
00013 #include <QtDebug>
00014 #include <QList>
00015 
00016 QString createCommandString(State *state, const QPointF &pos)
00017 {
00018     return QObject::tr("%1 at (%2, %3)")
00019         .arg(state->getName())
00020         .arg(pos.x())
00021         .arg(pos.y());
00022 }
00023 
00024 //<-- ShowGridFrameCommand --------------------------------------------------
00025 
00026 ShowGridFrameCommand::ShowGridFrameCommand(Editor *editor, bool origGrid, bool grid,
00027                                                            bool origFrame, bool frame)
00028 :   m_editor(editor),
00029     m_origGrid(origGrid), m_grid(grid),
00030     m_origFrame(origFrame), m_frame(frame)
00031 {
00032 
00033 }
00034 
00035 void ShowGridFrameCommand::undo()
00036 {
00037     m_editor->setShowGridFrame(m_origGrid, m_origFrame);
00038 
00039     setText(getMsg());
00040 }
00041 
00042 void ShowGridFrameCommand::redo()
00043 {
00044     m_editor->setShowGridFrame(m_grid, m_frame);
00045     setText(getMsg());
00046 }
00047 
00048 QString ShowGridFrameCommand::getMsg() const
00049 {
00050     QString msg = "";
00051     if (m_origGrid != m_grid)
00052     {
00053         msg += "Show Grid ";
00054         msg += m_grid ? "on" : "off";
00055     }
00056     if (m_origFrame != m_frame)
00057     {
00058         if (!msg.isEmpty()) msg += " / ";
00059         msg += "Show Frame ";
00060         msg += m_frame ? "on" : "off";
00061     }
00062     if (msg.isEmpty())
00063     {
00064         Q_ASSERT(0 && "nothing to be done!");
00065         msg = "Show Grid/Frame no action";
00066     }
00067 
00068     return msg;
00069 }
00070 
00071 //-------------------------------------------------- ShowGridFrameCommand -->
00072 
00073 
00074 
00075 //<-- StateMoveCommand ------------------------------------------------------
00076 
00077 StateMoveCommand::StateMoveCommand(State *state, const QPointF &oldPos, QUndoCommand *parent)
00078 : QUndoCommand(parent), state(state), oldPos(oldPos)
00079 {
00080     newPos = state->pos();
00081 }
00082 
00083 void StateMoveCommand::undo()
00084 {
00085     state->setPos(oldPos);
00086     state->scene()->update();
00087     setText(QObject::tr("Move %1")
00088         .arg(createCommandString(state, newPos)));
00089 }
00090 
00091 void StateMoveCommand::redo()
00092 {
00093     state->setPos(newPos);
00094     state->scene()->update();
00095     setText(QObject::tr("Move %1")
00096         .arg(createCommandString(state, newPos)));
00097 }
00098 
00099 //------------------------------------------------------ StateMoveCommand -->
00100 
00101 
00102 
00103 //<-- StateAddCommand -------------------------------------------------------
00104 
00105 StateAddCommand::StateAddCommand(Editor *editor, State *state, QUndoCommand *parent)
00106 : QUndoCommand(parent), editor(editor), state(state)
00107 {}
00108 
00109 StateAddCommand::~StateAddCommand()
00110 {
00111     if (wasUndo) delete state; // smazou se jen states ktere nejsou na scene!
00112 }
00113 
00114 void StateAddCommand::undo()
00115 {
00116     wasUndo = true;
00117     editor->removeFromListsAndScene(state);
00118     setText(QObject::tr("Add State %1")
00119         .arg(createCommandString(state, state->pos())));
00120 }
00121 
00122 void StateAddCommand::redo()
00123 {
00124     wasUndo = false;
00125     editor->addToListsAndScene(state);
00126     setText(QObject::tr("Add State %1")
00127         .arg(createCommandString(state, state->pos())));
00128 }
00129 
00130 //------------------------------------------------------- StateAddCommand -->
00131 
00132 
00133 
00134 //<-- StateDeleteCommand ----------------------------------------------------
00135 
00136 StateDeleteCommand::StateDeleteCommand(Editor *editor, State *state, QUndoCommand *parent)
00137 : QUndoCommand(parent), editor(editor), state(state)
00138 {
00139     transitionList = state->getTransitionList();
00140 }
00141 
00142 StateDeleteCommand::~StateDeleteCommand()
00143 {
00144     if (!wasUndo) 
00145     {
00146         delete state;
00147         foreach (Transition *tr, transitionList)
00148         { // TODO: check all posibilities -> if transition is in ANY list everywhere
00149             delete tr;
00150         }
00151     }
00152 }
00153 
00154 void StateDeleteCommand::undo()
00155 {
00156     wasUndo = true;
00157     editor->addToListsAndScene(state);
00158     for (int i=0; i<transitionList.size(); i++)
00159     {
00160         editor->addToListsAndScene(transitionList[i]);
00161     }
00162     setText(QObject::tr("Delete State %1")
00163         .arg(createCommandString(state, state->pos())));
00164 }
00165 
00166 void StateDeleteCommand::redo()
00167 {
00168     wasUndo = false;
00169     editor->removeFromListsAndScene(state);
00170     for (int i=0; i<transitionList.size(); i++)
00171     {
00172         editor->removeFromListsAndScene(transitionList[i]);
00173     }
00174     setText(QObject::tr("Delete State %1")
00175         .arg(createCommandString(state, state->pos())));
00176 }
00177 
00178 //--------------------------------------------------- StateDeleteCommand -->
00179 
00180 
00181 
00182 //<-- StateEditCommand -----------------------------------------------------
00183 
00184 StateEditCommand::StateEditCommand(Editor *editor, State *state, QString label, QString name, bool db, bool dimmed,
00185                                    bool autoNammed, QUndoCommand *parent)
00186 : QUndoCommand(parent), editor(editor), state(state), label_new(label), name_new(name), db_new(db),
00187   dimmed_new(dimmed), an_new(autoNammed)
00188 {
00189   label_old = state->getLabel();
00190   name_old = state->getName();
00191   db_old = state->isDoubleBorder();
00192   dimmed_old = state->isDimmed();
00193   an_old = state->isAutoNammed();
00194 }
00195 
00196 void StateEditCommand::undo(){
00197     state->setLabel(label_old);
00198     editor->renameState(state, name_old);
00199     state->setDoubleBorder(db_old);
00200     state->setDimmed(dimmed_old);
00201     state->setAutoNammed(an_old);
00202     setText(QObject::tr("Edit State %1")
00203         .arg(createCommandString(state, state->pos())));
00204     state->update();
00205 }
00206 
00207 void StateEditCommand::redo(){
00208     state->setLabel(label_new);
00209     editor->renameState(state, name_new);
00210     state->setDoubleBorder(db_new);
00211     state->setDimmed(dimmed_new);
00212     state->setAutoNammed(an_new);
00213     setText(QObject::tr("Edit State %1")
00214         .arg(createCommandString(state, state->pos())));
00215     state->update();
00216 }
00217 
00218 //----------------------------------------------------- StateEditCommand -->
00219 
00220 
00221 
00222 //<-- StateEditCommand -----------------------------------------------------
00223 
00224 StateEditWithDelCommand::StateEditWithDelCommand(Editor *editor, State *state_backup, State *state_new,
00225                         QUndoCommand *parent)
00226 : QUndoCommand(parent), editor(editor), state_backup(state_backup), state_new(state_new)
00227 {
00228     transitionList = state_backup->getTransitionList();
00229 }
00230 
00231 StateEditWithDelCommand::~StateEditWithDelCommand()
00232 {
00233     if (wasUndo)
00234     {
00235         delete state_new;
00236     }
00237     else
00238     {
00239         delete state_backup;
00240     }
00241 }
00242 
00243 void StateEditWithDelCommand::undo()
00244 {
00245     wasUndo = true;
00246     editor->removeFromListsAndScene(state_new);
00247     editor->addToListsAndScene(state_backup);
00248   
00249     state_backup->setTransitionList(transitionList); // move list of transitions
00250     state_new->clearTransitionList();
00251   
00252     for (int i=0; i<transitionList.size(); i++)
00253     {
00254         if (transitionList[i]->getStartState() == state_new)
00255             transitionList[i]->setStartState(state_backup);
00256         else
00257             transitionList[i]->setEndState(state_backup);
00258     }
00259 
00260     state_backup->adjustTransitions();
00261     setText(QObject::tr("EditWithDel State"));
00262 }
00263 
00264 void StateEditWithDelCommand::redo()
00265 {
00266     wasUndo = false;
00267     editor->removeFromListsAndScene(state_backup);
00268     editor->addToListsAndScene(state_new);
00269 
00270     state_new->setTransitionList(transitionList); // move list of transitions
00271     state_backup->clearTransitionList();
00272 
00273     for (int i=0; i<transitionList.size(); i++){
00274         if (transitionList[i]->getStartState() == state_backup)
00275             transitionList[i]->setStartState(state_new);
00276         else
00277             transitionList[i]->setEndState(state_new);
00278     }
00279 
00280     copyExtendedParameters(state_new, state_backup);
00281 
00282     state_new->adjustTransitions();
00283     setText(QObject::tr("EditWithDel State"));
00284 }
00285 
00286 void StateEditWithDelCommand::copyExtendedParameters(State* s1, State* const s2)
00287 {    
00288     s1->stateFillColor = s2->stateFillColor;
00289     s1->stateFillStatus = s2->stateFillStatus;    
00290     s1->stateLabelColor = s2->stateLabelColor;
00291     s1->setStateLabelScale(s2->stateLabelScale);
00292     s1->stateLineColor = s2->stateLineColor;
00293     s1->setStateLineDoubleCoef(s2->stateLineDoubleCoef);
00294     s1->setStateLineDoubleSep(s2->stateLineDoubleSep);
00295     s1->stateLineStyle = s2->stateLineStyle;
00296     s1->setStateLineWidth(s2->stateLineWidth);
00297 
00298     s1->dimStateFillColor = s2->dimStateFillColor;    
00299     s1->dimStateLabelColor = s2->dimStateLabelColor;
00300     s1->setDimStateLineCoef(s2->dimStateLineCoef);
00301     s1->dimStateLineColor = s2->dimStateLineColor;
00302     s1->dimStateLineStyle = s2->dimStateLineStyle;
00303 }
00304 
00305 //----------------------------------------------------- StateEditCommand -->
00306 
00307 
00308 
00309 //<-- StateEditExtendedCommand ---------------------------------------------
00310 
00311 StateEditExtendedCommand::StateEditExtendedCommand
00312 (State *state, Qt::PenStyle lineS, float lineW, const QString &lineC,
00313  const QString &labelC, float labelS, Qt::BrushStyle fillS, 
00314  const QString &fillC, Qt::PenStyle dimLineS, const QString &dimLineC,
00315  float dimLineCoef, const QString &dimLabelC, const QString &dimFillC,
00316  float lineDC, float lineDS, QUndoCommand *parent)
00317 : QUndoCommand(parent), state(state),
00318   lineStyle(lineS), lineWidth(lineW), lineColor(lineC),
00319   labelColor(labelC), labelScale(labelS), fillStatus(fillS), fillColor(fillC),
00320   dimLineStyle(dimLineS), dimLineColor(dimLineC), dimLineCoef(dimLineCoef),
00321   dimLabelColor(dimLabelC), dimFillColor(dimFillC), 
00322   lineDoubleCoef(lineDC), lineDoubleSep(lineDS)
00323 {
00324   lineStyle_old = state->stateLineStyle;
00325   lineWidth_old = state->stateLineWidth;
00326   lineColor_old = state->stateLineColor;
00327   labelColor_old = state->stateLabelColor;
00328   labelScale_old = state->stateLabelScale;
00329   fillStatus_old = state->stateFillStatus;
00330   fillColor_old = state->stateFillColor;
00331   
00332   dimLineStyle_old = state->dimStateLineStyle;
00333   dimLineColor_old = state->dimStateLineColor;
00334   dimLineCoef_old = state->dimStateLineCoef;
00335   dimLabelColor_old = state->dimStateLabelColor;
00336   dimFillColor_old = state->dimStateFillColor;
00337   
00338   lineDoubleCoef_old = state->stateLineDoubleCoef;
00339   lineDoubleSep_old = state->stateLineDoubleSep;
00340 }
00341 
00342 void StateEditExtendedCommand::undo(){
00343   state->stateLineStyle = lineStyle_old;
00344   state->setStateLineWidth(lineWidth_old);
00345   state->stateLineColor = lineColor_old;
00346   state->stateLabelColor = labelColor_old;
00347   state->setStateLabelScale(labelScale_old);
00348   state->stateFillStatus = fillStatus_old;
00349   state->stateFillColor = fillColor_old;
00350   
00351   state->dimStateLineStyle = dimLineStyle_old;
00352   state->dimStateLineColor = dimLineColor_old;
00353   state->setDimStateLineCoef(dimLineCoef_old);
00354   state->dimStateLabelColor = dimLabelColor_old;
00355   state->dimStateFillColor = dimFillColor_old;
00356   
00357   state->setStateLineDoubleCoef(lineDoubleCoef_old);
00358   state->setStateLineDoubleSep(lineDoubleSep_old);
00359   
00360   state->update();
00361   state->adjustTransitions();
00362   
00363   setText(QObject::tr("Edit state %1 params")
00364     .arg(createCommandString(state, state->pos())));
00365 }
00366 
00367 void StateEditExtendedCommand::redo(){
00368   state->stateLineStyle = lineStyle;
00369   state->setStateLineWidth(lineWidth);
00370   state->stateLineColor = lineColor;
00371   state->stateLabelColor = labelColor;
00372   state->setStateLabelScale(labelScale);
00373   state->stateFillStatus = fillStatus;
00374   state->stateFillColor = fillColor;
00375   
00376   state->dimStateLineStyle = dimLineStyle;
00377   state->dimStateLineColor = dimLineColor;
00378   state->setDimStateLineCoef(dimLineCoef);
00379   state->dimStateLabelColor = dimLabelColor;
00380   state->dimStateFillColor = dimFillColor;
00381   
00382   state->setStateLineDoubleCoef(lineDoubleCoef);
00383   state->setStateLineDoubleSep(lineDoubleSep);
00384   
00385   state->update();
00386   state->adjustTransitions();
00387   
00388   setText(QObject::tr("Edit state %1 params")
00389     .arg(createCommandString(state, state->pos())));
00390 }
00391 
00392 //--------------------------------------------- StateEditExtendedCommand -->
00393 
00394 
00395 
00396 //<-- TransitionAddCommand -------------------------------------------------
00397 
00398 TransitionAddCommand::TransitionAddCommand(Editor *editor, Transition *transition, QUndoCommand *parent)
00399 : QUndoCommand(parent), editor(editor), transition(transition)
00400 {}
00401 
00402 TransitionAddCommand::~TransitionAddCommand(){
00403   if (wasUndo) delete transition; // smazou se jen transitions ktere nejsou na scene!
00404 }
00405 
00406 void TransitionAddCommand::undo(){
00407   wasUndo = true;
00408   editor->removeFromListsAndScene(transition);
00409   setText(QObject::tr("Add Transition"));
00410 }
00411 
00412 void TransitionAddCommand::redo(){
00413   wasUndo = false;
00414   editor->addToListsAndScene(transition);  
00415   setText(QObject::tr("Add Transition"));
00416 }
00417 
00418 //------------------------------------------------- TransitionAddCommand -->
00419 
00420 
00421 
00422 //<-- TransitionDeleteCommand ----------------------------------------------
00423 
00424 TransitionDeleteCommand::TransitionDeleteCommand(Editor *editor, Transition *transition, QUndoCommand *parent)
00425 : QUndoCommand(parent), editor(editor), transition(transition)
00426 {}
00427 
00428 TransitionDeleteCommand::~TransitionDeleteCommand(){
00429   if (!wasUndo){
00430     delete transition; // transition ktere jsem deletnul je treba vymazat fyzicky
00431   }
00432 }
00433 
00434 void TransitionDeleteCommand::undo(){
00435   wasUndo = true;
00436   editor->addToListsAndScene(transition);
00437   setText(QObject::tr("Del Transition"));
00438 }
00439 
00440 void TransitionDeleteCommand::redo(){
00441   wasUndo = false;
00442   editor->removeFromListsAndScene(transition);
00443   setText(QObject::tr("Del Transition"));
00444 }
00445 
00446 //---------------------------------------------- TransitionDeleteCommand -->
00447 
00448 
00449 
00450 //<-- OneStateTransitionEditCommand ----------------------------------------
00451 
00452 OneStateTransitionEditCommand::OneStateTransitionEditCommand
00453 (OneStateTransition *transition, QString label, float labelPos, int direction, 
00454  bool dimmed, QUndoCommand *parent)
00455 :   QUndoCommand(parent), tr(transition),
00456     lab_new(label), labelPos_new(labelPos), dir_new(direction), dimmed_new(dimmed)
00457 {
00458   lab_old = tr->getLabelText();
00459   labelPos_old = tr->getLabelPos();
00460   dir_old = tr->getDirection();
00461   dimmed_old = tr->isDimmed();
00462 }
00463 
00464 void OneStateTransitionEditCommand::undo(){
00465   tr->setLabelText(lab_old);
00466   tr->setLabelPos(labelPos_old);
00467   tr->setDirection(dir_old);
00468   tr->setDimmed(dimmed_old);
00469   tr->adjust();
00470   setText(QObject::tr("Edit Transition"));
00471 }
00472 
00473 void OneStateTransitionEditCommand::redo(){
00474   tr->setLabelText(lab_new);
00475   tr->setLabelPos(labelPos_new);
00476   tr->setDirection(dir_new);
00477   tr->setDimmed(dimmed_new);
00478   tr->adjust();
00479   setText(QObject::tr("Edit Transition"));
00480 }
00481 
00482 //---------------------------------------- OneStateTransitionEditCommand -->
00483 
00484 
00485 //<-- TwoStatesTransitionEditCommand ---------------------------------------
00486 
00487 TwoStatesTransitionEditCommand::TwoStatesTransitionEditCommand
00488 (TwoStatesTransition *tr, QString label, float labelPos, bool dimmed, bool leftOriented, 
00489  int arcAngle, int arcAngleB, float ncurv, QUndoCommand *parent)
00490 : QUndoCommand(parent), tr(tr),
00491   lab_new(label), labelPos_new(labelPos), dimmed_new(dimmed), lo_new(leftOriented)
00492   , angle_new(arcAngle), angleB_new(arcAngleB), ncurv_new(ncurv)
00493 {
00494   lab_old = tr->getLabelText();
00495   labelPos_old = tr->getLabelPos();
00496   dimmed_old = tr->isDimmed();
00497   lo_old = tr->isLeftOriented();  
00498   angle_old = tr->getArcAngle();
00499   angleB_old = tr->getArcAngleB();
00500   ncurv_old = tr->getNCurv();
00501 }
00502 
00503 void TwoStatesTransitionEditCommand::undo(){
00504   tr->setLabelText(lab_old);
00505   tr->setLabelPos(labelPos_old);
00506   tr->setLeftOriented(lo_old);
00507   tr->setDimmed(dimmed_old);
00508   tr->setArcAngle(angle_old);
00509   tr->setArcAngleB(angleB_old);
00510   tr->setNCurv(ncurv_old);
00511   tr->adjust();
00512   setText(QObject::tr("Edit Transition"));
00513 }
00514 
00515 void TwoStatesTransitionEditCommand::redo(){
00516   tr->setLabelText(lab_new);
00517   tr->setLabelPos(labelPos_new);
00518   tr->setLeftOriented(lo_new);
00519   tr->setDimmed(dimmed_new);
00520   tr->setArcAngle(angle_new);
00521   tr->setArcAngleB(angleB_new);
00522   tr->setNCurv(ncurv_new);
00523   tr->adjust();
00524   setText(QObject::tr("Edit Transition"));
00525 }
00526 
00527 //---------------------------------------------- TwoStatesTransitionEditCommand -->
00528 
00529 
00530 
00531 
00532 //<-- TransitionEditWithDelCommand ------------------------------------------------
00533 
00534 TransitionEditWithDelCommand::TransitionEditWithDelCommand
00535 (Editor *editor, Transition *tr_backup, Transition *tr_new, QUndoCommand *parent)
00536 : QUndoCommand(parent), editor(editor), tr_backup(tr_backup), tr_new(tr_new)
00537 {}
00538 
00539 TransitionEditWithDelCommand::~TransitionEditWithDelCommand(){
00540     if (wasUndo)
00541     {
00542         delete tr_new;
00543     }
00544     else
00545     {
00546         delete tr_backup;
00547     }
00548 }
00549 
00550 void TransitionEditWithDelCommand::undo()
00551 {
00552     wasUndo = true;
00553     
00554     tr_backup->nextLabels = tr_new->nextLabels;
00555     
00556     editor->removeFromListsAndScene(tr_new);
00557     editor->addToListsAndScene(tr_backup);
00558     
00559     tr_new->nextLabels.clear();
00560     
00561     tr_backup->adjust();
00562     setText(QObject::tr("EditWithDel Transition"));
00563 }
00564 
00565 void TransitionEditWithDelCommand::redo()
00566 {
00567     wasUndo = false;
00568     
00569     tr_new->nextLabels = tr_backup->nextLabels;
00570 
00571     editor->removeFromListsAndScene(tr_backup);
00572     editor->addToListsAndScene(tr_new);
00573     
00574     
00575     tr_backup->nextLabels.clear();
00576 
00577     copyExtendedParameters(tr_new, tr_backup);
00578 
00579     tr_new->adjust();
00580     setText(QObject::tr("EditWithDel Transition"));
00581 }
00582 
00583 void TransitionEditWithDelCommand::copyExtendedParameters(Transition *tr1, Transition* const tr2)
00584 {    
00585     tr1->edgeLabelColor = tr2->edgeLabelColor;
00586     tr1->setEdgeLabelScale(tr2->edgeLabelScale);
00587     tr1->edgeLineBorderCoef = tr2->edgeLineBorderCoef;
00588     tr1->edgeLineBorderColor = tr2->edgeLineBorderColor;
00589     tr1->edgeLineColor = tr2->edgeLineColor;
00590     tr1->edgeLineDblCoef = tr2->edgeLineDblCoef;
00591     tr1->edgeLineDblSep = tr2->edgeLineDblSep;
00592     tr1->edgeLineDblStatus = tr2->edgeLineDblStatus;
00593     tr1->edgeLineStyle = tr2->edgeLineStyle;
00594     tr1->setEdgeLineWidth(tr2->edgeLineWidth);
00595     
00596     tr1->dimEdgeLabelColor = tr2->dimEdgeLabelColor;
00597     tr1->setDimEdgeLineCoef(tr2->dimEdgeLineCoef);
00598     tr1->dimEdgeLineColor = tr2->dimEdgeLineColor;
00599     tr1->dimEdgeLineStyle = tr2->dimEdgeLineStyle;
00600 }
00601 
00602 //------------------------------------------------ TransitionEditWithDelCommand -->
00603 
00604 
00605 
00606 //<-- TransitionEditExtendedCommand -----------------------------------------------
00607 
00608 TransitionEditExtendedCommand::TransitionEditExtendedCommand
00609 (Transition *tr, Qt::PenStyle lineS, float lineW, const QString &lineC,
00610  const QString &labelC, float labelS, bool lineDoubleS, Qt::PenStyle dimLineS, 
00611  const QString &dimLineC, float dimLineCoef, const QString &dimLabelC,
00612  float borderCoef, const QString &borderColor,
00613  float lineDC, float lineDS, QUndoCommand *parent)
00614 : QUndoCommand(parent), tr(tr),
00615   lineStyle(lineS), lineWidth(lineW), lineColor(lineC),
00616   labelColor(labelC), labelScale(labelS), lineDoubleStatus(lineDoubleS),
00617   dimLineStyle(dimLineS), dimLineColor(dimLineC), dimLineCoef(dimLineCoef),
00618   dimLabelColor(dimLabelC), borderCoef(borderCoef), borderColor(borderColor),
00619   lineDoubleCoef(lineDC), lineDoubleSep(lineDS)
00620 {
00621   lineStyle_old = tr->edgeLineStyle;
00622   lineWidth_old = tr->edgeLineWidth;
00623   lineColor_old = tr->edgeLineColor;
00624   labelColor_old = tr->edgeLabelColor;
00625   labelScale_old = tr->edgeLabelScale;
00626   lineDoubleStatus_old = tr->edgeLineDblStatus;
00627   
00628   dimLineStyle_old = tr->dimEdgeLineStyle;
00629   dimLineColor_old = tr->dimEdgeLineColor;
00630   dimLineCoef_old = tr->dimEdgeLineCoef;
00631   dimLabelColor_old = tr->dimEdgeLabelColor;
00632   
00633   borderCoef_old = tr->edgeLineBorderCoef;
00634   borderColor_old = tr->edgeLineBorderColor;
00635   
00636   lineDoubleCoef_old = tr->edgeLineDblCoef;
00637   lineDoubleSep_old = tr->edgeLineDblSep;
00638 }
00639 
00640 void TransitionEditExtendedCommand::undo(){
00641   tr->edgeLineStyle = lineStyle_old;
00642   tr->setEdgeLineWidth(lineWidth_old);
00643   tr->edgeLineColor = lineColor_old;
00644   tr->edgeLabelColor = labelColor_old;
00645   tr->setEdgeLabelScale(labelScale_old);
00646   tr->edgeLineDblStatus = lineDoubleStatus_old;
00647   
00648   tr->dimEdgeLineStyle = dimLineStyle_old;
00649   tr->dimEdgeLineColor = dimLineColor_old;
00650   tr->setDimEdgeLineCoef(dimLineCoef_old);
00651   tr->dimEdgeLabelColor = dimLabelColor_old;
00652   
00653   tr->edgeLineBorderCoef = borderCoef_old;
00654   tr->edgeLineBorderColor = borderColor_old;
00655   
00656   tr->edgeLineDblCoef = lineDoubleCoef_old;
00657   tr->edgeLineDblSep = lineDoubleSep_old;
00658   
00659   tr->update();
00660   setText(QObject::tr("Transition params change"));
00661 }
00662 
00663 void TransitionEditExtendedCommand::redo(){
00664   tr->edgeLineStyle = lineStyle;
00665   tr->setEdgeLineWidth(lineWidth);
00666   tr->edgeLineColor = lineColor;
00667   tr->edgeLabelColor = labelColor;
00668   tr->setEdgeLabelScale(labelScale);
00669   tr->edgeLineDblStatus = lineDoubleStatus;
00670   
00671   tr->dimEdgeLineStyle = dimLineStyle;
00672   tr->dimEdgeLineColor = dimLineColor;
00673   tr->setDimEdgeLineCoef(dimLineCoef);
00674   tr->dimEdgeLabelColor = dimLabelColor;
00675   
00676   tr->edgeLineBorderCoef = borderCoef;
00677   tr->edgeLineBorderColor = borderColor;
00678   
00679   tr->edgeLineDblCoef = lineDoubleCoef;
00680   tr->edgeLineDblSep = lineDoubleSep;
00681   
00682   tr->update();
00683   setText(QObject::tr("Transition params change"));
00684 }
00685 
00686 //--------------------------------------------- TransitionEditExtendedCommand -->
00687 
00688 
00689 
00690 //<-- NextLabelAddCommand --------------------------------------------------------
00691 
00692 NextLabelAddCommand::NextLabelAddCommand(Editor *editor, LabelX *label, QUndoCommand *parent)
00693 : QUndoCommand(parent), editor(editor), label(label)
00694 {
00695 }
00696 
00697 NextLabelAddCommand::~NextLabelAddCommand()
00698 {
00699   if (wasUndo)
00700   {
00701     delete label;
00702   }
00703 }
00704 
00705 void NextLabelAddCommand::undo()
00706 {
00707     wasUndo = true;
00708     editor->removeFromListAndScene(label);
00709     setText(QObject::tr("NextLabel added"));
00710 }
00711 
00712 void NextLabelAddCommand::redo()
00713 {    
00714     wasUndo = false;
00715     editor->addToListAndScene(label);
00716     label->getTransition()->adjust();
00717     setText(QObject::tr("NextLabel added"));
00718 }
00719 
00720 //--------------------------------------------------------- NextLabelAddCommand -->
00721 
00722 
00723 
00724 //<-- NextLabelDeleteCommand ------------------------------------------------------
00725 
00726 NextLabelDeleteCommand::NextLabelDeleteCommand(Editor *editor, LabelX *label, QUndoCommand *parent)
00727 : QUndoCommand(parent), editor(editor), label(label)
00728 {
00729 }
00730 
00731 NextLabelDeleteCommand::~NextLabelDeleteCommand()
00732 {
00733   if (!wasUndo)
00734   {
00735     delete label;
00736   }
00737 }
00738 
00739 void NextLabelDeleteCommand::undo()
00740 {
00741     wasUndo = true;
00742     editor->addToListAndScene(label);
00743     setText(QObject::tr("NextLabel delete"));
00744 }
00745 
00746 void NextLabelDeleteCommand::redo()
00747 {
00748     wasUndo = false;
00749     editor->removeFromListAndScene(label);
00750     setText(QObject::tr("NextLabel delete"));
00751 }
00752 
00753 //------------------------------------------------------ NextLabelDeleteCommand -->
00754 
00755 
00756 
00757 //<-- NextLabelEditCommand --------------------------------------------------------
00758 
00759 NextLabelEditCommand::NextLabelEditCommand
00760 (LabelX *label, const QString &labelText, float labelPos, bool isLeft, QUndoCommand *parent)
00761 : QUndoCommand(parent), label(label), labelText_new(labelText), labelPos_new(labelPos), isLeft_new(isLeft)
00762 {
00763     labelText_backup = label->text();
00764     labelPos_backup = label->posParam();
00765     isLeft_backup = label->left();
00766 }
00767 
00768 void NextLabelEditCommand::undo()
00769 {
00770     label->setText(labelText_backup);
00771     label->setPosParam(labelPos_backup);
00772     label->setLeftOriented(isLeft_backup);
00773     label->getTransition()->adjust();
00774     setText(QObject::tr("NextLabel edit"));
00775 }
00776 
00777 void NextLabelEditCommand::redo()
00778 {
00779     label->setText(labelText_new);
00780     label->setPosParam(labelPos_new);
00781     label->setLeftOriented(isLeft_new);   
00782     label->getTransition()->adjust();
00783     setText(QObject::tr("NextLabel edit"));
00784 }
00785 
00786 //-------------------------------------------------------- NextLabelEditCommand -->
00787 
00788 
00789 
00790 //<-- EditorChangeGridRectCommand -------------------------------------------------
00791 
00792 EditorChangeGridRectCommand::EditorChangeGridRectCommand
00793 (Editor *editor, QRect gridRect, int border, QUndoCommand *parent)
00794 : QUndoCommand(parent), editor(editor), gridRect_new(gridRect), border_new(border)
00795 {
00796   gridRect_old = editor->getGridRect();
00797   border_old = editor->getBorder();
00798 }
00799 
00800 void EditorChangeGridRectCommand::undo()
00801 {
00802   editor->setBorder(border_old); // has to be before setGridRect, because this method use border value!
00803   editor->setGridRect(gridRect_old);  
00804   setText(QObject::tr("Change GridRect"));
00805 }
00806 
00807 void EditorChangeGridRectCommand::redo()
00808 {
00809   editor->setBorder(border_new); // has to be before setGridRect, because this method use border value!
00810   editor->setGridRect(gridRect_new);
00811   setText(QObject::tr("Change GridRect"));
00812 }
00813 
00814 //------------------------------------------------- EditorChangeGridRectCommand -->
00815 
00816 
00817 
00818 //<-- StateStyleChangeCommand ---------------------------------------------
00819 
00820 StateStyleChangeCommand::StateStyleChangeCommand
00821 (Editor *editor, int changeT, Qt::PenStyle lineS, float lineW, const QString &lineC,
00822  const QString &labelC, float labelS, Qt::BrushStyle fillS, 
00823  const QString &fillC, Qt::PenStyle dimLineS, const QString &dimLineC,
00824  float dimLineCoef, const QString &dimLabelC, const QString &dimFillC,
00825  float lineDC, float lineDS, QUndoCommand *parent)
00826 : QUndoCommand(parent), editor(editor), changeType(changeT),
00827   lineStyle(lineS), lineWidth(lineW), lineColor(lineC),
00828   labelColor(labelC), labelScale(labelS), fillStatus(fillS), fillColor(fillC),
00829   dimLineStyle(dimLineS), dimLineColor(dimLineC), dimLineCoef(dimLineCoef),
00830   dimLabelColor(dimLabelC), dimFillColor(dimFillC), 
00831   lineDoubleCoef(lineDC), lineDoubleSep(lineDS)
00832 {
00833   lineStyle_old = editor->stateLineStyle;
00834   lineWidth_old = editor->stateLineWidth;
00835   lineColor_old = editor->stateLineColor;
00836   labelColor_old = editor->stateLabelColor;
00837   labelScale_old = editor->stateLabelScale;
00838   fillStatus_old = editor->stateFillStatus;
00839   fillColor_old = editor->stateFillColor;
00840   
00841   dimLineStyle_old = editor->dimStateLineStyle;
00842   dimLineColor_old = editor->dimStateLineColor;
00843   dimLineCoef_old = editor->dimStateLineCoef;
00844   dimLabelColor_old = editor->dimStateLabelColor;
00845   dimFillColor_old = editor->dimStateFillColor;
00846   
00847   lineDoubleCoef_old = editor->stateLineDoubleCoef;
00848   lineDoubleSep_old = editor->stateLineDoubleSep;
00849   
00850   changedStates.clear();
00851   if (changeType == 1)
00852   foreach(State *state, editor->getStateList()){
00853     if ((state->stateLineStyle == editor->stateLineStyle) && 
00854         (state->stateLineWidth == 1) &&
00855         (state->stateLineColor == editor->stateLineColor) &&
00856         (state->stateLabelColor == editor->stateLabelColor) &&
00857         (state->stateLabelScale == 1) &&
00858         (state->stateFillStatus == editor->stateFillStatus) &&
00859         (state->stateFillColor == editor->stateFillColor) &&
00860         (state->dimStateLineStyle == editor->dimStateLineStyle) &&
00861         (state->dimStateLineColor == editor->dimStateLineColor) &&
00862         (state->dimStateLineCoef == editor->dimStateLineCoef) &&
00863         (state->dimStateLabelColor == editor->dimStateLabelColor) &&
00864         (state->dimStateFillColor == editor->dimStateFillColor) &&
00865         (state->stateLineDoubleCoef == editor->stateLineDoubleCoef) &&
00866         (state->stateLineDoubleSep == editor->stateLineDoubleSep)){
00867       changedStates << state;
00868     }
00869   }
00870   else if (changeType == 2){
00871     changedStates = editor->getStateList();
00872     lineStyleMap.clear(); lineWidthMap.clear(); lineColorMap.clear();
00873     labelColorMap.clear(); labelScaleMap.clear(); fillStatusMap.clear();
00874     fillColorMap.clear();
00875     dimLineStyleMap.clear(); dimLineColorMap.clear(); dimLineCoefMap.clear();
00876     dimLabelColorMap.clear(); dimFillColorMap.clear();
00877     lineDoubleCoefMap.clear(); lineDoubleSepMap.clear();
00878     foreach (State *state, editor->getStateList())
00879     {
00880       lineStyleMap.insert(state, state->stateLineStyle);
00881       lineWidthMap.insert(state, state->stateLineWidth);
00882       lineColorMap.insert(state, state->stateLineColor);
00883       labelColorMap.insert(state, state->stateLabelColor);
00884       labelScaleMap.insert(state, state->stateLineWidth);
00885       fillStatusMap.insert(state, state->stateFillStatus);
00886       fillColorMap.insert(state, state->stateFillColor);
00887       dimLineStyleMap.insert(state, state->dimStateLineStyle);
00888       dimLineColorMap.insert(state, state->dimStateLineColor);
00889       dimLineCoefMap.insert(state, state->dimStateLineCoef);
00890       dimLabelColorMap.insert(state, state->dimStateLabelColor);
00891       dimFillColorMap.insert(state, state->dimStateFillColor);
00892       lineDoubleCoefMap.insert(state, state->stateLineDoubleCoef);
00893       lineDoubleSepMap.insert(state, state->stateLineDoubleSep);
00894     }
00895   }
00896 }
00897 
00898 void StateStyleChangeCommand::undo()
00899 {
00900   editor->stateLineStyle = lineStyle_old;
00901   editor->stateLineWidth = lineWidth_old;
00902   editor->stateLineColor = lineColor_old;
00903   editor->stateLabelColor = labelColor_old;
00904   editor->stateLabelScale = labelScale_old;
00905   editor->stateFillStatus = fillStatus_old;
00906   editor->stateFillColor = fillColor_old;
00907   
00908   editor->dimStateLineStyle = dimLineStyle_old;
00909   editor->dimStateLineColor = dimLineColor_old;
00910   editor->dimStateLineCoef = dimLineCoef_old;
00911   editor->dimStateLabelColor = dimLabelColor_old;
00912   editor->dimStateFillColor = dimFillColor_old;
00913   
00914   editor->stateLineDoubleCoef = lineDoubleCoef_old;
00915   editor->stateLineDoubleSep = lineDoubleSep_old;
00916 
00917   if (changeType == 1){
00918     foreach (State *state, changedStates){
00919       state->stateLineStyle = lineStyle_old;
00920       //state->stateLineWidth = 1;
00921       state->stateLineColor = lineColor_old;
00922       state->stateLabelColor = labelColor_old;
00923       //state->stateLabelScale = 1;
00924       state->stateFillStatus = fillStatus_old;
00925       state->stateFillColor = fillColor_old;
00926       
00927       state->dimStateLineStyle = dimLineStyle_old;
00928       state->dimStateLineColor = dimLineColor_old;
00929       state->setDimStateLineCoef(dimLineCoef_old);
00930       state->dimStateLabelColor = dimLabelColor_old;
00931       state->dimStateFillColor = dimFillColor_old;
00932       
00933       state->setStateLineDoubleCoef(lineDoubleCoef_old);
00934       state->setStateLineDoubleSep(lineDoubleSep_old);
00935     }
00936   }
00937   else if (changeType == 2){
00938     foreach (State *state, changedStates){
00939       state->stateLineStyle = lineStyleMap.value(state);
00940       state->setStateLineWidth(lineWidthMap.value(state));
00941       state->stateLineColor = lineColorMap.value(state);
00942       state->stateLabelColor = labelColorMap.value(state);
00943       state->setStateLabelScale(labelScaleMap.value(state));
00944       state->stateFillStatus = fillStatusMap.value(state);
00945       state->stateFillColor = fillColorMap.value(state);
00946       
00947       state->dimStateLineStyle = dimLineStyleMap.value(state);
00948       state->dimStateLineColor = dimLineColorMap.value(state);
00949       state->setDimStateLineCoef(dimLineCoefMap.value(state));
00950       state->dimStateLabelColor = dimLabelColorMap.value(state);
00951       state->dimStateFillColor = dimFillColorMap.value(state);
00952       
00953       state->setStateLineDoubleCoef(lineDoubleCoefMap.value(state));
00954       state->setStateLineDoubleSep(lineDoubleSepMap.value(state));
00955     }
00956   }
00957   
00958   editor->update();
00959   
00960   QString s_arg = "";
00961   if (changeType == 1){
00962     s_arg = " - non changed states";
00963   }
00964   else if (changeType == 2){
00965     s_arg = " - to all states";
00966   }
00967   setText(QObject::tr("Change state style%1").arg(s_arg));
00968 }
00969 
00970 void StateStyleChangeCommand::redo(){
00971   editor->stateLineStyle = lineStyle;
00972   editor->stateLineWidth = lineWidth;
00973   editor->stateLineColor = lineColor;
00974   editor->stateLabelColor = labelColor;
00975   editor->stateLabelScale = labelScale;
00976   editor->stateFillStatus = fillStatus;
00977   editor->stateFillColor = fillColor;
00978   
00979   editor->dimStateLineStyle = dimLineStyle;
00980   editor->dimStateLineColor = dimLineColor;
00981   editor->dimStateLineCoef = dimLineCoef;
00982   editor->dimStateLabelColor = dimLabelColor;
00983   editor->dimStateFillColor = dimFillColor;
00984   
00985   editor->stateLineDoubleCoef = lineDoubleCoef;
00986   editor->stateLineDoubleSep = lineDoubleSep;
00987   
00988   if (changeType != 0){
00989     foreach(State *state, changedStates){
00990       state->stateLineStyle = lineStyle;
00991       state->setStateLineWidth(1);
00992       state->stateLineColor = lineColor;
00993       state->stateLabelColor = labelColor;
00994       state->setStateLabelScale(1);
00995       state->stateFillStatus = fillStatus;
00996       state->stateFillColor = fillColor;
00997 
00998       state->dimStateLineStyle = dimLineStyle;
00999       state->dimStateLineColor = dimLineColor;
01000       state->setDimStateLineCoef(dimLineCoef);
01001       state->dimStateLabelColor = dimLabelColor;
01002       state->dimStateFillColor = dimFillColor;
01003 
01004       state->setStateLineDoubleCoef(lineDoubleCoef);
01005       state->setStateLineDoubleSep(lineDoubleSep);
01006     }
01007   }
01008   
01009   editor->update();
01010   
01011   QString s_arg = "";
01012   if (changeType == 1){
01013     s_arg = " - non changed states";
01014   }
01015   else if (changeType == 2){
01016     s_arg = " - to all states";
01017   }
01018   setText(QObject::tr("Change state style%1").arg(s_arg));
01019 }
01020 
01021 //--------------------------------------------- StateStyleChangeCommand -->
01022 
01023 
01024 
01025 //<-- TransitionStyleChangeCommand ---------------------------------------------
01026 
01027 TransitionStyleChangeCommand::TransitionStyleChangeCommand
01028 (Editor *editor, int changeT, Qt::PenStyle lineS, float lineW, const QString &lineC,
01029  const QString &labelC, float labelS, bool lineDoubleS, Qt::PenStyle dimLineS, 
01030  const QString &dimLineC, float dimLineCoef, const QString &dimLabelC,
01031  float borderCoef, const QString &borderColor,
01032  float lineDC, float lineDS, QUndoCommand *parent)
01033 : QUndoCommand(parent), editor(editor), changeType(changeT),
01034   lineStyle(lineS), lineWidth(lineW), lineColor(lineC),
01035   labelColor(labelC), labelScale(labelS), lineDoubleStatus(lineDoubleS),
01036   dimLineStyle(dimLineS), dimLineColor(dimLineC), dimLineCoef(dimLineCoef),
01037   dimLabelColor(dimLabelC), borderCoef(borderCoef), borderColor(borderColor),
01038   lineDoubleCoef(lineDC), lineDoubleSep(lineDS)
01039 {
01040   lineStyle_old = editor->edgeLineStyle;
01041   lineWidth_old = editor->edgeLineWidth;
01042   lineColor_old = editor->edgeLineColor;
01043   labelColor_old = editor->edgeLabelColor;
01044   labelScale_old = editor->edgeLabelScale;
01045   lineDoubleStatus_old = editor->edgeLineDblStatus;
01046   
01047   dimLineStyle_old = editor->dimEdgeLineStyle;
01048   dimLineColor_old = editor->dimEdgeLineColor;
01049   dimLineCoef_old = editor->dimEdgeLineCoef;
01050   dimLabelColor_old = editor->dimEdgeLabelColor;
01051   
01052   borderCoef_old = editor->edgeLineBorderCoef;
01053   borderColor_old = editor->edgeLineBorderColor;
01054   
01055   lineDoubleCoef_old = editor->edgeLineDblCoef;
01056   lineDoubleSep_old = editor->edgeLineDblSep;
01057   
01058   changedTransitions.clear();
01059   if (changeType == 1)
01060   foreach(Transition *tr, editor->getTransitionList())
01061   {
01062     if ((tr->edgeLineStyle == editor->edgeLineStyle) && 
01063         (tr->edgeLineWidth == 1) &&
01064         (tr->edgeLineColor == editor->edgeLineColor) &&
01065         (tr->edgeLabelColor == editor->edgeLabelColor) &&
01066         (tr->edgeLabelScale == 1) &&
01067         (tr->edgeLineDblStatus == editor->edgeLineDblStatus) &&
01068         (tr->dimEdgeLineStyle == editor->dimEdgeLineStyle) &&
01069         (tr->dimEdgeLineColor == editor->dimEdgeLineColor) &&
01070         (tr->dimEdgeLineCoef == editor->dimEdgeLineCoef) &&
01071         (tr->dimEdgeLabelColor == editor->dimEdgeLabelColor) &&
01072         (tr->edgeLineBorderCoef == editor->edgeLineBorderCoef) &&
01073         (tr->edgeLineBorderColor == editor->edgeLineBorderColor) &&
01074         (tr->edgeLineDblCoef == editor->edgeLineDblCoef) &&
01075         (tr->edgeLineDblSep == editor->edgeLineDblSep)){
01076       changedTransitions << tr;
01077     }
01078   }
01079   else if (changeType == 2)
01080   {
01081     changedTransitions = editor->getTransitionList();
01082     lineStyleMap.clear(); lineWidthMap.clear(); lineColorMap.clear();
01083     labelColorMap.clear(); labelScaleMap.clear(); lineDoubleStatusMap.clear();
01084     dimLineStyleMap.clear(); dimLineColorMap.clear(); dimLineCoefMap.clear();
01085     dimLabelColorMap.clear();
01086     lineBorderCoefMap.clear(); lineBorderColorMap.clear();
01087     lineDoubleCoefMap.clear(); lineDoubleSepMap.clear();
01088     foreach (Transition *tr, editor->getTransitionList())
01089     {
01090       lineStyleMap.insert(tr, tr->edgeLineStyle);
01091       lineWidthMap.insert(tr, tr->edgeLineWidth);
01092       lineColorMap.insert(tr, tr->edgeLineColor);
01093       labelColorMap.insert(tr, tr->edgeLabelColor);
01094       labelScaleMap.insert(tr, tr->edgeLabelScale);
01095       lineDoubleStatusMap.insert(tr, tr->edgeLineDblStatus);
01096       dimLineStyleMap.insert(tr, tr->dimEdgeLineStyle);
01097       dimLineColorMap.insert(tr, tr->dimEdgeLineColor);
01098       dimLineCoefMap.insert(tr, tr->dimEdgeLineCoef);
01099       dimLabelColorMap.insert(tr, tr->dimEdgeLabelColor);
01100       lineBorderCoefMap.insert(tr, tr->edgeLineBorderCoef);
01101       lineBorderColorMap.insert(tr, tr->edgeLineBorderColor);
01102       lineDoubleCoefMap.insert(tr, tr->edgeLineDblCoef);
01103       lineDoubleSepMap.insert(tr, tr->edgeLineDblSep);
01104     }
01105   }
01106 }
01107 
01108 void TransitionStyleChangeCommand::undo(){
01109   editor->edgeLineStyle = lineStyle_old;
01110   editor->edgeLineWidth = lineWidth_old;
01111   editor->edgeLineColor = lineColor_old;
01112   editor->edgeLabelColor = labelColor_old;
01113   editor->edgeLabelScale = labelScale_old;
01114   editor->edgeLineDblStatus = lineDoubleStatus_old;
01115   
01116   editor->dimEdgeLineStyle = dimLineStyle_old;
01117   editor->dimEdgeLineColor = dimLineColor_old;
01118   editor->dimEdgeLineCoef = dimLineCoef_old;
01119   editor->dimEdgeLabelColor = dimLabelColor_old;
01120   
01121   editor->edgeLineBorderCoef = borderCoef_old;
01122   editor->edgeLineBorderColor = borderColor_old;
01123   
01124   editor->edgeLineDblCoef = lineDoubleCoef_old;
01125   editor->edgeLineDblSep = lineDoubleSep_old;
01126   
01127   if (changeType == 1){
01128     foreach (Transition *tr, changedTransitions){
01129       tr->edgeLineStyle = lineStyle_old;
01130       tr->setEdgeLineWidth(lineWidth_old);
01131       tr->edgeLineColor = lineColor_old;
01132       tr->edgeLabelColor = labelColor_old;
01133       tr->setEdgeLabelScale(labelScale_old);
01134       tr->edgeLineDblStatus = lineDoubleStatus_old;
01135       
01136       tr->dimEdgeLineStyle = dimLineStyle_old;
01137       tr->dimEdgeLineColor = dimLineColor_old;
01138       tr->setDimEdgeLineCoef(dimLineCoef_old);
01139       tr->dimEdgeLabelColor = dimLabelColor_old;
01140       
01141       tr->edgeLineBorderCoef = borderCoef_old;
01142       tr->edgeLineBorderColor = borderColor_old;
01143       
01144       tr->edgeLineDblCoef = lineDoubleCoef_old;
01145       tr->edgeLineDblSep = lineDoubleSep_old;
01146     }
01147   }
01148   else if (changeType == 2){
01149     foreach (Transition *tr, changedTransitions){
01150       tr->edgeLineStyle = lineStyleMap.value(tr);
01151       tr->setEdgeLineWidth(lineWidthMap.value(tr));
01152       tr->edgeLineColor = lineColorMap.value(tr);
01153       tr->edgeLabelColor = labelColorMap.value(tr);
01154       tr->setEdgeLabelScale(labelScaleMap.value(tr));
01155       tr->edgeLineDblStatus = lineDoubleStatusMap.value(tr);
01156       
01157       tr->dimEdgeLineStyle = dimLineStyleMap.value(tr);
01158       tr->dimEdgeLineColor = dimLineColorMap.value(tr);
01159       tr->setDimEdgeLineCoef(dimLineCoefMap.value(tr));
01160       tr->dimEdgeLabelColor = dimLabelColorMap.value(tr);
01161       
01162       tr->edgeLineBorderCoef = lineBorderCoefMap.value(tr);
01163       tr->edgeLineBorderColor = lineBorderColorMap.value(tr);
01164       
01165       tr->edgeLineDblCoef = lineDoubleCoefMap.value(tr);
01166       tr->edgeLineDblSep = lineDoubleSepMap.value(tr);
01167     }
01168   }  
01169   
01170   editor->update();
01171   
01172   QString s_arg = "";
01173   if (changeType == 1){
01174     s_arg = " - non changed transitions";
01175   }
01176   else if (changeType == 2){
01177     s_arg = " - to all transitions";
01178   }
01179   setText(QObject::tr("Change transition style%1").arg(s_arg));
01180 }
01181 
01182 void TransitionStyleChangeCommand::redo(){
01183   editor->edgeLineStyle = lineStyle;
01184   editor->edgeLineWidth = lineWidth;
01185   editor->edgeLineColor = lineColor;
01186   editor->edgeLabelColor = labelColor;
01187   editor->edgeLabelScale = labelScale;
01188   editor->edgeLineDblStatus = lineDoubleStatus;
01189   
01190   editor->dimEdgeLineStyle = dimLineStyle;
01191   editor->dimEdgeLineColor = dimLineColor;
01192   editor->dimEdgeLineCoef = dimLineCoef;
01193   editor->dimEdgeLabelColor = dimLabelColor;
01194   
01195   editor->edgeLineBorderCoef = borderCoef;
01196   editor->edgeLineBorderColor = borderColor;
01197   
01198   editor->edgeLineDblCoef = lineDoubleCoef;
01199   editor->edgeLineDblSep = lineDoubleSep;
01200   
01201   if (changeType != 0){
01202     foreach(Transition *tr, changedTransitions){
01203       tr->edgeLineStyle = lineStyle;
01204       tr->setEdgeLineWidth(lineWidth);
01205       tr->edgeLineColor = lineColor;
01206       tr->edgeLabelColor = labelColor;
01207       tr->setEdgeLabelScale(labelScale);
01208       tr->edgeLineDblStatus = lineDoubleStatus;
01209       
01210       tr->dimEdgeLineStyle = dimLineStyle;
01211       tr->dimEdgeLineColor = dimLineColor;
01212       tr->setDimEdgeLineCoef(dimLineCoef);
01213       tr->dimEdgeLabelColor = dimLabelColor;
01214       
01215       tr->edgeLineBorderCoef = borderCoef;
01216       tr->edgeLineBorderColor = borderColor;
01217       
01218       tr->edgeLineDblCoef = lineDoubleCoef;
01219       tr->edgeLineDblSep = lineDoubleSep;
01220     }
01221   }
01222   
01223   editor->update();
01224   QString s_arg = "";
01225   if (changeType == 1){
01226     s_arg = " - non changed transitions";
01227   }
01228   else if (changeType == 2){
01229     s_arg = " - to all transitions";
01230   }
01231   setText(QObject::tr("Change transition style%1").arg(s_arg));
01232 }
01233 
01234 //--------------------------------------------- TransitionStyleChangeCommand -->
01235 
01236 
01237 
01238 //<-- GeneratedGraphAddCommand -------------------------------------------------
01239 
01240 GeneratedGraphAddCommand::GeneratedGraphAddCommand(Editor *editor, 
01241   const QList<State *> &stateList, QRect gr_new, QUndoCommand *parent)
01242 : QUndoCommand(parent), editor(editor), stateList(stateList),
01243   gridRect_new(gr_new), wasUndo(false)
01244 {
01245   gridRect_old = editor->getGridRect();
01246 }
01247 
01248 GeneratedGraphAddCommand::~GeneratedGraphAddCommand(){  
01249   if (wasUndo){ // delete all items if undo was used
01250     foreach(State *state, stateList){
01251       delete state;
01252     }  
01253   }
01254 }
01255 
01256 void GeneratedGraphAddCommand::undo(){
01257     if (gridRect_new != gridRect_old) 
01258         editor->setGridRect(gridRect_old);
01259   
01260     foreach(State *state, stateList)
01261     {
01262         foreach(Transition *tr, state->getTransitionList())
01263         {
01264             if (state == tr->getStartState()) // remove tr only once
01265                 editor->removeFromListAndScene(tr);
01266         }
01267         editor->removeFromListsAndScene(state);
01268     }
01269   
01270     setText(QObject::tr("Generated graph add"));
01271     wasUndo = true;
01272 }
01273 
01274 void GeneratedGraphAddCommand::redo(){
01275   if (gridRect_new != gridRect_old) 
01276     editor->setGridRect(gridRect_new);
01277   if (wasUndo){ // no do at first
01278     foreach(State *state, stateList){
01279       editor->addToListsAndScene(state);
01280       foreach(Transition *tr, state->getTransitionList())
01281       {
01282           if (state == tr->getStartState()) // add tr only once
01283               editor->addToListAndScene(tr);
01284       }
01285     }
01286   }  
01287   
01288   setText(QObject::tr("Generated graph add"));
01289   wasUndo = false;
01290 }
01291 
01292 //------------------------------------------------- GeneratedGraphAddCommand -->
01293 
01294 
01295 
01296 //<-- ItemsAddCommand ----------------------------------------------------------
01297 
01298 ItemsAddCommand::ItemsAddCommand(Editor *editor, 
01299   const QList<State *> &stateList, QRect gr_new, QUndoCommand *parent)
01300 : QUndoCommand(parent), editor(editor), stateList(stateList),
01301   gridRect_new(gr_new), wasUndo(false)
01302 {
01303     gridRect_old = editor->getGridRect();
01304 }
01305 
01306 ItemsAddCommand::~ItemsAddCommand()
01307 {
01308     if (wasUndo)
01309     { // delete all items if undo was used -> 
01310       // transitions and labels are deleted through state's destructor
01311         foreach(State *state, stateList)
01312         {
01313             delete state;
01314         }
01315     }
01316 }
01317 
01318 void ItemsAddCommand::undo()
01319 {
01320     if (gridRect_new != gridRect_old) 
01321         editor->setGridRect(gridRect_old);
01322   
01323     foreach(State *state, stateList)
01324     {
01325         foreach(Transition *tr, state->getTransitionList())
01326         {
01327             if (state == tr->getStartState()) // remove tr only once
01328                 editor->removeFromListAndScene(tr);
01329         }
01330         editor->removeFromListsAndScene(state);
01331     }
01332   
01333     setText(QObject::tr("Items added"));
01334     wasUndo = true;
01335 }
01336 
01337 void ItemsAddCommand::redo()
01338 {
01339     if (gridRect_new != gridRect_old) 
01340         editor->setGridRect(gridRect_new);    
01341     
01342     foreach(State *state, stateList)
01343     {
01344         editor->addToListsAndScene(state);
01345         foreach(Transition *tr, state->getTransitionList())
01346         {
01347             if (state == tr->getStartState()) // add tr only once
01348             {
01349                 editor->addToListAndScene(tr);
01350             }
01351         }    
01352     }
01353 
01354     setText(QObject::tr("Items added"));
01355     wasUndo = false;
01356 }
01357 
01358 //---------------------------------------------------------- ItemsAddCommand -->
01359 
01360 
01361 
01362 //<-- ItemsRemoveCommand -------------------------------------------------------
01363 
01364 ItemsRemoveCommand::ItemsRemoveCommand(Editor *editor, const QList<State *> &stateList,
01365                                        const QList<Transition *> &transitionList,
01366                                        QUndoCommand *parent)
01367 : QUndoCommand(parent), editor(editor), stateList(stateList),
01368   transitionList(transitionList), wasUndo(false)
01369 {}
01370 
01371 ItemsRemoveCommand::~ItemsRemoveCommand()
01372 {
01373     if (!wasUndo)
01374     {
01375         foreach(State *state, stateList)
01376         {
01377             delete state;
01378         }
01379 
01380         foreach(Transition *transition, transitionList)
01381         {
01382             delete transition;
01383         }
01384     }
01385 }
01386 
01387 void ItemsRemoveCommand::undo()
01388 {
01389     foreach(State *state, stateList)
01390     {
01391         editor->addToListsAndScene(state);
01392     }
01393 
01394     foreach(Transition *transition, transitionList)
01395     {
01396         editor->addToListsAndScene(transition);
01397     }
01398 
01399     wasUndo = true;
01400     setText(QObject::tr("Items removed"));
01401 }
01402 
01403 void ItemsRemoveCommand::redo()
01404 {
01405     foreach(State *state, stateList)
01406     {
01407         editor->removeFromListsAndScene(state);
01408     }
01409 
01410     foreach(Transition *transition, transitionList)
01411     {
01412         editor->removeFromListsAndScene(transition);
01413     }
01414 
01415     wasUndo = false;
01416     setText(QObject::tr("Items removed"));
01417 }
01418 
01419 //------------------------------------------------------- ItemsRemoveCommand -->
01420 
01421 
01422 
01423 //<-- StateSetMarkedCommand ----------------------------------------------------
01424 
01425 StatesSetMarkedCommand::StatesSetMarkedCommand(QList<State*> states, bool marked, QUndoCommand *parent)
01426 : QUndoCommand(parent), m_states(states), m_marked(marked)
01427 {}
01428 
01429 StatesSetMarkedCommand::~StatesSetMarkedCommand()
01430 {}
01431 
01432 void StatesSetMarkedCommand::undo()
01433 {
01434     foreach(State *state, m_states)
01435     {
01436         state->setMarked(!m_marked);
01437     }
01438     setText(QObject::tr(m_marked ? "States mark" : "States unmark"));
01439 }
01440 
01441 void StatesSetMarkedCommand::redo()
01442 {
01443     foreach(State *state, m_states)
01444     {
01445         state->setMarked(m_marked);
01446     }
01447     setText(QObject::tr(m_marked ? "States mark" : "States unmark"));
01448 }
01449 
01450 //---------------------------------------------------- StateSetMarkedCommand -->

Generated on Tue Jan 4 2011 03:03:22 for Autoamata editor by  doxygen 1.7.0