TextEditor: Simplify TextMarkRegistry

The registry is an implementation detail and doesn't need to be exported
so move it to the textmark.cpp file.

Change-Id: Ic103b122cb20063fa4bc220bdc90cecff27054aa
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2017-05-29 14:30:43 +02:00
parent c3579c9dae
commit daac41338e
7 changed files with 52 additions and 105 deletions

View File

@@ -214,7 +214,6 @@ HEADERS += texteditorplugin.h \
circularclipboardassist.h \
textmark.h \
codeassist/keywordscompletionassist.h \
textmarkregistry.h \
marginsettings.h \
blockrange.h \
completionsettingspage.h \

View File

@@ -143,7 +143,6 @@ Project {
"texteditorsettings.h",
"textmark.cpp",
"textmark.h",
"textmarkregistry.h",
"textstyles.h",
"typingsettings.cpp",
"typingsettings.h",

View File

@@ -37,7 +37,6 @@
#include "snippets/snippetprovider.h"
#include "texteditoractionhandler.h"
#include "texteditorsettings.h"
#include "textmarkregistry.h"
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -130,8 +129,6 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
m_outlineFactory = new OutlineFactory;
addAutoReleasedObject(m_outlineFactory);
m_baseTextMarkRegistry = new TextMarkRegistry(this);
addAutoReleasedObject(new FindInFiles);
addAutoReleasedObject(new FindInCurrentFile);
addAutoReleasedObject(new FindInOpenFiles);
@@ -211,11 +208,6 @@ LineNumberFilter *TextEditorPlugin::lineNumberFilter()
return m_instance->m_lineNumberFilter;
}
TextMarkRegistry *TextEditorPlugin::baseTextMarkRegistry()
{
return m_instance->m_baseTextMarkRegistry;
}
void TextEditorPlugin::updateSearchResultsFont(const FontSettings &settings)
{
if (auto window = SearchResultWindow::instance()) {

View File

@@ -37,7 +37,6 @@ namespace Internal {
class LineNumberFilter;
class OutlineFactory;
class TextMarkRegistry;
class TextEditorPlugin : public ExtensionSystem::IPlugin
{
@@ -55,7 +54,6 @@ public:
void extensionsInitialized();
static LineNumberFilter *lineNumberFilter();
static TextMarkRegistry *baseTextMarkRegistry();
private:
void updateSearchResultsFont(const TextEditor::FontSettings &);
@@ -65,7 +63,6 @@ private:
TextEditorSettings *m_settings = nullptr;
LineNumberFilter *m_lineNumberFilter = nullptr;
OutlineFactory *m_outlineFactory = nullptr;
TextMarkRegistry *m_baseTextMarkRegistry = nullptr;
#ifdef WITH_TESTS
private slots:

View File

@@ -25,7 +25,6 @@
#include "textmark.h"
#include "textdocument.h"
#include "textmarkregistry.h"
#include "texteditor.h"
#include "texteditorplugin.h"
@@ -41,6 +40,32 @@ using namespace TextEditor::Internal;
namespace TextEditor {
class TextMarkRegistry : public QObject
{
Q_OBJECT
public:
static void add(TextMark *mark);
static bool remove(TextMark *mark);
static Utils::Theme::Color categoryColor(Core::Id category);
static bool categoryHasColor(Core::Id category);
static void setCategoryColor(Core::Id category, Utils::Theme::Color color);
static QString defaultToolTip(Core::Id category);
static void setDefaultToolTip(Core::Id category, const QString &toolTip);
private:
TextMarkRegistry(QObject *parent);
static TextMarkRegistry* instance();
void editorOpened(Core::IEditor *editor);
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
void allDocumentsRenamed(const QString &oldName, const QString &newName);
QHash<Utils::FileName, QSet<TextMark *> > m_marks;
QHash<Core::Id, Utils::Theme::Color> m_colors;
QHash<Core::Id, QString> m_defaultToolTips;
};
TextMarkRegistry *m_instance = nullptr;
TextMark::TextMark(const QString &fileName, int lineNumber, Id category, double widthFactor)
: m_baseTextDocument(0),
m_fileName(fileName),
@@ -51,12 +76,12 @@ TextMark::TextMark(const QString &fileName, int lineNumber, Id category, double
m_widthFactor(widthFactor)
{
if (!m_fileName.isEmpty())
TextEditorPlugin::baseTextMarkRegistry()->add(this);
TextMarkRegistry::add(this);
}
TextMark::~TextMark()
{
TextEditorPlugin::baseTextMarkRegistry()->remove(this);
TextMarkRegistry::remove(this);
if (m_baseTextDocument)
m_baseTextDocument->removeMark(this);
m_baseTextDocument = 0;
@@ -72,10 +97,10 @@ void TextMark::updateFileName(const QString &fileName)
if (fileName == m_fileName)
return;
if (!m_fileName.isEmpty())
TextEditorPlugin::baseTextMarkRegistry()->remove(this);
TextMarkRegistry::remove(this);
m_fileName = fileName;
if (!m_fileName.isEmpty())
TextEditorPlugin::baseTextMarkRegistry()->add(this);
TextMarkRegistry::add(this);
}
int TextMark::lineNumber() const
@@ -121,22 +146,22 @@ const QIcon &TextMark::icon() const
Theme::Color TextMark::categoryColor(Id category)
{
return TextEditorPlugin::baseTextMarkRegistry()->categoryColor(category);
return TextMarkRegistry::categoryColor(category);
}
bool TextMark::categoryHasColor(Id category)
{
return TextEditorPlugin::baseTextMarkRegistry()->categoryHasColor(category);
return TextMarkRegistry::categoryHasColor(category);
}
void TextMark::setCategoryColor(Id category, Theme::Color color)
{
TextEditorPlugin::baseTextMarkRegistry()->setCategoryColor(category, color);
TextMarkRegistry::setCategoryColor(category, color);
}
void TextMark::setDefaultToolTip(Id category, const QString &toolTip)
{
TextEditorPlugin::baseTextMarkRegistry()->setDefaultToolTip(category, toolTip);
TextMarkRegistry::setDefaultToolTip(category, toolTip);
}
void TextMark::updateMarker()
@@ -219,7 +244,7 @@ bool TextMark::addToolTipContent(QLayout *target)
{
QString text = m_toolTip;
if (text.isEmpty()) {
text = TextEditorPlugin::baseTextMarkRegistry()->defaultToolTip(m_category);
text = TextMarkRegistry::defaultToolTip(m_category);
if (text.isEmpty())
return false;
}
@@ -267,7 +292,7 @@ TextMarkRegistry::TextMarkRegistry(QObject *parent)
void TextMarkRegistry::add(TextMark *mark)
{
m_marks[FileName::fromString(mark->fileName())].insert(mark);
instance()->m_marks[FileName::fromString(mark->fileName())].insert(mark);
auto document = qobject_cast<TextDocument*>(DocumentModel::documentForFilePath(mark->fileName()));
if (!document)
return;
@@ -276,40 +301,47 @@ void TextMarkRegistry::add(TextMark *mark)
bool TextMarkRegistry::remove(TextMark *mark)
{
return m_marks[FileName::fromString(mark->fileName())].remove(mark);
return instance()->m_marks[FileName::fromString(mark->fileName())].remove(mark);
}
Theme::Color TextMarkRegistry::categoryColor(Id category)
{
return m_colors.value(category, Theme::ProjectExplorer_TaskWarn_TextMarkColor);
return instance()->m_colors.value(category, Theme::ProjectExplorer_TaskWarn_TextMarkColor);
}
bool TextMarkRegistry::categoryHasColor(Id category)
{
return m_colors.contains(category);
return instance()->m_colors.contains(category);
}
void TextMarkRegistry::setCategoryColor(Id category, Theme::Color newColor)
{
Theme::Color &color = m_colors[category];
Theme::Color &color = instance()->m_colors[category];
if (color == newColor)
return;
color = newColor;
}
QString TextMarkRegistry::defaultToolTip(Id category) const
QString TextMarkRegistry::defaultToolTip(Id category)
{
return m_defaultToolTips[category];
return instance()->m_defaultToolTips[category];
}
void TextMarkRegistry::setDefaultToolTip(Id category, const QString &toolTip)
{
QString &defaultToolTip = m_defaultToolTips[category];
QString &defaultToolTip = instance()->m_defaultToolTips[category];
if (defaultToolTip == toolTip)
return;
defaultToolTip = toolTip;
}
TextMarkRegistry *TextMarkRegistry::instance()
{
if (!m_instance)
m_instance = new TextMarkRegistry(TextEditorPlugin::instance());
return m_instance;
}
void TextMarkRegistry::editorOpened(IEditor *editor)
{
auto document = qobject_cast<TextDocument *>(editor ? editor->document() : 0);
@@ -361,3 +393,5 @@ void TextMarkRegistry::allDocumentsRenamed(const QString &oldName, const QString
}
} // namespace TextEditor
#include "textmark.moc"

View File

@@ -45,8 +45,6 @@ namespace TextEditor {
class BaseTextEditor;
class TextDocument;
namespace Internal { class TextMarkRegistry; }
class TEXTEDITOR_EXPORT TextMark
{
public:
@@ -102,7 +100,6 @@ public:
private:
Q_DISABLE_COPY(TextMark)
friend class Internal::TextMarkRegistry;
TextDocument *m_baseTextDocument;
QString m_fileName;

View File

@@ -1,71 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <utils/fileutils.h>
#include <QColor>
#include <QHash>
#include <QObject>
#include <QSet>
#include <coreplugin/id.h>
#include <utils/theme/theme.h>
namespace Core {
class IEditor;
class IDocument;
}
namespace TextEditor {
class TextMark;
namespace Internal {
class TextMarkRegistry : public QObject
{
Q_OBJECT
public:
TextMarkRegistry(QObject *parent);
void add(TextMark *mark);
bool remove(TextMark *mark);
Utils::Theme::Color categoryColor(Core::Id category);
bool categoryHasColor(Core::Id category);
void setCategoryColor(Core::Id category, Utils::Theme::Color color);
QString defaultToolTip(Core::Id category) const;
void setDefaultToolTip(Core::Id category, const QString &toolTip);
private:
void editorOpened(Core::IEditor *editor);
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
void allDocumentsRenamed(const QString &oldName, const QString &newName);
QHash<Utils::FileName, QSet<TextMark *> > m_marks;
QHash<Core::Id, Utils::Theme::Color> m_colors;
QHash<Core::Id, QString> m_defaultToolTips;
};
} // namespace Internal
} // namespace TextEditor