KPeople

match.cpp
1 /*
2  KPeople - Duplicates
3  SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7 
8 #include "match_p.h"
9 #include <KLocalizedString>
10 
11 using namespace KPeople;
12 
13 Match::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 
23 bool 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 
32 bool 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 
40 QStringList 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 
56 QString 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 
67 QList<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"
const QLatin1String name
static const QString NameProperty
String property representing the display name of the contact.
void append(const T &value)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool isValid() const const
static const QString EmailProperty
String property representing the preferred name of the contact.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jan 27 2022 22:42:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.