forked from qt-creator/qt-creator
CppTools: Export some symbol search-related functionality
We want to re-use it elsewhere. Change-Id: Iefd8464c56ddc8bb2fc5a3349cd833b094c61da7 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -55,10 +55,80 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace CppTools::Internal;
|
|
||||||
using namespace CppTools;
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
|
namespace CppTools {
|
||||||
|
|
||||||
|
SearchResultColor::Style colorStyleForUsageType(CPlusPlus::Usage::Type type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case CPlusPlus::Usage::Type::Read:
|
||||||
|
return SearchResultColor::Style::Alt1;
|
||||||
|
case CPlusPlus::Usage::Type::Initialization:
|
||||||
|
case CPlusPlus::Usage::Type::Write:
|
||||||
|
case CPlusPlus::Usage::Type::WritableRef:
|
||||||
|
return SearchResultColor::Style::Alt2;
|
||||||
|
case CPlusPlus::Usage::Type::Declaration:
|
||||||
|
case CPlusPlus::Usage::Type::Other:
|
||||||
|
return SearchResultColor::Style::Default;
|
||||||
|
}
|
||||||
|
return SearchResultColor::Style::Default; // For dumb compilers.
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *CppSearchResultFilter::createWidget()
|
||||||
|
{
|
||||||
|
const auto widget = new QWidget;
|
||||||
|
const auto layout = new QVBoxLayout(widget);
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
const auto readsCheckBox = new QCheckBox(Internal::CppFindReferences::tr("Reads"));
|
||||||
|
readsCheckBox->setChecked(m_showReads);
|
||||||
|
const auto writesCheckBox = new QCheckBox(Internal::CppFindReferences::tr("Writes"));
|
||||||
|
writesCheckBox->setChecked(m_showWrites);
|
||||||
|
const auto declsCheckBox = new QCheckBox(Internal::CppFindReferences::tr("Declarations"));
|
||||||
|
declsCheckBox->setChecked(m_showDecls);
|
||||||
|
const auto otherCheckBox = new QCheckBox(Internal::CppFindReferences::tr("Other"));
|
||||||
|
otherCheckBox->setChecked(m_showOther);
|
||||||
|
layout->addWidget(readsCheckBox);
|
||||||
|
layout->addWidget(writesCheckBox);
|
||||||
|
layout->addWidget(declsCheckBox);
|
||||||
|
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(declsCheckBox, &QCheckBox::toggled,
|
||||||
|
this, [this](bool checked) { setValue(m_showDecls, checked); });
|
||||||
|
connect(otherCheckBox, &QCheckBox::toggled,
|
||||||
|
this, [this](bool checked) { setValue(m_showOther, checked); });
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CppSearchResultFilter::matches(const SearchResultItem &item) const
|
||||||
|
{
|
||||||
|
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:
|
||||||
|
return m_showDecls;
|
||||||
|
case CPlusPlus::Usage::Type::Other:
|
||||||
|
return m_showOther;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppSearchResultFilter::setValue(bool &member, bool value)
|
||||||
|
{
|
||||||
|
member = value;
|
||||||
|
emit filterChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
|
||||||
static QByteArray getSource(const Utils::FilePath &fileName,
|
static QByteArray getSource(const Utils::FilePath &fileName,
|
||||||
const WorkingCopy &workingCopy)
|
const WorkingCopy &workingCopy)
|
||||||
{
|
{
|
||||||
@@ -171,65 +241,6 @@ static QList<QByteArray> fullIdForSymbol(CPlusPlus::Symbol *symbol)
|
|||||||
|
|
||||||
namespace {
|
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(CppFindReferences::tr("Reads"));
|
|
||||||
readsCheckBox->setChecked(m_showReads);
|
|
||||||
const auto writesCheckBox = new QCheckBox(CppFindReferences::tr("Writes"));
|
|
||||||
writesCheckBox->setChecked(m_showWrites);
|
|
||||||
const auto declsCheckBox = new QCheckBox(CppFindReferences::tr("Declarations"));
|
|
||||||
declsCheckBox->setChecked(m_showDecls);
|
|
||||||
const auto otherCheckBox = new QCheckBox(CppFindReferences::tr("Other"));
|
|
||||||
otherCheckBox->setChecked(m_showOther);
|
|
||||||
layout->addWidget(readsCheckBox);
|
|
||||||
layout->addWidget(writesCheckBox);
|
|
||||||
layout->addWidget(declsCheckBox);
|
|
||||||
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(declsCheckBox, &QCheckBox::toggled,
|
|
||||||
this, [this](bool checked) { setValue(m_showDecls, 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:
|
|
||||||
return m_showDecls;
|
|
||||||
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_showDecls = true;
|
|
||||||
bool m_showOther = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ProcessFile
|
class ProcessFile
|
||||||
{
|
{
|
||||||
const WorkingCopy workingCopy;
|
const WorkingCopy workingCopy;
|
||||||
@@ -400,7 +411,7 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
|
|||||||
SearchResultWindow::PreserveCaseDisabled,
|
SearchResultWindow::PreserveCaseDisabled,
|
||||||
QLatin1String("CppEditor"));
|
QLatin1String("CppEditor"));
|
||||||
search->setTextToReplace(replacement);
|
search->setTextToReplace(replacement);
|
||||||
search->setFilter(new Filter);
|
search->setFilter(new CppSearchResultFilter);
|
||||||
auto renameFilesCheckBox = new QCheckBox();
|
auto renameFilesCheckBox = new QCheckBox();
|
||||||
renameFilesCheckBox->setVisible(false);
|
renameFilesCheckBox->setVisible(false);
|
||||||
search->setAdditionalReplaceWidget(renameFilesCheckBox);
|
search->setAdditionalReplaceWidget(renameFilesCheckBox);
|
||||||
@@ -615,20 +626,6 @@ static void displayResults(SearchResult *search, QFutureWatcher<CPlusPlus::Usage
|
|||||||
{
|
{
|
||||||
CppFindReferencesParameters parameters = search->userData().value<CppFindReferencesParameters>();
|
CppFindReferencesParameters parameters = search->userData().value<CppFindReferencesParameters>();
|
||||||
|
|
||||||
static const auto colorStyleForUsageType = [](CPlusPlus::Usage::Type type) {
|
|
||||||
switch (type) {
|
|
||||||
case CPlusPlus::Usage::Type::Read:
|
|
||||||
return SearchResultColor::Style::Alt1;
|
|
||||||
case CPlusPlus::Usage::Type::Initialization:
|
|
||||||
case CPlusPlus::Usage::Type::Write:
|
|
||||||
case CPlusPlus::Usage::Type::WritableRef:
|
|
||||||
return SearchResultColor::Style::Alt2;
|
|
||||||
case CPlusPlus::Usage::Type::Declaration:
|
|
||||||
case CPlusPlus::Usage::Type::Other:
|
|
||||||
return SearchResultColor::Style::Default;
|
|
||||||
}
|
|
||||||
return SearchResultColor::Style::Default; // For dumb compilers.
|
|
||||||
};
|
|
||||||
for (int index = first; index != last; ++index) {
|
for (int index = first; index != last; ++index) {
|
||||||
const CPlusPlus::Usage result = watcher->future().resultAt(index);
|
const CPlusPlus::Usage result = watcher->future().resultAt(index);
|
||||||
SearchResultItem item;
|
SearchResultItem item;
|
||||||
@@ -881,3 +878,6 @@ void CppFindReferences::createWatcher(const QFuture<CPlusPlus::Usage> &future, S
|
|||||||
watcher->setPendingResultsLimit(1);
|
watcher->setPendingResultsLimit(1);
|
||||||
watcher->setFuture(future);
|
watcher->setFuture(future);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace CppTools
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "cpptools_global.h"
|
||||||
|
|
||||||
|
#include <coreplugin/find/searchresultwindow.h>
|
||||||
#include <cplusplus/FindUsages.h>
|
#include <cplusplus/FindUsages.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@@ -45,6 +48,21 @@ class Node;
|
|||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
class CppModelManager;
|
class CppModelManager;
|
||||||
|
|
||||||
|
Core::SearchResultColor::Style CPPTOOLS_EXPORT colorStyleForUsageType(CPlusPlus::Usage::Type type);
|
||||||
|
|
||||||
|
class CPPTOOLS_EXPORT CppSearchResultFilter : public Core::SearchResultFilter
|
||||||
|
{
|
||||||
|
QWidget *createWidget() override;
|
||||||
|
bool matches(const Core::SearchResultItem &item) const override;
|
||||||
|
|
||||||
|
void setValue(bool &member, bool value);
|
||||||
|
|
||||||
|
bool m_showReads = true;
|
||||||
|
bool m_showWrites = true;
|
||||||
|
bool m_showDecls = true;
|
||||||
|
bool m_showOther = true;
|
||||||
|
};
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CppFindReferencesParameters
|
class CppFindReferencesParameters
|
||||||
|
|||||||
Reference in New Issue
Block a user