aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeandro Melo <leandro.melo@nokia.com>2011-08-02 12:26:00 +0200
committerLeandro T. C. Melo <leandro.melo@nokia.com>2011-08-02 13:07:36 +0200
commit3bf883997f1cc4e0564795c75b77cac5b451cbb3 (patch)
tree0e4a7f1c32dfa41696ca9afc3675e418bb30ade3
parentebb238c88580d6841763187810b6af588f785757 (diff)
Fix crash when spliting GLSL editor
Not a good idea to keep the editor stored since when removing a split, for example, the editor will go away and the highlighter is not aware of it anyhow since it actually belongs to the document. Although it's not necessary for the fix this patch add another constructor to SyntaxHighlighter which takes the BaseTextDocument. This is convenient. Task-number: QTCREATORBUG-5695 Change-Id: Ic91837b7d91ebd3a44c16e2fd589d7f6c5c0c002 Reviewed-on: http://codereview.qt.nokia.com/2508 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
-rw-r--r--src/plugins/glsleditor/glsleditor.cpp7
-rw-r--r--src/plugins/glsleditor/glsleditor.h2
-rw-r--r--src/plugins/glsleditor/glslhighlighter.cpp8
-rw-r--r--src/plugins/glsleditor/glslhighlighter.h3
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.cpp8
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.h2
6 files changed, 20 insertions, 10 deletions
diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp
index 18fa55228f..b6d1f32856 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 ba228f4c22..703569357f 100644
--- a/src/plugins/glsleditor/glsleditor.h
+++ b/src/plugins/glsleditor/glsleditor.h
@@ -100,7 +100,7 @@ public:
QSet<QString> 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 7a5cb702d8..2055ac1ffc 100644
--- a/src/plugins/glsleditor/glslhighlighter.cpp
+++ b/src/plugins/glsleditor/glslhighlighter.cpp
@@ -34,6 +34,7 @@
#include <glsl/glsllexer.h>
#include <glsl/glslparser.h>
#include <texteditor/basetextdocumentlayout.h>
+#include <texteditor/basetextdocument.h>
#include <QtCore/QDebug>
@@ -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<BaseTextDocument*>(parent())->mimeType());
lex.setVariant(variant);
int initialState = state;
diff --git a/src/plugins/glsleditor/glslhighlighter.h b/src/plugins/glsleditor/glslhighlighter.h
index e9dc44ef7e..1d52f98d52 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<QTextCharFormat> &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 3dfe2b9a11..f10b203786 100644
--- a/src/plugins/texteditor/syntaxhighlighter.cpp
+++ b/src/plugins/texteditor/syntaxhighlighter.cpp
@@ -30,6 +30,7 @@
**************************************************************************/
#include "syntaxhighlighter.h"
+#include "basetextdocument.h"
#include <qtextdocument.h>
#include <qtextlayout.h>
@@ -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 fe61561fc2..112dd65378 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();