diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-03-25 15:27:39 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-03-26 20:03:32 +0000 |
commit | 742a07ece1c99db964617015c06a05b4cb0dd995 (patch) | |
tree | f34d3a8e6b53660689b78bd7f33fa2cf9de7c2b1 /src/gui/text | |
parent | e79b1dcdf542be3a20d5c21ea163ff857ed875bf (diff) |
Use QScopedValueRollback more as a reentrancy guard
It is documented for the use, but we were rarely using it.
Change-Id: I812b9e6c8fbf204aba43ce2b79eca308ca75de88
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qsyntaxhighlighter.cpp | 7 | ||||
-rw-r--r-- | src/gui/text/qtextdocument_p.cpp | 18 | ||||
-rw-r--r-- | src/gui/text/qtextdocument_p.h | 2 |
3 files changed, 15 insertions, 12 deletions
diff --git a/src/gui/text/qsyntaxhighlighter.cpp b/src/gui/text/qsyntaxhighlighter.cpp index 102a776ed3..cf584f6980 100644 --- a/src/gui/text/qsyntaxhighlighter.cpp +++ b/src/gui/text/qsyntaxhighlighter.cpp @@ -45,6 +45,7 @@ #include <private/qtextdocument_p.h> #include <qtextlayout.h> #include <qpointer.h> +#include <qscopedvaluerollback.h> #include <qtextobject.h> #include <qtextcursor.h> #include <qdebug.h> @@ -68,14 +69,14 @@ public: void reformatBlocks(int from, int charsRemoved, int charsAdded); void reformatBlock(const QTextBlock &block); - inline void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation) { - inReformatBlocks = true; + inline void rehighlight(QTextCursor &cursor, QTextCursor::MoveOperation operation) + { + QScopedValueRollback<bool> bg(inReformatBlocks, true); cursor.beginEditBlock(); int from = cursor.position(); cursor.movePosition(operation); reformatBlocks(from, 0, cursor.position() - from); cursor.endEditBlock(); - inReformatBlocks = false; } inline void _q_delayedRehighlight() { diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index c0a0c1a177..0e3c8d0e83 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -40,6 +40,7 @@ #include <private/qtools_p.h> #include <qdebug.h> +#include <qscopedvaluerollback.h> #include "qtextdocument_p.h" #include "qtextdocument.h" #include <qtextformat.h> @@ -274,9 +275,10 @@ void QTextDocumentPrivate::clear() rtFrame = 0; init(); cursors = oldCursors; - inContentsChange = true; - emit q->contentsChange(0, len, 0); - inContentsChange = false; + { + QScopedValueRollback<bool> bg(inContentsChange, true); + emit q->contentsChange(0, len, 0); + } if (lout) lout->documentChanged(0, len, 0); } QT_CATCH(...) { @@ -309,9 +311,10 @@ void QTextDocumentPrivate::setLayout(QAbstractTextDocumentLayout *layout) it->free(); emit q->documentLayoutChanged(); - inContentsChange = true; - emit q->contentsChange(0, 0, length()); - inContentsChange = false; + { + QScopedValueRollback<bool> bg(inContentsChange, true); + emit q->contentsChange(0, 0, length()); + } if (lout) lout->documentChanged(0, 0, length()); } @@ -1213,9 +1216,8 @@ void QTextDocumentPrivate::finishEdit() if (lout && docChangeFrom >= 0) { if (!inContentsChange) { - inContentsChange = true; + QScopedValueRollback<bool> bg(inContentsChange, true); emit q->contentsChange(docChangeFrom, docChangeOldLength, docChangeLength); - inContentsChange = false; } lout->documentChanged(docChangeFrom, docChangeOldLength, docChangeLength); } diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index d95f5bef6a..a8e17bfc08 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -339,6 +339,7 @@ private: int lastBlockCount; public: + bool inContentsChange; QTextOption defaultTextOption; Qt::CursorMoveStyle defaultCursorMoveStyle; #ifndef QT_NO_CSSPARSER @@ -346,7 +347,6 @@ public: #endif int maximumBlockCount; uint needsEnsureMaximumBlockCount : 1; - uint inContentsChange : 1; uint blockCursorAdjustment : 1; QSizeF pageSize; QString title; |