connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument()));
- baseTextDocument()->setSyntaxHighlighter(new Highlighter(this, document()));
+ new Highlighter(baseTextDocument());
// if (m_modelManager) {
// m_semanticHighlighter->setModelManager(m_modelManager);
{
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.
}
}
-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;
QSet<QString> identifiers() const;
- int languageVariant() const;
+ static int languageVariant(const QString &mimeType);
Document::Ptr glslDocument() const;
#include <glsl/glsllexer.h>
#include <glsl/glslparser.h>
#include <texteditor/basetextdocumentlayout.h>
+#include <texteditor/basetextdocument.h>
#include <QtCore/QDebug>
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)
{
}
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;
NumGLSLFormats
};
- explicit Highlighter(GLSLTextEditorWidget *editor, QTextDocument *parent);
+ explicit Highlighter(TextEditor::BaseTextDocument *parent);
virtual ~Highlighter();
void setFormats(const QVector<QTextCharFormat> &formats);
private:
QTextCharFormat m_formats[NumGLSLFormats];
- GLSLTextEditorWidget *m_editor;
};
} // namespace Internal
**************************************************************************/
#include "syntaxhighlighter.h"
+#include "basetextdocument.h"
#include <qtextdocument.h>
#include <qtextlayout.h>
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
namespace TextEditor {
+class BaseTextDocument;
class SyntaxHighlighterPrivate;
class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject
public:
SyntaxHighlighter(QObject *parent);
SyntaxHighlighter(QTextDocument *parent);
+ SyntaxHighlighter(BaseTextDocument *parent);
SyntaxHighlighter(QTextEdit *parent);
virtual ~SyntaxHighlighter();