org.kde.koala
public class KFind extends QObject
UNKNOWN: A generic implementation of the "find" function.
etail:
This class includes prompt handling etc. Also provides some
static functions which can be used to create custom behavior
instead of using the class directly.
xample:
To use the class to implement a complete find feature:
In the slot connected to the find action, after using KFindDialog:
// This creates a find-next-prompt dialog if needed.
m_find = new KFind(pattern, options, this);
// Connect highlight signal to code which handles highlighting
// of found text.
connect( m_find, SIGNAL("highlight( String, int, int )"),
this, SLOT("slotHighlight( String, int, int )") );
// Connect findNext signal - called when pressing the button in the dialog
connect( m_find, SIGNAL("findNext()"),
this, SLOT("slotFindNext()") );
If you are using a non-modal find dialog (the recommended new way
in KDE-3.2), you should call right away m_find.closeFindNextDialog().
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();
void slotFindNext()
{
KFind.Result res = KFind.NoMatch;
while ( res == KFind.NoMatch &&
Don't forget to delete m_find in the destructor of your class,
unless you gave it a parent widget on construction.
This implementation allows to have a "Find Next" action, which resumes the
search, even if the user closed the "Find Next" dialog.
A "Find Previous" action can simply switch temporarily the value of
FindBackwards and call slotFindNext() - and reset the value afterwards.
See KFindSignals for signals emitted by KFind @brief A generic implementation of the "find" function.
Field Summary | |
---|---|
static int | Match |
static int | NoMatch |
Constructor Summary | |
---|---|
protected | KFind(Class dummy) |
KFind(String pattern, long options, QWidget parent)
Only use this constructor if you don't use KFindDialog, or if
you use it as a modal dialog. |
Method Summary | |
---|---|
String | className() |
void | closeFindNextDialog()
Close the "find next? |
protected QWidget | dialogsParent() |
void | displayFinalDialog()
Displays the final dialog saying "no match was found", if that was the case.
|
void | dispose() Delete the wrapped C++ instance ahead of finalize() |
protected void | finalize() Deletes the wrapped C++ instance |
int | find()
Walk the text fragment (e.g. text-processor line, kspread cell) looking for matches.
|
static int | find(String text, String pattern, int index, long options, int[] matchedlength)
Search the given string, and returns whether a match was found. |
static int | find(String text, QRegExp pattern, int index, long options, int[] matchedlength) |
KDialogBase | findNextDialog(boolean create)
Return (or create) the dialog that shows the "find next? |
KDialogBase | findNextDialog() |
int | index() |
boolean | isDisposed() Has the wrapped C++ instance been deleted? |
QMetaObject | metaObject() |
boolean | needData() |
int | numMatches()
Return the number of matches found (i.e. the number of times
the highlight signal was emitted).
|
long | options()
Return the current options.
|
protected QWidget | parentWidget() |
String | pattern() |
void | resetCounts()
Call this to reset the numMatches count
(and the numReplacements count for a KReplace).
|
void | setData(String data, int startPos)
Call this when needData returns true, before calling find(). |
void | setData(String data) |
void | setData(int id, String data, int startPos)
Call this when needData returns true, before calling find(). |
void | setData(int id, String data) |
void | setOptions(long options)
Set new options. |
void | setPattern(String pattern)
Change the pattern we're looking for |
boolean | shouldRestart(boolean forceAsking, boolean showNumMatches)
Returns true if we should restart the search from scratch.
|
boolean | shouldRestart(boolean forceAsking) |
boolean | shouldRestart() |
protected void | slotDialogClosed() |
protected void | slotFindNext() |
boolean | validateMatch(String text, int index, int matchedlength)
Virtual method, which allows applications to add extra checks for
validating a candidate match. |
UNKNOWN: Only use this constructor if you don't use KFindDialog, or if you use it as a modal dialog.
UNKNOWN: Close the "find next?" dialog.
UNKNOWN: Displays the final dialog saying "no match was found", if that was the case.
UNKNOWN: Walk the text fragment (e.
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 of the string that was matched
Returns: The index at which a match was found, or -1 if no match was found.
UNKNOWN: Search the given string, and returns whether a match was found.
UNKNOWN: Return (or create) the dialog that shows the "find next?" prompt.
Returns: the current matching index ( or -1 ). Same as the matchingIndex parameter passed to highlight. You usually don't need to use this, except maybe when updating the current data, so you need to call setData( newData, index() ).
UNKNOWN:
Returns: 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()).
UNKNOWN:
UNKNOWN: Return the number of matches found (i.
UNKNOWN: Return the current options.
Returns: the pattern we're currently looking for
UNKNOWN:
UNKNOWN: Call this to reset the numMatches count (and the numReplacements count for a KReplace).
Parameters: data the text fragment (line) startPos 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.
UNKNOWN: Call this when needData returns true, before calling find().
Parameters: id the id of the text fragment data the text fragment (line) startPos 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.
UNKNOWN: Call this when needData returns true, before calling find().
UNKNOWN: Set new options.
UNKNOWN: Change the pattern we're looking for
Parameters: forceAsking set to true if the user modified the document during the search. In that case it makes sense to restart the search again. showNumMatches 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).
UNKNOWN: Returns true if we should restart the search from scratch.
Parameters: text The current text fragment index The starting index where the candidate match was found matchedlength The length of the candidate match
UNKNOWN: Virtual method, which allows applications to add extra checks for validating a candidate match.