41void examples(QUndoStack *stack, QString *document,
int idx,
const QString &text)
46 stack->push(command1);
48 stack->push(command2);
53 stack->push(command3);
61 QUndoCommand *insertRed =
new QUndoCommand();
62 insertRed->setText(
"insert red text");
64 new InsertText(document, idx, text, insertRed);
65 new SetColor(document, idx, text.length(), Qt::red, insertRed);
67 stack.push(insertRed);
82void wrap( QUndoStack &stack, QString *document,
int idx,
const QString &text)
85 stack.beginMacro(
"insert red text");
86 stack.push(
new InsertText(document, idx, text));
87 stack.push(
new SetColor(document, idx, text.length(), Qt::red));
93 QUndoCommand *insertRed =
new QUndoCommand();
94 insertRed->setText(
"insert red text");
96 new InsertText(document, idx, text, insertRed);
97 new SetColor(document, idx, text.length(), Qt::red, insertRed);
99 stack.push(insertRed);
bool mergeWith(const QUndoCommand *other) override
[3]
AppendText(QString *doc, const QString &text)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
InsertText(QString *doc, int idx, const QString &text, QUndoCommand *parent=nullptr)
SetColor(QString *doc, int idx, int len, const Qt::GlobalColor &color, QUndoCommand *parent=nullptr)