summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qsyntaxhighlighter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text/qsyntaxhighlighter.cpp')
-rw-r--r--src/gui/text/qsyntaxhighlighter.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/gui/text/qsyntaxhighlighter.cpp b/src/gui/text/qsyntaxhighlighter.cpp
index 5d6c0052f4..5f1a53b556 100644
--- a/src/gui/text/qsyntaxhighlighter.cpp
+++ b/src/gui/text/qsyntaxhighlighter.cpp
@@ -50,7 +50,6 @@
#include <qtextobject.h>
#include <qtextcursor.h>
#include <qdebug.h>
-#include <qtextedit.h>
#include <qtimer.h>
QT_BEGIN_NAMESPACE
@@ -311,10 +310,19 @@ void QSyntaxHighlighterPrivate::reformatBlock(const QTextBlock &block)
/*!
Constructs a QSyntaxHighlighter with the given \a parent.
+
+ If the parent is a QTextEdit, it installs the syntaxhighlighter on the
+ parents document. The specified QTextEdit also becomes the owner of
+ the QSyntaxHighlighter.
*/
QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent)
: QObject(*new QSyntaxHighlighterPrivate, parent)
{
+ if (parent->inherits("QTextEdit")) {
+ QTextDocument *doc = qobject_cast<QTextDocument *>(parent->property("document").value<QObject *>());
+ if (doc)
+ setDocument(doc);
+ }
}
/*!
@@ -329,17 +337,6 @@ QSyntaxHighlighter::QSyntaxHighlighter(QTextDocument *parent)
}
/*!
- Constructs a QSyntaxHighlighter and installs it on \a parent 's
- QTextDocument. The specified QTextEdit also becomes the owner of
- the QSyntaxHighlighter.
-*/
-QSyntaxHighlighter::QSyntaxHighlighter(QTextEdit *parent)
- : QObject(*new QSyntaxHighlighterPrivate, parent)
-{
- setDocument(parent->document());
-}
-
-/*!
Destructor. Uninstalls this syntax highlighter from the text document.
*/
QSyntaxHighlighter::~QSyntaxHighlighter()