00001
00002
00003
00004
00005
00006
00007 #include "CmdAbstract.h"
00008 #include "CmdFactory.h"
00009 #include "CmdMediator.h"
00010 #include "CmdRedoForTest.h"
00011 #include "CmdStackShadow.h"
00012 #include "CmdUndoForTest.h"
00013 #include "Document.h"
00014 #include "DocumentSerialize.h"
00015 #include "Logger.h"
00016 #include "MainWindow.h"
00017 #include <QUndoCommand>
00018 #include <QXmlStreamReader>
00019 #include "Xml.h"
00020
00021 CmdStackShadow::CmdStackShadow() :
00022 m_mainWindow (0)
00023 {
00024 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::CmdStackShadow";
00025 }
00026
00027 bool CmdStackShadow::canRedo() const
00028 {
00029 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::canRedo";
00030
00031 bool canRedo = (m_cmdList.count () > 0);
00032
00033 return canRedo;
00034 }
00035
00036 void CmdStackShadow::loadCommands (MainWindow &mainWindow,
00037 Document &document,
00038 QXmlStreamReader &reader)
00039 {
00040 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::loadCommands";
00041
00042
00043 m_mainWindow = &mainWindow;
00044
00045
00046 connect (this, SIGNAL (signalRedo ()), mainWindow.cmdMediator(), SLOT (redo ()));
00047 connect (this, SIGNAL (signalUndo ()), mainWindow.cmdMediator(), SLOT (undo ()));
00048
00049
00050 CmdFactory factory;
00051 while (!reader.atEnd() && !reader.hasError()) {
00052
00053 if ((loadNextFromReader (reader) == QXmlStreamReader::StartElement) &&
00054 (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
00055
00056
00057 m_cmdList.push_back (factory.createCmd (mainWindow,
00058 document,
00059 reader));
00060 }
00061 }
00062 }
00063
00064 void CmdStackShadow::slotRedo ()
00065 {
00066 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::slotRedo";
00067
00068 if (m_cmdList.count() > 0) {
00069
00070
00071 QUndoCommand *cmd = dynamic_cast<QUndoCommand*> (m_cmdList.front());
00072
00073
00074 m_cmdList.pop_front();
00075
00076 if (m_mainWindow != 0) {
00077
00078 CmdRedoForTest *cmdRedoForTest = dynamic_cast<CmdRedoForTest*> (cmd);
00079 CmdUndoForTest *cmdUndoForTest = dynamic_cast<CmdUndoForTest*> (cmd);
00080
00081 if (cmdRedoForTest != 0) {
00082
00083
00084
00085 emit (signalRedo ());
00086
00087 } else if (cmdUndoForTest != 0) {
00088
00089
00090
00091 emit (signalUndo ());
00092
00093 } else {
00094
00095
00096 m_mainWindow->cmdMediator()->push(cmd);
00097
00098 }
00099 }
00100 }
00101 }
00102
00103 void CmdStackShadow::slotUndo()
00104 {
00105 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::slotUndo";
00106
00107 CmdListInternal::iterator itr;
00108 for (itr = m_cmdList.begin(); itr != m_cmdList.end(); itr++) {
00109
00110 CmdAbstract *cmd = *itr;
00111 delete cmd;
00112 }
00113
00114 m_cmdList.clear();
00115 }