A Searchable object interface based on iterative searching. More...
#include <klfiteratorsearchable.h>
Classes | |
struct | IterPosData |
Public Types | |
typedef Iter | SearchIterator |
Public Member Functions | |
KLFIteratorSearchable () | |
virtual | ~KLFIteratorSearchable () |
virtual SearchIterator | searchIterBegin ()=0 |
virtual SearchIterator | searchIterEnd ()=0 |
virtual SearchIterator | searchIterAdvance (const SearchIterator &pos, bool forward)=0 |
SearchIterator | searchIterNext (const SearchIterator &pos) |
SearchIterator | searchIterPrev (const SearchIterator &pos) |
virtual SearchIterator | searchIterStartFrom (bool forward) |
virtual bool | searchIterMatches (const SearchIterator &pos, const QString &queryString)=0 |
virtual void | searchPerformed (const SearchIterator &resultMatchPosition, bool found, const QString &queryString) |
virtual void | searchMoveToIterPos (const SearchIterator &pos) |
virtual void | searchPerformed (const SearchIterator &resultMatchPosition) |
virtual void | searchAborted () |
virtual Pos | searchStartFrom (bool forward) |
virtual void | searchPerformed (const QString &queryString, bool found, const Pos &pos) |
virtual void | searchMoveToPos (const Pos &pos) |
virtual SearchIterator | searchIterFind (const SearchIterator &startPos, const QString &queryString, bool forward) |
Find occurence of a search string. | |
virtual SearchIterator | searchIterFindNext (bool forward) |
Find the next occurence of previous search string. | |
virtual Pos | searchFind (const QString &queryString, const Pos &fromPos, bool forward) |
SearchIterator | searchAdvanceIteratorSafe (const SearchIterator &it, int n=1) |
SearchIterator | searchAdvanceIteratorCycle (const SearchIterator &it, int n=1, bool skipEnd=false) |
Protected Member Functions | |
SearchIterator | searchCurrentIterPos () const |
A Searchable object interface based on iterative searching.
Most searchable displays work with iterators, or objects that behave as such. This can be, for example, an integer position in a displayed list. When searchFind() is called, then usually the search iteratively looks at all items in the list, until a match is found.
This class implements an interface of such iterator-based searchable displays for use as a KLFSearchable, to be searched with a KLFSearchBar for example.
The iterator may be any object that:
int
, QModelIndex
, ...)The functions searchIterBegin() and searchIterEnd() have to be implemented, to return respectively an iterator position for the first valid displayed element, and an iterator for the one-after-last-valid displayed item.
The function searchIterAdvance(), by default uses operator-(Iter, int) and operator+(Iter, int) to increment or decrement the iterator by one. If this is not the correct way to increment/decrement an iterator, reimplement this function to perform the job correctly. (for example to walk with QModelIndex'es in a tree view).
The search functions defined in this class guarantee never to increment an iterator that is already equal to searchIterEnd(), and never to decrement an operator that is equal to searchIterBegin().
The searchIterMatches() has to be reimplemented to say whether the data displayed at the given position matches with the query string.
This class provides implementations for KLFSearchable's searchFind(), searchFindNext() and searchAbort(). Additionally, it provides searchIterFind(), searchIterFindNext() which are a bit more flexible than KLFSearchable's base functions (for example by returning the match position!).
Definition at line 73 of file klfiteratorsearchable.h.
typedef Iter KLFIteratorSearchable< Iter >::SearchIterator |
Definition at line 84 of file klfiteratorsearchable.h.
KLFIteratorSearchable< Iter >::KLFIteratorSearchable | ( | ) | [inline] |
Definition at line 76 of file klfiteratorsearchable.h.
virtual KLFIteratorSearchable< Iter >::~KLFIteratorSearchable | ( | ) | [inline, virtual] |
Definition at line 80 of file klfiteratorsearchable.h.
virtual void KLFIteratorSearchable< Iter >::searchAborted | ( | ) | [inline, virtual] |
Implements KLFPosSearchable.
Reimplemented in KLFItemViewSearchTarget.
Definition at line 158 of file klfiteratorsearchable.h.
SearchIterator KLFIteratorSearchable< Iter >::searchAdvanceIteratorCycle | ( | const SearchIterator & | it, |
int | n = 1 , |
||
bool | skipEnd = false |
||
) | [inline] |
Advances the iterator it
by n
steps (which may be negative). If the end is reached, the iterator wraps back to the beginning. if skipEnd
is true, then the position when it is equal to searchIterEnd() is skipped.
Definition at line 310 of file klfiteratorsearchable.h.
SearchIterator KLFIteratorSearchable< Iter >::searchAdvanceIteratorSafe | ( | const SearchIterator & | it, |
int | n = 1 |
||
) | [inline] |
Advances iterator it
safely, that means it increments or decrements the iterator while always making sure not to perform illegal operations like increment an iterator that has arrived at searchIterEnd() and making sure not to decrement an iterator that has arrived at searchIterBegin().
Iterators that have arrived to searchIterEnd() or searchIterBegin(), when again incremented (resp. decremented), wrap around and start again from the other end. Namely decrementing an iterator equal to searchIterBegin() will give you searchIterEnd() and incrementing searchIterEnd() will yield searchIterBegin().
Definition at line 292 of file klfiteratorsearchable.h.
SearchIterator KLFIteratorSearchable< Iter >::searchCurrentIterPos | ( | ) | const [inline, protected] |
Definition at line 326 of file klfiteratorsearchable.h.
virtual Pos KLFIteratorSearchable< Iter >::searchFind | ( | const QString & | queryString, |
const Pos & | fromPos, | ||
bool | forward | ||
) | [inline, virtual] |
Implements KLFPosSearchable.
Definition at line 271 of file klfiteratorsearchable.h.
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterAdvance | ( | const SearchIterator & | pos, |
bool | forward | ||
) | [pure virtual] |
Increment or decrement iterator. The default implementation does pos+1
or pos-1
; you can re-implement this function if your iterator cannot be incremented/decremented this way.
Implemented in KLFItemViewSearchTarget.
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterBegin | ( | ) | [pure virtual] |
Returns the first valid SearchIterator
object. This should point to the element at top of the display, or be equal to searchIterEnd() if the display is empty.
Implemented in KLFItemViewSearchTarget.
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterEnd | ( | ) | [pure virtual] |
Returns the one-after-last-valid SearchIterator
object. This should NOT point to a valid object, however it should either be equal to searchIterBegin() if the display is empty, or if searchIterPrev() is called on it it should validly point on the last object in display.
Implemented in KLFItemViewSearchTarget.
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterFind | ( | const SearchIterator & | startPos, |
const QString & | queryString, | ||
bool | forward | ||
) | [inline, virtual] |
Find occurence of a search string.
Extension of searchFind(). Looks for queryString
starting at position startPos
.
This function returns the position to the first match, or searchIterEnd() if no match was found.
This function starts searching immediately after startPos
, in forward direction, if forward
is TRUE, and searches immediately before from c startPos, in reverse direction, if forward
is FALSE.
This function need not be reimplemented, the default implementation should suffice for most cases.
Definition at line 201 of file klfiteratorsearchable.h.
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterFindNext | ( | bool | forward | ) | [inline, virtual] |
Find the next occurence of previous search string.
Extension of searchFindNext(), in that this function returns the position of the next match.
Returns searchIterEnd() if no match was found.
This function need not be reimplemented, the default implementation should suffice for most cases.
Definition at line 218 of file klfiteratorsearchable.h.
virtual bool KLFIteratorSearchable< Iter >::searchIterMatches | ( | const SearchIterator & | pos, |
const QString & | queryString | ||
) | [pure virtual] |
See if the data pointed at by pos
matches the query string queryString
. Return TRUE if it does match, or FALSE if it does not match.
pos
is garanteed to point on a valid object (this function will never be called with pos
equal to searchIterEnd()).
Implemented in KLFItemViewSearchTarget.
SearchIterator KLFIteratorSearchable< Iter >::searchIterNext | ( | const SearchIterator & | pos | ) | [inline] |
Increment iterator. Shortcut for searchIterAdvance() with forward
= TRUE.
Definition at line 103 of file klfiteratorsearchable.h.
SearchIterator KLFIteratorSearchable< Iter >::searchIterPrev | ( | const SearchIterator & | pos | ) | [inline] |
Decrement iterator. Shortcut for searchIterAdvance() with forward
= FALSE.
Definition at line 106 of file klfiteratorsearchable.h.
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterStartFrom | ( | bool | forward | ) | [inline, virtual] |
Returns the position from where we should start the search, given the current view situation. This can be reimplemented to start the search for example from the current scroll position in the display.
If forward
is TRUE, then the search is about to be performed forward, otherwise it is about to be performed in reverse direction.
The default implementation returns searchIterEnd().
Definition at line 115 of file klfiteratorsearchable.h.
virtual void KLFIteratorSearchable< Iter >::searchMoveToIterPos | ( | const SearchIterator & | pos | ) | [inline, virtual] |
Virtual handler that is called when the current search position moves, eg. we moved to next match. For example, reimplement this function to select the corresponding item in a list (possibly scrolling the list) to display the matching item to the user.
Reimplemented in KLFItemViewSearchTarget.
Definition at line 140 of file klfiteratorsearchable.h.
virtual void KLFIteratorSearchable< Iter >::searchMoveToPos | ( | const Pos & | pos | ) | [inline, virtual] |
Reimplemented from KLFPosSearchable.
Definition at line 182 of file klfiteratorsearchable.h.
virtual void KLFIteratorSearchable< Iter >::searchPerformed | ( | const SearchIterator & | resultMatchPosition, |
bool | found, | ||
const QString & | queryString | ||
) | [inline, virtual] |
Virtual handler for the subclass to act upon the result of a search. A subclass may for example want to select the matched item in a list to make it conspicuous to the user.
resultMatchPosition
is the position of the item that matched the search. If resultMatchPosition
is equal to searchIterEnd(), then the search failed (no match was found). (Note in this case calling searchFindNext() again will wrap the search).
The base implementation does nothing.
Reimplemented in KLFItemViewSearchTarget.
Definition at line 134 of file klfiteratorsearchable.h.
virtual void KLFIteratorSearchable< Iter >::searchPerformed | ( | const SearchIterator & | resultMatchPosition | ) | [inline, virtual] |
Virtual handler for the subclass to act upon the result of a search. Same as searchPerformed(const SearchIterator&, bool, const QString&), but with less pararmeters. This function is exactly called when the other function is called, too.
Definition at line 147 of file klfiteratorsearchable.h.
virtual void KLFIteratorSearchable< Iter >::searchPerformed | ( | const QString & | queryString, |
bool | found, | ||
const Pos & | pos | ||
) | [inline, virtual] |
Reimplemented from KLFPosSearchable. This function calls the searchPerformed(const SearchIterator&) functions. In subclasses, reimplement one of those instead.
Reimplemented from KLFPosSearchable.
Definition at line 176 of file klfiteratorsearchable.h.
virtual Pos KLFIteratorSearchable< Iter >::searchStartFrom | ( | bool | forward | ) | [inline, virtual] |
Reimplemented from KLFPosSearchable.
Definition at line 168 of file klfiteratorsearchable.h.