diff options
author | hjk <qtc-committer@nokia.com> | 2009-10-26 11:40:33 (GMT) |
---|---|---|
committer | hjk <qtc-committer@nokia.com> | 2009-10-30 10:24:29 (GMT) |
commit | 1bed105d048531e3e260eff0ef2533d7cc8ba7fb (patch) | |
tree | 29b181d552a8bfaf4ab0ddf877259e85c458421b /src/gui/text | |
parent | d670ef51fe76adccd6f4d017f6a23940ab5284ee (diff) | |
download | Qt-1bed105d048531e3e260eff0ef2533d7cc8ba7fb.zip Qt-1bed105d048531e3e260eff0ef2533d7cc8ba7fb.tar.gz Qt-1bed105d048531e3e260eff0ef2533d7cc8ba7fb.tar.bz2 |
introduce int QTextDocument::available{Undo,Redo}Steps() const;
Formerly, QTextDocument::revision() could be used to guesstimate the
number of available undo steps that was used in Qt Creator to store
cursor positions in parallel to the actual text contents. Now that
revision() is strictly increasing, another means is needed, therefore
the new functions providing the needed data.
Reviewed-by: mae
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 27 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.h | 3 | ||||
-rw-r--r-- | src/gui/text/qtextdocument_p.h | 3 |
3 files changed, 33 insertions, 0 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index a8956b8..5398111 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -956,6 +956,8 @@ QString QTextDocument::defaultStyleSheet() const /*! Returns true if undo is available; otherwise returns false. + + \sa isRedoAvailable(), availableUndoSteps() */ bool QTextDocument::isUndoAvailable() const { @@ -965,6 +967,8 @@ bool QTextDocument::isUndoAvailable() const /*! Returns true if redo is available; otherwise returns false. + + \sa isUndoAvailable(), availableRedoSteps() */ bool QTextDocument::isRedoAvailable() const { @@ -972,6 +976,29 @@ bool QTextDocument::isRedoAvailable() const return d->isRedoAvailable(); } +/*! \since 4.6 + + Returns the number of available undo steps. + + \sa isUndoAvailable() +*/ +int QTextDocument::availableUndoSteps() const +{ + Q_D(const QTextDocument); + return d->availableUndoSteps(); +} + +/*! \since 4.6 + + Returns the number of available redo steps. + + \sa isRedoAvailable() +*/ +int QTextDocument::availableRedoSteps() const +{ + Q_D(const QTextDocument); + return d->availableRedoSteps(); +} /*! \since 4.4 diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index e52716a..d217a4d 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -142,6 +142,9 @@ public: bool isUndoAvailable() const; bool isRedoAvailable() const; + int availableUndoSteps() const; + int availableRedoSteps() const; + int revision() const; void setDocumentLayout(QAbstractTextDocumentLayout *layout); diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index ce25c57..c10855b 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -212,6 +212,9 @@ public: inline bool isUndoAvailable() const { return undoEnabled && undoState > 0; } inline bool isRedoAvailable() const { return undoEnabled && undoState < undoStack.size(); } + inline int availableUndoSteps() const { return undoEnabled ? undoState : 0; } + inline int availableRedoSteps() const { return undoEnabled ? qMax(undoStack.size() - undoState - 1, 0) : 0; } + inline QString buffer() const { return text; } QString plainText() const; inline int length() const { return fragments.length(); } |