[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
KLFIteratorSearchable< Iter > Class Template Referenceabstract

A Searchable object interface based on iterative searching. More...

#include <klfiteratorsearchable.h>

Inheritance diagram for KLFIteratorSearchable< Iter >:
Inheritance graph
[legend]
Collaboration diagram for KLFIteratorSearchable< Iter >:
Collaboration graph
[legend]

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. More...
 
virtual SearchIterator searchIterFindNext (bool forward)
 Find the next occurence of previous search string. More...
 
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)
 
- Public Member Functions inherited from KLFPosSearchable
virtual void searchReinitialized ()
 
virtual QString searchQueryString () const
 The current query string. More...
 
virtual void setSearchQueryString (const QString &s)
 
virtual bool searchHasInterruptRequested ()
 
virtual void setSearchInterruptRequested (bool on)
 
- Public Member Functions inherited from KLFTarget
 KLFTarget ()
 
virtual ~KLFTarget ()
 

Protected Member Functions

SearchIterator searchCurrentIterPos () const
 

Additional Inherited Members

- Protected Attributes inherited from KLFTarget
QList< KLFTargeter * > pTargetOf
 

Detailed Description

template<class Iter>
class KLFIteratorSearchable< Iter >

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:

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.

Member Typedef Documentation

◆ SearchIterator

template<class Iter>
typedef Iter KLFIteratorSearchable< Iter >::SearchIterator

Definition at line 84 of file klfiteratorsearchable.h.

Constructor & Destructor Documentation

◆ KLFIteratorSearchable()

template<class Iter>
KLFIteratorSearchable< Iter >::KLFIteratorSearchable ( )
inline

Definition at line 76 of file klfiteratorsearchable.h.

◆ ~KLFIteratorSearchable()

template<class Iter>
virtual KLFIteratorSearchable< Iter >::~KLFIteratorSearchable ( )
inlinevirtual

Definition at line 80 of file klfiteratorsearchable.h.

Member Function Documentation

◆ searchAborted()

template<class Iter>
virtual void KLFIteratorSearchable< Iter >::searchAborted ( )
inlinevirtual

Implements KLFPosSearchable.

Reimplemented in KLFItemViewSearchTarget.

Definition at line 158 of file klfiteratorsearchable.h.

Referenced by KLFItemViewSearchTarget::searchAborted().

◆ searchAdvanceIteratorCycle()

template<class Iter>
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.

◆ searchAdvanceIteratorSafe()

template<class Iter>
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().

Bug:
THIS FUNCITON IS VERY CLOSE TO searchAdvanceIteratorCycle ! DON'T DUPLICATE CODE !

Definition at line 292 of file klfiteratorsearchable.h.

◆ searchCurrentIterPos()

template<class Iter>
SearchIterator KLFIteratorSearchable< Iter >::searchCurrentIterPos ( ) const
inlineprotected

Definition at line 326 of file klfiteratorsearchable.h.

◆ searchFind()

template<class Iter>
virtual Pos KLFIteratorSearchable< Iter >::searchFind ( const QString queryString,
const Pos fromPos,
bool  forward 
)
inlinevirtual

Implements KLFPosSearchable.

Definition at line 271 of file klfiteratorsearchable.h.

◆ searchIterAdvance()

template<class Iter>
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.

◆ searchIterBegin()

template<class Iter>
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.

◆ searchIterEnd()

template<class Iter>
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.

◆ searchIterFind()

template<class Iter>
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterFind ( const SearchIterator startPos,
const QString queryString,
bool  forward 
)
inlinevirtual

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.

◆ searchIterFindNext()

template<class Iter>
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterFindNext ( bool  forward)
inlinevirtual

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.

◆ searchIterMatches()

template<class Iter>
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.

◆ searchIterNext()

template<class Iter>
SearchIterator KLFIteratorSearchable< Iter >::searchIterNext ( const SearchIterator pos)
inline

Increment iterator. Shortcut for searchIterAdvance() with forward = TRUE.

Definition at line 103 of file klfiteratorsearchable.h.

◆ searchIterPrev()

template<class Iter>
SearchIterator KLFIteratorSearchable< Iter >::searchIterPrev ( const SearchIterator pos)
inline

Decrement iterator. Shortcut for searchIterAdvance() with forward = FALSE.

Definition at line 106 of file klfiteratorsearchable.h.

◆ searchIterStartFrom()

template<class Iter>
virtual SearchIterator KLFIteratorSearchable< Iter >::searchIterStartFrom ( bool  forward)
inlinevirtual

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.

◆ searchMoveToIterPos()

template<class Iter>
virtual void KLFIteratorSearchable< Iter >::searchMoveToIterPos ( const SearchIterator pos)
inlinevirtual

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.

◆ searchMoveToPos()

template<class Iter>
virtual void KLFIteratorSearchable< Iter >::searchMoveToPos ( const Pos pos)
inlinevirtual

Reimplemented from KLFPosSearchable.

Definition at line 182 of file klfiteratorsearchable.h.

◆ searchPerformed() [1/3]

template<class Iter>
virtual void KLFIteratorSearchable< Iter >::searchPerformed ( const SearchIterator resultMatchPosition,
bool  found,
const QString queryString 
)
inlinevirtual

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.

◆ searchPerformed() [2/3]

template<class Iter>
virtual void KLFIteratorSearchable< Iter >::searchPerformed ( const SearchIterator resultMatchPosition)
inlinevirtual

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.

◆ searchPerformed() [3/3]

template<class Iter>
virtual void KLFIteratorSearchable< Iter >::searchPerformed ( const QString queryString,
bool  found,
const Pos pos 
)
inlinevirtual

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.

◆ searchStartFrom()

template<class Iter>
virtual Pos KLFIteratorSearchable< Iter >::searchStartFrom ( bool  forward)
inlinevirtual

Reimplemented from KLFPosSearchable.

Definition at line 168 of file klfiteratorsearchable.h.


The documentation for this class was generated from the following file:

Generated by doxygen 1.8.13