Version: 9.12.0
QtxSearchTool Class Reference

Context search tool. More...

#include <QtxSearchTool.h>

Inheritance diagram for QtxSearchTool:
Inheritance graph

Classes

class  Searcher
 Generic searcher class. More...
 

Public Types

enum  Controls {
  Search = 0x00000001 , Next = 0x00000002 , Prev = 0x00000004 , First = 0x00000008 ,
  Last = 0x00000010 , Close = 0x00000020 , Case = 0x00000040 , RegExp = 0x00000080 ,
  Wrap = 0x00000100 , Basic = Search | Next | Prev | Close , Standard = Basic | First | Last , Modifiers = Case | RegExp | Wrap ,
  All = Standard | Modifiers
}
 Search tool controls. More...
 
enum  Activator {
  None = 0x00000000 , HotKey = 0x00000001 , SlashKey = 0x00000002 , StandardKey = 0x00000004 ,
  PrintKey = 0x00000008 , Any = HotKey | SlashKey | StandardKey | PrintKey
}
 

Public Slots

virtual void find ()
 Activate search tool. More...
 
virtual void findNext ()
 Find next appropriate data. More...
 
virtual void findPrevious ()
 Find previous appropriate data. More...
 
virtual void findFirst ()
 Find first appropriate data. More...
 
virtual void findLast ()
 Find last appropriate data. More...
 

Public Member Functions

 QtxSearchTool (QWidget *, QWidget *=0, int=All, Qt::Orientation=Qt::Vertical)
 Constructor. More...
 
 QtxSearchTool (QWidget *, int=All, Qt::Orientation=Qt::Vertical)
 Constructor. More...
 
virtual ~QtxSearchTool ()
 Destructor. More...
 
QWidgetwatchedWidget () const
 Get watched widget. More...
 
void setWatchedWidget (QWidget *)
 Set watched widget. More...
 
Searchersearcher () const
 Get current searcher. More...
 
void setSearcher (Searcher *)
 Assign searcher. More...
 
int activators () const
 Get activators. More...
 
void setActivators (const int)
 Set activators. More...
 
int controls () const
 Get controls. More...
 
void setControls (const int)
 Set controls. More...
 
QList< QKeySequence > shortcuts () const
 Get shortcuts. More...
 
void setShortcuts (const QKeySequence &)
 Set shortcuts. More...
 
void setShortcuts (const QList< QKeySequence > &)
 Set shortcuts. More...
 
int addCustomWidget (QWidget *, int=-1)
 Add custom widget. More...
 
QWidgetcustomWidget (int) const
 Get custom widget by ID. More...
 
int customWidgetId (QWidget *) const
 Get custom widget ID. More...
 
bool isAutoHideEnabled () const
 Check if auto-hide of the tool widget is enabled. More...
 
void enableAutoHide (bool)
 Set/clear auto-hide option. More...
 
bool isCaseSensitive () const
 Get 'case sensitive search' option value. More...
 
bool isRegExpSearch () const
 Get 'regular expression search' option value. More...
 
bool isSearchWrapped () const
 Get 'search wrapping' option value. More...
 
void setCaseSensitive (bool)
 Set 'case sensitive search' option value. More...
 
void setRegExpSearch (bool)
 Set 'regular expression search' option value. More...
 
void setSearchWrapped (bool)
 Set 'search wrapping' option value. More...
 
virtual bool event (QEvent *)
 Customize event handling. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filter events from the watched widget. More...
 

Private Types

enum  {
  fAny , fNext , fPrevious , fFirst ,
  fLast
}
 Find operation type. More...
 
typedef QPointer< QShortcut > ShortcutPtr
 
typedef QList< ShortcutPtrShortcutList
 

Private Slots

void find (const QString &, int=fAny)
 Perform search. More...
 
void modifierSwitched ()
 Called when any search modifier is switched. More...
 

Private Member Functions

void init (Qt::Orientation)
 Initialize the search tool widget. More...
 
bool focused () const
 Check if any child widget has input focus. More...
 
void clearShortcuts ()
 Clear shortcuts. More...
 
void initShortcuts (const QList< QKeySequence > &)
 Install shortcuts. More...
 
void updateShortcuts ()
 Update shortcuts state. More...
 
void updateControls ()
 Update controls state. More...
 

Private Attributes

QWidgetmyBtnWidget
 
QWidgetmyModWidget
 
QLineEditmyData
 
QToolButtonmyToFirst
 
QToolButtonmyToLast
 
QToolButtonmyNext
 
QToolButtonmyPrev
 
QToolButtonmyClose
 
QCheckBox * myIsCaseSens
 
QCheckBox * myIsRegExp
 
QCheckBox * myWrap
 
QWidgetmyWatched
 
SearchermySearcher
 
int myControls
 
int myActivators
 
ShortcutList myShortcuts
 
QTimer * myAutoHideTimer
 
bool myAutoHideEnabled
 
QMap< int, QWidget * > myWidgets
 

Detailed Description

Context search tool.

The QtxSearchTool class implements a specific context search tool widget which can be embedded into any GUI element. It represents the usual dialog panel with the line edit box used to enter text to be searched and set of buttons, like "Find Next", "Find Previous", etc. In addition, the search modifiers like "Case sensitive search", "Wrap search" are provided.

Actually the class QtxSearchTool does not perform a serach itself - it is only the generic widget. To use this widget, you have to install a searcher depending on your needs. This should be a successor of the class QtxSearchTool::Searcher - it is the class which will perform actual search of the data in your widget according to the widget type.

For the current moment, only one standard searcher is implemented: it is the class QtxTreeViewSearcher, which can be used to search the text data in the tree view widget (QTreeView). See this class for more details.

The usual usage of the searcher widget is the following:

QTreeView* tree = new QTreeView( this );
st->setSearcher( new QtxTreeViewSearcher( tree ) );
Context search tool.
Definition: QtxSearchTool.h:41
void setActivators(const int)
Set activators.
Definition: QtxSearchTool.cxx:400
@ Standard
standard controls: same as Basic plus "first" and "last" buttons
Definition: QtxSearchTool.h:68
@ SlashKey
search tool is activated by splash key ( / )
Definition: QtxSearchTool.h:76
@ StandardKey
search tool is activated by standard key combination (e.g. F3)
Definition: QtxSearchTool.h:77
QtxSearchTool(QWidget *, QWidget *=0, int=All, Qt::Orientation=Qt::Vertical)
Constructor.
Definition: QtxSearchTool.cxx:273
void setSearcher(Searcher *)
Assign searcher.
Definition: QtxSearchTool.cxx:378
A QTreeView class based searcher.
Definition: QtxSearchTool.h:179

Note, that controls to be displayed by the search tool widget are passed as ORed flags to the widget's constructor. At any time, the available controls can be set/get with setControls() and controls() methods. By default, all widgets are displayed (see also QtxSearchTool::Controls enumeration).

The class QtxSearchTool also provides a way to add custom widgets - these widgets are displayed at the bottom area of the tool box. Use method addCustomWidget() to add custom widget to the search tool box. Your searcher class can use custom widgets to perform advanced search.

The class supports different ways of the activation, all of them can be switched on/off with setActivators() method. See QtxSearchTool::Activator enumeration for more details. By default, all methods are switched on: default hot key is <Ctrl> and standard key bindings are the platform dependent keyboard shortcuts. Shortcuts can be assigned with the setShortcuts() methods.

Member Typedef Documentation

◆ ShortcutList

◆ ShortcutPtr

typedef QPointer<QShortcut> QtxSearchTool::ShortcutPtr
private

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Find operation type.

Enumerator
fAny 

find any appropriate

fNext 

find next appropriate

fPrevious 

find previous appropriate

fFirst 

find first appropriate

fLast 

find last appropriate

◆ Activator

Enumerator
None 

search tool can be activated programmatically only

HotKey 

search tool is activated by hot key

SlashKey 

search tool is activated by splash key ( / )

StandardKey 

search tool is activated by standard key combination (e.g. F3)

PrintKey 

search tool is activated when user types any print key

Any 

search tool is activated by any of above mentioned ways

◆ Controls

Search tool controls.

Enumerator
Search 

line edit field for searched text

Next 

'find next' button

Prev 

'find previous' button

First 

'find first' button

Last 

'find last' button

Close 

'close' button

Case 

'case sensitive search' check box

RegExp 

'regular expression' check box

Wrap 

'wrap search' check box

Basic 

basic controls: text field, "next", "prev" and "close" buttons

Standard 

standard controls: same as Basic plus "first" and "last" buttons

Modifiers 

search modifiers check boxes

All 

all controls

Constructor & Destructor Documentation

◆ QtxSearchTool() [1/2]

QtxSearchTool::QtxSearchTool ( QWidget parent,
QWidget watched = 0,
int  controls = All,
Qt::Orientation  orientation = Qt::Vertical 
)

Constructor.

Creates a search tool widget with parent widget parent and watched widget watched. The controls to be displayed can be passed via controls parameter. By default, all controls are displayed.

Parameters
parentparent widget
watchedwatched widget
controlsORed controls flags (QtxSearchTool::Controls)
See also
setWatchedWidget(), setControls()

References init().

◆ QtxSearchTool() [2/2]

QtxSearchTool::QtxSearchTool ( QWidget parent,
int  controls = All,
Qt::Orientation  orientation = Qt::Vertical 
)

Constructor.

Creates a search tool widget with parent widget parent. Parameter parent is also used to set watched widget. The controls to be displayed can be passed via controls parameter. By default, all controls are displayed.

Parameters
parentparent widget
controlsORed controls flags (QtxSearchTool::Controls)
See also
setWatchedWidget(), setControls()

References init().

◆ ~QtxSearchTool()

QtxSearchTool::~QtxSearchTool ( )
virtual

Destructor.

References clearShortcuts(), and mySearcher.

Member Function Documentation

◆ activators()

int QtxSearchTool::activators ( ) const

Get activators.

Returns
activators currently enabled (ORed QtxSearchTool::Activator flags)
See also
setActivators()

References myActivators.

◆ addCustomWidget()

int QtxSearchTool::addCustomWidget ( QWidget w,
int  id = -1 
)

Add custom widget.

Parameters
wcustom widget to be added
idwidget unique ID to be used (if < 0, automatically assigned)
Returns
widget unique ID
See also
customWidget(), customWidgetId()

References myWidgets.

◆ clearShortcuts()

void QtxSearchTool::clearShortcuts ( )
private

Clear shortcuts.

References myShortcuts.

◆ controls()

int QtxSearchTool::controls ( ) const

Get controls.

Returns
controls currently enabled (ORed QtxSearchTool::Controls flags)
See also
setControls()

References myControls.

◆ customWidget()

QWidget * QtxSearchTool::customWidget ( int  id) const

Get custom widget by ID.

Parameters
idwidget ID
Returns
custom widget or 0 if not found
See also
addCustomWidget(), customWidgetId()

References myWidgets.

◆ customWidgetId()

int QtxSearchTool::customWidgetId ( QWidget w) const

Get custom widget ID.

Parameters
wcustom widget
Returns
custom widget ID or -1 if widget does not belong to the search tool
See also
addCustomWidget(), customWidget()

References myWidgets.

◆ enableAutoHide()

void QtxSearchTool::enableAutoHide ( bool  enable)

Set/clear auto-hide option.

By default, the search tool widget is automatically hidden after 10 seconds of idle (only if watched widget has input focus).

Parameters
enablenew option state
See also
isAutoHideEnabled()

References focused(), myAutoHideEnabled, and myAutoHideTimer.

◆ event()

bool QtxSearchTool::event ( QEvent e)
virtual

Customize event handling.

Parameters
eevent
Returns
true if event has been handled

References myWatched, and updateShortcuts().

◆ eventFilter()

bool QtxSearchTool::eventFilter ( QObject o,
QEvent e 
)
virtual

Filter events from the watched widget.

Parameters
oobject
eevent
Returns
true if further event processing should be stopped

References find(), findNext(), focused(), isAutoHideEnabled(), myActivators, myAutoHideTimer, myData, myWatched, PrintKey, and SlashKey.

◆ find [1/2]

void QtxSearchTool::find ( )
virtualslot

Activate search tool.

Call this method to start new search.

References myAutoHideTimer, and myData.

◆ find [2/2]

void QtxSearchTool::find ( const QString &  what,
int  where = fAny 
)
privateslot

◆ findFirst

void QtxSearchTool::findFirst ( )
virtualslot

Find first appropriate data.

Call this method to find the very first appropriate data.

References fFirst, find(), and myData.

◆ findLast

void QtxSearchTool::findLast ( )
virtualslot

Find last appropriate data.

Call this method to find the very last appropriate data.

References find(), fLast, and myData.

◆ findNext

void QtxSearchTool::findNext ( )
virtualslot

Find next appropriate data.

Call this method to repeat the search in the forward direction.

References find(), fNext, and myData.

◆ findPrevious

void QtxSearchTool::findPrevious ( )
virtualslot

Find previous appropriate data.

Call this method to repeat the search in the backward direction.

References find(), fPrevious, and myData.

◆ focused()

bool QtxSearchTool::focused ( ) const
private

Check if any child widget has input focus.

Returns
true if any child widget has input focus

◆ init()

◆ initShortcuts()

void QtxSearchTool::initShortcuts ( const QList< QKeySequence > &  accels)
private

Install shortcuts.

Parameters
accelsshortcuts list

References clearShortcuts(), DefaultAutoHideDelay, find(), VTK::Find(), findNext(), findPrevious(), myAutoHideTimer, myShortcuts, myWatched, and updateShortcuts().

◆ isAutoHideEnabled()

bool QtxSearchTool::isAutoHideEnabled ( ) const

Check if auto-hide of the tool widget is enabled.

By default, the search tool widget is automatically hidden after 10 seconds of idle (only if watched widget has input focus).

Returns
true if auto-hide option is set
See also
enableAutoHide()

References myAutoHideEnabled.

◆ isCaseSensitive()

bool QtxSearchTool::isCaseSensitive ( ) const

Get 'case sensitive search' option value.

This method returns true if 'case sensitive search' control is enabled and switched on.

Returns
true if case sensitive search is performed
See also
isRegExpSearch(), isSearchWrapped(), setControls()
setCaseSensitive(), setRegExpSearch(), setSearchWrapped()

References Case, myControls, and myIsCaseSens.

◆ isRegExpSearch()

bool QtxSearchTool::isRegExpSearch ( ) const

Get 'regular expression search' option value.

This method returns true if 'regular expression search' control is enabled and switched on.

Returns
true if regular expression search is performed
See also
isCaseSensitive(), isSearchWrapped(), setControls()
setCaseSensitive(), setRegExpSearch(), setSearchWrapped()

References myControls, myIsRegExp, and RegExp.

◆ isSearchWrapped()

bool QtxSearchTool::isSearchWrapped ( ) const

Get 'search wrapping' option value.

This method returns true if 'wrap search' control is enabled and switched on.

Returns
true if search wrapping is enabled
See also
isCaseSensitive(), isRegExpSearch(), setControls()
setCaseSensitive(), setRegExpSearch(), setSearchWrapped()

References myControls, myWrap, and Wrap.

◆ modifierSwitched

void QtxSearchTool::modifierSwitched ( )
privateslot

Called when any search modifier is switched.

References find(), and myData.

◆ searcher()

QtxSearchTool::Searcher * QtxSearchTool::searcher ( ) const

Get current searcher.

Returns
currently set searcher (QtxSearchTool::Searcher)
See also
setSearcher()

References mySearcher.

◆ setActivators()

void QtxSearchTool::setActivators ( const int  flags)

Set activators.

Parameters
flagsset activators to be used (ORed QtxSearchTool::Activator flags)
See also
activators()

References myActivators, and updateShortcuts().

◆ setCaseSensitive()

void QtxSearchTool::setCaseSensitive ( bool  on)

Set 'case sensitive search' option value.

Parameters
onnew option state
See also
setRegExpSearch(), setSearchWrapped(), setControls()
isCaseSensitive(), isRegExpSearch(), isSearchWrapped()

References Case, myControls, and myIsCaseSens.

◆ setControls()

void QtxSearchTool::setControls ( const int  ctrls)

Set controls.

Parameters
ctrlscontrols to be displayed (ORed QtxSearchTool::Controls flags)
See also
controls()

References myControls, and updateControls().

◆ setRegExpSearch()

void QtxSearchTool::setRegExpSearch ( bool  on)

Set 'regular expression search' option value.

Parameters
onnew option state
See also
setCaseSensitive(), setSearchWrapped(), setControls()
isCaseSensitive(), isRegExpSearch(), isSearchWrapped()

References myControls, myIsRegExp, and RegExp.

◆ setSearcher()

void QtxSearchTool::setSearcher ( QtxSearchTool::Searcher s)

Assign searcher.

Note: the search tool takes ownership to the searcher and destroys it when deleted.

Parameters
ssearcher to be used (QtxSearchTool::Searcher)
See also
searcher()

References mySearcher.

◆ setSearchWrapped()

void QtxSearchTool::setSearchWrapped ( bool  on)

Set 'search wrapping' option value.

Parameters
onnew option state
See also
setCaseSensitive(), setRegExpSearch(), setControls()
isCaseSensitive(), isRegExpSearch(), isSearchWrapped()

References myControls, myWrap, and Wrap.

◆ setShortcuts() [1/2]

void QtxSearchTool::setShortcuts ( const QKeySequence &  accel)

Set shortcuts.

Parameters
accelshortcut binding(s) to be used
See also
shortcuts()

◆ setShortcuts() [2/2]

void QtxSearchTool::setShortcuts ( const QList< QKeySequence > &  accels)

Set shortcuts.

Parameters
accelshortcut bindings to be used
See also
shortcuts()

References initShortcuts().

◆ setWatchedWidget()

void QtxSearchTool::setWatchedWidget ( QWidget watched)

Set watched widget.

Watched widget is that one for which shortcut bindings are set. When this widget has focus and any hot key binbding is pressed by the user, the search tool box is activated. The same occurs if slash key is pressed and QtxSearchTool::SlashKey activator is enabled. If the QtxSearchTool::PrintKey activator is enabled, the tool box is activated if any printed key is pressed by the user.

Parameters
watcheda widget to be watched by the search tool
See also
watchedWidget(), activators(), setActivators()

References initShortcuts(), myWatched, and shortcuts().

◆ shortcuts()

QList< QKeySequence > QtxSearchTool::shortcuts ( ) const

Get shortcuts.

Note: the standard bindings are not include to the resulting list.

Returns
list of shortcuts bindings currently set
See also
setShortcuts()

References myShortcuts.

◆ updateControls()

void QtxSearchTool::updateControls ( )
private

◆ updateShortcuts()

void QtxSearchTool::updateShortcuts ( )
private

Update shortcuts state.

References HotKey, myActivators, myShortcuts, and StandardKey.

◆ watchedWidget()

QWidget * QtxSearchTool::watchedWidget ( ) const

Get watched widget.

Returns
currently used watched widget
See also
setWatchedWidget(), activators(), setActivators()

References myWatched.

Member Data Documentation

◆ myActivators

int QtxSearchTool::myActivators
private

◆ myAutoHideEnabled

bool QtxSearchTool::myAutoHideEnabled
private

◆ myAutoHideTimer

QTimer* QtxSearchTool::myAutoHideTimer
private

◆ myBtnWidget

QWidget* QtxSearchTool::myBtnWidget
private

◆ myClose

QToolButton* QtxSearchTool::myClose
private

◆ myControls

int QtxSearchTool::myControls
private

◆ myData

QLineEdit* QtxSearchTool::myData
private

◆ myIsCaseSens

QCheckBox* QtxSearchTool::myIsCaseSens
private

◆ myIsRegExp

QCheckBox* QtxSearchTool::myIsRegExp
private

◆ myModWidget

QWidget* QtxSearchTool::myModWidget
private

◆ myNext

QToolButton* QtxSearchTool::myNext
private

◆ myPrev

QToolButton* QtxSearchTool::myPrev
private

◆ mySearcher

Searcher* QtxSearchTool::mySearcher
private

◆ myShortcuts

ShortcutList QtxSearchTool::myShortcuts
private

◆ myToFirst

QToolButton* QtxSearchTool::myToFirst
private

◆ myToLast

QToolButton* QtxSearchTool::myToLast
private

◆ myWatched

QWidget* QtxSearchTool::myWatched
private

◆ myWidgets

QMap<int, QWidget*> QtxSearchTool::myWidgets
private

◆ myWrap

QCheckBox* QtxSearchTool::myWrap
private

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