diff options
author | Lauro Neto <lauro.neto@openbossa.org> | 2010-04-27 18:12:50 -0300 |
---|---|---|
committer | Renato Filho <renato.filho@openbossa.org> | 2010-04-28 16:36:47 -0300 |
commit | aaece960d3cf1c9d19dd84fe8171769517647724 (patch) | |
tree | ea2e20d2c8738cc407f60b10b6cccfb4e1fc2b70 /doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp | |
parent | 685246809debe672a0007b67fe78f7c77bad6739 (diff) |
Adding ./doc from boost
Reviewer: Lauro Moura <lauro.neto@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp')
-rw-r--r-- | doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp new file mode 100644 index 000000000..283392bbd --- /dev/null +++ b/doc/codesnippets/doc/src/snippets/code/src_gui_util_qundostack.cpp @@ -0,0 +1,70 @@ +//! [0] +class AppendText(QUndoCommand): + self.m_document = '' + self.m_text = '' + + def AppendText(self, doc, text): + self.m_document = doc + self.m_text = text + self.setText("append text") + + def undo(self): + self.m_document.chop(self.m_text.length()) + + def redo(self): + self.m_document->append(self.m_text) +//! [0] + + +//! [1] +command1 = MyCommand() +stack.push(command1) +command2 = MyCommand() +stack.push(command2) + +stack.undo() + +command3 = MyCommand() +stack.push(command3) # command2 gets deleted +//! [1] + + +//! [2] +insertRed = QUndoCommand() # an empty command +insertRed.setText("insert red text") + +InsertText(document, idx, text, insertRed) # becomes child of insertRed +SetColor(document, idx, text.length(), Qt.red, insertRed) + +stack.push(insertRed) +//! [2] + + +//! [3] +class AppendText(QUndoCommand): + ... + def mergeWith(self, other): + if other.id() != self.id(): # make sure other is also an AppendText command + return False + m_text += other.m_text + return True +//! [3] + + +//! [4] +stack.beginMacro("insert red text") +stack.push(InsertText(document, idx, text)) +stack.push(SetColor(document, idx, text.length(), Qt.red)) +stack.endMacro() # indexChanged() is emitted +//! [4] + + +//! [5] +insertRed = QUndoCommand() # an empty command +insertRed.setText("insert red text") + +InsertText(document, idx, text, insertRed) # becomes child of insertRed +SetColor(document, idx, text.length(), Qt.red, insertRed) + +stack.push(insertRed) +//! [5] |