00001
00002
00003
00004
00005
00006
00007 #include "CmdAbstract.h"
00008 #include "DataKey.h"
00009 #include "Document.h"
00010 #include "DocumentHashGenerator.h"
00011 #include "EngaugeAssert.h"
00012 #include "GraphicsItemType.h"
00013 #include "GraphicsScene.h"
00014 #include "GraphicsView.h"
00015 #include "Logger.h"
00016 #include "MainWindow.h"
00017 #include "Point.h"
00018 #include <QGraphicsItem>
00019
00020 CmdAbstract::CmdAbstract(MainWindow &mainWindow,
00021 Document &document,
00022 const QString &cmdDescription) :
00023 QUndoCommand (cmdDescription),
00024 m_mainWindow (mainWindow),
00025 m_document (document),
00026 m_isFirstRedo (true)
00027 {
00028 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::CmdAbstract";
00029 }
00030
00031 CmdAbstract::~CmdAbstract()
00032 {
00033 }
00034
00035 Document &CmdAbstract::document ()
00036 {
00037 return m_document;
00038 }
00039
00040 const Document &CmdAbstract::document () const
00041 {
00042 return m_document;
00043 }
00044
00045 MainWindow &CmdAbstract::mainWindow ()
00046 {
00047 return m_mainWindow;
00048 }
00049
00050 void CmdAbstract::redo ()
00051 {
00052
00053 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::redo";
00054
00055 if (m_isFirstRedo) {
00056
00057 m_identifierIndexBeforeRedo = Point::identifierIndex ();
00058
00059 } else {
00060
00061
00062
00063 Point::setIdentifierIndex (m_identifierIndexBeforeRedo);
00064
00065 }
00066
00067
00068 cmdRedo ();
00069
00070 if (m_isFirstRedo) {
00071
00072 m_isFirstRedo = false;
00073 m_identifierIndexAfterRedo = Point::identifierIndex();
00074
00075 }
00076
00077 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::redo identifierIndex=" << m_identifierIndexBeforeRedo << "->"
00078 << m_identifierIndexAfterRedo;
00079 }
00080
00081 void CmdAbstract::resetSelection(const PointIdentifiers &pointIdentifiersToSelect)
00082 {
00083 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::resetSelection";
00084
00085 QList<QGraphicsItem *> items = mainWindow().view().items();
00086 QList<QGraphicsItem *>::iterator itrS;
00087 for (itrS = items.begin (); itrS != items.end (); itrS++) {
00088
00089 QGraphicsItem *item = *itrS;
00090 bool selected = false;
00091 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT) {
00092
00093 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
00094
00095 selected = pointIdentifiersToSelect.contains (pointIdentifier);
00096 }
00097
00098 item->setSelected (selected);
00099 }
00100 }
00101
00102 void CmdAbstract::saveOrCheckPostCommandDocumentStateHash (const Document &document)
00103 {
00104
00105
00106 DocumentHashGenerator documentHashGenerator;
00107 DocumentHash documentHash = documentHashGenerator.generate (document);
00108
00109 if (m_documentHashPost.count() == 0) {
00110
00111
00112 m_documentHashPost = documentHash;
00113
00114 } else {
00115
00116
00117 ENGAUGE_ASSERT (documentHash == m_documentHashPost);
00118
00119 }
00120
00121 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::saveOrCheckPostCommandDocumentStateHash stateHash=" << m_documentHashPost.data ();
00122
00123 }
00124
00125 void CmdAbstract::saveOrCheckPreCommandDocumentStateHash (const Document &document)
00126 {
00127
00128
00129 DocumentHashGenerator documentHashGenerator;
00130 DocumentHash documentHash = documentHashGenerator.generate (document);
00131
00132 if (m_documentHashPre.count() == 0) {
00133
00134
00135 m_documentHashPre = documentHash;
00136
00137 } else {
00138
00139
00140 ENGAUGE_ASSERT (documentHash == m_documentHashPre);
00141
00142 }
00143
00144 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::saveOrCheckPreCommandDocumentStateHash stateHash=" << m_documentHashPre.data ();
00145
00146 }
00147
00148 void CmdAbstract::undo ()
00149 {
00150 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::undo identifierIndex=" << m_identifierIndexAfterRedo << "->"
00151 << m_identifierIndexBeforeRedo;
00152
00153 Point::setIdentifierIndex (m_identifierIndexAfterRedo);
00154
00155
00156 cmdUndo ();
00157
00158 Point::setIdentifierIndex (m_identifierIndexBeforeRedo);
00159 }