KDevelop API Documentation

KoReplace Class Reference

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

#include <koReplace.h>

Inheritance diagram for KoReplace:

KDialogBase KDialog QDialog List of all members.

Signals

void highlight (const QString &text, int matchingIndex, int matchedLength, const QRect &expose)
 Connect to this slot to implement highlighting of found text during the replace operation.

void replace (const QString &text, int replacementIndex, int replacedLength, int matchedLength, const QRect &expose)
 Connect to this slot to implement updating of replaced text during the replace operation.


Public Member Functions

 KoReplace (const QString &pattern, const QString &replacement, long options, QWidget *parent=0)
 Will create a prompt dialog and use it as needed.

 ~KoReplace ()
bool replace (QString &text, const QRect &expose)
 Walk the text fragment (e.g.

virtual bool validateMatch (const QString &, int, int)
void abort ()
 Abort the current find/replace process.


Static Public Member Functions

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

int replace (QString &text, const QRegExp &pattern, const QString &replacement, int index, long options, int *replacedLength)

Private Slots

void slotUser1 ()
void slotUser2 ()
void slotUser3 ()
void slotClose ()

Private Member Functions

void doReplace ()

Static Private Member Functions

int replace (QString &text, const QString &replacement, int index, int length)

Private Attributes

QString m_pattern
QRegExpm_regExp
QString m_replacement
long m_options
QWidgetm_parent
unsigned m_replacements
QString m_text
int m_index
QRect m_expose
int m_matchedLength
bool m_cancelled
KoReplacePrivate * d

Detailed Description

A generic implementation of the "replace" 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 replace feature:

  // This creates a replace-on-prompt dialog if needed.
  dialog = new KoReplace(find, replace, options);

  // Connect signals to code which handles highlighting
  // of found text, and on-the-fly replacement.
  QObject::connect(
      dialog, SIGNAL( highlight( const QString &, int, int, const QRect & ) ),
      this, SLOT( highlight( const QString &, int, int, const QRect & ) ) );
  QObject::connect(
      dialog, SIGNAL( replace( const QString &, int, int, const QRect & ) ),
      this, SLOT( replace( const QString &, int, int, const QRect & ) ) );

  for (text chosen by option SelectedText and in a direction set by FindBackwards)
  {
      dialog->replace()
  }
  delete dialog;

 

Definition at line 185 of file koReplace.h.


Constructor & Destructor Documentation

KoReplace::KoReplace const QString pattern,
const QString replacement,
long  options,
QWidget parent = 0
 

Will create a prompt dialog and use it as needed.

Definition at line 92 of file koReplace.cpp.

References KoReplace(), m_cancelled, m_options, m_parent, m_pattern, m_regExp, m_replacement, and m_replacements.

Referenced by KoReplace().

KoReplace::~KoReplace  ) 
 

Definition at line 113 of file koReplace.cpp.

References m_cancelled, m_parent, and m_replacements.


Member Function Documentation

void KoReplace::abort  ) 
 

Abort the current find/replace process.

Call this when the parent widget is getting destroyed.

Definition at line 125 of file koReplace.cpp.

References slotClose().

Referenced by QEditorView::doReplace().

void KoReplace::doReplace  )  [private]
 

Definition at line 250 of file koReplace.cpp.

References m_expose, m_index, m_matchedLength, m_options, m_replacement, m_replacements, m_text, and replace().

Referenced by replace(), and slotUser3().

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

Connect to this slot to implement highlighting of found text during the replace operation.

Referenced by replace().

int KoReplace::replace QString text,
const QString replacement,
int  index,
int  length
[static, private]
 

Definition at line 209 of file koReplace.cpp.

References length(), replace(), and text().

void KoReplace::replace const QString text,
int  replacementIndex,
int  replacedLength,
int  matchedLength,
const QRect expose
[signal]
 

Connect to this slot to implement updating of replaced text during the replace operation.

int KoReplace::replace QString text,
const QRegExp pattern,
const QString replacement,
int  index,
long  options,
int *  replacedLength
[static]
 

Definition at line 193 of file koReplace.cpp.

References replace(), and text().

int KoReplace::replace QString text,
const QString pattern,
const QString replacement,
int  index,
long  options,
int *  replacedLength
[static]
 

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

If one is, the replacement string length 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.
replacement The replacement string.
index The starting index into the string.
options The options to use.
replacedLength The replaced length.
Returns:
The index at which a match was found, or -1 if no match was found.

Definition at line 177 of file koReplace.cpp.

References replace(), and text().

bool KoReplace::replace QString text,
const QRect expose
 

Walk the text fragment (e.g.

kwrite line, kspread cell) looking for matches. For each match, if prompt-on-replace is specified, emits the expose() signal and displays the prompt-for-replace dialog before doing the replace.

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

Definition at line 130 of file koReplace.cpp.

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

Referenced by doReplace(), QEditorView::process(), replace(), and slotUser1().

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

Reimplemented from KDialogBase.

Definition at line 119 of file koReplace.cpp.

References m_cancelled.

Referenced by abort().

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

Reimplemented from KDialogBase.

Definition at line 217 of file koReplace.cpp.

References m_expose, m_index, m_matchedLength, m_options, m_replacement, m_replacements, m_text, and replace().

void KoReplace::slotUser2  )  [private, virtual, slot]
 

Reimplemented from KDialogBase.

Definition at line 236 of file koReplace.cpp.

References m_index, and m_options.

void KoReplace::slotUser3  )  [private, virtual, slot]
 

Reimplemented from KDialogBase.

Definition at line 244 of file koReplace.cpp.

References doReplace().

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

Parameters:
text The text fragment to modify
index The starting index where there is word found.
matchedlength The length of word found

Definition at line 212 of file koReplace.h.

Referenced by replace().


Member Data Documentation

KoReplacePrivate* KoReplace::d [private]
 

Definition at line 272 of file koReplace.h.

bool KoReplace::m_cancelled [private]
 

Definition at line 266 of file koReplace.h.

Referenced by KoReplace(), replace(), slotClose(), and ~KoReplace().

QRect KoReplace::m_expose [private]
 

Definition at line 264 of file koReplace.h.

Referenced by doReplace(), replace(), and slotUser1().

int KoReplace::m_index [private]
 

Definition at line 263 of file koReplace.h.

Referenced by doReplace(), replace(), slotUser1(), and slotUser2().

int KoReplace::m_matchedLength [private]
 

Definition at line 265 of file koReplace.h.

Referenced by doReplace(), replace(), and slotUser1().

long KoReplace::m_options [private]
 

Definition at line 259 of file koReplace.h.

Referenced by doReplace(), KoReplace(), replace(), slotUser1(), and slotUser2().

QWidget* KoReplace::m_parent [private]
 

Definition at line 260 of file koReplace.h.

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

QString KoReplace::m_pattern [private]
 

Definition at line 256 of file koReplace.h.

Referenced by KoReplace(), and replace().

QRegExp* KoReplace::m_regExp [private]
 

Definition at line 257 of file koReplace.h.

Referenced by KoReplace(), and replace().

QString KoReplace::m_replacement [private]
 

Definition at line 258 of file koReplace.h.

Referenced by doReplace(), KoReplace(), and slotUser1().

unsigned KoReplace::m_replacements [private]
 

Definition at line 261 of file koReplace.h.

Referenced by doReplace(), KoReplace(), slotUser1(), and ~KoReplace().

QString KoReplace::m_text [private]
 

Definition at line 262 of file koReplace.h.

Referenced by doReplace(), replace(), and slotUser1().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:02:04 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003