forked from qt-creator/qt-creator
CppEditor: Consider symbol occurrences in comments
... when renaming. For local renaming, we consider only function parameters. Task-number: QTCREATORBUG-12051 Change-Id: I7948d69f11b97663c9bd747ae6241a82dd9bdd82 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -82,9 +82,26 @@ int SearchResultTreeItem::insertionIndex(const QString &text, SearchResultTreeIt
|
||||
}
|
||||
|
||||
int SearchResultTreeItem::insertionIndex(const Utils::SearchResultItem &item,
|
||||
SearchResultTreeItem **existingItem) const
|
||||
SearchResultTreeItem **existingItem,
|
||||
SearchResult::AddMode mode) const
|
||||
{
|
||||
return insertionIndex(item.lineText(), existingItem);
|
||||
switch (mode) {
|
||||
case SearchResult::AddSortedByContent:
|
||||
return insertionIndex(item.lineText(), existingItem);
|
||||
case SearchResult::AddSortedByPosition:
|
||||
break;
|
||||
case Core::SearchResult::AddOrdered:
|
||||
QTC_ASSERT(false, return 0);
|
||||
}
|
||||
|
||||
static const auto cmp = [](const SearchResultTreeItem *a, const Utils::Text::Position b) {
|
||||
return a->item.mainRange().begin < b;
|
||||
};
|
||||
const auto insertionPosition =
|
||||
std::lower_bound(m_children.begin(), m_children.end(), item.mainRange().begin, cmp);
|
||||
if (existingItem)
|
||||
*existingItem = nullptr;
|
||||
return insertionPosition - m_children.begin();
|
||||
}
|
||||
|
||||
void SearchResultTreeItem::insertChild(int index, SearchResultTreeItem *child)
|
||||
|
||||
@@ -21,7 +21,8 @@ public:
|
||||
SearchResultTreeItem *parent() const;
|
||||
SearchResultTreeItem *childAt(int index) const;
|
||||
int insertionIndex(const QString &text, SearchResultTreeItem **existingItem) const;
|
||||
int insertionIndex(const Utils::SearchResultItem &item, SearchResultTreeItem **existingItem) const;
|
||||
int insertionIndex(const Utils::SearchResultItem &item, SearchResultTreeItem **existingItem,
|
||||
SearchResult::AddMode mode) const;
|
||||
void insertChild(int index, SearchResultTreeItem *child);
|
||||
void insertChild(int index, const Utils::SearchResultItem &item);
|
||||
void appendChild(const Utils::SearchResultItem &item);
|
||||
|
||||
@@ -402,10 +402,10 @@ void SearchResultTreeModel::addResultsToCurrentParent(const SearchResultItems &i
|
||||
m_currentParent->appendChild(item);
|
||||
}
|
||||
endInsertRows();
|
||||
} else if (mode == SearchResult::AddSorted) {
|
||||
} else {
|
||||
for (const SearchResultItem &item : items) {
|
||||
SearchResultTreeItem *existingItem;
|
||||
const int insertionIndex = m_currentParent->insertionIndex(item, &existingItem);
|
||||
const int insertionIndex = m_currentParent->insertionIndex(item, &existingItem, mode);
|
||||
if (existingItem) {
|
||||
existingItem->setGenerated(false);
|
||||
existingItem->item = item;
|
||||
|
||||
@@ -478,7 +478,7 @@ void SearchResultWidget::doReplace()
|
||||
{
|
||||
m_infoBar.clear();
|
||||
setShowReplaceUI(false);
|
||||
emit replaceButtonClicked(m_replaceTextEdit->text(), checkedItems(),
|
||||
emit replaceButtonClicked(m_replaceTextEdit->text(), items(true),
|
||||
m_preserveCaseSupported && m_preserveCaseCheck->isChecked());
|
||||
}
|
||||
|
||||
@@ -496,7 +496,7 @@ void SearchResultWidget::searchAgain()
|
||||
emit searchAgainRequested();
|
||||
}
|
||||
|
||||
SearchResultItems SearchResultWidget::checkedItems() const
|
||||
SearchResultItems SearchResultWidget::items(bool checkedOnly) const
|
||||
{
|
||||
SearchResultItems result;
|
||||
SearchResultFilterModel *model = m_searchResultTreeView->model();
|
||||
@@ -508,7 +508,7 @@ SearchResultItems SearchResultWidget::checkedItems() const
|
||||
const QModelIndex textIndex = model->index(rowIndex, 0, fileIndex);
|
||||
const SearchResultTreeItem * const rowItem = model->itemForIndex(textIndex);
|
||||
QTC_ASSERT(rowItem != nullptr, continue);
|
||||
if (rowItem->checkState())
|
||||
if (!checkedOnly || rowItem->checkState())
|
||||
result << rowItem->item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ public:
|
||||
bool hasFilter() const;
|
||||
void showFilterWidget(QWidget *parent);
|
||||
void setReplaceEnabled(bool enabled);
|
||||
Utils::SearchResultItems items(bool checkedOnly) const;
|
||||
|
||||
public slots:
|
||||
void finishSearch(bool canceled, const QString &reason);
|
||||
@@ -103,7 +104,6 @@ private:
|
||||
void continueAfterSizeWarning();
|
||||
void cancelAfterSizeWarning();
|
||||
|
||||
Utils::SearchResultItems checkedItems() const;
|
||||
void updateMatchesFoundLabel();
|
||||
|
||||
SearchResultTreeView *m_searchResultTreeView = nullptr;
|
||||
|
||||
@@ -900,6 +900,11 @@ void Core::SearchResult::makeNonInteractive(const std::function<void ()> &callba
|
||||
m_finishedHandler = callback;
|
||||
}
|
||||
|
||||
Utils::SearchResultItems SearchResult::allItems() const
|
||||
{
|
||||
return m_widget->items(false);
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
#include "searchresultwindow.moc"
|
||||
|
||||
@@ -43,7 +43,8 @@ class CORE_EXPORT SearchResult : public QObject
|
||||
|
||||
public:
|
||||
enum AddMode {
|
||||
AddSorted,
|
||||
AddSortedByContent,
|
||||
AddSortedByPosition,
|
||||
AddOrdered
|
||||
};
|
||||
|
||||
@@ -57,6 +58,7 @@ public:
|
||||
void setAdditionalReplaceWidget(QWidget *widget);
|
||||
void makeNonInteractive(const std::function<void()> &callback);
|
||||
bool isInteractive() const { return !m_finishedHandler; }
|
||||
Utils::SearchResultItems allItems() const;
|
||||
|
||||
public slots:
|
||||
void addResult(const Utils::SearchResultItem &item);
|
||||
|
||||
Reference in New Issue
Block a user