KCompletion

kcompletionmatches.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1999, 2000, 2001 Carsten Pfeiffer <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "kcompletionmatches.h"
9 
10 #include <kcompletion.h>
11 #include <kcompletion_p.h> // for KCompletionMatchesWrapper
12 
13 class KCompletionMatchesPrivate
14 {
15 public:
16  KCompletionMatchesPrivate(bool sort, KCompletionMatches *parent)
17  : sorting(sort)
18  , q_ptr(parent)
19  {
20  }
21 
22  bool sorting;
23  KCompletionMatches *const q_ptr;
24 
25  Q_DECLARE_PUBLIC(KCompletionMatches)
26 };
27 
29  : KSortableList<QString, int>()
30  , d_ptr(new KCompletionMatchesPrivate(o.sorting(), this))
31 {
33 }
34 
36 {
38  if (*this == o) {
39  return *this;
40  }
42  d->sorting = o.sorting();
43 
44  return *this;
45 }
46 
48  : d_ptr(new KCompletionMatchesPrivate(sort_P, this))
49 {
50 }
51 
52 KCompletionMatches::KCompletionMatches(const KCompletionMatchesWrapper &matches)
53  : d_ptr(new KCompletionMatchesPrivate(matches.sorting(), this))
54 {
55  if (matches.m_sortedList != nullptr) {
56  KCompletionMatchesList::operator=(*matches.m_sortedList);
57  } else {
58  const QStringList l = matches.list();
59  for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
61  }
62  }
63 }
64 
66 {
67 }
68 
70 {
71  Q_D(const KCompletionMatches);
72  if (d->sorting && sort_P) {
73  const_cast<KCompletionMatches *>(this)->sort();
74  }
75  QStringList stringList;
76  // high weight == sorted last -> reverse the sorting here
77  for (ConstIterator it = begin(); it != end(); ++it) {
78  stringList.prepend((*it).value());
79  }
80  return stringList;
81 }
82 
84 {
85  Q_D(const KCompletionMatches);
86  return d->sorting;
87 }
88 
90 {
91  Iterator it1;
92  Iterator it2;
93  for (it1 = begin(); it1 != end(); ++it1) {
94  for ((it2 = it1), ++it2; it2 != end();) {
95  if ((*it1).value() == (*it2).value()) {
96  // use the max height
97  (*it1).first = qMax((*it1).key(), (*it2).key());
98  it2 = erase(it2);
99  continue;
100  }
101  ++it2;
102  }
103  }
104 }
QStringList list(bool sort=true) const
Returns the matches as a QStringList.
void prepend(const T &value)
List for keeping matches returned from KCompletion.
QList< T > & operator=(const QList< T > &other)
void sort()
Sorts the KSortableItems.
typedef ConstIterator
QList::iterator erase(QList::iterator pos)
KCompletionMatches & operator=(const KCompletionMatches &)
assignment operator.
~KCompletionMatches()
default destructor.
KCompletionMatches(bool sort)
Default constructor.
QList::iterator begin()
QList::iterator end()
bool sorting() const
If sorting() returns false, the matches aren't sorted by their weight, even if true is passed to list...
void removeDuplicates()
Removes duplicate matches.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Jun 26 2022 04:11:17 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.