diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 18fa55228f3..b6d1f328562 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -163,7 +163,7 @@ GLSLTextEditorWidget::GLSLTextEditorWidget(QWidget *parent) : connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument())); - baseTextDocument()->setSyntaxHighlighter(new Highlighter(this, document())); + new Highlighter(baseTextDocument()); // if (m_modelManager) { // m_semanticHighlighter->setModelManager(m_modelManager); @@ -312,7 +312,7 @@ void GLSLTextEditorWidget::updateDocumentNow() { m_updateDocumentTimer->stop(); - int variant = languageVariant(); + int variant = languageVariant(mimeType()); const QString contents = toPlainText(); // get the code from the editor const QByteArray preprocessedCode = contents.toLatin1(); // ### use the QtCreator C++ preprocessor. @@ -371,10 +371,9 @@ void GLSLTextEditorWidget::updateDocumentNow() } } -int GLSLTextEditorWidget::languageVariant() const +int GLSLTextEditorWidget::languageVariant(const QString &type) { int variant = 0; - QString type = mimeType(); bool isVertex = false; bool isFragment = false; bool isDesktop = false; diff --git a/src/plugins/glsleditor/glsleditor.h b/src/plugins/glsleditor/glsleditor.h index ba228f4c22d..703569357fc 100644 --- a/src/plugins/glsleditor/glsleditor.h +++ b/src/plugins/glsleditor/glsleditor.h @@ -100,7 +100,7 @@ public: QSet identifiers() const; - int languageVariant() const; + static int languageVariant(const QString &mimeType); Document::Ptr glslDocument() const; diff --git a/src/plugins/glsleditor/glslhighlighter.cpp b/src/plugins/glsleditor/glslhighlighter.cpp index 7a5cb702d88..2055ac1ffc8 100644 --- a/src/plugins/glsleditor/glslhighlighter.cpp +++ b/src/plugins/glsleditor/glslhighlighter.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -41,8 +42,8 @@ using namespace GLSLEditor; using namespace GLSLEditor::Internal; using namespace TextEditor; -Highlighter::Highlighter(GLSLTextEditorWidget *editor, QTextDocument *parent) - : TextEditor::SyntaxHighlighter(parent), m_editor(editor) +Highlighter::Highlighter(BaseTextDocument *parent) + : TextEditor::SyntaxHighlighter(parent) { } @@ -72,7 +73,8 @@ void Highlighter::highlightBlock(const QString &text) lex.setState(state); lex.setScanKeywords(false); lex.setScanComments(true); - const int variant = m_editor->languageVariant(); + const int variant = + GLSLTextEditorWidget::languageVariant(static_cast(parent())->mimeType()); lex.setVariant(variant); int initialState = state; diff --git a/src/plugins/glsleditor/glslhighlighter.h b/src/plugins/glsleditor/glslhighlighter.h index e9dc44ef7e3..1d52f98d528 100644 --- a/src/plugins/glsleditor/glslhighlighter.h +++ b/src/plugins/glsleditor/glslhighlighter.h @@ -60,7 +60,7 @@ public: NumGLSLFormats }; - explicit Highlighter(GLSLTextEditorWidget *editor, QTextDocument *parent); + explicit Highlighter(TextEditor::BaseTextDocument *parent); virtual ~Highlighter(); void setFormats(const QVector &formats); @@ -72,7 +72,6 @@ protected: private: QTextCharFormat m_formats[NumGLSLFormats]; - GLSLTextEditorWidget *m_editor; }; } // namespace Internal diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp index 3dfe2b9a118..f10b2037860 100644 --- a/src/plugins/texteditor/syntaxhighlighter.cpp +++ b/src/plugins/texteditor/syntaxhighlighter.cpp @@ -30,6 +30,7 @@ **************************************************************************/ #include "syntaxhighlighter.h" +#include "basetextdocument.h" #include #include @@ -324,6 +325,13 @@ SyntaxHighlighter::SyntaxHighlighter(QTextDocument *parent) setDocument(parent); } +SyntaxHighlighter::SyntaxHighlighter(BaseTextDocument *parent) + : d_ptr(new SyntaxHighlighterPrivate) +{ + d_ptr->q_ptr = this; + parent->setSyntaxHighlighter(this); // Extra logic (including setting the parent). +} + /*! Constructs a SyntaxHighlighter and installs it on \a parent 's QTextDocument. The specified QTextEdit also becomes the owner of diff --git a/src/plugins/texteditor/syntaxhighlighter.h b/src/plugins/texteditor/syntaxhighlighter.h index fe61561fc21..112dd65378a 100644 --- a/src/plugins/texteditor/syntaxhighlighter.h +++ b/src/plugins/texteditor/syntaxhighlighter.h @@ -49,6 +49,7 @@ QT_END_NAMESPACE namespace TextEditor { +class BaseTextDocument; class SyntaxHighlighterPrivate; class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject @@ -58,6 +59,7 @@ class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject public: SyntaxHighlighter(QObject *parent); SyntaxHighlighter(QTextDocument *parent); + SyntaxHighlighter(BaseTextDocument *parent); SyntaxHighlighter(QTextEdit *parent); virtual ~SyntaxHighlighter();