Swap order of undo and redo commands

This commit is contained in:
G.K.MacGregor
2020-10-25 18:03:10 +00:00
parent 151d842bc0
commit 01dcff944d
2 changed files with 49 additions and 54 deletions

View File

@@ -314,15 +314,6 @@ OverwriteCharacterCommand::OverwriteCharacterCommand(TeletextDocument *teletextD
m_newCharacter = newCharacter;
}
void OverwriteCharacterCommand::undo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_oldCharacter);
m_teletextDocument->moveCursor(m_row, m_column);
setText(QObject::tr("overwrite char"));
emit m_teletextDocument->contentsChange(m_row);
}
void OverwriteCharacterCommand::redo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
@@ -333,6 +324,15 @@ void OverwriteCharacterCommand::redo()
emit m_teletextDocument->contentsChange(m_row);
}
void OverwriteCharacterCommand::undo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_oldCharacter);
m_teletextDocument->moveCursor(m_row, m_column);
setText(QObject::tr("overwrite char"));
emit m_teletextDocument->contentsChange(m_row);
}
ToggleMosaicBitCommand::ToggleMosaicBitCommand(TeletextDocument *teletextDocument, unsigned char bitToToggle, QUndoCommand *parent) : QUndoCommand(parent)
{
@@ -347,19 +347,19 @@ ToggleMosaicBitCommand::ToggleMosaicBitCommand(TeletextDocument *teletextDocumen
m_newCharacter = m_oldCharacter ^ bitToToggle;
}
void ToggleMosaicBitCommand::undo()
void ToggleMosaicBitCommand::redo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_oldCharacter);
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_newCharacter);
m_teletextDocument->moveCursor(m_row, m_column);
setText(QObject::tr("mosaic"));
emit m_teletextDocument->contentsChange(m_row);
}
void ToggleMosaicBitCommand::redo()
void ToggleMosaicBitCommand::undo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_newCharacter);
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, m_oldCharacter);
m_teletextDocument->moveCursor(m_row, m_column);
setText(QObject::tr("mosaic"));
emit m_teletextDocument->contentsChange(m_row);
@@ -375,6 +375,7 @@ bool ToggleMosaicBitCommand::mergeWith(const QUndoCommand *command)
return true;
}
BackspaceCommand::BackspaceCommand(TeletextDocument *teletextDocument, QUndoCommand *parent) : QUndoCommand(parent)
{
m_teletextDocument = teletextDocument;
@@ -389,6 +390,15 @@ BackspaceCommand::BackspaceCommand(TeletextDocument *teletextDocument, QUndoComm
m_deletedCharacter = teletextDocument->currentSubPage()->character(m_row, m_column);
}
void BackspaceCommand::redo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, 0x20);
m_teletextDocument->moveCursor(m_row, m_column);
setText(QObject::tr("backspace"));
emit m_teletextDocument->contentsChange(m_row);
}
void BackspaceCommand::undo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
@@ -399,15 +409,6 @@ void BackspaceCommand::undo()
emit m_teletextDocument->contentsChange(m_row);
}
void BackspaceCommand::redo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setCharacter(m_row, m_column, 0x20);
m_teletextDocument->moveCursor(m_row, m_column);
setText(QObject::tr("backspace"));
emit m_teletextDocument->contentsChange(m_row);
}
InsertSubPageCommand::InsertSubPageCommand(TeletextDocument *teletextDocument, bool afterCurrentSubPage, bool copySubPage, QUndoCommand *parent) : QUndoCommand(parent)
{
@@ -416,17 +417,17 @@ InsertSubPageCommand::InsertSubPageCommand(TeletextDocument *teletextDocument, b
m_copySubPage = copySubPage;
}
void InsertSubPageCommand::undo()
void InsertSubPageCommand::redo()
{
m_teletextDocument->deleteSubPage(m_newSubPageIndex);
//TODO should we always wrench to "subpage viewed when we inserted"? Or just if subpage viewed is being deleted?
m_teletextDocument->insertSubPage(m_newSubPageIndex, m_copySubPage);
m_teletextDocument->selectSubPageIndex(m_newSubPageIndex, true);
setText(QObject::tr("insert subpage"));
}
void InsertSubPageCommand::redo()
void InsertSubPageCommand::undo()
{
m_teletextDocument->insertSubPage(m_newSubPageIndex, m_copySubPage);
m_teletextDocument->deleteSubPage(m_newSubPageIndex);
//TODO should we always wrench to "subpage viewed when we inserted"? Or just if subpage viewed is being deleted?
m_teletextDocument->selectSubPageIndex(m_newSubPageIndex, true);
setText(QObject::tr("insert subpage"));
}
@@ -441,19 +442,19 @@ SetColourCommand::SetColourCommand(TeletextDocument *teletextDocument, int colou
m_newColour = newColour;
}
void SetColourCommand::undo()
void SetColourCommand::redo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_oldColour);
m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_newColour);
emit m_teletextDocument->colourChanged(m_colourIndex);
setText(QObject::tr("colour change"));
emit m_teletextDocument->refreshNeeded();
}
void SetColourCommand::redo()
void SetColourCommand::undo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_newColour);
m_teletextDocument->currentSubPage()->setCLUT(m_colourIndex, m_oldColour);
emit m_teletextDocument->colourChanged(m_colourIndex);
setText(QObject::tr("colour change"));
emit m_teletextDocument->refreshNeeded();
@@ -469,17 +470,6 @@ ResetCLUTCommand::ResetCLUTCommand(TeletextDocument *teletextDocument, int colou
m_oldColourEntry[i&7] = teletextDocument->currentSubPage()->CLUT(i);
}
void ResetCLUTCommand::undo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
for (int i=m_colourTable*8; i<m_colourTable*8+8; i++) {
m_teletextDocument->currentSubPage()->setCLUT(i, m_oldColourEntry[i&7]);
emit m_teletextDocument->colourChanged(i);
}
setText(QObject::tr("CLUT %1 reset").arg(m_colourTable));
emit m_teletextDocument->refreshNeeded();
}
void ResetCLUTCommand::redo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
@@ -490,3 +480,14 @@ void ResetCLUTCommand::redo()
setText(QObject::tr("CLUT %1 reset").arg(m_colourTable));
emit m_teletextDocument->refreshNeeded();
}
void ResetCLUTCommand::undo()
{
m_teletextDocument->selectSubPageIndex(m_subPageIndex);
for (int i=m_colourTable*8; i<m_colourTable*8+8; i++) {
m_teletextDocument->currentSubPage()->setCLUT(i, m_oldColourEntry[i&7]);
emit m_teletextDocument->colourChanged(i);
}
setText(QObject::tr("CLUT %1 reset").arg(m_colourTable));
emit m_teletextDocument->refreshNeeded();
}