KDevelop API Documentation

KoFind Class Reference

A generic implementation of the "find" function. More...

#include <koFind.h>

Inheritance diagram for KoFind:

Inheritance graph
[legend]
Collaboration diagram for KoFind:

Collaboration graph
[legend]
List of all members.

Signals

void highlight (const QString &text, int matchingIndex, int matchedLength, const QRect &expose)

Public Member Functions

 KoFind (const QString &pattern, long options, QWidget *parent=0)
 ~KoFind ()
bool find (const QString &text, const QRect &expose)
 Walk the text fragment (e.g.
virtual bool validateMatch (const QString &, int, int)
void abort ()
 Abort the current find process.

Static Public Member Functions

int find (const QString &text, const QString &pattern, int index, long options, int *matchedlength)
 Search the given string, and returns whether a match was found.
int find (const QString &text, const QRegExp &pattern, int index, long options, int *matchedlength)

Private Slots

virtual void slotUser1 ()
virtual void slotClose ()

Static Private Member Functions

bool isInWord (QChar ch)
bool isWholeWords (const QString &text, int starts, int matchedLength)

Private Attributes

QString m_pattern
QRegExpm_regExp
long m_options
QWidgetm_parent
unsigned m_matches
QString m_text
int m_index
QRect m_expose
int m_matchedLength
bool m_cancelled
KoFindPrivate * d

Detailed Description

A generic implementation of the "find" function.

Author:
S.R.Haque <srhaque@iee.org>
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.

Example

To use the class to implement a complete find feature:

  // This creates a find-next-prompt dialog if needed.
  dialog = new KoFind(find, options);

  // Connect signals to code which handles highlighting
  // of found text.
  connect(dialog, SIGNAL( highlight( const QString &, int, int, const QRect & ) ),
          this, SLOT( highlight( const QString &, int, int, const QRect & ) ) );

  // Loop over all the text fragments of our document or selection
  for (text chosen by option SelectedText and in a direction set by FindBackwards)
       // don't forget to honour FromCursor too
  {
      // Let KoFind inspect the text fragment, and display a dialog if a match is found
      if ( !dialog->find( text_fragment, region_to_expose ) )
          break; // if cancelled by user
  }
  delete dialog;

 

Definition at line 260 of file koFind.h.


Constructor & Destructor Documentation

KoFind::KoFind const QString pattern,
long  options,
QWidget parent = 0
 

Definition at line 367 of file koFind.cpp.

References m_cancelled, m_matches, m_options, m_parent, m_pattern, m_regExp, and KDialogBase::setMainWidget().

KoFind::~KoFind  ) 
 

Definition at line 388 of file koFind.cpp.

References KMessageBox::information(), m_matches, and m_parent.


Member Function Documentation

void KoFind::abort  ) 
 

Abort the current find process.

Call this when the parent widget is getting destroyed.

Definition at line 400 of file koFind.cpp.

References slotClose().

Referenced by QEditorView::doFind().

int KoFind::find const QString text,
const QRegExp pattern,
int  index,
long  options,
int *  matchedlength
[static]
 

Definition at line 514 of file koFind.cpp.

References isWholeWords(), and text().

int KoFind::find const QString text,
const QString pattern,
int  index,
long  options,
int *  matchedlength
[static]
 

Search the given string, and returns whether a match was found.

If one is, the length of the string matched is also returned.

A performance optimised version of the function is provided for use with regular expressions.

Parameters:
text The string to search.
pattern The pattern to look for.
index The starting index into the string.
options The options to use.
matchedlength The length that matched.
Returns:
The index at which a match was found, or -1 if no match was found.

Definition at line 444 of file koFind.cpp.

References find(), isWholeWords(), and text().

bool KoFind::find const QString text,
const QRect expose
 

Walk the text fragment (e.g.

kwrite line, kspread cell) looking for matches. For each match, emits the expose() signal and displays the find-again dialog proceeding.

Parameters:
text The text fragment to modify.
expose The region to expose
Returns:
false if the user elected to discontinue the find.

Definition at line 405 of file koFind.cpp.

References highlight(), m_expose, m_index, m_matchedLength, m_options, m_pattern, m_regExp, m_text, text(), and validateMatch().

Referenced by find(), QEditorView::process(), and KoReplace::replace().

void KoFind::highlight const QString text,
int  matchingIndex,
int  matchedLength,
const QRect expose
[signal]
 

Referenced by find().

bool KoFind::isInWord QChar  ch  )  [static, private]
 

Definition at line 580 of file koFind.cpp.

Referenced by isWholeWords().

bool KoFind::isWholeWords const QString text,
int  starts,
int  matchedLength
[static, private]
 

Definition at line 585 of file koFind.cpp.

References isInWord(), and text().

Referenced by find().

void KoFind::slotClose  )  [private, virtual, slot]
 

Reimplemented from KDialogBase.

Definition at line 394 of file koFind.cpp.

References m_cancelled.

Referenced by abort().

void KoFind::slotUser1  )  [private, virtual, slot]
 

Reimplemented from KDialogBase.

Definition at line 598 of file koFind.cpp.

References m_index, m_matches, and m_options.

virtual bool KoFind::validateMatch const QString ,
int  ,
int 
[inline, virtual]
 

Definition at line 282 of file koFind.h.

Referenced by find().


Member Data Documentation

KoFindPrivate* KoFind::d [private]
 

Definition at line 331 of file koFind.h.

bool KoFind::m_cancelled [private]
 

Definition at line 324 of file koFind.h.

Referenced by KoFind(), and slotClose().

QRect KoFind::m_expose [private]
 

Definition at line 322 of file koFind.h.

Referenced by find().

int KoFind::m_index [private]
 

Definition at line 321 of file koFind.h.

Referenced by find(), and slotUser1().

int KoFind::m_matchedLength [private]
 

Definition at line 323 of file koFind.h.

Referenced by find().

unsigned KoFind::m_matches [private]
 

Definition at line 319 of file koFind.h.

Referenced by KoFind(), slotUser1(), and ~KoFind().

long KoFind::m_options [private]
 

Definition at line 317 of file koFind.h.

Referenced by find(), KoFind(), and slotUser1().

QWidget* KoFind::m_parent [private]
 

Definition at line 318 of file koFind.h.

Referenced by KoFind(), and ~KoFind().

QString KoFind::m_pattern [private]
 

Definition at line 315 of file koFind.h.

Referenced by find(), and KoFind().

QRegExp* KoFind::m_regExp [private]
 

Definition at line 316 of file koFind.h.

Referenced by find(), and KoFind().

QString KoFind::m_text [private]
 

Definition at line 320 of file koFind.h.

Referenced by find().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:27:22 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003