KCompletion

kcompletion.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 "kcompletion.h"
9 #include "kcompletion_p.h"
10 #include <kcompletion_debug.h>
11 
12 #include <QCollator>
13 
14 void KCompletionPrivate::init()
15 {
16  completionMode = KCompletion::CompletionPopup;
17  treeNodeAllocator = KCompTreeNode::allocator(); // keep strong-ref to allocator instance
18  treeRoot = new KCompTreeNode;
19  beep = true;
20  ignoreCase = false;
21  hasMultipleMatches = false;
22  rotationIndex = 0;
23 }
24 
25 void KCompletionPrivate::addWeightedItem(const QString &item)
26 {
27  Q_Q(KCompletion);
28  if (order != KCompletion::Weighted) {
29  q->addItem(item, 0);
30  return;
31  }
32 
33  int len = item.length();
34  uint weight = 0;
35 
36  // find out the weighting of this item (appended to the string as ":num")
37  int index = item.lastIndexOf(QLatin1Char(':'));
38  if (index > 0) {
39  bool ok;
40  weight = item.midRef(index + 1).toUInt(&ok);
41  if (!ok) {
42  weight = 0;
43  }
44 
45  len = index; // only insert until the ':'
46  }
47 
48  q->addItem(item.left(len), weight);
49  return;
50 }
51 
52 // tries to complete "string" from the tree-root
53 QString KCompletionPrivate::findCompletion(const QString &string)
54 {
55  QChar ch;
57  const KCompTreeNode *node = treeRoot;
58 
59  // start at the tree-root and try to find the search-string
60  for (int i = 0; i < string.length(); i++) {
61  ch = string.at(i);
62  node = node->find(ch);
63 
64  if (node) {
65  completion += ch;
66  } else {
67  return QString(); // no completion
68  }
69  }
70 
71  // Now we have the last node of the to be completed string.
72  // Follow it as long as it has exactly one child (= longest possible
73  // completion)
74 
75  while (node->childrenCount() == 1) {
76  node = node->firstChild();
77  if (!node->isNull()) {
78  completion += *node;
79  }
80  }
81  // if multiple matches and auto-completion mode
82  // -> find the first complete match
83  if (node && node->childrenCount() > 1) {
84  hasMultipleMatches = true;
85 
86  if (completionMode == KCompletion::CompletionAuto) {
87  rotationIndex = 1;
88  if (order != KCompletion::Weighted) {
89  while ((node = node->firstChild())) {
90  if (!node->isNull()) {
91  completion += *node;
92  } else {
93  break;
94  }
95  }
96  } else {
97  // don't just find the "first" match, but the one with the
98  // highest priority
99 
100  const KCompTreeNode *temp_node = nullptr;
101  while (1) {
102  int count = node->childrenCount();
103  temp_node = node->firstChild();
104  uint weight = temp_node->weight();
105  const KCompTreeNode *hit = temp_node;
106  for (int i = 1; i < count; i++) {
107  temp_node = node->childAt(i);
108  if (temp_node->weight() > weight) {
109  hit = temp_node;
110  weight = hit->weight();
111  }
112  }
113  // 0x0 has the highest priority -> we have the best match
114  if (hit->isNull()) {
115  break;
116  }
117 
118  node = hit;
119  completion += *node;
120  }
121  }
122  }
123  }
124 
125  return completion;
126 }
127 
129  : d_ptr(new KCompletionPrivate(this))
130 {
131  Q_D(KCompletion);
132  d->init();
134 }
135 
137 {
138 }
139 
141 {
142  Q_D(KCompletion);
143  d->order = order;
144  d->matches.setSorting(order);
145 }
146 
148 {
149  Q_D(const KCompletion);
150  return d->order;
151 }
152 
154 {
155  Q_D(KCompletion);
156  d->ignoreCase = ignoreCase;
157 }
158 
159 bool KCompletion::ignoreCase() const
160 {
161  Q_D(const KCompletion);
162  return d->ignoreCase;
163 }
164 
165 void KCompletion::setItems(const QStringList &itemList)
166 {
167  clear();
168  insertItems(itemList);
169 }
170 
172 {
173  Q_D(KCompletion);
174  bool weighted = (d->order == Weighted);
176  if (weighted) { // determine weight
177  for (it = items.begin(); it != items.end(); ++it) {
178  d->addWeightedItem(*it);
179  }
180  } else {
181  for (it = items.begin(); it != items.end(); ++it) {
182  addItem(*it, 0);
183  }
184  }
185 }
186 
188 {
189  Q_D(const KCompletion);
190  KCompletionMatchesWrapper list; // unsorted
191  bool addWeight = (d->order == Weighted);
192  list.extractStringsFromNode(d->treeRoot, QString(), addWeight);
193 
194  return list.list();
195 }
196 
198 {
199  Q_D(const KCompletion);
200  return (d->treeRoot->childrenCount() == 0);
201 }
202 
204 {
205 }
206 
208 {
209 }
210 
212 {
213 }
214 
215 void KCompletion::addItem(const QString &item)
216 {
217  Q_D(KCompletion);
218  d->matches.clear();
219  d->rotationIndex = 0;
220  d->lastString.clear();
221 
222  addItem(item, 0);
223 }
224 
225 void KCompletion::addItem(const QString &item, uint weight)
226 {
227  Q_D(KCompletion);
228  if (item.isEmpty()) {
229  return;
230  }
231 
232  KCompTreeNode *node = d->treeRoot;
233  int len = item.length();
234 
235  bool sorted = (d->order == Sorted);
236  bool weighted = ((d->order == Weighted) && weight > 1);
237 
238  // knowing the weight of an item, we simply add this weight to all of its
239  // nodes.
240 
241  for (int i = 0; i < len; i++) {
242  node = node->insert(item.at(i), sorted);
243  if (weighted) {
244  node->confirm(weight - 1); // node->insert() sets weighting to 1
245  }
246  }
247 
248  // add 0x0-item as delimiter with evtl. weight
249  node = node->insert(0x0, true);
250  if (weighted) {
251  node->confirm(weight - 1);
252  }
253 // qDebug("*** added: %s (%i)", item.toLatin1().constData(), node->weight());
254 }
255 
257 {
258  Q_D(KCompletion);
259  d->matches.clear();
260  d->rotationIndex = 0;
261  d->lastString.clear();
262 
263  d->treeRoot->remove(item);
264 }
265 
267 {
268  Q_D(KCompletion);
269  d->matches.clear();
270  d->rotationIndex = 0;
271  d->lastString.clear();
272 
273  delete d->treeRoot;
274  d->treeRoot = new KCompTreeNode;
275 }
276 
278 {
279  Q_D(KCompletion);
280  if (d->completionMode == CompletionNone) {
281  return QString();
282  }
283 
284  //qDebug() << "KCompletion: completing: " << string;
285 
286  d->matches.clear();
287  d->rotationIndex = 0;
288  d->hasMultipleMatches = false;
289  d->lastMatch = d->currentMatch;
290 
291  // in Shell-completion-mode, emit all matches when we get the same
292  // complete-string twice
293  if (d->completionMode == CompletionShell &&
294  string == d->lastString) {
295  // Don't use d->matches since calling postProcessMatches()
296  // on d->matches here would interfere with call to
297  // postProcessMatch() during rotation
298 
299  d->matches.findAllCompletions(d->treeRoot, string, d->ignoreCase, d->hasMultipleMatches);
300  QStringList l = d->matches.list();
301  postProcessMatches(&l);
302  emit matches(l);
303 
304  return QString();
305  }
306 
307  QString completion;
308  // in case-insensitive popup mode, we search all completions at once
309  if (d->completionMode == CompletionPopup ||
310  d->completionMode == CompletionPopupAuto) {
311  d->matches.findAllCompletions(d->treeRoot, string, d->ignoreCase, d->hasMultipleMatches);
312  if (!d->matches.isEmpty()) {
313  completion = d->matches.first();
314  }
315  } else {
316  completion = d->findCompletion(string);
317  }
318 
319  if (d->hasMultipleMatches) {
320  emit multipleMatches();
321  }
322 
323  d->lastString = string;
324  d->currentMatch = completion;
325 
326  postProcessMatch(&completion);
327 
328  if (!string.isEmpty()) { // only emit match when string is not empty
329  //qDebug() << "KCompletion: Match: " << completion;
330  emit match(completion);
331  }
332 
333  return completion;
334 }
335 
337 {
338  Q_D(const KCompletion);
339  // get all items in the tree, eventually in sorted order
340  KCompletionMatchesWrapper allItems(d->order);
341  allItems.extractStringsFromNode(d->treeRoot, QString(), false);
342 
343  QStringList list = allItems.list();
344 
345  // subStringMatches is invoked manually, via a shortcut
346  if (list.isEmpty()) {
347  return list;
348  }
349 
350  if (string.isEmpty()) { // shortcut
351  postProcessMatches(&list);
352  return list;
353  }
354 
356  for (QStringList::ConstIterator it = list.constBegin(), total = list.constEnd(); it != total; ++it) {
357  QString item = *it;
358  if (item.indexOf(string, 0, Qt::CaseInsensitive) != -1) { // always case insensitive
359  postProcessMatch(&item);
360  matches.append(item);
361  }
362  }
363 
364  return matches;
365 }
366 
368 {
369  Q_D(KCompletion);
370  d->completionMode = mode;
371 }
372 
374 {
375  Q_D(const KCompletion);
376  return d->completionMode;
377 }
378 
380 {
381  Q_D(KCompletion);
382  // Don't use d->matches since calling postProcessMatches()
383  // on d->matches here would interfere with call to
384  // postProcessMatch() during rotation
385  KCompletionMatchesWrapper matches(d->order);
386  bool dummy;
387  matches.findAllCompletions(d->treeRoot, d->lastString, d->ignoreCase, dummy);
388  QStringList l = matches.list();
389  postProcessMatches(&l);
390  return l;
391 }
392 
394 {
395  Q_D(KCompletion);
396  // Don't use d->matches since calling postProcessMatches()
397  // on d->matches here would interfere with call to
398  // postProcessMatch() during rotation
399  KCompletionMatchesWrapper matches(d->order);
400  bool dummy;
401  matches.findAllCompletions(d->treeRoot, d->lastString, d->ignoreCase, dummy);
402  KCompletionMatches ret(matches);
403  postProcessMatches(&ret);
404  return ret;
405 }
406 
408 {
409  Q_D(KCompletion);
410  KCompletionMatchesWrapper matches(d->order);
411  bool dummy;
412  matches.findAllCompletions(d->treeRoot, string, d->ignoreCase, dummy);
413  QStringList l = matches.list();
414  postProcessMatches(&l);
415  return l;
416 }
417 
419 {
420  Q_D(KCompletion);
421  KCompletionMatchesWrapper matches(d->order);
422  bool dummy;
423  matches.findAllCompletions(d->treeRoot, string, d->ignoreCase, dummy);
424  KCompletionMatches ret(matches);
425  postProcessMatches(&ret);
426  return ret;
427 }
428 
430 {
431  Q_D(KCompletion);
432  d->beep = enable;
433 }
434 
436 {
437  Q_D(const KCompletion);
438  return d->beep;
439 }
440 
442 {
443  Q_D(const KCompletion);
444  return d->hasMultipleMatches;
445 }
446 
449 
451 {
452  Q_D(KCompletion);
453  QString completion;
454  d->lastMatch = d->currentMatch;
455 
456  if (d->matches.isEmpty()) {
457  d->matches.findAllCompletions(d->treeRoot, d->lastString, d->ignoreCase, d->hasMultipleMatches);
458  if (!d->matches.isEmpty()) {
459  completion = d->matches.first();
460  }
461  d->currentMatch = completion;
462  d->rotationIndex = 0;
463  postProcessMatch(&completion);
464  emit match(completion);
465  return completion;
466  }
467 
468  QStringList matches = d->matches.list();
469  d->lastMatch = matches[ d->rotationIndex++ ];
470 
471  if (d->rotationIndex == matches.count()) {
472  d->rotationIndex = 0;
473  }
474 
475  completion = matches[ d->rotationIndex ];
476  d->currentMatch = completion;
477  postProcessMatch(&completion);
478  emit match(completion);
479  return completion;
480 }
481 
483 {
484  Q_D(const KCompletion);
485  return d->lastMatch;
486 }
487 
489 {
490  Q_D(KCompletion);
491  QString completion;
492  d->lastMatch = d->currentMatch;
493 
494  if (d->matches.isEmpty()) {
495  d->matches.findAllCompletions(d->treeRoot, d->lastString, d->ignoreCase, d->hasMultipleMatches);
496  if (!d->matches.isEmpty()) {
497  completion = d->matches.last();
498  }
499  d->currentMatch = completion;
500  d->rotationIndex = 0;
501  postProcessMatch(&completion);
502  emit match(completion);
503  return completion;
504  }
505 
506  QStringList matches = d->matches.list();
507  d->lastMatch = matches[ d->rotationIndex ];
508 
509  if (d->rotationIndex == 0) {
510  d->rotationIndex = matches.count();
511  }
512 
513  d->rotationIndex--;
514 
515  completion = matches[ d->rotationIndex ];
516  d->currentMatch = completion;
517  postProcessMatch(&completion);
518  emit match(completion);
519  return completion;
520 }
521 
524 
525 // Implements the tree. Every node is a QChar and has a list of children, which
526 // are Nodes as well.
527 // QChar( 0x0 ) is used as the delimiter of a string; the last child of each
528 // inserted string is 0x0.
529 
530 KCompTreeNode::~KCompTreeNode()
531 {
532  // delete all children
533  KCompTreeNode *cur = m_children.begin();
534  while (cur) {
535  KCompTreeNode *next = cur->m_next;
536  delete m_children.remove(cur);
537  cur = next;
538  }
539 }
540 
541 // Adds a child-node "ch" to this node. If such a node is already existent,
542 // it will not be created. Returns the new/existing node.
543 KCompTreeNode *KCompTreeNode::insert(const QChar &ch, bool sorted)
544 {
545  KCompTreeNode *child = find(ch);
546  if (!child) {
547  child = new KCompTreeNode(ch);
548 
549  // FIXME, first (slow) sorted insertion implementation
550  if (sorted) {
551  KCompTreeNode *prev = nullptr;
552  KCompTreeNode *cur = m_children.begin();
553  while (cur) {
554  if (ch > *cur) {
555  prev = cur;
556  cur = cur->m_next;
557  } else {
558  break;
559  }
560  }
561  if (prev) {
562  m_children.insert(prev, child);
563  } else {
564  m_children.prepend(child);
565  }
566  }
567 
568  else {
569  m_children.append(child);
570  }
571  }
572 
573  // implicit weighting: the more often an item is inserted, the higher
574  // priority it gets.
575  child->confirm();
576 
577  return child;
578 }
579 
580 // Iteratively removes a string from the tree. The nicer recursive
581 // version apparently was a little memory hungry (see #56757)
582 void KCompTreeNode::remove(const QString &str)
583 {
584  QString string = str;
585  string += QChar(0x0);
586 
587  QVector<KCompTreeNode *> deletables(string.length() + 1);
588 
589  KCompTreeNode *child = nullptr;
590  KCompTreeNode *parent = this;
591  deletables.replace(0, parent);
592 
593  int i = 0;
594  for (; i < string.length(); i++) {
595  child = parent->find(string.at(i));
596  if (child) {
597  deletables.replace(i + 1, child);
598  } else {
599  break;
600  }
601 
602  parent = child;
603  }
604 
605  for (; i >= 1; i--) {
606  parent = deletables.at(i - 1);
607  child = deletables.at(i);
608  if (child->m_children.count() == 0) {
609  delete parent->m_children.remove(child);
610  }
611  }
612 }
613 
614 QStringList KCompletionMatchesWrapper::list() const
615 {
616  if (m_sortedList && m_dirty) {
617  m_sortedList->sort();
618  m_dirty = false;
619 
620  m_stringList.clear();
621 
622  // high weight == sorted last -> reverse the sorting here
623  QList<KSortableItem<QString> >::const_iterator it;
624  for (it = m_sortedList->constBegin(); it != m_sortedList->constEnd(); ++it) {
625  m_stringList.prepend((*it).value());
626  }
627  } else if (m_compOrder == KCompletion::Sorted) {
628  QCollator c;
630  std::stable_sort(m_stringList.begin(), m_stringList.end(), c);
631  }
632 
633  return m_stringList;
634 }
635 
636 void KCompletionMatchesWrapper::findAllCompletions(const KCompTreeNode *treeRoot,const QString &string, bool ignoreCase, bool &hasMultipleMatches)
637 {
638  //qDebug() << "*** finding all completions for " << string;
639 
640  if (string.isEmpty()) {
641  return;
642  }
643 
644  if (ignoreCase) { // case insensitive completion
645  extractStringsFromNodeCI(treeRoot, QString(), string);
646  hasMultipleMatches = (count() > 1);
647  return;
648  }
649 
650  QChar ch;
651  QString completion;
652  const KCompTreeNode *node = treeRoot;
653 
654  // start at the tree-root and try to find the search-string
655  for (int i = 0; i < string.length(); i++) {
656  ch = string.at(i);
657  node = node->find(ch);
658 
659  if (node) {
660  completion += ch;
661  } else {
662  return; // no completion -> return empty list
663  }
664  }
665 
666  // Now we have the last node of the to be completed string.
667  // Follow it as long as it has exactly one child (= longest possible
668  // completion)
669 
670  while (node->childrenCount() == 1) {
671  node = node->firstChild();
672  if (!node->isNull()) {
673  completion += *node;
674  }
675  // qDebug() << completion << node->latin1();
676  }
677 
678  // there is just one single match)
679  if (node->childrenCount() == 0) {
680  append(node->weight(), completion);
681  }
682 
683  else {
684  // node has more than one child
685  // -> recursively find all remaining completions
686  hasMultipleMatches = true;
687  extractStringsFromNode(node, completion);
688  }
689 }
690 
691 void KCompletionMatchesWrapper::extractStringsFromNode(const KCompTreeNode *node, const QString &beginning, bool addWeight)
692 {
693  if (!node) {
694  return;
695  }
696 
697  // qDebug() << "Beginning: " << beginning;
698  const KCompTreeChildren *list = node->children();
699  QString string;
700  QString w;
701 
702  // loop thru all children
703  for (KCompTreeNode *cur = list->begin(); cur; cur = cur->m_next) {
704  string = beginning;
705  node = cur;
706  if (!node->isNull()) {
707  string += *node;
708  }
709 
710  while (node && node->childrenCount() == 1) {
711  node = node->firstChild();
712  if (node->isNull()) {
713  break;
714  }
715  string += *node;
716  }
717 
718  if (node && node->isNull()) { // we found a leaf
719  if (addWeight) {
720  // add ":num" to the string to store the weighting
721  string += QLatin1Char(':');
722  w.setNum(node->weight());
723  string.append(w);
724  }
725  append(node->weight(), string);
726  }
727 
728  // recursively find all other strings.
729  if (node && node->childrenCount() > 1) {
730  extractStringsFromNode(node, string, addWeight);
731  }
732  }
733 }
734 
735 void KCompletionMatchesWrapper::extractStringsFromNodeCI(const KCompTreeNode *node, const QString &beginning, const QString &restString)
736 {
737  if (restString.isEmpty()) {
738  extractStringsFromNode(node, beginning, false /*noweight*/);
739  return;
740  }
741 
742  QChar ch1 = restString.at(0);
743  QString newRest = restString.mid(1);
744  KCompTreeNode *child1, *child2;
745 
746  child1 = node->find(ch1); // the correct match
747  if (child1)
748  extractStringsFromNodeCI(child1, beginning + QChar(*child1), newRest);
749 
750  // append the case insensitive matches, if available
751  if (ch1.isLetter()) {
752  // find out if we have to lower or upper it. Is there a better way?
753  QChar ch2 = ch1.toLower();
754  if (ch1 == ch2) {
755  ch2 = ch1.toUpper();
756  }
757  if (ch1 != ch2) {
758  child2 = node->find(ch2);
759  if (child2)
760  extractStringsFromNodeCI(child2, beginning + QChar(*child2), newRest);
761  }
762  }
763 }
764 
765 void KCompTreeNodeList::append(KCompTreeNode *item)
766 {
767  m_count++;
768  if (!m_last) {
769  m_last = item;
770  m_last->m_next = nullptr;
771  m_first = item;
772  return;
773  }
774  m_last->m_next = item;
775  item->m_next = nullptr;
776  m_last = item;
777 }
778 
779 void KCompTreeNodeList::prepend(KCompTreeNode *item)
780 {
781  m_count++;
782  if (!m_last) {
783  m_last = item;
784  m_last->m_next = nullptr;
785  m_first = item;
786  return;
787  }
788  item->m_next = m_first;
789  m_first = item;
790 }
791 
792 void KCompTreeNodeList::insert(KCompTreeNode *after, KCompTreeNode *item)
793 {
794  if (!after) {
795  append(item);
796  return;
797  }
798 
799  m_count++;
800 
801  item->m_next = after->m_next;
802  after->m_next = item;
803 
804  if (after == m_last) {
805  m_last = item;
806  }
807 }
808 
809 KCompTreeNode *KCompTreeNodeList::remove(KCompTreeNode *item)
810 {
811  if (!m_first || !item) {
812  return nullptr;
813  }
814  KCompTreeNode *cur = nullptr;
815 
816  if (item == m_first) {
817  m_first = m_first->m_next;
818  } else {
819  cur = m_first;
820  while (cur && cur->m_next != item) {
821  cur = cur->m_next;
822  }
823  if (!cur) {
824  return nullptr;
825  }
826  cur->m_next = item->m_next;
827  }
828  if (item == m_last) {
829  m_last = cur;
830  }
831  m_count--;
832  return item;
833 }
834 
835 KCompTreeNode *KCompTreeNodeList::at(uint index) const
836 {
837  KCompTreeNode *cur = m_first;
838  while (index-- && cur) {
839  cur = cur->m_next;
840  }
841  return cur;
842 }
843 
844 QSharedPointer<KZoneAllocator> KCompTreeNode::m_alloc(new KZoneAllocator(8*1024));
845 
virtual void clear()
Removes all inserted items.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
QString & append(QChar ch)
Lists all possible matches in a popup list box to choose from.
Definition: kcompletion.h:149
virtual void setSoundsEnabled(bool enable)
Enables/disables emitting a sound when.
Use alphabetically sorted order.
Definition: kcompletion.h:161
Use weighted order.
Definition: kcompletion.h:163
bool isEmpty() const
Returns true if the completion object contains no entries.
Text is automatically filled in whenever possible.
Definition: kcompletion.h:137
const QList< QKeySequence > & completion()
QStringList items() const
Returns a list of all items inserted into KCompletion.
CompOrder
Constants that represent the order in which KCompletion performs completion lookups.
Definition: kcompletion.h:161
virtual const QString & lastMatch() const
Returns the last match.
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
virtual void postProcessMatches(QStringList *matchList) const
This method is called before a list of all available completions is emitted via matches().
bool isLetter() const const
void match(const QString &item)
This signal is emitted when a match is found.
Use order of insertion.
Definition: kcompletion.h:162
int count(const T &value) const const
void append(const T &value)
No completion is used.
Definition: kcompletion.h:133
QStringList allMatches()
Returns a list of all items matching the last completed string.
CaseInsensitive
CompletionMode
This enum describes the completion mode used for by the KCompletion class.
Definition: kcompletion.h:129
bool isEmpty() const const
bool isEmpty() const const
A generic class for completing QStrings.
Definition: kcompletion.h:115
void insertItems(const QStringList &items)
Inserts items into the list of possible completions.
virtual void setIgnoreCase(bool ignoreCase)
Setting this to true makes KCompletion behave case insensitively.
This structure is returned by KCompletion::allWeightedMatches().
virtual void postProcessMatch(QString *match) const
This method is called after a completion is found and before the matching string is emitted...
void matches(const QStringList &matchlist)
This signal is emitted by makeCompletion() in shell-completion mode when the same string is passed to...
QList::iterator end()
void multipleMatches()
This signal is emitted when calling makeCompletion() and more than one matching item is found...
QString nextMatch()
Returns the next item from the list of matching items.
QStringRef midRef(int position, int n) const const
QChar toLower() const const
CompOrder order() const
Returns the completion order.
virtual ~KCompletion()
Destructor, nothing special here, either.
virtual void setCompletionMode(CompletionMode mode)
Sets the completion mode.
void setCaseSensitivity(Qt::CaseSensitivity sensitivity)
const T & at(int i) const const
uint toUInt(bool *ok, int base) const const
Completes text much in the same way as a typical *nix shell would.
Definition: kcompletion.h:145
virtual QString makeCompletion(const QString &string)
Attempts to find an item in the list of available completions that begins with string.
QString mid(int position, int n) const const
QChar toUpper() const const
QString & setNum(short n, int base)
const QChar at(int position) const const
typedef ConstIterator
bool ignoreCase() const
Returns whether KCompletion acts case insensitively or not.
bool soundsEnabled() const
Tells you whether KCompletion will emit sounds on certain occasions.
int length() const const
QStringList substringCompletion(const QString &string) const
Returns a list of all completion items that contain the given string.
QString left(int n) const const
void removeItem(const QString &item)
Removes an item from the list of available completions.
void addItem(const QString &item)
Adds an item to the list of available completions.
void replace(int i, const T &value)
void sort(Qt::CaseSensitivity cs)
void prepend(const T &value)
bool hasMultipleMatches() const
Returns true when more than one match is found.
Lists all possible matches in a popup list box to choose from, and automatically fills the result whe...
Definition: kcompletion.h:154
QList::const_iterator constEnd() const const
QString::iterator begin()
QList::const_iterator constBegin() const const
QObject * parent() const const
KCompletionMatches allWeightedMatches()
Returns a list of all items matching the last completed string.
virtual void setItems(const QStringList &itemList)
Sets the list of items available for completion.
QList::iterator begin()
virtual void setOrder(CompOrder order)
KCompletion offers three different ways in which it offers its items:
QString previousMatch()
Returns the next item from the list of matching items.
CompletionMode completionMode() const
Returns the current completion mode.
KCompletion()
Constructor, nothing special here :)
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.