diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index b1520aebc80..01aa5234720 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -290,9 +290,9 @@ void GitEditorWidget::init() VcsBase::VcsBaseEditorWidget::init(); Core::Id editorId = editor()->document()->id(); if (editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID) - new GitSubmitHighlighter(textDocument()); + textDocument()->setSyntaxHighlighter(new GitSubmitHighlighter); else if (editorId == Git::Constants::GIT_REBASE_EDITOR_ID) - new GitRebaseHighlighter(textDocument()); + textDocument()->setSyntaxHighlighter(new GitRebaseHighlighter); } void GitEditorWidget::addDiffActions(QMenu *menu, const VcsBase::DiffChunk &chunk) diff --git a/src/plugins/git/githighlighters.cpp b/src/plugins/git/githighlighters.cpp index aca4944cfc9..d87a0d456d1 100644 --- a/src/plugins/git/githighlighters.cpp +++ b/src/plugins/git/githighlighters.cpp @@ -40,17 +40,6 @@ static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b"; GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) : TextEditor::SyntaxHighlighter(parent) -{ - initialize(); -} - -GitSubmitHighlighter::GitSubmitHighlighter(TextEditor::BaseTextDocument *parent) : - TextEditor::SyntaxHighlighter(parent) -{ - initialize(); -} - -void GitSubmitHighlighter::initialize() { static QVector categories; if (categories.isEmpty()) @@ -108,7 +97,7 @@ GitRebaseHighlighter::RebaseAction::RebaseAction(const QString ®exp, { } -GitRebaseHighlighter::GitRebaseHighlighter(TextEditor::BaseTextDocument *parent) : +GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) : TextEditor::SyntaxHighlighter(parent), m_hashChar(QLatin1Char('#')), m_changeNumberPattern(QLatin1String(CHANGE_PATTERN)) diff --git a/src/plugins/git/githighlighters.h b/src/plugins/git/githighlighters.h index de77e975af4..c9aa130586a 100644 --- a/src/plugins/git/githighlighters.h +++ b/src/plugins/git/githighlighters.h @@ -32,8 +32,6 @@ #include -namespace TextEditor { class FontSettings; } - namespace Git { namespace Internal { @@ -55,13 +53,10 @@ enum Format { class GitSubmitHighlighter : public TextEditor::SyntaxHighlighter { public: - explicit GitSubmitHighlighter(QTextEdit *parent); - explicit GitSubmitHighlighter(TextEditor::BaseTextDocument *parent); + explicit GitSubmitHighlighter(QTextEdit *parent = 0); void highlightBlock(const QString &text); private: - void initialize(); - enum State { None = -1, Header, Other }; QRegExp m_keywordPattern; QChar m_hashChar; @@ -72,7 +67,7 @@ private: class GitRebaseHighlighter : public TextEditor::SyntaxHighlighter { public: - explicit GitRebaseHighlighter(TextEditor::BaseTextDocument *parent); + explicit GitRebaseHighlighter(QTextDocument *parent = 0); void highlightBlock(const QString &text); private: diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 58a3d461b05..48e2faec4a1 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -374,7 +374,7 @@ GlslEditorFactory::GlslEditorFactory() setEditorWidgetCreator([]() { return new GlslEditorWidget; }); setEditorCreator([]() { return new GlslEditor; }); setIndenterCreator([]() { return new GlslIndenter; }); - setSyntaxHighlighterCreator([]() { return new Highlighter; }); + setSyntaxHighlighterCreator([]() { return new GlslHighlighter; }); setEditorActionHandlers(Constants::C_GLSLEDITOR_ID, TextEditorActionHandler::Format diff --git a/src/plugins/glsleditor/glsleditorplugin.cpp b/src/plugins/glsleditor/glsleditorplugin.cpp index 6cc286f863a..3034bbaad0e 100644 --- a/src/plugins/glsleditor/glsleditorplugin.cpp +++ b/src/plugins/glsleditor/glsleditorplugin.cpp @@ -212,7 +212,7 @@ bool GlslEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er addAutoReleasedObject(wizard); auto hf = new HighlighterFactory; - hf->setProductType(); + hf->setProductType(); hf->setId(Constants::C_GLSLEDITOR_ID); hf->addMimeType(Constants::GLSL_MIMETYPE); hf->addMimeType(Constants::GLSL_MIMETYPE_VERT); diff --git a/src/plugins/glsleditor/glslhighlighter.cpp b/src/plugins/glsleditor/glslhighlighter.cpp index f8e01e92b3a..9ccc12a8367 100644 --- a/src/plugins/glsleditor/glslhighlighter.cpp +++ b/src/plugins/glsleditor/glslhighlighter.cpp @@ -35,23 +35,12 @@ #include -using namespace GlslEditor; -using namespace GlslEditor::Internal; using namespace TextEditor; -Highlighter::Highlighter(QTextDocument *parent) - : TextEditor::SyntaxHighlighter(parent) -{ - init(); -} +namespace GlslEditor { +namespace Internal { -Highlighter::Highlighter(BaseTextDocument *parent) - : TextEditor::SyntaxHighlighter(parent) -{ - init(); -} - -void Highlighter::init() +GlslHighlighter::GlslHighlighter() { static QVector categories; if (categories.isEmpty()) { @@ -71,12 +60,7 @@ void Highlighter::init() setTextFormatCategories(categories); } -Highlighter::~Highlighter() -{ - -} - -void Highlighter::highlightBlock(const QString &text) +void GlslHighlighter::highlightBlock(const QString &text) { const int previousState = previousBlockState(); int state = 0, initialBraceDepth = 0; @@ -265,7 +249,7 @@ void Highlighter::highlightBlock(const QString &text) setCurrentBlockState((braceDepth << 8) | lex.state()); } -void Highlighter::highlightLine(const QString &text, int position, int length, +void GlslHighlighter::highlightLine(const QString &text, int position, int length, const QTextCharFormat &format) { const QTextCharFormat visualSpaceFormat = formatForCategory(GLSLVisualWhitespace); @@ -288,7 +272,7 @@ void Highlighter::highlightLine(const QString &text, int position, int length, } } -bool Highlighter::isPPKeyword(const QStringRef &text) const +bool GlslHighlighter::isPPKeyword(const QStringRef &text) const { switch (text.length()) { @@ -427,3 +411,6 @@ void Highlighter::highlightBlock(const QString &text) setCurrentBlockState((braceDepth << 8) | lex.state()); } #endif + +} // namespace Internal +} // namespace GlslEditor diff --git a/src/plugins/glsleditor/glslhighlighter.h b/src/plugins/glsleditor/glslhighlighter.h index d979bc639f4..c294c797dcf 100644 --- a/src/plugins/glsleditor/glslhighlighter.h +++ b/src/plugins/glsleditor/glslhighlighter.h @@ -26,6 +26,7 @@ ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ****************************************************************************/ + #ifndef GLSLHIGHLIGHTER_H #define GLSLHIGHLIGHTER_H @@ -34,9 +35,7 @@ namespace GlslEditor { namespace Internal { -class GlslEditorWidget; - -class Highlighter : public TextEditor::SyntaxHighlighter +class GlslHighlighter : public TextEditor::SyntaxHighlighter { Q_OBJECT @@ -57,17 +56,12 @@ public: NumGLSLFormats }; - explicit Highlighter(QTextDocument *parent = 0); - explicit Highlighter(TextEditor::BaseTextDocument *parent); - virtual ~Highlighter(); + GlslHighlighter(); protected: void highlightBlock(const QString &text); void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format); bool isPPKeyword(const QStringRef &text) const; - -private: - void init(); }; } // namespace Internal diff --git a/src/plugins/pythoneditor/tools/pythonhighlighter.cpp b/src/plugins/pythoneditor/tools/pythonhighlighter.cpp index e69b95a163c..24df0857f03 100644 --- a/src/plugins/pythoneditor/tools/pythonhighlighter.cpp +++ b/src/plugins/pythoneditor/tools/pythonhighlighter.cpp @@ -44,8 +44,7 @@ #include namespace PythonEditor { - -using namespace PythonEditor::Internal; +namespace Internal { /** * @class PyEditor::Highlighter @@ -65,20 +64,7 @@ using namespace PythonEditor::Internal; * @endcode */ -PythonHighlighter::PythonHighlighter(QTextDocument *parent) : - TextEditor::SyntaxHighlighter(parent) -{ - init(); -} - -/// New instance created when opening any document in editor -PythonHighlighter::PythonHighlighter(TextEditor::BaseTextDocument *parent) : - TextEditor::SyntaxHighlighter(parent) -{ - init(); -} - -void PythonHighlighter::init() +PythonHighlighter::PythonHighlighter() { static QVector categories; if (categories.isEmpty()) { @@ -98,11 +84,6 @@ void PythonHighlighter::init() setTextFormatCategories(categories); } -/// Instance destroyed when one of documents closed from editor -PythonHighlighter::~PythonHighlighter() -{ -} - /** * @brief Highlighter::highlightBlock highlights single line of Python code * @param text is single line without EOLN symbol. Access to all block data @@ -123,11 +104,9 @@ void PythonHighlighter::highlightBlock(const QString &text) /** * @return True if this keyword is acceptable at start of import line */ -static inline -bool isImportKeyword(const QString &keyword) +static bool isImportKeyword(const QString &keyword) { - return (keyword == QLatin1String("import") - || keyword == QLatin1String("from")); + return keyword == QLatin1String("import") || keyword == QLatin1String("from"); } /** @@ -175,4 +154,5 @@ void PythonHighlighter::highlightImport(Scanner &scanner) } } +} // namespace Internal } // namespace PythonEditor diff --git a/src/plugins/pythoneditor/tools/pythonhighlighter.h b/src/plugins/pythoneditor/tools/pythonhighlighter.h index 70846f38988..4bafa4ca006 100644 --- a/src/plugins/pythoneditor/tools/pythonhighlighter.h +++ b/src/plugins/pythoneditor/tools/pythonhighlighter.h @@ -33,26 +33,24 @@ #include namespace PythonEditor { +namespace Internal { -namespace Internal { class Scanner; } +class Scanner; class PythonHighlighter : public TextEditor::SyntaxHighlighter { - Q_OBJECT public: - explicit PythonHighlighter(QTextDocument *parent = 0); - explicit PythonHighlighter(TextEditor::BaseTextDocument *parent); - virtual ~PythonHighlighter(); + PythonHighlighter(); protected: - virtual void highlightBlock(const QString &text); + void highlightBlock(const QString &text); private: int highlightLine(const QString &text, int initialState); void highlightImport(Internal::Scanner &scanner); - void init(); }; +} // namespace Internal } // namespace PythonEditor #endif // PYTHONHIGHLIGHTER_H diff --git a/src/plugins/qmljseditor/qmljseditordocument.cpp b/src/plugins/qmljseditor/qmljseditordocument.cpp index 85b9172652b..62396d426fe 100644 --- a/src/plugins/qmljseditor/qmljseditordocument.cpp +++ b/src/plugins/qmljseditor/qmljseditordocument.cpp @@ -538,7 +538,7 @@ QmlJSEditorDocument::QmlJSEditorDocument() setId(Constants::C_QMLJSEDITOR_ID); connect(this, SIGNAL(tabSettingsChanged()), d, SLOT(invalidateFormatterCache())); - setSyntaxHighlighter(new Highlighter(document())); + setSyntaxHighlighter(new QmlJSHighlighter(document())); setIndenter(new Internal::Indenter); } diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp index 4651bfe584b..c2f4fc84a47 100644 --- a/src/plugins/qmljseditor/qmljseditorplugin.cpp +++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp @@ -113,7 +113,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e addAutoReleasedObject(new QmlJSSnippetProvider); auto hf = new TextEditor::HighlighterFactory; - hf->setProductType(); + hf->setProductType(); hf->setId(Constants::C_QMLJSEDITOR_ID); hf->addMimeType(QmlJSTools::Constants::QML_MIMETYPE); hf->addMimeType(QmlJSTools::Constants::QMLPROJECT_MIMETYPE); diff --git a/src/plugins/qmljseditor/qmljshighlighter.cpp b/src/plugins/qmljseditor/qmljshighlighter.cpp index 8ce15adae4b..b710b7dd393 100644 --- a/src/plugins/qmljseditor/qmljshighlighter.cpp +++ b/src/plugins/qmljseditor/qmljshighlighter.cpp @@ -33,11 +33,13 @@ #include -using namespace QmlJSEditor; using namespace QmlJS; +using namespace TextEditor; -Highlighter::Highlighter(QTextDocument *parent) - : TextEditor::SyntaxHighlighter(parent), +namespace QmlJSEditor { + +QmlJSHighlighter::QmlJSHighlighter(QTextDocument *parent) + : SyntaxHighlighter(parent), m_qmlEnabled(true), m_braceDepth(0), m_foldingIndent(0), @@ -57,21 +59,21 @@ Highlighter::Highlighter(QTextDocument *parent) setTextFormatCategories(categories); } -Highlighter::~Highlighter() +QmlJSHighlighter::~QmlJSHighlighter() { } -bool Highlighter::isQmlEnabled() const +bool QmlJSHighlighter::isQmlEnabled() const { return m_qmlEnabled; } -void Highlighter::setQmlEnabled(bool qmlEnabled) +void QmlJSHighlighter::setQmlEnabled(bool qmlEnabled) { m_qmlEnabled = qmlEnabled; } -void Highlighter::highlightBlock(const QString &text) +void QmlJSHighlighter::highlightBlock(const QString &text) { const QList tokens = m_scanner(text, onBlockStart()); @@ -200,7 +202,7 @@ void Highlighter::highlightBlock(const QString &text) onBlockEnd(m_scanner.state()); } -bool Highlighter::maybeQmlKeyword(const QStringRef &text) const +bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const { if (text.isEmpty()) return false; @@ -224,7 +226,7 @@ bool Highlighter::maybeQmlKeyword(const QStringRef &text) const return false; } -bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const +bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringRef &text) const { if (text.isEmpty()) return false; @@ -281,13 +283,13 @@ bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const return false; } -int Highlighter::onBlockStart() +int QmlJSHighlighter::onBlockStart() { m_currentBlockParentheses.clear(); m_braceDepth = 0; m_foldingIndent = 0; m_inMultilineComment = false; - if (TextEditor::TextBlockUserData *userData = TextEditor::BaseTextDocumentLayout::testUserData(currentBlock())) { + if (TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(currentBlock())) { userData->setFoldingIndent(0); userData->setFoldingStartIncluded(false); userData->setFoldingEndIncluded(false); @@ -305,34 +307,35 @@ int Highlighter::onBlockStart() return state; } -void Highlighter::onBlockEnd(int state) +void QmlJSHighlighter::onBlockEnd(int state) { setCurrentBlockState((m_braceDepth << 8) | state); - TextEditor::BaseTextDocumentLayout::setParentheses(currentBlock(), m_currentBlockParentheses); - TextEditor::BaseTextDocumentLayout::setFoldingIndent(currentBlock(), m_foldingIndent); + BaseTextDocumentLayout::setParentheses(currentBlock(), m_currentBlockParentheses); + BaseTextDocumentLayout::setFoldingIndent(currentBlock(), m_foldingIndent); } -void Highlighter::onOpeningParenthesis(QChar parenthesis, int pos, bool atStart) +void QmlJSHighlighter::onOpeningParenthesis(QChar parenthesis, int pos, bool atStart) { if (parenthesis == QLatin1Char('{') || parenthesis == QLatin1Char('[') || parenthesis == QLatin1Char('+')) { ++m_braceDepth; // if a folding block opens at the beginning of a line, treat the entire line // as if it were inside the folding block if (atStart) - TextEditor::BaseTextDocumentLayout::userData(currentBlock())->setFoldingStartIncluded(true); + BaseTextDocumentLayout::userData(currentBlock())->setFoldingStartIncluded(true); } m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Opened, parenthesis, pos)); } -void Highlighter::onClosingParenthesis(QChar parenthesis, int pos, bool atEnd) +void QmlJSHighlighter::onClosingParenthesis(QChar parenthesis, int pos, bool atEnd) { if (parenthesis == QLatin1Char('}') || parenthesis == QLatin1Char(']') || parenthesis == QLatin1Char('-')) { --m_braceDepth; if (atEnd) - TextEditor::BaseTextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true); + BaseTextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true); else m_foldingIndent = qMin(m_braceDepth, m_foldingIndent); // folding indent is the minimum brace depth of a block } m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Closed, parenthesis, pos)); } +} // namespace QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljshighlighter.h b/src/plugins/qmljseditor/qmljshighlighter.h index 29412eedeac..8979ce34b51 100644 --- a/src/plugins/qmljseditor/qmljshighlighter.h +++ b/src/plugins/qmljseditor/qmljshighlighter.h @@ -39,13 +39,13 @@ namespace QmlJSEditor { -class QMLJSEDITOR_EXPORT Highlighter : public TextEditor::SyntaxHighlighter +class QMLJSEDITOR_EXPORT QmlJSHighlighter : public TextEditor::SyntaxHighlighter { Q_OBJECT public: - Highlighter(QTextDocument *parent = 0); - virtual ~Highlighter(); + QmlJSHighlighter(QTextDocument *parent = 0); + virtual ~QmlJSHighlighter(); enum { NumberFormat, @@ -76,16 +76,13 @@ protected: bool maybeQmlBuiltinType(const QStringRef &text) const; private: - typedef TextEditor::Parenthesis Parenthesis; - typedef TextEditor::Parentheses Parentheses; - bool m_qmlEnabled; int m_braceDepth; int m_foldingIndent; bool m_inMultilineComment; QmlJS::Scanner m_scanner; - Parentheses m_currentBlockParentheses; + TextEditor::Parentheses m_currentBlockParentheses; }; } // namespace QmlJSEditor diff --git a/src/plugins/qmljseditor/qmljssnippetprovider.cpp b/src/plugins/qmljseditor/qmljssnippetprovider.cpp index c7e8b0cca62..84bd6545980 100644 --- a/src/plugins/qmljseditor/qmljssnippetprovider.cpp +++ b/src/plugins/qmljseditor/qmljssnippetprovider.cpp @@ -64,7 +64,7 @@ QString QmlJSSnippetProvider::displayName() const void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const { - editor->textDocument()->setSyntaxHighlighter(new Highlighter); + editor->textDocument()->setSyntaxHighlighter(new QmlJSHighlighter); editor->textDocument()->setIndenter(new Indenter); editor->setAutoCompleter(new AutoCompleter); } diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp index bd99b752bc4..39b4d1812e8 100644 --- a/src/plugins/texteditor/syntaxhighlighter.cpp +++ b/src/plugins/texteditor/syntaxhighlighter.cpp @@ -282,13 +282,6 @@ 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 4f7292d13ec..094930782b3 100644 --- a/src/plugins/texteditor/syntaxhighlighter.h +++ b/src/plugins/texteditor/syntaxhighlighter.h @@ -47,7 +47,6 @@ QT_END_NAMESPACE namespace TextEditor { -class BaseTextDocument; class FontSettings; class SyntaxHighlighterPrivate; @@ -56,9 +55,8 @@ class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject Q_OBJECT Q_DECLARE_PRIVATE(SyntaxHighlighter) public: - SyntaxHighlighter(QObject *parent); + SyntaxHighlighter(QObject *parent = 0); SyntaxHighlighter(QTextDocument *parent); - SyntaxHighlighter(BaseTextDocument *parent); SyntaxHighlighter(QTextEdit *parent); virtual ~SyntaxHighlighter(); diff --git a/tests/auto/generichighlighter/highlighterengine/highlightermock.h b/tests/auto/generichighlighter/highlighterengine/highlightermock.h index d8c2ec8a64b..e9bbb694594 100644 --- a/tests/auto/generichighlighter/highlighterengine/highlightermock.h +++ b/tests/auto/generichighlighter/highlighterengine/highlightermock.h @@ -34,13 +34,6 @@ #include -namespace TextEditor { -namespace Internal { -class Context; -class HighlightDefinition; -} -} - struct HighlightSequence { HighlightSequence() {}