From 5d15076ea14262b474dd60768e6d80ef498cfdd1 Mon Sep 17 00:00:00 2001 From: jkobus Date: Fri, 13 Sep 2013 12:13:10 +0200 Subject: Fix compilation of generichighlighter test on Windows Change-Id: I25c2f68528ede12fa900ea86973c6df39667c421 Reviewed-by: Jarek Kobus Reviewed-by: Christian Stenger --- src/plugins/diffeditor/diffeditorwidget.cpp | 7 +- .../texteditor/generichighlighter/highlighter.cpp | 17 +++-- .../texteditor/generichighlighter/highlighter.h | 23 +++---- .../generichighlighter/highlighterutils.cpp | 70 -------------------- .../generichighlighter/highlighterutils.h | 53 --------------- src/plugins/texteditor/highlighterutils.cpp | 76 ++++++++++++++++++++++ src/plugins/texteditor/highlighterutils.h | 55 ++++++++++++++++ src/plugins/texteditor/plaintexteditor.cpp | 2 +- src/plugins/texteditor/texteditor.pro | 4 +- src/plugins/texteditor/texteditor.qbs | 6 +- 10 files changed, 162 insertions(+), 151 deletions(-) delete mode 100644 src/plugins/texteditor/generichighlighter/highlighterutils.cpp delete mode 100644 src/plugins/texteditor/generichighlighter/highlighterutils.h create mode 100644 src/plugins/texteditor/highlighterutils.cpp create mode 100644 src/plugins/texteditor/highlighterutils.h (limited to 'src') diff --git a/src/plugins/diffeditor/diffeditorwidget.cpp b/src/plugins/diffeditor/diffeditorwidget.cpp index 8c0c43b570..4960b19263 100644 --- a/src/plugins/diffeditor/diffeditorwidget.cpp +++ b/src/plugins/diffeditor/diffeditorwidget.cpp @@ -45,8 +45,7 @@ #include #include #include -#include -#include +#include #include #include @@ -278,9 +277,7 @@ void MultiHighlighter::setDocuments(const QListsetDocument(document); } if (!highlighter) { - TextEditor::Highlighter *h = new TextEditor::Highlighter(); - highlighter = h; - setMimeTypeForHighlighter(h, mimeType); + highlighter = createGenericSyntaxHighlighter(mimeType); highlighter->setDocument(document); } m_documents.append(document); diff --git a/src/plugins/texteditor/generichighlighter/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp index 7cd1bfca37..06106e9703 100644 --- a/src/plugins/texteditor/generichighlighter/highlighter.cpp +++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp @@ -35,7 +35,7 @@ #include "highlighterexception.h" #include "progressdata.h" #include "reuse.h" -#include +#include "tabsettings.h" #include #include @@ -50,8 +50,6 @@ namespace { static const QLatin1Char kHash('#'); } -const Highlighter::KateFormatMap Highlighter::m_kateFormats; - Highlighter::Highlighter(QTextDocument *parent) : TextEditor::SyntaxHighlighter(parent), m_regionDepth(0), @@ -92,7 +90,14 @@ Highlighter::BlockData::BlockData() : m_foldingIndentDelta(0), m_originalObserva Highlighter::BlockData::~BlockData() {} -Highlighter::KateFormatMap::KateFormatMap() +// Mapping from Kate format strings to format ids. +struct KateFormatMap +{ + KateFormatMap(); + QHash m_ids; +}; + +KateFormatMap::KateFormatMap() { m_ids.insert(QLatin1String("dsNormal"), Highlighter::Normal); m_ids.insert(QLatin1String("dsKeyword"), Highlighter::Keyword); @@ -110,6 +115,8 @@ Highlighter::KateFormatMap::KateFormatMap() m_ids.insert(QLatin1String("dsOthers"), Highlighter::Others); } +Q_GLOBAL_STATIC(KateFormatMap, kateFormatMap) + void Highlighter::setDefaultContext(const QSharedPointer &defaultContext) { m_defaultContext = defaultContext; @@ -404,7 +411,7 @@ void Highlighter::applyFormat(int offset, return; } - TextFormatId formatId = m_kateFormats.m_ids.value(itemData->style(), Normal); + TextFormatId formatId = kateFormatMap()->m_ids.value(itemData->style(), Normal); if (formatId != Normal) { QTextCharFormat format = formatForCategory(formatId); if (itemData->isCustomized()) { diff --git a/src/plugins/texteditor/generichighlighter/highlighter.h b/src/plugins/texteditor/generichighlighter/highlighter.h index 470506fdf4..968a48a6c1 100644 --- a/src/plugins/texteditor/generichighlighter/highlighter.h +++ b/src/plugins/texteditor/generichighlighter/highlighter.h @@ -30,12 +30,12 @@ #ifndef HIGHLIGHTER_H #define HIGHLIGHTER_H -#include -#include -#include - #include "context.h" +// Yes, this is correct. These are found somewhere else when building the autotest. +#include +#include + #include #include #include @@ -55,7 +55,12 @@ class ProgressData; } // namespace Internal -class TEXTEDITOR_EXPORT Highlighter : public TextEditor::SyntaxHighlighter +/* + Warning: Due to a very ugly hack with generichighlighter test + you can't export this class, so that it would be used from + other plugins. That's why highlighterutils.h was introduced. +*/ +class Highlighter : public TextEditor::SyntaxHighlighter { Q_OBJECT @@ -129,14 +134,6 @@ private: void applyIndentationBasedFolding(const QString &text) const; int neighbouringNonEmptyBlockIndent(QTextBlock block, const bool previous) const; - // Mapping from Kate format strings to format ids. - struct KateFormatMap - { - KateFormatMap(); - QHash m_ids; - }; - static const KateFormatMap m_kateFormats; - struct BlockData : TextBlockUserData { BlockData(); diff --git a/src/plugins/texteditor/generichighlighter/highlighterutils.cpp b/src/plugins/texteditor/generichighlighter/highlighterutils.cpp deleted file mode 100644 index 4ecd5b675c..0000000000 --- a/src/plugins/texteditor/generichighlighter/highlighterutils.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "highlighterutils.h" -#include "highlighter.h" -#include "highlightdefinition.h" -#include "manager.h" -#include - -using namespace TextEditor; -using namespace Internal; - -QString TextEditor::findDefinitionId(const Core::MimeType &mimeType, - bool considerParents) -{ - QString definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.aliases()); - if (definitionId.isEmpty() && considerParents) { - definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.subClassesOf()); - if (definitionId.isEmpty()) { - foreach (const QString &parent, mimeType.subClassesOf()) { - const Core::MimeType &parentMimeType = Core::MimeDatabase::findByType(parent); - definitionId = findDefinitionId(parentMimeType, considerParents); - } - } - } - return definitionId; -} - -void TextEditor::setMimeTypeForHighlighter(Highlighter *highlighter, const Core::MimeType &mimeType) -{ - const QString type = mimeType.type(); - QString definitionId = Manager::instance()->definitionIdByMimeType(type); - if (definitionId.isEmpty()) - definitionId = findDefinitionId(mimeType, true); - - if (!definitionId.isEmpty()) { - const QSharedPointer &definition = - Manager::instance()->definition(definitionId); - if (!definition.isNull() && definition->isValid()) { - highlighter->setDefaultContext(definition->initialContext()); - } - } - -} diff --git a/src/plugins/texteditor/generichighlighter/highlighterutils.h b/src/plugins/texteditor/generichighlighter/highlighterutils.h deleted file mode 100644 index a781ac7e17..0000000000 --- a/src/plugins/texteditor/generichighlighter/highlighterutils.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef HIGHLIGHTERUTILS_H -#define HIGHLIGHTERUTILS_H - -#include -#include - -/* These methods were originally a part of TextEditor::Highlighter, - * but due to a very hackish test of that generic highlighter, - * there methods must be outside. */ - -namespace Core { -class MimeType; -} - -namespace TextEditor { - -class Highlighter; - -void TEXTEDITOR_EXPORT setMimeTypeForHighlighter(Highlighter *highlighter, const Core::MimeType &mimeType); -QString TEXTEDITOR_EXPORT findDefinitionId(const Core::MimeType &mimeType, bool considerParents); - -} // namespace TextEditor - -#endif // HIGHLIGHTERUTILS_H diff --git a/src/plugins/texteditor/highlighterutils.cpp b/src/plugins/texteditor/highlighterutils.cpp new file mode 100644 index 0000000000..360bb7bb91 --- /dev/null +++ b/src/plugins/texteditor/highlighterutils.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "highlighterutils.h" +#include "generichighlighter/highlighter.h" +#include "generichighlighter/highlightdefinition.h" +#include "generichighlighter/manager.h" +#include + +using namespace TextEditor; +using namespace Internal; + +QString TextEditor::findDefinitionId(const Core::MimeType &mimeType, + bool considerParents) +{ + QString definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.aliases()); + if (definitionId.isEmpty() && considerParents) { + definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.subClassesOf()); + if (definitionId.isEmpty()) { + foreach (const QString &parent, mimeType.subClassesOf()) { + const Core::MimeType &parentMimeType = Core::MimeDatabase::findByType(parent); + definitionId = findDefinitionId(parentMimeType, considerParents); + } + } + } + return definitionId; +} + +void TextEditor::setMimeTypeForHighlighter(Highlighter *highlighter, const Core::MimeType &mimeType) +{ + const QString type = mimeType.type(); + QString definitionId = Manager::instance()->definitionIdByMimeType(type); + if (definitionId.isEmpty()) + definitionId = findDefinitionId(mimeType, true); + + if (!definitionId.isEmpty()) { + const QSharedPointer &definition = + Manager::instance()->definition(definitionId); + if (!definition.isNull() && definition->isValid()) { + highlighter->setDefaultContext(definition->initialContext()); + } + } +} + +SyntaxHighlighter *TextEditor::createGenericSyntaxHighlighter(const Core::MimeType &mimeType) +{ + TextEditor::Highlighter *highlighter = new TextEditor::Highlighter(); + setMimeTypeForHighlighter(highlighter, mimeType); + return highlighter; +} diff --git a/src/plugins/texteditor/highlighterutils.h b/src/plugins/texteditor/highlighterutils.h new file mode 100644 index 0000000000..dd6bc5343d --- /dev/null +++ b/src/plugins/texteditor/highlighterutils.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef HIGHLIGHTERUTILS_H +#define HIGHLIGHTERUTILS_H + +#include +#include "texteditor_global.h" + +/* These methods were originally a part of TextEditor::Highlighter, + * but due to a very hackish test of that generic highlighter, + * there methods must be outside. */ + +namespace Core { +class MimeType; +} + +namespace TextEditor { + +class Highlighter; +class SyntaxHighlighter; + +void setMimeTypeForHighlighter(Highlighter *highlighter, const Core::MimeType &mimeType); +QString findDefinitionId(const Core::MimeType &mimeType, bool considerParents); +TEXTEDITOR_EXPORT SyntaxHighlighter *createGenericSyntaxHighlighter(const Core::MimeType &mimeType); + +} // namespace TextEditor + +#endif // HIGHLIGHTERUTILS_H diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp index 410032a6ac..573961cc23 100644 --- a/src/plugins/texteditor/plaintexteditor.cpp +++ b/src/plugins/texteditor/plaintexteditor.cpp @@ -33,7 +33,7 @@ #include "texteditorsettings.h" #include "basetextdocument.h" #include "normalindenter.h" -#include "generichighlighter/highlighterutils.h" +#include "highlighterutils.h" #include #include #include diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro index 723dbda613..2a449986b6 100644 --- a/src/plugins/texteditor/texteditor.pro +++ b/src/plugins/texteditor/texteditor.pro @@ -38,6 +38,7 @@ SOURCES += texteditorplugin.cpp \ indenter.cpp \ quickfix.cpp \ syntaxhighlighter.cpp \ + highlighterutils.cpp \ generichighlighter/itemdata.cpp \ generichighlighter/specificrules.cpp \ generichighlighter/rule.cpp \ @@ -54,7 +55,6 @@ SOURCES += texteditorplugin.cpp \ generichighlighter/highlightersettings.cpp \ generichighlighter/managedefinitionsdialog.cpp \ generichighlighter/definitiondownloader.cpp \ - generichighlighter/highlighterutils.cpp \ refactoringchanges.cpp \ refactoroverlay.cpp \ outlinefactory.cpp \ @@ -146,6 +146,7 @@ HEADERS += texteditorplugin.h \ quickfix.h \ ihighlighterfactory.h \ syntaxhighlighter.h \ + highlighterutils.h \ generichighlighter/reuse.h \ generichighlighter/itemdata.h \ generichighlighter/specificrules.h \ @@ -166,7 +167,6 @@ HEADERS += texteditorplugin.h \ generichighlighter/managedefinitionsdialog.h \ generichighlighter/highlightdefinitionmetadata.h \ generichighlighter/definitiondownloader.h \ - generichighlighter/highlighterutils.h \ refactoringchanges.h \ refactoroverlay.h \ outlinefactory.h \ diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs index 637b756fbc..cf5e4b68e6 100644 --- a/src/plugins/texteditor/texteditor.qbs +++ b/src/plugins/texteditor/texteditor.qbs @@ -10,6 +10,8 @@ QtcPlugin { Depends { name: "Find" } Depends { name: "Locator" } + cpp.includePaths: base.concat([path]) // Needed for the highlighterengine autotest. + files: [ "autocompleter.cpp", "autocompleter.h", @@ -78,6 +80,8 @@ QtcPlugin { "fontsettingspage.ui", "helpitem.cpp", "helpitem.h", + "highlighterutils.cpp", + "highlighterutils.h", "icodestylepreferences.cpp", "icodestylepreferences.h", "icodestylepreferencesfactory.cpp", @@ -216,8 +220,6 @@ QtcPlugin { "highlightersettingspage.cpp", "highlightersettingspage.h", "highlightersettingspage.ui", - "highlighterutils.cpp", - "highlighterutils.h", "includerulesinstruction.cpp", "includerulesinstruction.h", "itemdata.cpp", -- cgit v1.2.1