forked from qt-creator/qt-creator
Core: Add infrastructure to do additional filtering on search results
... and make use of it to let users filter C++ "find references" results by access type. Fixes: QTCREATORBUG-19373 Change-Id: Ib5cadde1cfd235026d8e69da51daa6374808d3f3 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
#include <QCheckBox>
|
||||
#include <QDir>
|
||||
#include <QFutureWatcher>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <functional>
|
||||
|
||||
@@ -169,6 +170,58 @@ static QList<QByteArray> fullIdForSymbol(CPlusPlus::Symbol *symbol)
|
||||
|
||||
namespace {
|
||||
|
||||
class Filter : public Core::SearchResultFilter
|
||||
{
|
||||
QWidget *createWidget() override
|
||||
{
|
||||
const auto widget = new QWidget;
|
||||
const auto layout = new QVBoxLayout(widget);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
const auto readsCheckBox = new QCheckBox(tr("Reads"));
|
||||
readsCheckBox->setChecked(m_showReads);
|
||||
const auto writesCheckBox = new QCheckBox(tr("Writes"));
|
||||
writesCheckBox->setChecked(m_showWrites);
|
||||
const auto otherCheckBox = new QCheckBox(tr("Other"));
|
||||
otherCheckBox->setChecked(m_showOther);
|
||||
layout->addWidget(readsCheckBox);
|
||||
layout->addWidget(writesCheckBox);
|
||||
layout->addWidget(otherCheckBox);
|
||||
connect(readsCheckBox, &QCheckBox::toggled,
|
||||
this, [this](bool checked) { setValue(m_showReads, checked); });
|
||||
connect(writesCheckBox, &QCheckBox::toggled,
|
||||
this, [this](bool checked) { setValue(m_showWrites, checked); });
|
||||
connect(otherCheckBox, &QCheckBox::toggled,
|
||||
this, [this](bool checked) { setValue(m_showOther, checked); });
|
||||
return widget;
|
||||
}
|
||||
|
||||
bool matches(const SearchResultItem &item) const override
|
||||
{
|
||||
switch (static_cast<CPlusPlus::Usage::Type>(item.userData.toInt())) {
|
||||
case CPlusPlus::Usage::Type::Read:
|
||||
return m_showReads;
|
||||
case CPlusPlus::Usage::Type::Write:
|
||||
case CPlusPlus::Usage::Type::WritableRef:
|
||||
case CPlusPlus::Usage::Type::Initialization:
|
||||
return m_showWrites;
|
||||
case CPlusPlus::Usage::Type::Declaration:
|
||||
case CPlusPlus::Usage::Type::Other:
|
||||
return m_showOther;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void setValue(bool &member, bool value)
|
||||
{
|
||||
member = value;
|
||||
emit filterChanged();
|
||||
}
|
||||
|
||||
bool m_showReads = true;
|
||||
bool m_showWrites = true;
|
||||
bool m_showOther = true;
|
||||
};
|
||||
|
||||
class ProcessFile
|
||||
{
|
||||
const WorkingCopy workingCopy;
|
||||
@@ -339,6 +392,7 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
|
||||
SearchResultWindow::PreserveCaseDisabled,
|
||||
QLatin1String("CppEditor"));
|
||||
search->setTextToReplace(replacement);
|
||||
search->setFilter(new Filter);
|
||||
auto renameFilesCheckBox = new QCheckBox();
|
||||
renameFilesCheckBox->setVisible(false);
|
||||
search->setAdditionalReplaceWidget(renameFilesCheckBox);
|
||||
@@ -570,7 +624,8 @@ static void displayResults(SearchResult *search, QFutureWatcher<CPlusPlus::Usage
|
||||
for (int index = first; index != last; ++index) {
|
||||
const CPlusPlus::Usage result = watcher->future().resultAt(index);
|
||||
search->addResult(result.path.toString(), result.line, result.lineText,
|
||||
result.col, result.len, {}, colorStyleForUsageType(result.type));
|
||||
result.col, result.len, int(result.type),
|
||||
colorStyleForUsageType(result.type));
|
||||
|
||||
if (parameters.prettySymbolName.isEmpty())
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user