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  bool sorting;
21  KCompletionMatches * const q_ptr;
22 
23  Q_DECLARE_PUBLIC(KCompletionMatches)
24 };
25 
27  : KSortableList<QString, int>(),
28  d_ptr(new KCompletionMatchesPrivate(o.sorting(), this))
29 {
31 }
32 
34 {
35  Q_D(KCompletionMatches);
36  if (*this == o) {
37  return *this;
38  }
40  d->sorting = o.sorting();
41 
42  return *this;
43 }
44 
46  : d_ptr(new KCompletionMatchesPrivate(sort_P, this))
47 {
48 }
49 
50 KCompletionMatches::KCompletionMatches(const KCompletionMatchesWrapper &matches)
51  : d_ptr(new KCompletionMatchesPrivate(matches.sorting(), this))
52 {
53  if (matches.m_sortedList != nullptr) {
54  KCompletionMatchesList::operator=(*matches.m_sortedList);
55  } else {
56  const QStringList l = matches.list();
57  for (QStringList::ConstIterator it = l.begin();
58  it != l.end();
59  ++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, it2;
92  for (it1 = begin(); it1 != end(); ++it1) {
93  for ((it2 = it1), ++it2; it2 != end();) {
94  if ((*it1).value() == (*it2).value()) {
95  // use the max height
96  (*it1).first = qMax((*it1).key(), (*it2).key());
97  it2 = erase(it2);
98  continue;
99  }
100  ++it2;
101  }
102  }
103 }
QStringList list(bool sort=true) const
Returns the matches as a QStringList.
QList< T > & operator=(const QList< T > &other)
KSortableItem is a QPair that provides several operators for sorting.
Definition: ksortablelist.h:24
KCompletionMatches & operator=(const KCompletionMatches &)
assignment operator.
void sort()
Sorts the KSortableItems.
QList::iterator erase(QList::iterator pos)
void removeDuplicates()
Removes duplicate matches.
bool sorting() const
If sorting() returns false, the matches aren&#39;t sorted by their weight, even if true is passed to list...
This structure is returned by KCompletion::allWeightedMatches().
~KCompletionMatches()
default destructor.
QList::iterator end()
KSortableList is a QList which associates a key with each item in the list.
typedef ConstIterator
void prepend(const T &value)
QList::iterator begin()
KCompletionMatches(bool sort)
Default constructor.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 10 2020 22:55:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.