- Extending Qt Creator Manual
- QtCreator
- SearchResultWindow
- Extending Qt Creator Manual 13.0.0

# SearchResultWindow Class

class Core::SearchResultWindow

The SearchResultWindow class is the implementation of a commonly shared Search Results output pane. More...

Header: | #include <coreplugin/find/searchresultwindow.h>
Inherits: | Core::IOutputPane

- List of all members, including inherited members

## Public Types

enum | PreserveCaseMode { PreserveCaseEnabled, PreserveCaseDisabled }
enum | SearchMode { SearchOnly, SearchAndReplace }

## Public Functions

void | openNewSearchPanel()
void | setTabWidth(int tabWidth)
Core::SearchResult * | startNewSearch(const QString &label, const QString &toolTip, const QString &searchTerm, Core::SearchResultWindow::SearchMode searchOrSearchAndReplace = SearchOnly, Core::SearchResultWindow::PreserveCaseMode preserveCaseMode = PreserveCaseEnabled, const QString &cfgGroup = QString())

## Public Slots

virtual void | clearContents() override

## Static Public Members

Core::SearchResultWindow * | instance()

## Detailed Description

[Missing image qtcreator-search-results.webp]

Whenever you want to show the user a list of search results, or want to present UI for a global search and replace, use the single instance of this class.

In addition to being an implementation of an output pane, the SearchResultWindow has functions and enums that enable other plugins to show their search results and hook into the user actions for selecting an entry and performing a global replace.

Whenever you start a search, call startNewSearch(SearchMode) to initialize the Search Results output pane. The parameter determines if the GUI for replacing should be shown. The function returns a SearchResult object that is your hook into the signals from user interaction for this search. When you produce search results, call addResults() or addResult() to add them to the Search Results output pane. After the search has finished call finishSearch() to inform the Search Results output pane about it.

You will get activated() signals via your SearchResult instance when the user selects a search result item. If you started the search with the SearchAndReplace option, the replaceButtonClicked() signal is emitted when the user requests a replace.

## Member Type Documentation

### enum SearchResultWindow::PreserveCaseMode

This enum type specifies whether a search and replace should preserve the case of the replaced strings:

Constant | Value | Description
--- | --- | ---
`Core::SearchResultWindow::PreserveCaseEnabled` | `0` | The case is preserved when replacings strings.
`Core::SearchResultWindow::PreserveCaseDisabled` | `1` | The given case is used when replacing strings.

### enum SearchResultWindow::SearchMode

This enum type specifies whether a search should show the replace UI or not:

Constant | Value | Description
--- | --- | ---
`Core::SearchResultWindow::SearchOnly` | `0` | The search does not support replace.
`Core::SearchResultWindow::SearchAndReplace` | `1` | The search supports replace, so show the UI for it.

## Member Function Documentation

### `[override virtual slot]` void SearchResultWindow::clearContents()

Reimplements: IOutputPane::clearContents().

Clears the current contents of the Search Results output pane.

### `[static]` Core::SearchResultWindow *SearchResultWindow::instance()

Returns the single shared instance of the Search Results output pane.

### void SearchResultWindow::openNewSearchPanel()

Opens a new search panel.

### void SearchResultWindow::setTabWidth(int tabWidth)

Sets the Search Results tab width to tabWidth.

### Core::SearchResult *SearchResultWindow::startNewSearch(const QString &label, const QString &toolTip, const QString &searchTerm, Core::SearchResultWindow::SearchMode searchOrSearchAndReplace = SearchOnly, Core::SearchResultWindow::PreserveCaseMode preserveCaseMode = PreserveCaseEnabled, const QString &cfgGroup = QString())

Tells the Search Results output pane to start a new search.

The label should be a string that shortly describes the type of the search, that is, the search filter and possibly the most relevant search option, followed by a colon (:). For example: `Project 'myproject':` The searchTerm is shown after the colon.

The toolTip should elaborate on the search parameters, like file patterns that are searched and find flags.

If cfgGroup is not empty, it will be used for storing the do not ask again setting of a this change cannot be undone warning (which is implicitly requested by passing a non-empty group).

The searchOrSearchAndReplace parameter holds whether the search results pane should show a UI for a global search and replace action. The preserveCaseMode parameter holds whether the case of the search string should be preserved when replacing strings.

Returns a SearchResult object that is used for signaling user interaction with the results of this search. The search result window owns the returned SearchResult and might delete it any time, even while the search is running. For example, when the user clears the Search Results pane, or when the user opens so many other searches that this search falls out of the history.