- Extending Qt Creator Manual
- QtCreator
- IFindFilter
- Extending Qt Creator Manual 12.0.0-rc1

# IFindFilter Class

class Core::IFindFilter

The IFindFilter class is the base class for find implementations that are invoked by selecting Edit > Find/Replace > Advanced Find. More...

Header: | #include <coreplugin/find/ifindfilter.h>

## Detailed Description

Implementations of this class add an additional Scope to the Advanced Find dialog. That can be any search that requires the user to provide a text based search term (potentially with find flags like searching case sensitively or using regular expressions). Existing scopes are All Projects that searches from all files in all projects and Files in File System where the user provides a directory and file patterns to search.

To make your find scope available to the user, you need to implement this class, and register an instance of your subclass in the plugin manager.

A common way to present the search results to the user, is to use the shared Search Results pane.

If you want to implement a find filter that is doing a file based text search, you should use Core::BaseTextFind, which already implements all the details for this kind of search, only requiring you to provide an iterator over the file names of the files that should be searched.

If you want to implement a more specialized find filter, you need to:

- Start your search in a separate thread
- Make this known to the Core::ProgressManager, for a progress bar and the ability to cancel the search
- Interface with the shared Search Results pane, to show the search results, handle the event that the user click on one of the search result items, and possible handle a global replace of all or some of the search result items.

Luckily QtConcurrent and the search results pane provide the frameworks that make it relatively easy to implement, while ensuring a common way for the user.

The common pattern is roughly to first implement the actual search within a QtConcurrent based function. That is a function that takes a `QFutureInterface<MySearchResult> &future` as the first parameter and the other information needed for the search as additional parameters. It should set useful progress information on the QFutureInterface, regularly check for `future.isPaused()` and `future.isCanceled()`, and report the search results (possibly in chunks) via `future.reportResult`.

In the find filter's `find()` or `replaceAll()` function, get the shared Search Results window, initiate a new search and connect the signals for handling selection of results and the replace action (see the Core::SearchResultWindow class for details). Start your search implementation via the corresponding QtConcurrent functions. Add the returned QFuture object to the Core::ProgressManager. Use a QFutureWatcher on the returned QFuture object to receive a signal when your search implementation reports search results, and add these to the shared Search Results window.