forked from qt-creator/qt-creator
Editor: Simplify text marks
Moving defaultToolTip and color from TextMarkRegistry to TextMark. Allowing every instance of a TextMark object to define these information. Change-Id: Iec1794372cf902b34d343402074e3999e7f9faf7 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
#include "bookmarkmanager.h"
|
||||
#include "bookmarks_global.h"
|
||||
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QTextBlock>
|
||||
|
||||
@@ -36,8 +39,10 @@ Bookmark::Bookmark(int lineNumber, BookmarkManager *manager) :
|
||||
TextMark(QString(), lineNumber, Constants::BOOKMARKS_TEXT_MARK_CATEGORY),
|
||||
m_manager(manager)
|
||||
{
|
||||
setColor(Utils::Theme::Bookmarks_TextMarkColor);
|
||||
setIcon(Utils::Icons::BOOKMARK_TEXTEDITOR.icon());
|
||||
setDefaultToolTip(QApplication::translate("BookmarkManager", "Bookmark"));
|
||||
setPriority(TextEditor::TextMark::NormalPriority);
|
||||
setIcon(m_manager->bookmarkIcon());
|
||||
}
|
||||
|
||||
void Bookmark::removedFromEditor()
|
||||
|
@@ -320,7 +320,6 @@ void BookmarkView::gotoBookmark(const QModelIndex &index)
|
||||
////
|
||||
|
||||
BookmarkManager::BookmarkManager() :
|
||||
m_bookmarkIcon(Utils::Icons::BOOKMARK_TEXTEDITOR.pixmap()),
|
||||
m_selectionModel(new QItemSelectionModel(this, this))
|
||||
{
|
||||
connect(ICore::instance(), &ICore::contextChanged,
|
||||
@@ -330,9 +329,6 @@ BookmarkManager::BookmarkManager() :
|
||||
this, &BookmarkManager::loadBookmarks);
|
||||
|
||||
updateActionStatus();
|
||||
Bookmark::setCategoryColor(Constants::BOOKMARKS_TEXT_MARK_CATEGORY,
|
||||
Theme::Bookmarks_TextMarkColor);
|
||||
Bookmark::setDefaultToolTip(Constants::BOOKMARKS_TEXT_MARK_CATEGORY, tr("Bookmark"));
|
||||
}
|
||||
|
||||
BookmarkManager::~BookmarkManager()
|
||||
|
@@ -52,8 +52,6 @@ public:
|
||||
BookmarkManager();
|
||||
~BookmarkManager();
|
||||
|
||||
QIcon bookmarkIcon() const { return m_bookmarkIcon; }
|
||||
|
||||
void updateBookmark(Bookmark *bookmark);
|
||||
void updateBookmarkFileName(Bookmark *bookmark, const QString &oldFileName);
|
||||
void deleteBookmark(Bookmark *bookmark); // Does not remove the mark
|
||||
@@ -122,8 +120,6 @@ private:
|
||||
|
||||
DirectoryFileBookmarksMap m_bookmarksMap;
|
||||
|
||||
const QIcon m_bookmarkIcon;
|
||||
|
||||
QList<Bookmark *> m_bookmarksList;
|
||||
QItemSelectionModel *m_selectionModel;
|
||||
};
|
||||
|
@@ -46,20 +46,6 @@ namespace Internal {
|
||||
|
||||
namespace {
|
||||
|
||||
void initializeTextMarks()
|
||||
{
|
||||
TextEditor::TextMark::setCategoryColor(Core::Id(Constants::CLANG_WARNING),
|
||||
Utils::Theme::ClangCodeModel_Warning_TextMarkColor);
|
||||
TextEditor::TextMark::setCategoryColor(Core::Id(Constants::CLANG_ERROR),
|
||||
Utils::Theme::ClangCodeModel_Error_TextMarkColor);
|
||||
TextEditor::TextMark::setDefaultToolTip(Core::Id(Constants::CLANG_WARNING),
|
||||
QApplication::translate("Clang Code Model Marks",
|
||||
"Code Model Warning"));
|
||||
TextEditor::TextMark::setDefaultToolTip(Core::Id(Constants::CLANG_ERROR),
|
||||
QApplication::translate("Clang Code Model Marks",
|
||||
"Code Model Error"));
|
||||
}
|
||||
|
||||
void addProjectPanelWidget()
|
||||
{
|
||||
auto panelFactory = new ProjectExplorer::ProjectPanelFactory();
|
||||
@@ -85,7 +71,6 @@ bool ClangCodeModelPlugin::initialize(const QStringList &arguments, QString *err
|
||||
|
||||
CppTools::CppModelManager::instance()->activateClangCodeModel(&m_modelManagerSupportProvider);
|
||||
|
||||
initializeTextMarks();
|
||||
addProjectPanelWidget();
|
||||
|
||||
return true;
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLayout>
|
||||
#include <QString>
|
||||
|
||||
@@ -70,7 +71,13 @@ ClangTextMark::ClangTextMark(const QString &fileName,
|
||||
, m_diagnostic(diagnostic)
|
||||
, m_removedFromEditorHandler(removedHandler)
|
||||
{
|
||||
setPriority(TextEditor::TextMark::HighPriority);
|
||||
const bool warning = isWarningOrNote(diagnostic.severity());
|
||||
setColor(warning ? Utils::Theme::ClangCodeModel_Warning_TextMarkColor
|
||||
: Utils::Theme::ClangCodeModel_Error_TextMarkColor);
|
||||
setDefaultToolTip(warning ? QApplication::translate("Clang Code Model Marks", "Code Model Warning")
|
||||
: QApplication::translate("Clang Code Model Marks", "Code Model Error"));
|
||||
setPriority(warning ? TextEditor::TextMark::NormalPriority
|
||||
: TextEditor::TextMark::HighPriority);
|
||||
setIcon(diagnostic.severity());
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,6 @@ public:
|
||||
|
||||
private:
|
||||
void setIcon(ClangBackEnd::DiagnosticSeverity severity);
|
||||
|
||||
bool addToolTipContent(QLayout *target) override;
|
||||
void removedFromEditor() override;
|
||||
|
||||
|
@@ -55,6 +55,7 @@
|
||||
#include <modeltest.h>
|
||||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTimerEvent>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
@@ -156,8 +157,10 @@ public:
|
||||
BreakpointMarker(BreakpointItem *b, const QString &fileName, int lineNumber)
|
||||
: TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY_BREAKPOINT), m_bp(b)
|
||||
{
|
||||
setIcon(b->icon());
|
||||
setColor(Theme::Debugger_Breakpoint_TextMarkColor);
|
||||
setDefaultToolTip(QApplication::translate("BreakHandler", "Breakpoint"));
|
||||
setPriority(TextEditor::TextMark::NormalPriority);
|
||||
setIcon(b->icon());
|
||||
}
|
||||
|
||||
void removedFromEditor()
|
||||
@@ -894,10 +897,6 @@ BreakHandler::BreakHandler()
|
||||
: m_syncTimerId(-1)
|
||||
{
|
||||
qRegisterMetaType<BreakpointModelId>();
|
||||
TextEditor::TextMark::setCategoryColor(Constants::TEXT_MARK_CATEGORY_BREAKPOINT,
|
||||
Theme::Debugger_Breakpoint_TextMarkColor);
|
||||
TextEditor::TextMark::setDefaultToolTip(Constants::TEXT_MARK_CATEGORY_BREAKPOINT,
|
||||
tr("Breakpoint"));
|
||||
|
||||
#if USE_BREAK_MODEL_TEST
|
||||
new ModelTest(this, 0);
|
||||
|
@@ -30,6 +30,9 @@
|
||||
#include <coreplugin/ioutputpane.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
@@ -60,6 +63,12 @@ public:
|
||||
TextMark(fileName, lineNumber, categoryForType(type)),
|
||||
m_id(id)
|
||||
{
|
||||
setColor(type == Task::Error ? Utils::Theme::ProjectExplorer_TaskError_TextMarkColor
|
||||
: Utils::Theme::ProjectExplorer_TaskWarn_TextMarkColor);
|
||||
setDefaultToolTip(type == Task::Error ? QApplication::translate("TaskHub", "Error")
|
||||
: QApplication::translate("TaskHub", "Warning"));
|
||||
setPriority(type == Task::Error ? TextEditor::TextMark::NormalPriority
|
||||
: TextEditor::TextMark::LowPriority);
|
||||
setVisible(visible);
|
||||
}
|
||||
|
||||
@@ -105,12 +114,6 @@ TaskHub::TaskHub()
|
||||
m_instance = this;
|
||||
qRegisterMetaType<ProjectExplorer::Task>("ProjectExplorer::Task");
|
||||
qRegisterMetaType<QList<ProjectExplorer::Task> >("QList<ProjectExplorer::Task>");
|
||||
TaskMark::setCategoryColor(TASK_MARK_ERROR,
|
||||
Utils::Theme::ProjectExplorer_TaskError_TextMarkColor);
|
||||
TaskMark::setCategoryColor(TASK_MARK_WARNING,
|
||||
Utils::Theme::ProjectExplorer_TaskWarn_TextMarkColor);
|
||||
TaskMark::setDefaultToolTip(TASK_MARK_ERROR, tr("Error"));
|
||||
TaskMark::setDefaultToolTip(TASK_MARK_WARNING, tr("Warning"));
|
||||
}
|
||||
|
||||
TaskHub::~TaskHub()
|
||||
@@ -149,9 +152,8 @@ void TaskHub::addTask(Task task)
|
||||
|
||||
if (task.line != -1) {
|
||||
auto mark = new TaskMark(task.taskId, task.file.toString(), task.line, task.type, !task.icon.isNull());
|
||||
mark->setIcon(task.icon);
|
||||
mark->setPriority(TextEditor::TextMark::LowPriority);
|
||||
mark->setToolTip(task.description);
|
||||
mark->setIcon(task.icon);
|
||||
task.setMark(mark);
|
||||
}
|
||||
emit m_instance->taskAdded(task);
|
||||
|
@@ -5771,8 +5771,7 @@ void TextEditorWidgetPrivate::addSearchResultsToScrollBar(QVector<SearchResult>
|
||||
|
||||
Highlight markToHighlight(TextMark *mark, int lineNumber)
|
||||
{
|
||||
return Highlight(mark->category(), lineNumber,
|
||||
TextMark::categoryColor(mark->category()),
|
||||
return Highlight(mark->category(), lineNumber, mark->color(),
|
||||
textMarkPrioToScrollBarPrio(mark->priority()));
|
||||
}
|
||||
|
||||
@@ -5791,8 +5790,7 @@ void TextEditorWidgetPrivate::updateHighlightScrollBarNow()
|
||||
|
||||
// update text marks
|
||||
foreach (TextMark *mark, m_document->marks()) {
|
||||
Id category = mark->category();
|
||||
if (!mark->isVisible() || !TextMark::categoryHasColor(category))
|
||||
if (!mark->isVisible() || !mark->hasColor())
|
||||
continue;
|
||||
const QTextBlock &block = q->document()->findBlockByNumber(mark->lineNumber() - 1);
|
||||
if (block.isVisible())
|
||||
|
@@ -46,11 +46,6 @@ class TextMarkRegistry : public QObject
|
||||
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);
|
||||
@@ -60,20 +55,16 @@ private:
|
||||
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),
|
||||
m_lineNumber(lineNumber),
|
||||
m_priority(NormalPriority),
|
||||
m_visible(true),
|
||||
m_category(category),
|
||||
m_widthFactor(widthFactor)
|
||||
: m_fileName(fileName)
|
||||
, m_lineNumber(lineNumber)
|
||||
, m_visible(true)
|
||||
, m_category(category)
|
||||
, m_widthFactor(widthFactor)
|
||||
{
|
||||
if (!m_fileName.isEmpty())
|
||||
TextMarkRegistry::add(this);
|
||||
@@ -134,52 +125,12 @@ void TextMark::updateBlock(const QTextBlock &)
|
||||
void TextMark::removedFromEditor()
|
||||
{}
|
||||
|
||||
void TextMark::setIcon(const QIcon &icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
const QIcon &TextMark::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
Theme::Color TextMark::categoryColor(Id category)
|
||||
{
|
||||
return TextMarkRegistry::categoryColor(category);
|
||||
}
|
||||
|
||||
bool TextMark::categoryHasColor(Id category)
|
||||
{
|
||||
return TextMarkRegistry::categoryHasColor(category);
|
||||
}
|
||||
|
||||
void TextMark::setCategoryColor(Id category, Theme::Color color)
|
||||
{
|
||||
TextMarkRegistry::setCategoryColor(category, color);
|
||||
}
|
||||
|
||||
void TextMark::setDefaultToolTip(Id category, const QString &toolTip)
|
||||
{
|
||||
TextMarkRegistry::setDefaultToolTip(category, toolTip);
|
||||
}
|
||||
|
||||
void TextMark::updateMarker()
|
||||
{
|
||||
if (m_baseTextDocument)
|
||||
m_baseTextDocument->updateMark(this);
|
||||
}
|
||||
|
||||
void TextMark::setPriority(Priority priority)
|
||||
{
|
||||
m_priority = priority;
|
||||
}
|
||||
|
||||
TextMark::Priority TextMark::priority() const
|
||||
{
|
||||
return m_priority;
|
||||
}
|
||||
|
||||
bool TextMark::isVisible() const
|
||||
{
|
||||
return m_visible;
|
||||
@@ -192,11 +143,6 @@ void TextMark::setVisible(bool visible)
|
||||
m_baseTextDocument->updateMark(this);
|
||||
}
|
||||
|
||||
Id TextMark::category() const
|
||||
{
|
||||
return m_category;
|
||||
}
|
||||
|
||||
double TextMark::widthFactor() const
|
||||
{
|
||||
return m_widthFactor;
|
||||
@@ -244,7 +190,7 @@ bool TextMark::addToolTipContent(QLayout *target)
|
||||
{
|
||||
QString text = m_toolTip;
|
||||
if (text.isEmpty()) {
|
||||
text = TextMarkRegistry::defaultToolTip(m_category);
|
||||
text = m_defaultToolTip;
|
||||
if (text.isEmpty())
|
||||
return false;
|
||||
}
|
||||
@@ -258,24 +204,16 @@ bool TextMark::addToolTipContent(QLayout *target)
|
||||
return true;
|
||||
}
|
||||
|
||||
TextDocument *TextMark::baseTextDocument() const
|
||||
Theme::Color TextMark::color() const
|
||||
{
|
||||
return m_baseTextDocument;
|
||||
QTC_CHECK(m_hasColor);
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void TextMark::setBaseTextDocument(TextDocument *baseTextDocument)
|
||||
void TextMark::setColor(const Theme::Color &color)
|
||||
{
|
||||
m_baseTextDocument = baseTextDocument;
|
||||
}
|
||||
|
||||
QString TextMark::toolTip() const
|
||||
{
|
||||
return m_toolTip;
|
||||
}
|
||||
|
||||
void TextMark::setToolTip(const QString &toolTip)
|
||||
{
|
||||
m_toolTip = toolTip;
|
||||
m_hasColor = true;
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
TextMarkRegistry::TextMarkRegistry(QObject *parent)
|
||||
@@ -304,37 +242,6 @@ bool TextMarkRegistry::remove(TextMark *mark)
|
||||
return instance()->m_marks[FileName::fromString(mark->fileName())].remove(mark);
|
||||
}
|
||||
|
||||
Theme::Color TextMarkRegistry::categoryColor(Id category)
|
||||
{
|
||||
return instance()->m_colors.value(category, Theme::ProjectExplorer_TaskWarn_TextMarkColor);
|
||||
}
|
||||
|
||||
bool TextMarkRegistry::categoryHasColor(Id category)
|
||||
{
|
||||
return instance()->m_colors.contains(category);
|
||||
}
|
||||
|
||||
void TextMarkRegistry::setCategoryColor(Id category, Theme::Color newColor)
|
||||
{
|
||||
Theme::Color &color = instance()->m_colors[category];
|
||||
if (color == newColor)
|
||||
return;
|
||||
color = newColor;
|
||||
}
|
||||
|
||||
QString TextMarkRegistry::defaultToolTip(Id category)
|
||||
{
|
||||
return instance()->m_defaultToolTips[category];
|
||||
}
|
||||
|
||||
void TextMarkRegistry::setDefaultToolTip(Id category, const QString &toolTip)
|
||||
{
|
||||
QString &defaultToolTip = instance()->m_defaultToolTips[category];
|
||||
if (defaultToolTip == toolTip)
|
||||
return;
|
||||
defaultToolTip = toolTip;
|
||||
}
|
||||
|
||||
TextMarkRegistry *TextMarkRegistry::instance()
|
||||
{
|
||||
if (!m_instance)
|
||||
|
@@ -49,6 +49,7 @@ class TEXTEDITOR_EXPORT TextMark
|
||||
{
|
||||
public:
|
||||
TextMark(const QString &fileName, int lineNumber, Core::Id category, double widthFactor = 1.0);
|
||||
TextMark() = delete;
|
||||
virtual ~TextMark();
|
||||
|
||||
// determine order on markers on the same line.
|
||||
@@ -76,41 +77,46 @@ public:
|
||||
void addToToolTipLayout(QGridLayout *target);
|
||||
virtual bool addToolTipContent(QLayout *target);
|
||||
|
||||
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 void setDefaultToolTip(Core::Id category, const QString &toolTip);
|
||||
void setIcon(const QIcon &icon);
|
||||
const QIcon &icon() const;
|
||||
void setIcon(const QIcon &icon) { m_icon = icon; }
|
||||
const QIcon &icon() const { return m_icon; }
|
||||
// call this if the icon has changed.
|
||||
void updateMarker();
|
||||
Priority priority() const;
|
||||
void setPriority(Priority prioriy);
|
||||
Priority priority() const { return m_priority;}
|
||||
void setPriority(Priority prioriy) { m_priority = prioriy; }
|
||||
bool isVisible() const;
|
||||
void setVisible(bool isVisible);
|
||||
Core::Id category() const;
|
||||
Core::Id category() const { return m_category; }
|
||||
double widthFactor() const;
|
||||
void setWidthFactor(double factor);
|
||||
|
||||
TextDocument *baseTextDocument() const;
|
||||
void setBaseTextDocument(TextDocument *baseTextDocument);
|
||||
Utils::Theme::Color color() const;
|
||||
void setColor(const Utils::Theme::Color &color);
|
||||
bool hasColor() const { return m_hasColor; }
|
||||
|
||||
QString toolTip() const;
|
||||
void setToolTip(const QString &toolTip);
|
||||
QString defaultToolTip() const { return m_defaultToolTip; }
|
||||
void setDefaultToolTip(const QString &toolTip) { m_defaultToolTip = toolTip; }
|
||||
|
||||
TextDocument *baseTextDocument() const { return m_baseTextDocument; }
|
||||
void setBaseTextDocument(TextDocument *baseTextDocument) { m_baseTextDocument = baseTextDocument; }
|
||||
|
||||
QString toolTip() const { return m_toolTip; }
|
||||
void setToolTip(const QString &toolTip) { m_toolTip = toolTip; }
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(TextMark)
|
||||
|
||||
TextDocument *m_baseTextDocument;
|
||||
TextDocument *m_baseTextDocument = nullptr;
|
||||
QString m_fileName;
|
||||
int m_lineNumber;
|
||||
Priority m_priority;
|
||||
bool m_visible;
|
||||
int m_lineNumber = 0;
|
||||
Priority m_priority = LowPriority;
|
||||
bool m_visible = false;
|
||||
QIcon m_icon;
|
||||
QColor m_color;
|
||||
Utils::Theme::Color m_color;
|
||||
bool m_hasColor = false;
|
||||
Core::Id m_category;
|
||||
double m_widthFactor;
|
||||
double m_widthFactor = 1.0;
|
||||
QString m_toolTip;
|
||||
QString m_defaultToolTip;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
|
Reference in New Issue
Block a user