Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-updates > by-pkgid > 768f7d9f703884aa2562bf0a651086df > files > 4631

qtbase5-doc-5.9.4-1.1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qundostack.cpp -->
  <title>QUndoStack Class | Qt Widgets 5.9</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.9</td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-module.html">C++ Classes</a></td><td >QUndoStack</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#properties">Properties</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#public-slots">Public Slots</a></li>
<li class="level1"><a href="#signals">Signals</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#undo-and-redo-actions">Undo and Redo Actions</a></li>
<li class="level2"><a href="#command-compression-and-macros">Command Compression and Macros</a></li>
<li class="level2"><a href="#clean-state">Clean State</a></li>
<li class="level2"><a href="#obsolete-commands">Obsolete Commands</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QUndoStack Class</h1>
<!-- $$$QUndoStack-brief -->
<p>The <a href="qundostack.html">QUndoStack</a> class is a stack of <a href="qundocommand.html">QUndoCommand</a> objects. <a href="#details">More...</a></p>
<!-- @@@QUndoStack -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QUndoStack&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += widgets</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 4.2</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a></td></tr></table></div><ul>
<li><a href="qundostack-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="properties"></a>
<h2 id="properties">Properties</h2>
<ul>
<li class="fn"><b><a href="qundostack.html#active-prop">active</a></b> : bool</li>
<li class="fn"><b><a href="qundostack.html#undoLimit-prop">undoLimit</a></b> : int</li>
</ul>
<ul>
<li class="fn">1 property inherited from <a href="../qtcore/qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#QUndoStack">QUndoStack</a></b>(QObject *<i>parent</i> = Q_NULLPTR)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#dtor.QUndoStack">~QUndoStack</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#beginMacro">beginMacro</a></b>(const QString &amp;<i>text</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#canRedo">canRedo</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#canUndo">canUndo</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#cleanIndex">cleanIndex</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#clear">clear</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QUndoCommand *</td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#command">command</a></b>(int <i>index</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#count">count</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QAction *</td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#createRedoAction">createRedoAction</a></b>(QObject *<i>parent</i>, const QString &amp;<i>prefix</i> = QString()) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QAction *</td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#createUndoAction">createUndoAction</a></b>(QObject *<i>parent</i>, const QString &amp;<i>prefix</i> = QString()) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#endMacro">endMacro</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#index">index</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#active-prop">isActive</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#isClean">isClean</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#push">push</a></b>(QUndoCommand *<i>cmd</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#redoText">redoText</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#undoLimit-prop">setUndoLimit</a></b>(int <i>limit</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#text">text</a></b>(int <i>idx</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#undoLimit-prop">undoLimit</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#undoText">undoText</a></b>() const</td></tr>
</table></div>
<ul>
<li class="fn">32 public functions inherited from <a href="../qtcore/qobject.html#public-functions">QObject</a></li>
</ul>
<a name="public-slots"></a>
<h2 id="public-slots">Public Slots</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#redo">redo</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#resetClean">resetClean</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#active-prop">setActive</a></b>(bool <i>active</i> = true)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#setClean">setClean</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#setIndex">setIndex</a></b>(int <i>idx</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#undo">undo</a></b>()</td></tr>
</table></div>
<ul>
<li class="fn">1 public slot inherited from <a href="../qtcore/qobject.html#public-slots">QObject</a></li>
</ul>
<a name="signals"></a>
<h2 id="signals">Signals</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#canRedoChanged">canRedoChanged</a></b>(bool <i>canRedo</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#canUndoChanged">canUndoChanged</a></b>(bool <i>canUndo</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#cleanChanged">cleanChanged</a></b>(bool <i>clean</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#indexChanged">indexChanged</a></b>(int <i>idx</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#redoTextChanged">redoTextChanged</a></b>(const QString &amp;<i>redoText</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qundostack.html#undoTextChanged">undoTextChanged</a></b>(const QString &amp;<i>undoText</i>)</td></tr>
</table></div>
<ul>
<li class="fn">2 signals inherited from <a href="../qtcore/qobject.html#signals">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 public variable inherited from <a href="../qtcore/qobject.html#public-variables">QObject</a></li>
<li class="fn">10 static public members inherited from <a href="../qtcore/qobject.html#static-public-members">QObject</a></li>
<li class="fn">9 protected functions inherited from <a href="../qtcore/qobject.html#protected-functions">QObject</a></li>
<li class="fn">2 protected variables inherited from <a href="../qtcore/qobject.html#protected-variables">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QUndoStack-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qundostack.html">QUndoStack</a> class is a stack of <a href="qundocommand.html">QUndoCommand</a> objects.</p>
<p>For an overview of Qt's Undo Framework, see the overview document.</p>
<p>An undo stack maintains a stack of commands that have been applied to a document.</p>
<p>New commands are pushed on the stack using <a href="qundostack.html#push">push</a>(). Commands can be undone and redone using <a href="qundostack.html#undo">undo</a>() and <a href="qundostack.html#redo">redo</a>(), or by triggering the actions returned by <a href="qundostack.html#createUndoAction">createUndoAction</a>() and <a href="qundostack.html#createRedoAction">createRedoAction</a>().</p>
<p><a href="qundostack.html">QUndoStack</a> keeps track of the <i>current</i> command. This is the command which will be executed by the next call to <a href="qundostack.html#redo">redo</a>(). The index of this command is returned by <a href="qundostack.html#index">index</a>(). The state of the edited object can be rolled forward or back using <a href="qundostack.html#setIndex">setIndex</a>(). If the top-most command on the stack has already been redone, <a href="qundostack.html#index">index</a>() is equal to <a href="qundostack.html#count">count</a>().</p>
<p><a href="qundostack.html">QUndoStack</a> provides support for undo and redo actions, command compression, command macros, and supports the concept of a <i>clean state</i>.</p>
<a name="undo-and-redo-actions"></a>
<h3 >Undo and Redo Actions</h3>
<p><a href="qundostack.html">QUndoStack</a> provides convenient undo and redo <a href="qaction.html">QAction</a> objects, which can be inserted into a menu or a toolbar. When commands are undone or redone, <a href="qundostack.html">QUndoStack</a> updates the text properties of these actions to reflect what change they will trigger. The actions are also disabled when no command is available for undo or redo. These actions are returned by <a href="qundostack.html#createUndoAction">QUndoStack::createUndoAction</a>() and <a href="qundostack.html#createRedoAction">QUndoStack::createRedoAction</a>().</p>
<a name="command-compression-and-macros"></a>
<h3 >Command Compression and Macros</h3>
<p>Command compression is useful when several commands can be compressed into a single command that can be undone and redone in a single operation. For example, when a user types a character in a text editor, a new command is created. This command inserts the character into the document at the cursor position. However, it is more convenient for the user to be able to undo or redo typing of whole words, sentences, or paragraphs. Command compression allows these single-character commands to be merged into a single command which inserts or deletes sections of text. For more information, see <a href="qundocommand.html#mergeWith">QUndoCommand::mergeWith</a>() and <a href="qundostack.html#push">push</a>().</p>
<p>A command macro is a sequence of commands, all of which are undone and redone in one go. Command macros are created by giving a command a list of child commands. Undoing or redoing the parent command will cause the child commands to be undone or redone. Command macros may be created explicitly by specifying a parent in the <a href="qundocommand.html">QUndoCommand</a> constructor, or by using the convenience functions <a href="qundostack.html#beginMacro">beginMacro</a>() and <a href="qundostack.html#endMacro">endMacro</a>().</p>
<p>Although command compression and macros appear to have the same effect to the user, they often have different uses in an application. Commands that perform small changes to a document may be usefully compressed if there is no need to individually record them, and if only larger changes are relevant to the user. However, for commands that need to be recorded individually, or those that cannot be compressed, it is useful to use macros to provide a more convenient user experience while maintaining a record of each command.</p>
<a name="clean-state"></a>
<h3 >Clean State</h3>
<p><a href="qundostack.html">QUndoStack</a> supports the concept of a clean state. When the document is saved to disk, the stack can be marked as clean using <a href="qundostack.html#setClean">setClean</a>(). Whenever the stack returns to this state through undoing and redoing commands, it emits the signal <a href="qundostack.html#cleanChanged">cleanChanged</a>(). This signal is also emitted when the stack leaves the clean state. This signal is usually used to enable and disable the save actions in the application, and to update the document's title to reflect that it contains unsaved changes.</p>
<a name="obsolete-commands"></a>
<h3 >Obsolete Commands</h3>
<p><a href="qundostack.html">QUndoStack</a> is able to delete commands from the stack if the command is no longer needed. One example may be to delete a command when two commands are merged together in such a way that the merged command has no function. This can be seen with move commands where the user moves their mouse to one part of the screen and then moves it to the original position. The merged command results in a mouse movement of 0. This command can be deleted since it serves no purpose. Another example is with networking commands that fail due to connection issues. In this case, the command is to be removed from the stack because the <a href="qundostack.html#redo">redo</a>() and <a href="qundostack.html#undo">undo</a>() functions have no function since there was connection issues.</p>
<p>A command can be marked obsolete with the <a href="qundocommand.html#setObsolete">QUndoCommand::setObsolete</a>() function. The <a href="qundocommand.html#isObsolete">QUndoCommand::isObsolete</a>() flag is checked in <a href="qundostack.html#push">QUndoStack::push</a>(), <a href="qundostack.html#undo">QUndoStack::undo</a>(), <a href="qundostack.html#redo">QUndoStack::redo</a>(), and <a href="qundostack.html#setIndex">QUndoStack::setIndex</a>() after calling <a href="qundocommand.html#undo">QUndoCommand::undo</a>(), <a href="qundocommand.html#redo">QUndoCommand::redo</a>() and <a href="qundocommand.html">QUndoCommand</a>:mergeWith() where applicable.</p>
<p>If a command is set obsolete and the clean index is greater than or equal to the current command index, then the clean index will be reset when the command is deleted from the stack.</p>
</div>
<p><b>See also </b><a href="qundocommand.html">QUndoCommand</a> and <a href="qundoview.html">QUndoView</a>.</p>
<!-- @@@QUndoStack -->
<div class="prop">
<h2>Property Documentation</h2>
<!-- $$$active-prop$$$isActive$$$setActivebool -->
<h3 class="fn" id="active-prop"><a name="active-prop"></a><span class="name">active</span> : <span class="type">bool</span></h3>
<p>This property holds the active status of this stack.</p>
<p>An application often has multiple undo stacks, one for each opened document. The active stack is the one associated with the currently active document. If the stack belongs to a <a href="qundogroup.html">QUndoGroup</a>, calls to <a href="qundogroup.html#undo">QUndoGroup::undo</a>() or <a href="qundogroup.html#redo">QUndoGroup::redo</a>() will be forwarded to this stack when it is active. If the <a href="qundogroup.html">QUndoGroup</a> is watched by a <a href="qundoview.html">QUndoView</a>, the view will display the contents of this stack when it is active. If the stack does not belong to a <a href="qundogroup.html">QUndoGroup</a>, making it active has no effect.</p>
<p>It is the programmer's responsibility to specify which stack is active by calling setActive(), usually when the associated document window receives focus.</p>
<p><b>Access functions:</b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> bool </td><td class="memItemRight bottomAlign"><span class="name"><b>isActive</b></span>() const</td></tr>
<tr><td class="memItemLeft topAlign rightAlign"> void </td><td class="memItemRight bottomAlign"><span class="name"><b>setActive</b></span>(bool <i>active</i> = true)</td></tr>
</table></div>
<p><b>See also </b><a href="qundogroup.html">QUndoGroup</a>.</p>
<!-- @@@active -->
<!-- $$$undoLimit-prop$$$undoLimit$$$setUndoLimitint -->
<h3 class="fn" id="undoLimit-prop"><a name="undoLimit-prop"></a><span class="name">undoLimit</span> : <span class="type">int</span></h3>
<p>This property holds the maximum number of commands on this stack.</p>
<p>When the number of commands on a stack exceedes the stack's undoLimit, commands are deleted from the bottom of the stack. Macro commands (commands with child commands) are treated as one command. The default value is 0, which means that there is no limit.</p>
<p>This property may only be set when the undo stack is empty, since setting it on a non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack prints a warning and does nothing.</p>
<p>This property was introduced in  Qt 4.3.</p>
<p><b>Access functions:</b></p>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft topAlign rightAlign"> int </td><td class="memItemRight bottomAlign"><span class="name"><b>undoLimit</b></span>() const</td></tr>
<tr><td class="memItemLeft topAlign rightAlign"> void </td><td class="memItemRight bottomAlign"><span class="name"><b>setUndoLimit</b></span>(int <i>limit</i>)</td></tr>
</table></div>
<!-- @@@undoLimit -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QUndoStack[overload1]$$$QUndoStackQObject* -->
<h3 class="fn" id="QUndoStack"><a name="QUndoStack"></a>QUndoStack::<span class="name">QUndoStack</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = Q_NULLPTR)</h3>
<p>Constructs an empty undo stack with the parent <i>parent</i>. The stack will initially be in the clean state. If <i>parent</i> is a <a href="qundogroup.html">QUndoGroup</a> object, the stack is automatically added to the group.</p>
<p><b>See also </b><a href="qundostack.html#push">push</a>().</p>
<!-- @@@QUndoStack -->
<!-- $$$~QUndoStack[overload1]$$$~QUndoStack -->
<h3 class="fn" id="dtor.QUndoStack"><a name="dtor.QUndoStack"></a>QUndoStack::<span class="name">~QUndoStack</span>()</h3>
<p>Destroys the undo stack, deleting any commands that are on it. If the stack is in a <a href="qundogroup.html">QUndoGroup</a>, the stack is automatically removed from the group.</p>
<p><b>See also </b><a href="qundostack.html#QUndoStack">QUndoStack</a>().</p>
<!-- @@@~QUndoStack -->
<!-- $$$beginMacro[overload1]$$$beginMacroconstQString& -->
<h3 class="fn" id="beginMacro"><a name="beginMacro"></a><span class="type">void</span> QUndoStack::<span class="name">beginMacro</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>text</i>)</h3>
<p>Begins composition of a macro command with the given <i>text</i> description.</p>
<p>An empty command described by the specified <i>text</i> is pushed on the stack. Any subsequent commands pushed on the stack will be appended to the empty command's children until <a href="qundostack.html#endMacro">endMacro</a>() is called.</p>
<p>Calls to beginMacro() and <a href="qundostack.html#endMacro">endMacro</a>() may be nested, but every call to beginMacro() must have a matching call to <a href="qundostack.html#endMacro">endMacro</a>().</p>
<p>While a macro is being composed, the stack is disabled. This means that:</p>
<ul>
<li><a href="qundostack.html#indexChanged">indexChanged</a>() and <a href="qundostack.html#cleanChanged">cleanChanged</a>() are not emitted,</li>
<li><a href="qundostack.html#canUndo">canUndo</a>() and <a href="qundostack.html#canRedo">canRedo</a>() return false,</li>
<li>calling <a href="qundostack.html#undo">undo</a>() or <a href="qundostack.html#redo">redo</a>() has no effect,</li>
<li>the undo/redo actions are disabled.</li>
</ul>
<p>The stack becomes enabled and appropriate signals are emitted when <a href="qundostack.html#endMacro">endMacro</a>() is called for the outermost macro.</p>
<pre class="cpp">

  stack<span class="operator">.</span>beginMacro(<span class="string">&quot;insert red text&quot;</span>);
  stack<span class="operator">.</span>push(<span class="keyword">new</span> InsertText(document<span class="operator">,</span> idx<span class="operator">,</span> text));
  stack<span class="operator">.</span>push(<span class="keyword">new</span> SetColor(document<span class="operator">,</span> idx<span class="operator">,</span> text<span class="operator">.</span>length()<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>red));
  stack<span class="operator">.</span>endMacro(); <span class="comment">// indexChanged() is emitted</span>

