本文整理汇总了C++中TextDocument::textUndoStack方法的典型用法代码示例。如果您正苦于以下问题:C++ TextDocument::textUndoStack方法的具体用法?C++ TextDocument::textUndoStack怎么用?C++ TextDocument::textUndoStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextDocument
的用法示例。
在下文中一共展示了TextDocument::textUndoStack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testUndo
/// This method test the undo functionality of the text
void ReplaceSelectionCommandTest::testUndo()
{
TextEditorWidget* widget = new TextEditorWidget();
TextEditorController* ctrl = widget->controller();
TextDocument *doc = widget->textDocument();
TextBuffer* buf = doc->buffer();
// check if we can set the txt
ctrl->replaceSelection("test");
testEqual( buf->text(), "test" );
// test basic, undo/redo
ctrl->undo();
testEqual( buf->text(), "" );
// test coalesce
ctrl->replaceSelection("emma");
ctrl->replaceSelection(" sarah",true);
ctrl->replaceSelection(" david",true);
testEqual( buf->text(), "emma sarah david" );
ctrl->undo();
testEqual( buf->text(), "emma" );
ctrl->redo();
testEqual( buf->text(), "emma sarah david");
// test ranged replacement
doc->textUndoStack()->clear();
buf->setText("Blommers");
testEqual( buf->text(), "Blommers" );
// now replace 'mm' by nothing
TextRangeSet sel( doc );
sel.addRange(3,5);
ctrl->replaceRangeSet( sel, "" );
testEqual( buf->text(), "Bloers" );
ctrl->undo();
testEqual( buf->text(), "Blommers" );
ctrl->redo();
testEqual( buf->text(), "Bloers" );
delete widget;
}