KPeople

match.cpp
1/*
2 KPeople - Duplicates
3 SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "match_p.h"
9#include <KLocalizedString>
10
11using namespace KPeople;
12
13Match::Match(const QList<MatchReason> &reasons, const QPersistentModelIndex &a, const QPersistentModelIndex &b)
14 : reasons(reasons)
15 , indexA(a)
16 , indexB(b)
17{
18 if (indexB < indexA) {
19 qSwap(indexA, indexB);
20 }
21}
22
23bool Match::operator==(const Match &m) const
24{
25 /* clang-format off */
26 return reasons == m.reasons
27 && indexA == m.indexA
28 && indexB == m.indexB;
29 /* clang-format on */
30}
31
32bool Match::operator<(const Match &m) const
33{
34 /* clang-format off */
35 return indexA < m.indexA
36 || (indexA == m.indexA && indexB < m.indexB);
37 /* clang-format on */
38}
39
40QStringList Match::matchReasons() const
41{
42 QStringList ret;
43 for (MatchReason r : reasons) {
44 switch (r) {
45 case NameMatch:
46 ret += i18nc("@title:column", "Name");
47 break;
48 case EmailMatch:
49 ret += i18nc("@title:column", "E-mail");
50 break;
51 }
52 }
53 return ret;
54}
55
56QString Match::matchValue(MatchReason r, const AbstractContact::Ptr &addr)
57{
58 switch (r) {
59 case NameMatch:
60 return addr->customProperty(AbstractContact::NameProperty).toString();
61 case EmailMatch:
62 return addr->customProperty(AbstractContact::EmailProperty).toString();
63 }
64 Q_UNREACHABLE();
65}
66
67QList<Match::MatchReason> Match::matchAt(const AbstractContact::Ptr &value, const AbstractContact::Ptr &toCompare)
68{
70
71 QVariant name = value->customProperty(AbstractContact::NameProperty);
72 if (name.isValid() && name == toCompare->customProperty(AbstractContact::NameProperty)) {
73 ret.append(Match::NameMatch);
74 }
75
76 return ret;
77}
78
79#include "moc_match_p.cpp"
static const QString NameProperty
String property representing the display name of the contact.
static const QString EmailProperty
String property representing the preferred name of the contact.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString name(StandardShortcut id)
void append(QList< T > &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.