IFindFilter 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 <IFindFilter>

Public Functions

virtual QWidget *createConfigWidget()
virtual QKeySequence defaultShortcut() const
virtual QString displayName() const = 0
virtual void findAll(const QString &txt, Core::FindFlags findFlags) = 0
virtual QString id() const = 0
virtual bool isEnabled() const = 0
virtual bool isReplaceSupported() const
virtual bool isValid() const
virtual void readSettings(QSettings *settings)
virtual void replaceAll(const QString &txt, Core::FindFlags findFlags)
virtual bool showSearchTermInput() const
virtual Core::FindFlags supportedFindFlags() const
virtual void writeSettings(QSettings *settings)

Signals

void displayNameChanged()
void enabledChanged(bool enabled)
void validChanged(bool valid)

Static Public Members

const QList<Core::IFindFilter *> allFindFilters()
QString descriptionForFindFlags(Core::FindFlags flags)
QPixmap pixmapForFindFlags(Core::FindFlags flags)

Detailed Description

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

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.

Member Function Documentation

[static] const QList<Core::IFindFilter *> IFindFilter::allFindFilters()

Returns a list of find filters.

[virtual] QWidget *IFindFilter::createConfigWidget()

[virtual] QKeySequence IFindFilter::defaultShortcut() const

Returns the shortcut that can be used to open the advanced find dialog with this filter or scope preselected.

Usually return an empty shortcut here, the user can still choose and assign a specific shortcut to this find scope via the preferences.

[static] QString IFindFilter::descriptionForFindFlags(Core::FindFlags flags)

Returns descriptive text labels for the find flags flags.

[pure virtual] QString IFindFilter::displayName() const

[signal] void IFindFilter::displayNameChanged()

[signal] void IFindFilter::enabledChanged(bool enabled)

[pure virtual] void IFindFilter::findAll(const QString &txt, Core::FindFlags findFlags)

[pure virtual] QString IFindFilter::id() const

[pure virtual] bool IFindFilter::isEnabled() const

[virtual] bool IFindFilter::isReplaceSupported() const

[virtual] bool IFindFilter::isValid() const

[static] QPixmap IFindFilter::pixmapForFindFlags(Core::FindFlags flags)

Returns icons for the find flags flags.

[virtual] void IFindFilter::readSettings(QSettings *settings)

[virtual] void IFindFilter::replaceAll(const QString &txt, Core::FindFlags findFlags)

[virtual] bool IFindFilter::showSearchTermInput() const

[virtual] Core::FindFlags IFindFilter::supportedFindFlags() const

Returns the find flags, like whole words or regular expressions, that this find filter supports.

Depending on the returned value, the default find option widgets are enabled or disabled. The default is Core::FindCaseSensitively, Core::FindRegularExpression and Core::FindWholeWords.

[signal] void IFindFilter::validChanged(bool valid)

[virtual] void IFindFilter::writeSettings(QSettings *settings)