aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2020-01-03 14:43:35 +0100
committerDavid Schulz <david.schulz@qt.io>2020-01-07 19:02:12 +0000
commit67db5cb2de25d5e5290b04fa6b6677b605562f58 (patch)
treecf4dcab8d180fd6a90fddc504a36a09a31f8ef6c /src/plugins
parentff61ed69d39dcfe9ffffb5a3b263c32f834f9ec5 (diff)
Editor: Use optional for text mark color
instead of an additional hasColor member Change-Id: I658401bb91374b10420e070625cf61049cb3cc64 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/texteditor/texteditor.cpp9
-rw-r--r--src/plugins/texteditor/textmark.cpp9
-rw-r--r--src/plugins/texteditor/textmark.h7
3 files changed, 13 insertions, 12 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index f47b30b847c..35281ae54d2 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -6364,7 +6364,9 @@ void TextEditorWidgetPrivate::addSearchResultsToScrollBar(QVector<SearchResult>
Highlight markToHighlight(TextMark *mark, int lineNumber)
{
- return Highlight(mark->category(), lineNumber, mark->color(),
+ return Highlight(mark->category(),
+ lineNumber,
+ mark->color().value_or(Utils::Theme::TextColorNormal),
textMarkPrioToScrollBarPrio(mark->priority()));
}
@@ -6382,8 +6384,9 @@ void TextEditorWidgetPrivate::updateHighlightScrollBarNow()
addSearchResultsToScrollBar(m_searchResults);
// update text marks
- foreach (TextMark *mark, m_document->marks()) {
- if (!mark->isVisible() || !mark->hasColor())
+ const TextMarks marks = m_document->marks();
+ for (TextMark *mark : marks) {
+ if (!mark->isVisible() || !mark->color().has_value())
continue;
const QTextBlock &block = q->document()->findBlockByNumber(mark->lineNumber() - 1);
if (block.isVisible())
diff --git a/src/plugins/texteditor/textmark.cpp b/src/plugins/texteditor/textmark.cpp
index 693b4ccdc55..47e5f54f761 100644
--- a/src/plugins/texteditor/textmark.cpp
+++ b/src/plugins/texteditor/textmark.cpp
@@ -136,8 +136,9 @@ void TextMark::paintAnnotation(QPainter &painter, QRectF *annotationRect,
const AnnotationRects &rects = annotationRects(*annotationRect, painter.fontMetrics(),
fadeInOffset, fadeOutOffset);
- const QColor &markColor = m_hasColor ? Utils::creatorTheme()->color(m_color).toHsl()
- : painter.pen().color();
+ const QColor &markColor = m_color.has_value()
+ ? Utils::creatorTheme()->color(m_color.value()).toHsl()
+ : painter.pen().color();
const AnnotationColors &colors = AnnotationColors::getAnnotationColors(
markColor, painter.background().color());
@@ -327,15 +328,13 @@ bool TextMark::addToolTipContent(QLayout *target) const
return true;
}
-Theme::Color TextMark::color() const
+Utils::optional<Theme::Color> TextMark::color() const
{
- QTC_CHECK(m_hasColor);
return m_color;
}
void TextMark::setColor(const Theme::Color &color)
{
- m_hasColor = true;
m_color = color;
}
diff --git a/src/plugins/texteditor/textmark.h b/src/plugins/texteditor/textmark.h
index 2d049cbacc1..d8f0e3f7406 100644
--- a/src/plugins/texteditor/textmark.h
+++ b/src/plugins/texteditor/textmark.h
@@ -30,6 +30,7 @@
#include <coreplugin/id.h>
#include <utils/theme/theme.h>
#include <utils/fileutils.h>
+#include <utils/optional.h>
#include <QIcon>
#include <QVector>
@@ -108,9 +109,8 @@ public:
double widthFactor() const;
void setWidthFactor(double factor);
- Utils::Theme::Color color() const;
+ Utils::optional<Utils::Theme::Color> color() const;
void setColor(const Utils::Theme::Color &color);
- bool hasColor() const { return m_hasColor; }
QString defaultToolTip() const { return m_defaultToolTip; }
void setDefaultToolTip(const QString &toolTip) { m_defaultToolTip = toolTip; }
@@ -135,9 +135,8 @@ private:
int m_lineNumber = 0;
Priority m_priority = LowPriority;
QIcon m_icon;
- Utils::Theme::Color m_color = Utils::Theme::TextColorNormal;
+ Utils::optional<Utils::Theme::Color> m_color;
bool m_visible = false;
- bool m_hasColor = false;
Core::Id m_category;
double m_widthFactor = 1.0;
QString m_lineAnnotation;