#include <kcompletion.h>
Inheritance diagram for KCompletion:

Public Types | |
| enum | CompOrder { Sorted, Insertion, Weighted } |
Public Slots | |
| void | slotMakeCompletion (const QString &string) |
| void | slotPreviousMatch () |
| void | slotNextMatch () |
| void | insertItems (const QStringList &items) |
| virtual void | setItems (const QStringList &list) |
| void | addItem (const QString &item) |
| void | addItem (const QString &item, uint weight) |
| void | removeItem (const QString &item) |
| virtual void | clear () |
Signals | |
| void | match (const QString &item) |
| void | matches (const QStringList &matchlist) |
| void | multipleMatches () |
Public Methods | |
| KCompletion () | |
| virtual | ~KCompletion () |
| virtual QString | makeCompletion (const QString &string) |
| QStringList | substringCompletion (const QString &string) const |
| QString | previousMatch () |
| QString | nextMatch () |
| virtual const QString & | lastMatch () const |
| QStringList | items () const |
| virtual void | setCompletionMode (KGlobalSettings::Completion mode) |
| KGlobalSettings::Completion | completionMode () const |
| virtual void | setOrder (CompOrder order) |
| CompOrder | order () const |
| virtual void | setIgnoreCase (bool ignoreCase) |
| bool | ignoreCase () const |
| QStringList | allMatches () |
| QStringList | allMatches (const QString &string) |
| KCompletionMatches | allWeightedMatches () |
| KCompletionMatches | allWeightedMatches (const QString &string) |
| virtual void | setEnableSounds (bool enable) |
| bool | isSoundsEnabled () const |
| bool | hasMultipleMatches () const |
| void | enableSounds () |
| void | disableSounds () |
Protected Methods | |
| virtual void | postProcessMatch (QString *match) const |
| virtual void | postProcessMatches (QStringList *matches) const |
| virtual void | postProcessMatches (KCompletionMatches *matches) const |
This class offers easy use of "auto-completion", "manual-completion" or "shell completion" on QString objects. A common use is completing filenames or URLs (see KURLCompletion()). But it is not limited to URL-completion -- everything should be completable! The user should be able to complete email-addresses, telephone-numbers, commands, SQL queries, ... Every time your program knows what the user can type into an edit-field, you should offer completion. With KCompletion, this is very easy, and if you are using a line edit widget (KLineEdit), it is even more easy. Basically, you tell a KCompletion object what strings should be completable and whenever completion should be invoked, you call makeCompletion(). KLineEdit and (an editable) KComboBox even do this automatically for you.
KCompletion offers the completed string via the signal match() and all matching strings (when the result is ambiguous) via the method allMatches().
Notice: auto-completion, shell completion and manual completion work slightly differently:
A short example:
KCompletion completion; completion.setOrder( KCompletion::Sorted ); completion.addItem( "pfeiffer@kde.org" ); completion.addItem( "coolo@kde.org" ); completion.addItem( "carpdjih@sp.zrz.tu-berlin.de" ); completion.addItem( "carp@cs.tu-berlin.de" ); cout << completion.makeCompletion( "ca" ).latin1() << endl;In shell-completion-mode, this will be "carp"; in auto-completion- mode it will be "carp@cs.tu-berlin.de", as that is alphabetically smaller. If setOrder was set to Insertion, "carpdjih@sp.zrz.tu-berlin.de" would be completed in auto-completion-mode, as that was inserted before "carp@cs.tu-berlin.de".
You can dynamically update the completable items by removing and adding them whenever you want. For advanced usage, you could even use multiple KCompletion objects. E.g. imagine an editor like kwrite with multiple open files. You could store items of each file in a different KCompletion object, so that you know (and tell the user) where a completion comes from.
Note: KCompletion does not work with strings that contain 0x0 characters (unicode nul), as this is used internally as a delimiter.
You may inherit from KCompletion and override makeCompletion() in special cases (like reading directories/urls and then supplying the contents to KCompletion, as KURLCompletion does), but generally, this is not necessary.
Definition at line 130 of file kcompletion.h.
|
|
Constants that represent the order in which KCompletion performs completion-lookups.
Definition at line 143 of file kcompletion.h. Referenced by order(). |
|
|
Constructor, nothing special here :) |
|
|
Destructor, nothing special here, either. |
|
||||||||||||
|
Adds an item to the list of available completions. Resets the current item-state (previousMatch() and nextMatch() won't work anymore).
Sets the weighting of the item to
|
|
|
Adds an item to the list of available completions. Resets the current item-state (previousMatch() and nextMatch() won't work anymore).
|
|
|
Returns a list of all items matching
|
|
|
Returns a list of all items matching the last completed string. Might take some time, when you have LOTS of items.
|
|
|
Returns a list of all items matching
|
|
|
Returns a list of all items matching the last completed string. Might take some time, when you have LOTS of items. The matches are returned as KCompletionMatches, which also keeps the weight of the matches, allowing you to modify some matches or merge them with matches from another call to allWeightedMatches(), and sort the matches after that in order to have the matches ordered correctly.
|
|
|
Removes all inserted items. |
|
|
Return the current completion mode. May be different from KGlobalSettings::completionMode(), if you explicitly called setCompletionMode().
Definition at line 262 of file kcompletion.h. References KGlobalSettings::Completion. |
|
|
Definition at line 390 of file kcompletion.h. |
|
|
Definition at line 384 of file kcompletion.h. |
|
|
Returns true when more than one match is found.
Definition at line 377 of file kcompletion.h. |
|
|
Return whether KCompletion acts case insensitively or not. Default is false (case sensitive).
Definition at line 310 of file kcompletion.h. |
|
|
Inserts
|
|
|
Tells you whether KCompletion will play sounds on certain occasions. Default is enabled.
Definition at line 370 of file kcompletion.h. |
|
|
Returns a list of all items inserted into KCompletion. This is useful if you need to save the state of a KCompletion object and restore it later. Important note: when order() == Weighted, then every item in the stringlist has its weight appended, delimited by a colon. E.g. an item "www.kde.org" might look like "www.kde.org:4", where 4 is the weight. This is necessary so that you can save the items along with its weighting on disk and load them back with setItems(), restoring its weight as well. If you really don't want the appended weightings, call setOrder( KCompletion::Insertion ) before calling items().
|
|
|
Returns the last match. Might be useful if you need to check whether a completion is different from the last one.
Definition at line 222 of file kcompletion.h. |
|
|
Attempts to find an item in the list of available completions, that begins with In the latter case, a sound will be issued, depending on isSoundsEnabled(). If a match was found, it will also be emitted via the signal match(). If this is called twice or more often with the same string while no items were added or removed in the meantime, all available completions will be emitted via the signal matches(). This happens only in shell-completion-mode.
Reimplemented in KShellCompletion, and KURLCompletion. Referenced by slotMakeCompletion(). |
|
|
The matching item. Will be emitted by makeCompletion(), previousMatch() or nextMatch(). May be QString::null if there is no matching item.
Referenced by postProcessMatch(). |
|
|
All matching items. Will be emitted by makeCompletion() in shell- completion-mode, when the same string is passed to makeCompletion twice or more often.
Referenced by postProcessMatches(). |
|
|
This signal is emitted, when calling makeCompletion() and more than one matching item is found.
|
|
|
Returns the next item from the matching-items-list. When reaching the last item, the list is rotated, so it will return the first match and a sound is issued (depending on isSoundsEnabled()).
Referenced by slotNextMatch(). |
|
|
Returns the completion order.
Definition at line 293 of file kcompletion.h. References CompOrder. |
|
|
This method is called after a completion is found and before the matching string is emitted. You can override this method to modify the string that will be emitted. This is necessary e.g. in KURLCompletion(), where files with spaces in their names are shown escaped ("filename\ with\ spaces"), but stored unescaped inside KCompletion. Never delete that pointer! Default implementation does nothing.
Reimplemented in KShellCompletion, and KURLCompletion. Definition at line 519 of file kcompletion.h. References match(). |
|
|
This method is called before a list of all available completions is emitted via matches. You can override this method to modify the found items before match() or matches() are emitted. Never delete that pointer! Default implementation does nothing.
Reimplemented in KShellCompletion, and KURLCompletion. Definition at line 543 of file kcompletion.h. References matches(). |
|
|
This method is called before a list of all available completions is emitted via matches. You can override this method to modify the found items before match() or matches are emitted. Never delete that pointer! Default implementation does nothing.
Reimplemented in KShellCompletion, and KURLCompletion. Definition at line 531 of file kcompletion.h. References matches(). |
|
|
Returns the next item from the matching-items-list. When reaching the beginning, the list is rotated so it will return the last match and a sound is issued (depending on isSoundsEnabled()).
Referenced by slotPreviousMatch(). |
|
|
Removes an item from the list of available completions. Resets the current item-state (previousMatch() and nextMatch() won't work anymore).
|
|
|
Sets the completion mode to Auto/Manual, Shell or None. If you don't set the mode explicitly, the global default value KGlobalSettings::completionMode() is used. KGlobalSettings::CompletionNone disables completion.
|
|
|
Enables/disables playing a sound when
Definition at line 361 of file kcompletion.h. |
|
|
Setting this to true makes KCompletion behave case insensitively. E.g. makeCompletion( "CA" ); might return "carp@cs.tu-berlin.de". Default is false (case sensitive).
|
|
|
Sets the list of items available for completion. Removes all previous items. Notice: when order() == Weighted, then the weighting is looked up for every item in the stringlist. Every item should have ":number" appended, where number is an unsigned integer, specifying the weighting. If you don't like this, call setOrder( KCompletion::Insertion ) before calling setItems().
|
|
|
KCompletion offers three different ways in which it offers its items:
Note: Setting the order to sorted only affects new inserted items, already existing items will stay in the current order. So you probably want to call setOrder( Sorted ) before inserting items, when you want everything sorted. Default is insertion order.
|
|
|
Attempts to complete "string" and emits the completion via match(). Same as makeCompletion() (just as a slot).
Definition at line 400 of file kcompletion.h. References makeCompletion(). |
|
|
Searches the next matching item and emits it via match(). Same as nextMatch() (just as a slot).
Definition at line 418 of file kcompletion.h. References nextMatch(). |
|
|
Searches the previous matching item and emits it via match(). Same as previousMatch() (just as a slot).
Definition at line 409 of file kcompletion.h. References previousMatch(). |
|
|
Returns a list of all completion items that contain the given
|
1.2.18