diff --git a/src/plugins/coreplugin/find/searchresultitem.h b/src/plugins/coreplugin/find/searchresultitem.h index b1058db4538..f4e7a781628 100644 --- a/src/plugins/coreplugin/find/searchresultitem.h +++ b/src/plugins/coreplugin/find/searchresultitem.h @@ -124,6 +124,9 @@ public: SearchResultColor::Style style() const { return m_style; } void setStyle(SearchResultColor::Style style) { m_style = style; } + bool selectForReplacement() const { return m_selectForReplacement; } + void setSelectForReplacement(bool select) { m_selectForReplacement = select; } + private: QStringList m_path; // hierarchy to the parent item of this item QString m_lineText; // text to show for the item itself @@ -131,6 +134,7 @@ private: QVariant m_userData; // user data for identification of the item Search::TextRange m_mainRange; bool m_useTextEditorFont = false; + bool m_selectForReplacement = true; SearchResultColor::Style m_style = SearchResultColor::Style::Default; }; diff --git a/src/plugins/coreplugin/find/searchresulttreeitems.cpp b/src/plugins/coreplugin/find/searchresulttreeitems.cpp index 9f25167fcde..af2d21099fc 100644 --- a/src/plugins/coreplugin/find/searchresulttreeitems.cpp +++ b/src/plugins/coreplugin/find/searchresulttreeitems.cpp @@ -33,7 +33,7 @@ SearchResultTreeItem::SearchResultTreeItem(const SearchResultItem &item, : item(item), m_parent(parent), m_isGenerated(false), - m_checkState(Qt::Checked) + m_checkState(item.selectForReplacement() ? Qt::Checked : Qt::Unchecked) { } diff --git a/src/plugins/coreplugin/find/searchresulttreemodel.cpp b/src/plugins/coreplugin/find/searchresulttreemodel.cpp index a7d680b76ba..ed3bd28dec9 100644 --- a/src/plugins/coreplugin/find/searchresulttreemodel.cpp +++ b/src/plugins/coreplugin/find/searchresulttreemodel.cpp @@ -77,6 +77,7 @@ private: QSet addPath(const QStringList &path); QVariant data(const SearchResultTreeItem *row, int role) const; bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true); + void updateCheckStateFromChildren(const QModelIndex &idx, SearchResultTreeItem *item); QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped = nullptr) const; QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped = nullptr) const; @@ -247,31 +248,7 @@ bool SearchResultTreeModel::setCheckState(const QModelIndex &idx, Qt::CheckState item->setCheckState(checkState); if (firstCall) { emit dataChanged(idx, idx); - // check parents - SearchResultTreeItem *currentItem = item; - QModelIndex currentIndex = idx; - while (SearchResultTreeItem *parent = currentItem->parent()) { - bool hasChecked = false; - bool hasUnchecked = false; - for (int i = 0; i < parent->childrenCount(); ++i) { - SearchResultTreeItem *child = parent->childAt(i); - if (child->checkState() == Qt::Checked) - hasChecked = true; - else if (child->checkState() == Qt::Unchecked) - hasUnchecked = true; - else if (child->checkState() == Qt::PartiallyChecked) - hasChecked = hasUnchecked = true; - } - if (hasChecked && hasUnchecked) - parent->setCheckState(Qt::PartiallyChecked); - else if (hasChecked) - parent->setCheckState(Qt::Checked); - else - parent->setCheckState(Qt::Unchecked); - emit dataChanged(idx.parent(), idx.parent()); - currentItem = parent; - currentIndex = idx.parent(); - } + updateCheckStateFromChildren(idx.parent(), item->parent()); } // check children if (int children = item->childrenCount()) { @@ -282,6 +259,34 @@ bool SearchResultTreeModel::setCheckState(const QModelIndex &idx, Qt::CheckState return true; } +void SearchResultTreeModel::updateCheckStateFromChildren(const QModelIndex &idx, + SearchResultTreeItem *item) +{ + if (!item) + return; + + bool hasChecked = false; + bool hasUnchecked = false; + for (int i = 0; i < item->childrenCount(); ++i) { + SearchResultTreeItem *child = item->childAt(i); + if (child->checkState() == Qt::Checked) + hasChecked = true; + else if (child->checkState() == Qt::Unchecked) + hasUnchecked = true; + else if (child->checkState() == Qt::PartiallyChecked) + hasChecked = hasUnchecked = true; + } + if (hasChecked && hasUnchecked) + item->setCheckState(Qt::PartiallyChecked); + else if (hasChecked) + item->setCheckState(Qt::Checked); + else + item->setCheckState(Qt::Unchecked); + emit dataChanged(idx, idx); + + updateCheckStateFromChildren(idx.parent(), item->parent()); +} + void setDataInternal(const QModelIndex &index, const QVariant &value, int role); QVariant SearchResultTreeModel::data(const SearchResultTreeItem *row, int role) const @@ -418,6 +423,7 @@ void SearchResultTreeModel::addResultsToCurrentParent(const QListsetText(textToReplace); diff --git a/src/plugins/coreplugin/find/searchresultwidget.h b/src/plugins/coreplugin/find/searchresultwidget.h index e018a9e6939..49e7e6ed5b4 100644 --- a/src/plugins/coreplugin/find/searchresultwidget.h +++ b/src/plugins/coreplugin/find/searchresultwidget.h @@ -60,6 +60,7 @@ public: int count() const; void setSupportsReplace(bool replaceSupported, const QString &group); + bool supportsReplace() const; void setTextToReplace(const QString &textToReplace); QString textToReplace() const; diff --git a/src/plugins/coreplugin/find/searchresultwindow.cpp b/src/plugins/coreplugin/find/searchresultwindow.cpp index af87935623f..8c5bb5962c7 100644 --- a/src/plugins/coreplugin/find/searchresultwindow.cpp +++ b/src/plugins/coreplugin/find/searchresultwindow.cpp @@ -760,6 +760,11 @@ QVariant SearchResult::userData() const return m_userData; } +bool SearchResult::supportsReplace() const +{ + return m_widget->supportsReplace(); +} + /*! Returns the text that should replace the text in search results. */ diff --git a/src/plugins/coreplugin/find/searchresultwindow.h b/src/plugins/coreplugin/find/searchresultwindow.h index a4b8315565c..c7f4af7c569 100644 --- a/src/plugins/coreplugin/find/searchresultwindow.h +++ b/src/plugins/coreplugin/find/searchresultwindow.h @@ -69,6 +69,7 @@ public: void setUserData(const QVariant &data); QVariant userData() const; + bool supportsReplace() const; QString textToReplace() const; int count() const; void setSearchAgainSupported(bool supported); diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index c0860c073ed..64b7244e2b8 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -637,6 +638,8 @@ static void displayResults(SearchResult *search, QFutureWatchersupportsReplace()) + item.setSelectForReplacement(SessionManager::projectForFile(result.path)); search->addResult(item); if (parameters.prettySymbolName.isEmpty()) @@ -829,10 +832,13 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri const QString line = FindMacroUsesInFile::matchingLine(macro.bytesOffset(), source, &column); SearchResultItem item; - item.setFilePath(Utils::FilePath::fromString(macro.fileName())); + const Utils::FilePath filePath = Utils::FilePath::fromString(macro.fileName()); + item.setFilePath(filePath); item.setLineText(line); item.setMainRange(macro.line(), column, macro.nameToQString().length()); item.setUseTextEditorFont(true); + if (search->supportsReplace()) + item.setSelectForReplacement(SessionManager::projectForFile(filePath)); search->addResult(item); }