SearchResult Class | Extending Qt Creator Manual

- Extending Qt Creator Manual
- SearchResult
- Extending Qt Creator Manual 4.12.3

# SearchResult Class

class Core::SearchResult

The SearchResult class reports user interaction, such as the activation of a search result item. More...

Header: | #include <SearchResult>

- List of all members, including inherited members

## Public Types

enum | AddMode { AddSorted, AddOrdered }

## Public Functions

QWidget * | additionalReplaceWidget() const
int | count() const
void | setSearchAgainSupported(bool supported)
void | setUserData(const QVariant &data)
QString | textToReplace() const
QVariant | userData() const

## Public Slots

void | addResult(const QString &fileName, const QString &lineText, Search::TextRange mainRange, const QVariant &userData = QVariant())
void | addResult(const QString &fileName, int lineNumber, const QString &lineText, int searchTermStart, int searchTermLength, const QVariant &userData = QVariant())
void | addResults(const QList<Core::SearchResultItem> &items, Core::SearchResult::AddMode mode)
void | finishSearch(bool canceled)
void | popup()
void | restart()
void | setSearchAgainEnabled(bool enabled)
void | setTextToReplace(const QString &textToReplace)

## Signals

void | activated(const Core::SearchResultItem &item)
void | cancelled()
void | countChanged(int count)
void | paused(bool paused)
void | replaceButtonClicked(const QString &replaceText, const QList<Core::SearchResultItem> &checkedItems, bool preserveCase)
void | requestEnabledCheck()
void | searchAgainRequested()
void | visibilityChanged(bool visible)

## Detailed Description

Whenever a new search is initiated via startNewSearch, an instance of this class is returned to provide the initiator with the hooks for handling user interaction.

## Member Type Documentation

### enum SearchResult::AddMode

This enum type specifies whether the search results should be sorted or ordered:

Constant | Value | Description
--- | --- | ---
`Core::SearchResult::AddSorted` | `0` | The search results are sorted.
`Core::SearchResult::AddOrdered` | `1` | The search results are ordered.

## Member Function Documentation

### `[signal]` void SearchResult::activated(const Core::SearchResultItem &item)

Indicates that the user activated the search result item by double-clicking it, for example.

### `[slot]` void SearchResult::addResult(const QString &fileName, const QString &lineText, Search::TextRange mainRange, const QVariant &userData = QVariant())

Adds a single result line to the Search Results output pane.

mainRange specifies the region from the beginning of the search term through its length that should be visually marked. fileName and lineText are shown on the result line. You can attach arbitrary userData to the search result, which can be used, for example, when reacting to the signals of the search results for your search.

See also addResults().

### `[slot]` void SearchResult::addResult(const QString &fileName, int lineNumber, const QString &lineText, int searchTermStart, int searchTermLength, const QVariant &userData = QVariant())

Adds a single result line to the Search Results output pane.

fileName, lineNumber, and lineText are shown on the result line. searchTermStart and searchTermLength specify the region that should be visually marked (string position and length in lineText). You can attach arbitrary userData to the search result, which can be used, for example, when reacting to the signals of the search results for your search.

See also addResults().

### `[slot]` void SearchResult::addResults(const QList<Core::SearchResultItem> &items, Core::SearchResult::AddMode mode)

Adds the search result items to the Search Results output pane using mode.

See also addResult().

### `[signal]` void SearchResult::cancelled()

This signal is emitted if the user cancels the search.

### `[signal]` void SearchResult::countChanged(int count)

This signal is emitted when the number of search hits changes to count.

### `[slot]` void SearchResult::finishSearch(bool canceled)

Notifies the Search Results output pane that the current search has been canceled, and the UI should reflect that.

### `[signal]` void SearchResult::paused(bool paused)

This signal is emitted when the search status is set to paused.

### `[slot]` void SearchResult::popup()

Opens the Search Results output pane with this search.

### `[signal]` void SearchResult::replaceButtonClicked(const QString &replaceText, const QList<Core::SearchResultItem> &checkedItems, bool preserveCase)

Indicates that the user initiated a text replace by selecting Replace All, for example.

The signal reports the text to use for replacement in replaceText, the list of search result items that were selected by the user in checkedItems, and whether a search and replace should preserve the case of the replaced strings in preserveCase. The handler of this signal should apply the replace only on the selected items.

### `[signal]` void SearchResult::requestEnabledCheck()

This signal is emitted when the enabled status of search results is requested.

### `[slot]` void SearchResult::restart()

Removes all search results.

### `[signal]` void SearchResult::searchAgainRequested()

This signal is emitted when the Search Again button is selected.

### `[slot]` void SearchResult::setSearchAgainEnabled(bool enabled)

Sets whether the Seach Again button is enabled to enabled.

### `[slot]` void SearchResult::setTextToReplace(const QString &textToReplace)

Sets the value in the UI element that allows the user to type the text that should replace text in search results to textToReplace.

See also textToReplace().

### `[signal]` void SearchResult::visibilityChanged(bool visible)

This signal is emitted when the visibility of the search results changes to visible.

### QWidget *SearchResult::additionalReplaceWidget() const

Returns a UI for a global search and replace action.

### int SearchResult::count() const

Returns the number of search hits.

### void SearchResult::setSearchAgainSupported(bool supported)

Sets whether the Seach Again button is enabled to supported.

### void SearchResult::setUserData(const QVariant &data)

Attaches some random data to this search, that you can use later.

See also userData().

### QString SearchResult::textToReplace() const

Returns the text that should replace the text in search results.

See also setTextToReplace().

### QVariant SearchResult::userData() const

Returns the data that was attached to this search by calling setUserData().

See also setUserData().