Commit 3bf88399 authored by Leandro Melo's avatar Leandro Melo Committed by Leandro T. C. Melo

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/2508Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent ebb238c8
......@@ -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;
......
......@@ -100,7 +100,7 @@ public:
QSet<QString> identifiers() const;
int languageVariant() const;
static int languageVariant(const QString &mimeType);
Document::Ptr glslDocument() const;
......
......@@ -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;
......
......@@ -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
......
......@@ -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
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment