.PP
.TH "KFind" 3 "28 Jan 2004" "kutils Library" \" -*- nroff -*-
.ad l
.nh
.SH NAME
KFind \- A generic implementation of the 'find' function.  

.PP
.SH SYNOPSIS
.br
.PP
\fC#include <kfind.h>\fP
.PP
Inherits \fBQObject\fP.
.PP
Inherited by \fBKReplace\fP.
.PP
.SS "Public Types"

.in +1c
.ti -1c
.RI "enum \fBResult\fP { \fBNoMatch\fP, \fBMatch\fP }"
.br
.in -1c
.SS "Signals"

.in +1c
.ti -1c
.RI "void \fBhighlight\fP (const  \fBQString\fP &text, int matchingIndex, int matchedLength)"
.br
.RI "\fIConnect to this signal to implement highlighting of found text during the find operation. \fP"
.ti -1c
.RI "void \fBfindNext\fP ()"
.br
.ti -1c
.RI "void \fBoptionsChanged\fP ()"
.br
.RI "\fIEmitted when the options have changed. \fP"
.ti -1c
.RI "void \fBdialogClosed\fP ()"
.br
.RI "\fIEmitted when the 'find next' dialog is being closed. \fP"
.in -1c
.SS "Public Member Functions"

.in +1c
.ti -1c
.RI "\fBKFind\fP (const  \fBQString\fP &pattern, long options, \fBQWidget\fP *\fBparent\fP)"
.br
.ti -1c
.RI "bool \fBneedData\fP () const "
.br
.ti -1c
.RI "void \fBsetData\fP (const  \fBQString\fP &data, int startPos=-1)"
.br
.RI "\fICall this when needData returns true, before calling \fBfind\fP(). \fP"
.ti -1c
.RI "Result \fBfind\fP ()"
.br
.RI "\fIWalk the text fragment (e.g. \fP"
.ti -1c
.RI "long \fBoptions\fP () const "
.br
.RI "\fIReturn the current options. \fP"
.ti -1c
.RI "virtual void \fBsetOptions\fP (long options)"
.br
.RI "\fISet new options. \fP"
.ti -1c
.RI "int \fBnumMatches\fP () const "
.br
.RI "\fIReturn the number of matches found (i.e. \fP"
.ti -1c
.RI "virtual void \fBresetCounts\fP ()"
.br
.RI "\fICall this to reset the numMatches count (and the numReplacements count for a \fBKReplace\fP). \fP"
.ti -1c
.RI "virtual bool \fBvalidateMatch\fP (const  \fBQString\fP &, int, int)"
.br
.RI "\fIVirtual method, which allows applications to add extra checks for validating a candidate match. \fP"
.ti -1c
.RI "virtual bool \fBshouldRestart\fP (bool forceAsking=false, bool showNumMatches=true) const "
.br
.RI "\fIReturns true if we should restart the search from scratch. \fP"
.ti -1c
.RI "virtual void \fBdisplayFinalDialog\fP () const "
.br
.RI "\fIDisplays the final dialog saying 'no match was found', if that was the case. \fP"
.ti -1c
.RI "\fBKDialogBase\fP * \fBfindNextDialog\fP (bool create=false)"
.br
.RI "\fIReturn (or create) the dialog that shows the 'find next?' prompt. \fP"
.ti -1c
.RI "void \fBcloseFindNextDialog\fP ()"
.br
.RI "\fIClose the 'find next?' dialog. \fP"
.in -1c
.SS "Static Public Member Functions"

.in +1c
.ti -1c
.RI "int \fBfind\fP (const  \fBQString\fP &text, const  \fBQString\fP &pattern, int index, long options, int *matchedlength)"
.br
.RI "\fISearch the given string, and returns whether a match was found. \fP"
.ti -1c
.RI "int \fBfind\fP (const  \fBQString\fP &text, const  \fBQRegExp\fP &pattern, int index, long options, int *matchedlength)"
.br
.in -1c
.SS "Protected Slots"

.in +1c
.ti -1c
.RI "void \fBslotFindNext\fP ()"
.br
.ti -1c
.RI "void \fBslotDialogClosed\fP ()"
.br
.in -1c
.SS "Protected Member Functions"

.in +1c
.ti -1c
.RI "\fBKFind\fP (const  \fBQString\fP &pattern, const  \fBQString\fP &replacement, long options, \fBQWidget\fP *\fBparent\fP)"
.br
.ti -1c
.RI "\fBQWidget\fP * \fBparentWidget\fP () const "
.br
.in -1c
.SS "Friends"

.in +1c
.ti -1c
.RI "class \fBKReplace\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
A generic implementation of the 'find' function. 

\fBAuthor:\fP
.RS 4
S.R.Haque <srhaque@iee.org>, David Faure <faure@kde.org>
.RE
.PP
.PP
\fB Detail\fP
.PP
\fB This class includes prompt handling etc. Also provides some static functions which can be used to create custom behaviour instead of using the class directly.\fP
.PP
\fB \fP
.PP
\fB\fB Example\fP\fP
.PP
\fB\fB To use the class to implement a complete find feature:\fP\fP
.PP
\fB\fB In the slot connected to the find action, after using \fBKFindDialog\fP: 
.PP
.nf

.PP
\fP\fP
.PP
\fB\fB
.PP
.nf
  // This creates a find-next-prompt dialog if needed.
  m_find = new KFind(pattern, options);
.PP
\fP\fP
.PP
\fB\fB
.PP
.nf
  // Connect highlight signal to code which handles highlighting
  // of found text.
  connect( m_find, SIGNAL( \fBhighlight( const QString &, int, int )\fP ),
          this, SLOT( slotHighlight( const QString &, int, int ) ) );
  // Connect findNext signal - called when pressing the button in the dialog
  connect( m_find, SIGNAL( findNext() ),
          this, SLOT( slotFindNext() ) );
 
.PP
\fP\fP
.PP
\fB\fB Then initialize the variables determining the 'current position' (to the cursor, if the option FromCursor is set, to the beginning of the selection if the option SelectedText is set, and to the beginning of the document otherwise). Initialize the 'end of search' variables as well (end of doc or end of selection). Swap begin and end if FindBackwards. Finally, call slotFindNext();\fP\fP
.PP
\fB\fB 
.PP
.nf

  void slotFindNext()
  {
      KFind::Result res = KFind::NoMatch;
      while ( res == KFind::NoMatch &&  ) {
          if ( m_find->\fBneedData()\fP )
              m_find->setData( <current text fragment> );
.PP
\fP\fP
.PP
\fB\fB
.PP
.nf
          // Let KFind inspect the text fragment, and display a dialog if a match is found
          res = m_find->\fBfind()\fP;
.PP
\fP\fP
.PP
\fB\fB
.PP
.nf
          if ( res == KFind::NoMatch ) {
              <Move to the next non-empty text fragment, honouring the FindBackwards setting for the direction>
          }
      }
.PP
\fP\fP
.PP
\fB\fB
.PP
.nf
      if ( res == KFind::NoMatch ) // i.e. at end
          <Call either  m_find->\fBdisplayFinalDialog()\fP; delete m_find; m_find = 0L;
           or           if ( m_find->\fBshouldRestart()\fP ) { reinit and call slotFindNext(); }
                        else { delete m_find; m_find = 0L; }>
  }
 
.PP
\fP\fP
.PP
\fB\fB Don't forget delete m_find in the destructor of your class, unless you gave it a parent widget on construction.\fP\fP
.PP
\fB\fB This implementation allows to have a 'Find Next' action, which resumes the search, even if the user closed the 'Find Next' dialog.\fP\fP
.PP
\fB\fB A 'Find Previous' action can simply switch temporarily the value of FindBackwards and call slotFindNext() - and reset the value afterwards. \fP\fP
.PP
Definition at line 97 of file kfind.h.
.SH "Member Function Documentation"
.PP 
.SS "bool KFind::needData () const"
.PP
\fBReturns:\fP
.RS 4
true if the application must supply a new text fragment It also means the last call returned 'NoMatch'. But by storing this here the application doesn't have to store it in a member variable (between calls to slotFindNext()). 
.RE
.PP
Definition at line 81 of file kfind.cpp.
.PP
References QString::length().
.SS "void KFind::setData (const \fBQString\fP & data, int startPos = -1)"
.PP
Call this when needData returns true, before calling \fBfind\fP(). \fBParameters:\fP
.RS 4
\fIdata\fP the text fragment (line) 
.br
\fIstartPos\fP if set, the index at which the search should start. This is only necessary for the very first call to setData usually, for the 'find in selection' feature. A value of -1 (the default value) means 'process all the data', i.e. either 0 or data.length()-1 depending on FindBackwards. 
.RE
.PP
Definition at line 90 of file kfind.cpp.
.PP
References QString::length().
.SS "KFind::Result KFind::find ()"
.PP
Walk the text fragment (e.g. text-processor line, kspread cell) looking for matches. For each match, emits the \fBhighlight()\fP signal and displays the find-again dialog proceeding. Definition at line 117 of file kfind.cpp.
.PP
References findNextDialog(), highlight(), QDialog::show(), and validateMatch().
.PP
Referenced by find(), and KReplace::replace().
.SS "long KFind::options () const\fC [inline]\fP"
.PP
Return the current options. Warning: this is usually the same value as the one passed to the constructor, but options might change _during_ the replace operation: e.g. the 'All' button resets the PromptOnReplace flag. Definition at line 142 of file kfind.h.
.SS "void KFind::setOptions (long options)\fC [virtual]\fP"
.PP
Set new options. Usually this is used for setting or clearing the FindBackwards options. Definition at line 383 of file kfind.cpp.
.SS "int KFind::numMatches () const\fC [inline]\fP"
.PP
Return the number of matches found (i.e. the number of times the \fBhighlight\fP signal was emitted). If 0, can be used in a dialog box to tell the user 'no match was found'. The final dialog does so already, unless you used setDisplayFinalDialog(false). Definition at line 156 of file kfind.h.
.PP
Referenced by displayFinalDialog().
.SS "virtual void KFind::resetCounts ()\fC [inline, virtual]\fP"
.PP
Call this to reset the numMatches count (and the numReplacements count for a \fBKReplace\fP). Can be useful if reusing the same \fBKReplace\fP for different operations, or when restarting from the beginning of the document. Reimplemented in \fBKReplace\fP.
.PP
Definition at line 164 of file kfind.h.
.PP
Referenced by KReplace::resetCounts().
.SS "virtual bool KFind::validateMatch (const \fBQString\fP &, int, int)\fC [inline, virtual]\fP"
.PP
Virtual method, which allows applications to add extra checks for validating a candidate match. It's only necessary to reimplement this if the find dialog extension has been used to provide additional criterias.
.PP
\fBParameters:\fP
.RS 4
\fItext\fP The current text fragment 
.br
\fIindex\fP The starting index where the candidate match was found 
.br
\fImatchedlength\fP The length of the candidate match 
.RE
.PP
Definition at line 176 of file kfind.h.
.PP
Referenced by find(), and KReplace::replace().
.SS "bool KFind::shouldRestart (bool forceAsking = false, bool showNumMatches = true) const\fC [virtual]\fP"
.PP
Returns true if we should restart the search from scratch. Can ask the user, or return false (if we already searched the whole document).
.PP
\fBParameters:\fP
.RS 4
\fIforceAsking\fP set to true if the user modified the document during the search. In that case it makes sense to restart the search again.
.br
\fIshowNumMatches\fP set to true if the dialog should show the number of matches. Set to false if the application provides a 'find previous' action, in which case the match count will be erroneous when hitting the end, and we could even be hitting the beginning of the document (so not all matches have even been seen). 
.RE
.PP
Reimplemented in \fBKReplace\fP.
.PP
Definition at line 356 of file kfind.cpp.
.PP
References displayFinalDialog(), and KMessageBox::questionYesNo().
.SS "int KFind::find (const \fBQString\fP & text, const \fBQString\fP & pattern, int index, long options, int * matchedlength)\fC [static]\fP"
.PP
Search the given string, and returns whether a match was found. If one is, the length of the string matched is also returned.
.PP
A performance optimised version of the function is provided for use with regular expressions.
.PP
\fBParameters:\fP
.RS 4
\fItext\fP The string to search. 
.br
\fIpattern\fP The pattern to look for. 
.br
\fIindex\fP The starting index into the string. 
.br
\fIoptions.\fP The options to use. 
.RE
.PP
\fBReturns:\fP
.RS 4
The index at which a match was found, or -1 if no match was found. 
.RE
.PP
Definition at line 181 of file kfind.cpp.
.PP
References QString::find(), find(), QString::findRev(), and QString::length().
.SS "void KFind::displayFinalDialog () const\fC [virtual]\fP"
.PP
Displays the final dialog saying 'no match was found', if that was the case. Call either this or \fBshouldRestart()\fP. Reimplemented in \fBKReplace\fP.
.PP
Definition at line 346 of file kfind.cpp.
.PP
References QString::arg(), KMessageBox::information(), and numMatches().
.PP
Referenced by shouldRestart().
.SS "\fBKDialogBase\fP * KFind::findNextDialog (bool create = false)"
.PP
Return (or create) the dialog that shows the 'find next?' prompt. Usually you don't need to call this. One case where it can be useful, is when the user selects the 'Find' menu item while a find operation is under way. In that case, the program may want to call setActiveWindow() on that dialog. Definition at line 106 of file kfind.cpp.
.PP
References QObject::connect(), and KStdAction::create().
.PP
Referenced by find().
.SS "void KFind::closeFindNextDialog ()"
.PP
Close the 'find next?' dialog. The application should do this when the last match was hit. If the application deletes the KFind, then 'find previous' won't be possible anymore. Definition at line 388 of file kfind.cpp.
.PP
Referenced by KReplace::closeReplaceNextDialog().
.SS "void KFind::highlight (const \fBQString\fP & text, int matchingIndex, int matchedLength)\fC [signal]\fP"
.PP
Connect to this signal to implement highlighting of found text during the find operation. Referenced by find(), and KReplace::replace().
.SS "void KFind::optionsChanged ()\fC [signal]\fP"
.PP
Emitted when the options have changed. This can happen e.g. with 'Replace All', or if our 'find next' dialog gets a 'find previous' one day. 
.SS "void KFind::dialogClosed ()\fC [signal]\fP"
.PP
Emitted when the 'find next' dialog is being closed. Some apps might want to remove the highlighted text when this happens. Apps without support for 'Find Next' can also do m_find->\fBdeleteLater()\fP to terminate the find operation. 

.SH "Author"
.PP 
Generated automatically by Doxygen for kutils Library from the source code.
