KDevelop API Documentation

KoReplace Class Reference

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

#include <koReplace.h>

Inheritance diagram for KoReplace:

Inheritance graph
[legend]
Collaboration diagram for KoReplace:

Collaboration graph
[legend]
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 &text, int index, int matchedlength)
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 97 of file koReplace.cpp.

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

KoReplace::~KoReplace  ) 
 

Definition at line 118 of file koReplace.cpp.

References KMessageBox::information(), 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 130 of file koReplace.cpp.

References slotClose().

Referenced by QEditorView::doReplace().

void KoReplace::doReplace  )  [private]
 

Definition at line 255 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 214 of file koReplace.cpp.

References length(), 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 198 of file koReplace.cpp.

References KoFind::find(), 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 182 of file koReplace.cpp.

References KoFind::find(), 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 135 of file koReplace.cpp.

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

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

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

Reimplemented from KDialogBase.

Definition at line 124 of file koReplace.cpp.

References m_cancelled.

Referenced by abort().

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

Reimplemented from KDialogBase.

Definition at line 222 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 241 of file koReplace.cpp.

References m_index, and m_options.

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

Reimplemented from KDialogBase.

Definition at line 249 of file koReplace.cpp.

References doReplace().

bool KoReplace::validateMatch const QString text,
int  index,
int  matchedlength
[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 43 of file koReplace.cpp.

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(), and slotClose().

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.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:44:49 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003