aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/searchresultitem.cpp
blob: 2574473c9335cf676b42726c762e8f27c0bb72a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "searchresultitem.h"

namespace Utils {

SearchResultColor::SearchResultColor(const QColor &textBg, const QColor &textFg,
                                     const QColor &highlightBg, const QColor &highlightFg,
                                     const QColor &functionBg, const QColor &functionFg)
    : textBackground(textBg)
    , textForeground(textFg)
    , highlightBackground(highlightBg)
    , highlightForeground(highlightFg)
    , containingFunctionBackground(functionBg)
    , containingFunctionForeground(functionFg)
{
    if (!highlightBackground.isValid())
        highlightBackground = textBackground;
    if (!highlightForeground.isValid())
        highlightForeground = textForeground;
    if (!containingFunctionBackground.isValid())
        containingFunctionBackground = textBackground;
    if (!containingFunctionForeground.isValid())
        containingFunctionForeground = textForeground;
}

static QString displayText(const QString &line)
{
    QString result = line;
    auto end = result.end();
    for (auto it = result.begin(); it != end; ++it) {
        if (!it->isSpace() && !it->isPrint())
            *it = QChar('?');
    }
    return result;
}

void SearchResultItem::setDisplayText(const QString &text)
{
    setLineText(displayText(text));
}

void SearchResultItem::setMainRange(int line, int column, int length)
{
    m_mainRange = {{line, column}, {line, column + length}};
}

QTCREATOR_UTILS_EXPORT size_t qHash(SearchResultColor::Style style, uint seed)
{
    int a = int(style);
    return ::qHash(a, seed);
}

bool SearchResultItem::operator==(const SearchResultItem &other) const
{
    return m_path == other.m_path && m_lineText == other.m_lineText
        && m_userData == other.m_userData && m_mainRange == other.m_mainRange
        && m_useTextEditorFont == other.m_useTextEditorFont
        && m_selectForReplacement == other.m_selectForReplacement && m_style == other.m_style
        && m_containingFunctionName == other.m_containingFunctionName;
}

} // namespace Utils