</pre>
<p>This code is equivalent to:</p>
<pre class="cpp">

  <span class="type"><a href="qundocommand.html">QUndoCommand</a></span> <span class="operator">*</span>insertRed <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qundocommand.html">QUndoCommand</a></span>(); <span class="comment">// an empty command</span>
  insertRed<span class="operator">-</span><span class="operator">&gt;</span>setText(<span class="string">&quot;insert red text&quot;</span>);

  <span class="keyword">new</span> InsertText(document<span class="operator">,</span> idx<span class="operator">,</span> text<span class="operator">,</span> insertRed); <span class="comment">// becomes child of insertRed</span>
  <span class="keyword">new</span> SetColor(document<span class="operator">,</span> idx<span class="operator">,</span> text<span class="operator">.</span>length()<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>red<span class="operator">,</span> insertRed);

  stack<span class="operator">.</span>push(insertRed);

</pre>
<p><b>See also </b><a href="qundostack.html#endMacro">endMacro</a>().</p>
<!-- @@@beginMacro -->
<!-- $$$canRedo[overload1]$$$canRedo -->
<h3 class="fn" id="canRedo"><a name="canRedo"></a><span class="type">bool</span> QUndoStack::<span class="name">canRedo</span>() const</h3>
<p>Returns <code>true</code> if there is a command available for redo; otherwise returns <code>false</code>.</p>
<p>This function returns <code>false</code> if the stack is empty or if the top command on the stack has already been redone.</p>
<p>Synonymous with <a href="qundostack.html#index">index</a>() == <a href="qundostack.html#count">count</a>().</p>
<p><b>See also </b><a href="qundostack.html#index">index</a>() and <a href="qundostack.html#canUndo">canUndo</a>().</p>
<!-- @@@canRedo -->
<!-- $$$canRedoChanged[overload1]$$$canRedoChangedbool -->
<h3 class="fn" id="canRedoChanged"><a name="canRedoChanged"></a><code>[signal] </code><span class="type">void</span> QUndoStack::<span class="name">canRedoChanged</span>(<span class="type">bool</span> <i>canRedo</i>)</h3>
<p>This signal is emitted whenever the value of <a href="qundostack.html#canRedo">canRedo</a>() changes. It is used to enable or disable the redo action returned by <a href="qundostack.html#createRedoAction">createRedoAction</a>(). <i>canRedo</i> specifies the new value.</p>
<!-- @@@canRedoChanged -->
<!-- $$$canUndo[overload1]$$$canUndo -->
<h3 class="fn" id="canUndo"><a name="canUndo"></a><span class="type">bool</span> QUndoStack::<span class="name">canUndo</span>() const</h3>
<p>Returns <code>true</code> if there is a command available for undo; otherwise returns <code>false</code>.</p>
<p>This function returns <code>false</code> if the stack is empty, or if the bottom command on the stack has already been undone.</p>
<p>Synonymous with <a href="qundostack.html#index">index</a>() == 0.</p>
<p><b>See also </b><a href="qundostack.html#index">index</a>() and <a href="qundostack.html#canRedo">canRedo</a>().</p>
<!-- @@@canUndo -->
<!-- $$$canUndoChanged[overload1]$$$canUndoChangedbool -->
<h3 class="fn" id="canUndoChanged"><a name="canUndoChanged"></a><code>[signal] </code><span class="type">void</span> QUndoStack::<span class="name">canUndoChanged</span>(<span class="type">bool</span> <i>canUndo</i>)</h3>
<p>This signal is emitted whenever the value of <a href="qundostack.html#canUndo">canUndo</a>() changes. It is used to enable or disable the undo action returned by <a href="qundostack.html#createUndoAction">createUndoAction</a>(). <i>canUndo</i> specifies the new value.</p>
<!-- @@@canUndoChanged -->
<!-- $$$cleanChanged[overload1]$$$cleanChangedbool -->
<h3 class="fn" id="cleanChanged"><a name="cleanChanged"></a><code>[signal] </code><span class="type">void</span> QUndoStack::<span class="name">cleanChanged</span>(<span class="type">bool</span> <i>clean</i>)</h3>
<p>This signal is emitted whenever the stack enters or leaves the clean state. If <i>clean</i> is true, the stack is in a clean state; otherwise this signal indicates that it has left the clean state.</p>
<p><b>See also </b><a href="qundostack.html#isClean">isClean</a>() and <a href="qundostack.html#setClean">setClean</a>().</p>
<!-- @@@cleanChanged -->
<!-- $$$cleanIndex[overload1]$$$cleanIndex -->
<h3 class="fn" id="cleanIndex"><a name="cleanIndex"></a><span class="type">int</span> QUndoStack::<span class="name">cleanIndex</span>() const</h3>
<p>Returns the clean index. This is the index at which <a href="qundostack.html#setClean">setClean</a>() was called.</p>
<p>A stack may not have a clean index. This happens if a document is saved, some commands are undone, then a new command is pushed. Since <a href="qundostack.html#push">push</a>() deletes all the undone commands before pushing the new command, the stack can't return to the clean state again. In this case, this function returns -1. The -1 may also be returned after an explicit call to <a href="qundostack.html#resetClean">resetClean</a>().</p>
<p><b>See also </b><a href="qundostack.html#isClean">isClean</a>() and <a href="qundostack.html#setClean">setClean</a>().</p>
<!-- @@@cleanIndex -->
<!-- $$$clear[overload1]$$$clear -->
<h3 class="fn" id="clear"><a name="clear"></a><span class="type">void</span> QUndoStack::<span class="name">clear</span>()</h3>
<p>Clears the command stack by deleting all commands on it, and returns the stack to the clean state.</p>
<p>Commands are not undone or redone; the state of the edited object remains unchanged.</p>
<p>This function is usually used when the contents of the document are abandoned.</p>
<p><b>See also </b><a href="qundostack.html#QUndoStack">QUndoStack</a>().</p>
<!-- @@@clear -->
<!-- $$$command[overload1]$$$commandint -->
<h3 class="fn" id="command"><a name="command"></a>const <span class="type"><a href="qundocommand.html">QUndoCommand</a></span> *QUndoStack::<span class="name">command</span>(<span class="type">int</span> <i>index</i>) const</h3>
<p>Returns a const pointer to the command at <i>index</i>.</p>
<p>This function returns a const pointer, because modifying a command, once it has been pushed onto the stack and executed, almost always causes corruption of the state of the document, if the command is later undone or redone.</p>
<p>This function was introduced in  Qt 4.4.</p>
<p><b>See also </b><a href="qundocommand.html#child">QUndoCommand::child</a>().</p>
<!-- @@@command -->
<!-- $$$count[overload1]$$$count -->
<h3 class="fn" id="count"><a name="count"></a><span class="type">int</span> QUndoStack::<span class="name">count</span>() const</h3>
<p>Returns the number of commands on the stack. Macro commands are counted as one command.</p>
<p><b>See also </b><a href="qundostack.html#index">index</a>(), <a href="qundostack.html#setIndex">setIndex</a>(), and <a href="qundostack.html#command">command</a>().</p>
<!-- @@@count -->
<!-- $$$createRedoAction[overload1]$$$createRedoActionQObject*constQString& -->
<h3 class="fn" id="createRedoAction"><a name="createRedoAction"></a><span class="type"><a href="qaction.html">QAction</a></span> *QUndoStack::<span class="name">createRedoAction</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>prefix</i> = QString()) const</h3>
<p>Creates an redo <a href="qaction.html">QAction</a> object with the given <i>parent</i>.</p>
<p>Triggering this action will cause a call to <a href="qundostack.html#redo">redo</a>(). The text of this action is the text of the command which will be redone in the next call to <a href="qundostack.html#redo">redo</a>(), prefixed by the specified <i>prefix</i>. If there is no command available for redo, this action will be disabled.</p>
<p>If <i>prefix</i> is empty, the default template &quot;Redo %1&quot; is used instead of prefix. Before Qt 4.8, the prefix &quot;Redo&quot; was used by default.</p>
<p><b>See also </b><a href="qundostack.html#createUndoAction">createUndoAction</a>(), <a href="qundostack.html#canRedo">canRedo</a>(), and <a href="qundocommand.html#text">QUndoCommand::text</a>().</p>
<!-- @@@createRedoAction -->
<!-- $$$createUndoAction[overload1]$$$createUndoActionQObject*constQString& -->
<h3 class="fn" id="createUndoAction"><a name="createUndoAction"></a><span class="type"><a href="qaction.html">QAction</a></span> *QUndoStack::<span class="name">createUndoAction</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i>, const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>prefix</i> = QString()) const</h3>
<p>Creates an undo <a href="qaction.html">QAction</a> object with the given <i>parent</i>.</p>
<p>Triggering this action will cause a call to <a href="qundostack.html#undo">undo</a>(). The text of this action is the text of the command which will be undone in the next call to <a href="qundostack.html#undo">undo</a>(), prefixed by the specified <i>prefix</i>. If there is no command available for undo, this action will be disabled.</p>
<p>If <i>prefix</i> is empty, the default template &quot;Undo %1&quot; is used instead of prefix. Before Qt 4.8, the prefix &quot;Undo&quot; was used by default.</p>
<p><b>See also </b><a href="qundostack.html#createRedoAction">createRedoAction</a>(), <a href="qundostack.html#canUndo">canUndo</a>(), and <a href="qundocommand.html#text">QUndoCommand::text</a>().</p>
<!-- @@@createUndoAction -->
<!-- $$$endMacro[overload1]$$$endMacro -->
<h3 class="fn" id="endMacro"><a name="endMacro"></a><span class="type">void</span> QUndoStack::<span class="name">endMacro</span>()</h3>
<p>Ends composition of a macro command.</p>
<p>If this is the outermost macro in a set nested macros, this function emits <a href="qundostack.html#indexChanged">indexChanged</a>() once for the entire macro command.</p>
<p><b>See also </b><a href="qundostack.html#beginMacro">beginMacro</a>().</p>
<!-- @@@endMacro -->
<!-- $$$index[overload1]$$$index -->
<h3 class="fn" id="index"><a name="index"></a><span class="type">int</span> QUndoStack::<span class="name">index</span>() const</h3>
<p>Returns the index of the current command. This is the command that will be executed on the next call to <a href="qundostack.html#redo">redo</a>(). It is not always the top-most command on the stack, since a number of commands may have been undone.</p>
<p><b>See also </b><a href="qundostack.html#setIndex">setIndex</a>(), <a href="qundostack.html#undo">undo</a>(), <a href="qundostack.html#redo">redo</a>(), and <a href="qundostack.html#count">count</a>().</p>
<!-- @@@index -->
<!-- $$$indexChanged[overload1]$$$indexChangedint -->
<h3 class="fn" id="indexChanged"><a name="indexChanged"></a><code>[signal] </code><span class="type">void</span> QUndoStack::<span class="name">indexChanged</span>(<span class="type">int</span> <i>idx</i>)</h3>
<p>This signal is emitted whenever a command modifies the state of the document. This happens when a command is undone or redone. When a macro command is undone or redone, or <a href="qundostack.html#setIndex">setIndex</a>() is called, this signal is emitted only once.</p>
<p><i>idx</i> specifies the index of the current command, ie. the command which will be executed on the next call to <a href="qundostack.html#redo">redo</a>().</p>
<p><b>See also </b><a href="qundostack.html#index">index</a>() and <a href="qundostack.html#setIndex">setIndex</a>().</p>
<!-- @@@indexChanged -->
<!-- $$$isClean[overload1]$$$isClean -->
<h3 class="fn" id="isClean"><a name="isClean"></a><span class="type">bool</span> QUndoStack::<span class="name">isClean</span>() const</h3>
<p>If the stack is in the clean state, returns <code>true</code>; otherwise returns <code>false</code>.</p>
<p><b>See also </b><a href="qundostack.html#setClean">setClean</a>() and <a href="qundostack.html#cleanIndex">cleanIndex</a>().</p>
<!-- @@@isClean -->
<!-- $$$push[overload1]$$$pushQUndoCommand* -->
<h3 class="fn" id="push"><a name="push"></a><span class="type">void</span> QUndoStack::<span class="name">push</span>(<span class="type"><a href="qundocommand.html">QUndoCommand</a></span> *<i>cmd</i>)</h3>
<p>Pushes <i>cmd</i> on the stack or merges it with the most recently executed command. In either case, executes <i>cmd</i> by calling its <a href="qundostack.html#redo">redo</a>() function.</p>
<p>If <i>cmd</i>'s id is not -1, and if the id is the same as that of the most recently executed command, <a href="qundostack.html">QUndoStack</a> will attempt to merge the two commands by calling <a href="qundocommand.html#mergeWith">QUndoCommand::mergeWith</a>() on the most recently executed command. If <a href="qundocommand.html#mergeWith">QUndoCommand::mergeWith</a>() returns <code>true</code>, <i>cmd</i> is deleted.</p>
<p>After calling <a href="qundocommand.html#redo">QUndoCommand::redo</a>() and, if applicable, <a href="qundocommand.html#mergeWith">QUndoCommand::mergeWith</a>(), <a href="qundocommand.html#isObsolete">QUndoCommand::isObsolete</a>() will be called for <i>cmd</i> or the merged command. If <a href="qundocommand.html#isObsolete">QUndoCommand::isObsolete</a>() returns <code>true</code>, then <i>cmd</i> or the merged command will be deleted from the stack.</p>
<p>In all other cases <i>cmd</i> is simply pushed on the stack.</p>
<p>If commands were undone before <i>cmd</i> was pushed, the current command and all commands above it are deleted. Hence <i>cmd</i> always ends up being the top-most on the stack.</p>
<p>Once a command is pushed, the stack takes ownership of it. There are no getters to return the command, since modifying it after it has been executed will almost always lead to corruption of the document's state.</p>
<p><b>See also </b><a href="qundocommand.html#id">QUndoCommand::id</a>() and <a href="qundocommand.html#mergeWith">QUndoCommand::mergeWith</a>().</p>
<!-- @@@push -->
<!-- $$$redo[overload1]$$$redo -->
<h3 class="fn" id="redo"><a name="redo"></a><code>[slot] </code><span class="type">void</span> QUndoStack::<span class="name">redo</span>()</h3>
<p>Redoes the current command by calling <a href="qundocommand.html#redo">QUndoCommand::redo</a>(). Increments the current command index.</p>
<p>If the stack is empty, or if the top command on the stack has already been redone, this function does nothing.</p>
<p>If <a href="qundocommand.html#isObsolete">QUndoCommand::isObsolete</a>() returns true for the current command, then the command will be deleted from the stack. Additionally, if the clean index is greater than or equal to the current command index, then the clean index is reset.</p>
<p><b>See also </b><a href="qundostack.html#undo">undo</a>() and <a href="qundostack.html#index">index</a>().</p>
<!-- @@@redo -->
<!-- $$$redoText[overload1]$$$redoText -->
<h3 class="fn" id="redoText"><a name="redoText"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QUndoStack::<span class="name">redoText</span>() const</h3>
<p>Returns the text of the command which will be redone in the next call to <a href="qundostack.html#redo">redo</a>().</p>
<p><b>See also </b><a href="qundocommand.html#actionText">QUndoCommand::actionText</a>() and <a href="qundostack.html#undoText">undoText</a>().</p>
<!-- @@@redoText -->
<!-- $$$redoTextChanged[overload1]$$$redoTextChangedconstQString& -->
<h3 class="fn" id="redoTextChanged"><a name="redoTextChanged"></a><code>[signal] </code><span class="type">void</span> QUndoStack::<span class="name">redoTextChanged</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>redoText</i>)</h3>
<p>This signal is emitted whenever the value of <a href="qundostack.html#redoText">redoText</a>() changes. It is used to update the text property of the redo action returned by <a href="qundostack.html#createRedoAction">createRedoAction</a>(). <i>redoText</i> specifies the new text.</p>
<!-- @@@redoTextChanged -->
<!-- $$$resetClean[overload1]$$$resetClean -->
<h3 class="fn" id="resetClean"><a name="resetClean"></a><code>[slot] </code><span class="type">void</span> QUndoStack::<span class="name">resetClean</span>()</h3>
<p>Leaves the clean state and emits <a href="qundostack.html#cleanChanged">cleanChanged</a>() if the stack was clean. This method resets the clean index to -1.</p>
<p>This is typically called in the following cases, when a document has been:</p>
<ul>
<li>created basing on some template and has not been saved, so no filename has been associated with the document yet.</li>
<li>restored from a backup file.</li>
<li>changed outside of the editor and the user did not reload it.</li>
</ul>
<p>This function was introduced in  Qt 5.8.</p>
<p><b>See also </b><a href="qundostack.html#isClean">isClean</a>(), <a href="qundostack.html#setClean">setClean</a>(), and <a href="qundostack.html#cleanIndex">cleanIndex</a>().</p>
<!-- @@@resetClean -->
<!-- $$$setClean[overload1]$$$setClean -->
<h3 class="fn" id="setClean"><a name="setClean"></a><code>[slot] </code><span class="type">void</span> QUndoStack::<span class="name">setClean</span>()</h3>
<p>Marks the stack as clean and emits <a href="qundostack.html#cleanChanged">cleanChanged</a>() if the stack was not already clean.</p>
<p>This is typically called when a document is saved, for example.</p>
<p>Whenever the stack returns to this state through the use of undo/redo commands, it emits the signal <a href="qundostack.html#cleanChanged">cleanChanged</a>(). This signal is also emitted when the stack leaves the clean state.</p>
<p><b>See also </b><a href="qundostack.html#isClean">isClean</a>(), <a href="qundostack.html#resetClean">resetClean</a>(), and <a href="qundostack.html#cleanIndex">cleanIndex</a>().</p>
<!-- @@@setClean -->
<!-- $$$setIndex[overload1]$$$setIndexint -->
<h3 class="fn" id="setIndex"><a name="setIndex"></a><code>[slot] </code><span class="type">void</span> QUndoStack::<span class="name">setIndex</span>(<span class="type">int</span> <i>idx</i>)</h3>
<p>Repeatedly calls <a href="qundostack.html#undo">undo</a>() or <a href="qundostack.html#redo">redo</a>() until the current command index reaches <i>idx</i>. This function can be used to roll the state of the document forwards of backwards. <a href="qundostack.html#indexChanged">indexChanged</a>() is emitted only once.</p>
<p><b>See also </b><a href="qundostack.html#index">index</a>(), <a href="qundostack.html#count">count</a>(), <a href="qundostack.html#undo">undo</a>(), and <a href="qundostack.html#redo">redo</a>().</p>
<!-- @@@setIndex -->
<!-- $$$text[overload1]$$$textint -->
<h3 class="fn" id="text"><a name="text"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QUndoStack::<span class="name">text</span>(<span class="type">int</span> <i>idx</i>) const</h3>
<p>Returns the text of the command at index <i>idx</i>.</p>
<p><b>See also </b><a href="qundostack.html#beginMacro">beginMacro</a>().</p>
<!-- @@@text -->
<!-- $$$undo[overload1]$$$undo -->
<h3 class="fn" id="undo"><a name="undo"></a><code>[slot] </code><span class="type">void</span> QUndoStack::<span class="name">undo</span>()</h3>
<p>Undoes the command below the current command by calling <a href="qundocommand.html#undo">QUndoCommand::undo</a>(). Decrements the current command index.</p>
<p>If the stack is empty, or if the bottom command on the stack has already been undone, this function does nothing.</p>
<p>After the command is undone, if <a href="qundocommand.html#isObsolete">QUndoCommand::isObsolete</a>() returns <code>true</code>, then the command will be deleted from the stack. Additionally, if the clean index is greater than or equal to the current command index, then the clean index is reset.</p>
<p><b>See also </b><a href="qundostack.html#redo">redo</a>() and <a href="qundostack.html#index">index</a>().</p>
<!-- @@@undo -->
<!-- $$$undoText[overload1]$$$undoText -->
<h3 class="fn" id="undoText"><a name="undoText"></a><span class="type"><a href="../qtcore/qstring.html">QString</a></span> QUndoStack::<span class="name">undoText</span>() const</h3>
<p>Returns the text of the command which will be undone in the next call to <a href="qundostack.html#undo">undo</a>().</p>
<p><b>See also </b><a href="qundocommand.html#actionText">QUndoCommand::actionText</a>() and <a href="qundostack.html#redoText">redoText</a>().</p>
<!-- @@@undoText -->
<!-- $$$undoTextChanged[overload1]$$$undoTextChangedconstQString& -->
<h3 class="fn" id="undoTextChanged"><a name="undoTextChanged"></a><code>[signal] </code><span class="type">void</span> QUndoStack::<span class="name">undoTextChanged</span>(const <span class="type"><a href="../qtcore/qstring.html">QString</a></span> &amp;<i>undoText</i>)</h3>
<p>This signal is emitted whenever the value of <a href="qundostack.html#undoText">undoText</a>() changes. It is used to update the text property of the undo action returned by <a href="qundostack.html#createUndoAction">createUndoAction</a>(). <i>undoText</i> specifies the new text.</p>
<!-- @@@undoTextChanged -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>