• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • util
kcompletion.h
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 1999,2000 Carsten Pfeiffer <pfeiffer@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KCOMPLETION_H
21#define KCOMPLETION_H
22
23#include <kdeui_export.h>
24#include <kglobalsettings.h>
25#include <ksortablelist.h>
26#include <kshortcut.h>
27
28#include <QtCore/QMap>
29#include <QtCore/QObject>
30#include <QtCore/QString>
31#include <QtCore/QStringList>
32#include <QtCore/QPointer>
33
34class KCompTreeNode;
35class KCompletionPrivate;
36class KCompletionBasePrivate;
37class KCompletionMatchesWrapper;
38class KCompletionMatches;
39
130class KDEUI_EXPORT KCompletion : public QObject
131{
132 Q_ENUMS( CompOrder )
133 Q_PROPERTY( CompOrder order READ order WRITE setOrder )
134 Q_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase )
135 Q_PROPERTY( QStringList items READ items WRITE setItems )
136 Q_OBJECT
137
138public:
143 enum CompOrder { Sorted,
144 Insertion,
145 Weighted
146 };
147
151 KCompletion();
152
156 virtual ~KCompletion();
157
180 virtual QString makeCompletion( const QString& string );
181
190 QStringList substringCompletion( const QString& string ) const;
191
201 QString previousMatch();
202
212 QString nextMatch();
213
220 virtual const QString& lastMatch() const;
221
240 QStringList items() const;
241
245 bool isEmpty() const;
246
256 virtual void setCompletionMode( KGlobalSettings::Completion mode );
257
265 KGlobalSettings::Completion completionMode() const;
266
287 virtual void setOrder( CompOrder order );
288
294 CompOrder order() const;
295
303 virtual void setIgnoreCase( bool ignoreCase );
304
311 bool ignoreCase() const;
312
319 QStringList allMatches();
320
326 QStringList allMatches( const QString& string );
327
340 KCompletionMatches allWeightedMatches();
341
347 KCompletionMatches allWeightedMatches( const QString& string );
348
362 virtual void setSoundsEnabled( bool enable );
363
370 bool soundsEnabled() const;
371
377 bool hasMultipleMatches() const;
378
379public Q_SLOTS:
386 void slotMakeCompletion( const QString& string ) { //inline (redirect)
387 (void) makeCompletion( string );
388 }
389
395 void slotPreviousMatch() { //inline (redirect)
396 (void) previousMatch();
397 }
398
404 void slotNextMatch() { //inline (redirect)
405 (void) nextMatch();
406 }
407
408 // FIXME ###: KDE4: unify the nomenclature. We have insertItems, addItem,
409 // setItems...
415 void insertItems( const QStringList& items );
416
432 virtual void setItems( const QStringList& list);
433
440 void addItem( const QString& item);
441
453 void addItem( const QString& item, uint weight );
454
461 void removeItem( const QString& item);
462
466 virtual void clear();
467
468
469Q_SIGNALS:
476 void match( const QString& item);
477
484 void matches( const QStringList& matchlist);
485
491 void multipleMatches();
492
493protected:
507 virtual void postProcessMatch( QString *pMatch ) const;
508
519 virtual void postProcessMatches( QStringList * pMatches ) const;
520
531 virtual void postProcessMatches( KCompletionMatches * pMatches ) const;
532
533private:
534 void addWeightedItem( const QString& );
535 QString findCompletion( const QString& string );
536 void findAllCompletions( const QString&,
537 KCompletionMatchesWrapper *matches,
538 bool& hasMultipleMatches ) const;
539
540 void extractStringsFromNode( const KCompTreeNode *,
541 const QString& beginning,
542 KCompletionMatchesWrapper *matches,
543 bool addWeight = false ) const;
544 void extractStringsFromNodeCI( const KCompTreeNode *,
545 const QString& beginning,
546 const QString& restString,
547 KCompletionMatchesWrapper *matches) const;
548
549 enum BeepMode { NoMatch, PartialMatch, Rotation };
550 void doBeep( BeepMode ) const;
551
552private:
553 Q_DISABLE_COPY( KCompletion )
554 KCompletionPrivate* const d;
555};
556
557// some more helper stuff
558typedef KSortableList<QString> KCompletionMatchesList;
559class KCompletionMatchesPrivate;
560
578 */
579class KDEUI_EXPORT KCompletionMatches : public KCompletionMatchesList
580{
581public:
587 KCompletionMatches( bool sort );
588
592 KCompletionMatches( const KCompletionMatches& );
593
597 KCompletionMatches &operator=( const KCompletionMatches& );
598
602 KCompletionMatches( const KCompletionMatchesWrapper& matches );
603
607 ~KCompletionMatches();
612 void removeDuplicates();
619 QStringList list( bool sort = true ) const;
625 bool sorting() const;
626
627private:
628 KCompletionMatchesPrivate * const d;
629};
630
644 */
645class KDEUI_EXPORT KCompletionBase
646{
647public:
652 */
653 enum KeyBindingType {
657 TextCompletion,
661 PrevCompletionMatch,
665 NextCompletionMatch,
669 SubstringCompletion
670 };
671
672
673 // Map for the key binding types mentioned above.
674 typedef QMap<KeyBindingType, KShortcut> KeyBindingMap;
675
679 KCompletionBase();
680
684 virtual ~KCompletionBase();
685
701 KCompletion* completionObject( bool hsig = true );
702
719 virtual void setCompletionObject( KCompletion* compObj, bool hsig = true );
720
733 virtual void setHandleSignals( bool handle );
734
745 bool isCompletionObjectAutoDeleted() const;
746
756 void setAutoDeleteCompletionObject( bool autoDelete );
757
778 void setEnableSignals( bool enable );
779
785 bool handleSignals() const;
786
792 bool emitSignals() const;
793
814 virtual void setCompletionMode( KGlobalSettings::Completion mode );
815
824 KGlobalSettings::Completion completionMode() const;
825
856 bool setKeyBinding( KeyBindingType item , const KShortcut& key );
857
870 KShortcut getKeyBinding( KeyBindingType item ) const;
871
883 void useGlobalKeyBindings();
884
899 virtual void setCompletedText( const QString& text ) = 0;
900
908 virtual void setCompletedItems( const QStringList& items, bool autoSuggest =true ) = 0;
909
921 KCompletion* compObj() const;
922
923protected:
932 KeyBindingMap getKeyBindings() const;
933
939 void setDelegate( KCompletionBase *delegate );
940
946 KCompletionBase *delegate() const;
947
948private:
949 // This method simply sets the autodelete boolean for
950 // the completion object, the emit signals and handle
951 // signals internally flags to the provided values.
952 void setup( bool, bool, bool );
953
954 // BCI
955protected:
959 virtual void virtual_hook( int id, void* data );
960private:
961 Q_DISABLE_COPY( KCompletionBase )
962 KCompletionBasePrivate * const d;
963};
964
965#endif // KCOMPLETION_H
KCompletionBase::delegate
KCompletionBase * delegate() const
Returns the delegation object.
Definition kcompletionbase.cpp:91
KCompletionBase::handleSignals
bool handleSignals() const
Returns true if the object handles the signals.
Definition kcompletionbase.cpp:157
KCompletionBase::setDelegate
void setDelegate(KCompletionBase *delegate)
Sets or removes the delegation object.
Definition kcompletionbase.cpp:78
KCompletionBase::completionMode
KGlobalSettings::Completion completionMode() const
Returns the current completion mode.
Definition kcompletionbase.cpp:181
KCompletionBase::setCompletedItems
virtual void setCompletedItems(const QStringList &items, bool autoSuggest=true)=0
A pure virtual function that must be implemented by all inheriting classes.
KCompletionBase::setCompletedText
virtual void setCompletedText(const QString &text)=0
A pure virtual function that must be implemented by all inheriting classes.
KCompletionBase::setHandleSignals
virtual void setHandleSignals(bool handle)
Enables this object to handle completion and rotation events internally.
Definition kcompletionbase.cpp:127
KCompletionBase::compObj
KCompletion * compObj() const
Returns a pointer to the completion object.
Definition kcompletionbase.cpp:220
KCompletionBase::virtual_hook
virtual void virtual_hook(int id, void *data)
Virtual hook, used to add new "virtual" functions while maintaining binary compatibility.
Definition kcompletionbase.cpp:243
KCompletionBase::emitSignals
bool emitSignals() const
Returns true if the object emits the signals.
Definition kcompletionbase.cpp:162
KCompletionBase::setCompletionObject
virtual void setCompletionObject(KCompletion *compObj, bool hsig=true)
Sets up the completion object to be used.
Definition kcompletionbase.cpp:109
KCompletionBase::getKeyBindings
KeyBindingMap getKeyBindings() const
Returns a key-binding map.
Definition kcompletionbase.cpp:226
KCompletionBase::KeyBindingMap
QMap< KeyBindingType, KShortcut > KeyBindingMap
Definition kcompletion.h:673
KCompletionBase::completionObject
KCompletion * completionObject(bool hsig=true)
Returns a pointer to the current completion object.
Definition kcompletionbase.cpp:96
KCompletionBase::getKeyBinding
KShortcut getKeyBinding(KeyBindingType item) const
Returns the key-binding used for the specified item.
Definition kcompletionbase.cpp:201
KCompletionBase::setAutoDeleteCompletionObject
void setAutoDeleteCompletionObject(bool autoDelete)
Sets the completion object when this widget's destructor is called.
Definition kcompletionbase.cpp:141
KCompletionBase::setEnableSignals
void setEnableSignals(bool enable)
Sets the widget's ability to emit text completion and rotation signals.
Definition kcompletionbase.cpp:149
KCompletionBase::KCompletionBase
KCompletionBase()
Default constructor.
Definition kcompletionbase.cpp:60
KCompletionBase::isCompletionObjectAutoDeleted
bool isCompletionObjectAutoDeleted() const
Returns true if the completion object is deleted upon this widget's destruction.
Definition kcompletionbase.cpp:135
KCompletionBase::setKeyBinding
bool setKeyBinding(KeyBindingType item, const KShortcut &key)
Sets the key-binding to be used for manual text completion, text rotation in a history list as well a...
Definition kcompletionbase.cpp:186
KCompletionBase::useGlobalKeyBindings
void useGlobalKeyBindings()
Sets this object to use global values for key-bindings.
Definition kcompletionbase.cpp:206
KCompletionBase::setCompletionMode
virtual void setCompletionMode(KGlobalSettings::Completion mode)
Sets the type of completion to be used.
Definition kcompletionbase.cpp:167
KCompletionBase::KeyBindingType
KeyBindingType
Constants that represent the items whose short-cut key-binding is programmable.
Definition kcompletion.h:652
KCompletionBase::SubstringCompletion
@ SubstringCompletion
Substring completion (by default Ctrl-T).
Definition kcompletion.h:668
KCompletionBase::NextCompletionMatch
@ NextCompletionMatch
Switch to next completion (by default Ctrl-Down).
Definition kcompletion.h:664
KCompletionBase::PrevCompletionMatch
@ PrevCompletionMatch
Switch to previous completion (by default Ctrl-Up).
Definition kcompletion.h:660
KCompletionBase::TextCompletion
@ TextCompletion
Text completion (by default Ctrl-E).
Definition kcompletion.h:656
KCompletionMatches
This structure is returned by KCompletion::allWeightedMatches .
Definition kcompletion.h:579
KCompletionMatches::KCompletionMatches
KCompletionMatches(bool sort)
Default constructor.
Definition kcompletion.cpp:862
KCompletionMatches::list
QStringList list(bool sort=true) const
Returns the matches as a QStringList.
Definition kcompletion.cpp:886
KCompletionMatches::removeDuplicates
void removeDuplicates()
Removes duplicate matches.
Definition kcompletion.cpp:902
KCompletionMatches::sorting
bool sorting() const
If sorting() returns false, the matches aren't sorted by their weight, even if true is passed to list...
Definition kcompletion.cpp:897
KCompletionMatches::operator=
KCompletionMatches & operator=(const KCompletionMatches &)
assignment operator.
Definition kcompletion.cpp:852
KCompletion
A generic class for completing QStrings.
Definition kcompletion.h:131
KCompletion::slotPreviousMatch
void slotPreviousMatch()
Searches the previous matching item and emits it via match().
Definition kcompletion.h:395
KCompletion::setItems
virtual void setItems(const QStringList &list)
Sets the list of items available for completion.
Definition kcompletion.cpp:99
KCompletion::nextMatch
QString nextMatch()
Returns the next item from the matching-items-list.
Definition kcompletion.cpp:404
KCompletion::order
CompOrder order
Definition kcompletion.h:133
KCompletion::multipleMatches
void multipleMatches()
This signal is emitted, when calling makeCompletion() and more than one matching item is found.
KCompletion::makeCompletion
virtual QString makeCompletion(const QString &string)
Attempts to find an item in the list of available completions, that begins with string.
Definition kcompletion.cpp:229
KCompletion::matches
void matches(const QStringList &matchlist)
All matching items.
KCompletion::KCompletion
KCompletion()
Constructor, nothing special here :)
Definition kcompletion.cpp:67
KCompletion::setOrder
virtual void setOrder(CompOrder order)
KCompletion offers three different ways in which it offers its items:
Definition kcompletion.cpp:78
KCompletion::CompOrder
CompOrder
Constants that represent the order in which KCompletion performs completion-lookups.
Definition kcompletion.h:143
KCompletion::Insertion
@ Insertion
Use order of insertion.
Definition kcompletion.h:144
KCompletion::Weighted
@ Weighted
Use weighted order.
Definition kcompletion.h:145
KCompletion::Sorted
@ Sorted
Use alphabetically sorted order.
Definition kcompletion.h:143
KCompletion::ignoreCase
bool ignoreCase
Definition kcompletion.h:134
KCompletion::items
QStringList items
Definition kcompletion.h:135
KCompletion::setIgnoreCase
virtual void setIgnoreCase(bool ignoreCase)
Setting this to true makes KCompletion behave case insensitively.
Definition kcompletion.cpp:89
KCompletion::previousMatch
QString previousMatch()
Returns the next item from the matching-items-list.
Definition kcompletion.cpp:442
KCompletion::slotMakeCompletion
void slotMakeCompletion(const QString &string)
Attempts to complete "string" and emits the completion via match().
Definition kcompletion.h:386
KCompletion::match
void match(const QString &item)
The matching item.
KCompletion::slotNextMatch
void slotNextMatch()
Searches the next matching item and emits it via match().
Definition kcompletion.h:404
KCompletion::hasMultipleMatches
bool hasMultipleMatches() const
Returns true when more than one match is found.
Definition kcompletion.cpp:395
KCompletion::postProcessMatch
virtual void postProcessMatch(QString *pMatch) const
This method is called after a completion is found and before the matching string is emitted.
Definition kcompletion.cpp:134
KCompletion::postProcessMatches
virtual void postProcessMatches(QStringList *pMatches) const
This method is called before a list of all available completions is emitted via matches.
Definition kcompletion.cpp:138
KGlobalSettings::Completion
Completion
This enum describes the completion mode used for by the KCompletion class.
Definition kglobalsettings.h:179
KShortcut
Represents a keyboard shortcut.
Definition kshortcut.h:58
KSortableList
KSortableList< QString >::sort
void sort()
QMap
QObject
KCompletionMatchesList
KSortableList< QString > KCompletionMatchesList
Definition kcompletion.h:558
kdeui_export.h
kglobalsettings.h
addItem
static void addItem(KServiceGroup::List &sorted, const KSycocaEntry::Ptr &p, bool &addSeparator)
kshortcut.h
Defines platform-independent classes for keyboard shortcut handling.
ksortablelist.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 17 2025 00:00:00 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal