Swap order of undo and redo commands
This commit is contained in:
85
document.cpp
85
document.cpp
@@ -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();
|
||||
}
|
||||
|
||||
18
document.h
18
document.h
@@ -95,13 +95,10 @@ private:
|
||||
class OverwriteCharacterCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
// enum { Id = 1 };
|
||||
|
||||
OverwriteCharacterCommand(TeletextDocument *, unsigned char, QUndoCommand *parent = 0);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
// int id() const override { return Id; }
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
@@ -116,8 +113,8 @@ public:
|
||||
|
||||
ToggleMosaicBitCommand(TeletextDocument *, unsigned char, QUndoCommand *parent = 0);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
bool mergeWith(const QUndoCommand *) override;
|
||||
int id() const override { return Id; }
|
||||
|
||||
@@ -130,13 +127,10 @@ private:
|
||||
class BackspaceCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
// enum { Id = 3 };
|
||||
|
||||
BackspaceCommand(TeletextDocument *, QUndoCommand *parent = 0);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
// int id() const override { return Id; }
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
@@ -149,8 +143,8 @@ class InsertSubPageCommand : public QUndoCommand
|
||||
public:
|
||||
InsertSubPageCommand(TeletextDocument *, bool, bool, QUndoCommand *parent = 0);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
@@ -163,8 +157,8 @@ class SetColourCommand : public QUndoCommand
|
||||
public:
|
||||
SetColourCommand(TeletextDocument *, int, int, QUndoCommand *parent = 0);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
@@ -176,8 +170,8 @@ class ResetCLUTCommand : public QUndoCommand
|
||||
public:
|
||||
ResetCLUTCommand(TeletextDocument *, int, QUndoCommand *parent = 0);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
void undo() override;
|
||||
|
||||
private:
|
||||
TeletextDocument *m_teletextDocument;
|
||||
|
||||
Reference in New Issue
Block a user