forked from qt-creator/qt-creator
C++: Rename ModelItemInfo to IndexInfo.
And move it into its own header and source files. Change-Id: I37401badd819e028e1d767425759dc0ff27afe31 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -88,12 +88,12 @@ void ClangSymbolSearcher::search(const QLinkedList<Symbol> &allSymbols)
|
|||||||
}
|
}
|
||||||
++symbolNr;
|
++symbolNr;
|
||||||
|
|
||||||
CppTools::ModelItemInfo info;
|
CppTools::IndexItem info;
|
||||||
|
|
||||||
switch (s.m_kind) {
|
switch (s.m_kind) {
|
||||||
case Symbol::Enum:
|
case Symbol::Enum:
|
||||||
if (m_parameters.types & SymbolSearcher::Enums) {
|
if (m_parameters.types & SymbolSearcher::Enums) {
|
||||||
info.type = CppTools::ModelItemInfo::Enum;
|
info.type = CppTools::IndexItem::Enum;
|
||||||
info.symbolType = QLatin1String("enum");
|
info.symbolType = QLatin1String("enum");
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -101,7 +101,7 @@ void ClangSymbolSearcher::search(const QLinkedList<Symbol> &allSymbols)
|
|||||||
}
|
}
|
||||||
case Symbol::Class:
|
case Symbol::Class:
|
||||||
if (m_parameters.types & SymbolSearcher::Classes) {
|
if (m_parameters.types & SymbolSearcher::Classes) {
|
||||||
info.type = CppTools::ModelItemInfo::Class;
|
info.type = CppTools::IndexItem::Class;
|
||||||
info.symbolType = QLatin1String("class");
|
info.symbolType = QLatin1String("class");
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -112,14 +112,14 @@ void ClangSymbolSearcher::search(const QLinkedList<Symbol> &allSymbols)
|
|||||||
case Symbol::Constructor:
|
case Symbol::Constructor:
|
||||||
case Symbol::Destructor:
|
case Symbol::Destructor:
|
||||||
if (m_parameters.types & SymbolSearcher::Functions) {
|
if (m_parameters.types & SymbolSearcher::Functions) {
|
||||||
info.type = CppTools::ModelItemInfo::Function;
|
info.type = CppTools::IndexItem::Function;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case Symbol::Declaration:
|
case Symbol::Declaration:
|
||||||
if (m_parameters.types & SymbolSearcher::Declarations) {
|
if (m_parameters.types & SymbolSearcher::Declarations) {
|
||||||
info.type = CppTools::ModelItemInfo::Declaration;
|
info.type = CppTools::IndexItem::Declaration;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
@@ -1920,7 +1920,7 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
|
|||||||
QList<Core::LocatorFilterEntry> matches = classesFilter->matchesFor(dummyInterface, className);
|
QList<Core::LocatorFilterEntry> matches = classesFilter->matchesFor(dummyInterface, className);
|
||||||
bool classExists = false;
|
bool classExists = false;
|
||||||
foreach (const Core::LocatorFilterEntry &entry, matches) {
|
foreach (const Core::LocatorFilterEntry &entry, matches) {
|
||||||
ModelItemInfo::Ptr info = entry.internalData.value<ModelItemInfo::Ptr>();
|
IndexItem::Ptr info = entry.internalData.value<IndexItem::Ptr>();
|
||||||
if (info->symbolName() != className)
|
if (info->symbolName() != className)
|
||||||
continue;
|
continue;
|
||||||
classExists = true;
|
classExists = true;
|
||||||
|
@@ -125,16 +125,16 @@ public:
|
|||||||
break;
|
break;
|
||||||
if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->fileName())) {
|
if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->fileName())) {
|
||||||
QVector<Core::SearchResultItem> resultItems;
|
QVector<Core::SearchResultItem> resultItems;
|
||||||
search(it.value())->visitAllChildren([&](const ModelItemInfo::Ptr &info) {
|
search(it.value())->visitAllChildren([&](const IndexItem::Ptr &info) {
|
||||||
if (matcher.indexIn(info->symbolName()) != -1) {
|
if (matcher.indexIn(info->symbolName()) != -1) {
|
||||||
QString text = info->symbolName();
|
QString text = info->symbolName();
|
||||||
QString scope = info->symbolScope();
|
QString scope = info->symbolScope();
|
||||||
if (info->type() == ModelItemInfo::Function) {
|
if (info->type() == IndexItem::Function) {
|
||||||
QString name;
|
QString name;
|
||||||
info->unqualifiedNameAndScope(info->symbolName(), &name, &scope);
|
info->unqualifiedNameAndScope(info->symbolName(), &name, &scope);
|
||||||
text = name + info->symbolType();
|
text = name + info->symbolType();
|
||||||
} else if (info->type() == ModelItemInfo::Declaration){
|
} else if (info->type() == IndexItem::Declaration){
|
||||||
text = ModelItemInfo::representDeclaration(info->symbolName(),
|
text = IndexItem::representDeclaration(info->symbolName(),
|
||||||
info->symbolType());
|
info->symbolType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,12 +45,12 @@ CppClassesFilter::~CppClassesFilter()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QList<ModelItemInfo::Ptr> > CppClassesFilter::itemsToMatchUserInputAgainst() const
|
QList<QList<IndexItem::Ptr> > CppClassesFilter::itemsToMatchUserInputAgainst() const
|
||||||
{
|
{
|
||||||
return QList<QList<CppTools::ModelItemInfo::Ptr> >() << m_data->classes();
|
return QList<QList<CppTools::IndexItem::Ptr> >() << m_data->classes();
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::LocatorFilterEntry CppClassesFilter::filterEntryFromModelItemInfo(ModelItemInfo::Ptr info)
|
Core::LocatorFilterEntry CppClassesFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
|
||||||
{
|
{
|
||||||
const QVariant id = qVariantFromValue(info);
|
const QVariant id = qVariantFromValue(info);
|
||||||
Core::LocatorFilterEntry filterEntry(this, info->symbolName(), id, info->icon());
|
Core::LocatorFilterEntry filterEntry(this, info->symbolName(), id, info->icon());
|
||||||
|
@@ -45,8 +45,8 @@ public:
|
|||||||
~CppClassesFilter();
|
~CppClassesFilter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QList<CppTools::ModelItemInfo::Ptr> > itemsToMatchUserInputAgainst() const;
|
QList<QList<CppTools::IndexItem::Ptr> > itemsToMatchUserInputAgainst() const;
|
||||||
Core::LocatorFilterEntry filterEntryFromModelItemInfo(ModelItemInfo::Ptr info);
|
Core::LocatorFilterEntry filterEntryFromIndexItem(IndexItem::Ptr info);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
@@ -79,22 +79,22 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
|
|||||||
Snapshot snapshot = m_modelManager->snapshot();
|
Snapshot snapshot = m_modelManager->snapshot();
|
||||||
Document::Ptr thisDocument = snapshot.document(m_currentFileName);
|
Document::Ptr thisDocument = snapshot.document(m_currentFileName);
|
||||||
if (thisDocument)
|
if (thisDocument)
|
||||||
search(thisDocument)->visitAllChildren([&](const ModelItemInfo::Ptr &info){
|
search(thisDocument)->visitAllChildren([&](const IndexItem::Ptr &info){
|
||||||
m_itemsOfCurrentDoc.append(info);
|
m_itemsOfCurrentDoc.append(info);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
||||||
|
|
||||||
foreach (ModelItemInfo::Ptr info, m_itemsOfCurrentDoc) {
|
foreach (IndexItem::Ptr info, m_itemsOfCurrentDoc) {
|
||||||
if (future.isCanceled())
|
if (future.isCanceled())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
QString matchString = info->symbolName();
|
QString matchString = info->symbolName();
|
||||||
if (info->type() == ModelItemInfo::Declaration)
|
if (info->type() == IndexItem::Declaration)
|
||||||
matchString = ModelItemInfo::representDeclaration(info->symbolName(),
|
matchString = IndexItem::representDeclaration(info->symbolName(),
|
||||||
info->symbolType());
|
info->symbolType());
|
||||||
else if (info->type() == ModelItemInfo::Function)
|
else if (info->type() == IndexItem::Function)
|
||||||
matchString += info->symbolType();
|
matchString += info->symbolType();
|
||||||
|
|
||||||
if ((hasWildcard && regexp.exactMatch(matchString))
|
if ((hasWildcard && regexp.exactMatch(matchString))
|
||||||
@@ -103,7 +103,7 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
|
|||||||
QVariant id = qVariantFromValue(info);
|
QVariant id = qVariantFromValue(info);
|
||||||
QString name = matchString;
|
QString name = matchString;
|
||||||
QString extraInfo = info->symbolScope();
|
QString extraInfo = info->symbolScope();
|
||||||
if (info->type() == ModelItemInfo::Function) {
|
if (info->type() == IndexItem::Function) {
|
||||||
if (info->unqualifiedNameAndScope(matchString, &name, &extraInfo))
|
if (info->unqualifiedNameAndScope(matchString, &name, &extraInfo))
|
||||||
name += info->symbolType();
|
name += info->symbolType();
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor(
|
|||||||
|
|
||||||
void CppCurrentDocumentFilter::accept(Core::LocatorFilterEntry selection) const
|
void CppCurrentDocumentFilter::accept(Core::LocatorFilterEntry selection) const
|
||||||
{
|
{
|
||||||
ModelItemInfo::Ptr info = qvariant_cast<CppTools::ModelItemInfo::Ptr>(selection.internalData);
|
IndexItem::Ptr info = qvariant_cast<CppTools::IndexItem::Ptr>(selection.internalData);
|
||||||
Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column());
|
Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,7 +61,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
CppModelManager * m_modelManager;
|
CppModelManager * m_modelManager;
|
||||||
QString m_currentFileName;
|
QString m_currentFileName;
|
||||||
QList<ModelItemInfo::Ptr> m_itemsOfCurrentDoc;
|
QList<IndexItem::Ptr> m_itemsOfCurrentDoc;
|
||||||
SearchSymbols search;
|
SearchSymbols search;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -45,12 +45,12 @@ CppFunctionsFilter::~CppFunctionsFilter()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QList<CppTools::ModelItemInfo::Ptr> > CppFunctionsFilter::itemsToMatchUserInputAgainst() const
|
QList<QList<CppTools::IndexItem::Ptr> > CppFunctionsFilter::itemsToMatchUserInputAgainst() const
|
||||||
{
|
{
|
||||||
return QList<QList<CppTools::ModelItemInfo::Ptr> >() << m_data->functions();
|
return QList<QList<CppTools::IndexItem::Ptr> >() << m_data->functions();
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(ModelItemInfo::Ptr info)
|
Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
|
||||||
{
|
{
|
||||||
const QVariant id = qVariantFromValue(info);
|
const QVariant id = qVariantFromValue(info);
|
||||||
|
|
||||||
|
@@ -45,8 +45,8 @@ public:
|
|||||||
~CppFunctionsFilter();
|
~CppFunctionsFilter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QList<ModelItemInfo::Ptr> > itemsToMatchUserInputAgainst() const;
|
QList<QList<IndexItem::Ptr> > itemsToMatchUserInputAgainst() const;
|
||||||
Core::LocatorFilterEntry filterEntryFromModelItemInfo(ModelItemInfo::Ptr info);
|
Core::LocatorFilterEntry filterEntryFromIndexItem(IndexItem::Ptr info);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -53,22 +53,22 @@ CppLocatorData::CppLocatorData(CppModelManager *modelManager)
|
|||||||
this, SLOT(onAboutToRemoveFiles(QStringList)));
|
this, SLOT(onAboutToRemoveFiles(QStringList)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ModelItemInfo::Ptr> CppLocatorData::enums()
|
QList<IndexItem::Ptr> CppLocatorData::enums()
|
||||||
{
|
{
|
||||||
flushPendingDocument(true);
|
flushPendingDocument(true);
|
||||||
return allModelItemInfos(m_allEnums);
|
return allIndexItems(m_allEnums);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ModelItemInfo::Ptr> CppLocatorData::classes()
|
QList<IndexItem::Ptr> CppLocatorData::classes()
|
||||||
{
|
{
|
||||||
flushPendingDocument(true);
|
flushPendingDocument(true);
|
||||||
return allModelItemInfos(m_allClasses);
|
return allIndexItems(m_allClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ModelItemInfo::Ptr> CppLocatorData::functions()
|
QList<IndexItem::Ptr> CppLocatorData::functions()
|
||||||
{
|
{
|
||||||
flushPendingDocument(true);
|
flushPendingDocument(true);
|
||||||
return allModelItemInfos(m_allFunctions);
|
return allIndexItems(m_allFunctions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document)
|
void CppLocatorData::onDocumentUpdated(const CPlusPlus::Document::Ptr &document)
|
||||||
@@ -120,21 +120,19 @@ void CppLocatorData::flushPendingDocument(bool force)
|
|||||||
foreach (CPlusPlus::Document::Ptr doc, m_pendingDocuments) {
|
foreach (CPlusPlus::Document::Ptr doc, m_pendingDocuments) {
|
||||||
const QString fileName = findOrInsertFilePath(doc->fileName());
|
const QString fileName = findOrInsertFilePath(doc->fileName());
|
||||||
|
|
||||||
QList<ModelItemInfo::Ptr> resultsEnums;
|
QList<IndexItem::Ptr> resultsEnums;
|
||||||
QList<ModelItemInfo::Ptr> resultsClasses;
|
QList<IndexItem::Ptr> resultsClasses;
|
||||||
QList<ModelItemInfo::Ptr> resultsFunctions;
|
QList<IndexItem::Ptr> resultsFunctions;
|
||||||
|
|
||||||
const int sizeHint = m_allEnums[fileName].size() + m_allClasses[fileName].size()
|
m_search(doc)->visitAllChildren([&](const IndexItem::Ptr &info) {
|
||||||
+ m_allFunctions[fileName].size() + 10;
|
|
||||||
m_search(doc, sizeHint)->visitAllChildren([&](const ModelItemInfo::Ptr &info) {
|
|
||||||
switch (info->type()) {
|
switch (info->type()) {
|
||||||
case ModelItemInfo::Enum:
|
case IndexItem::Enum:
|
||||||
resultsEnums.append(info);
|
resultsEnums.append(info);
|
||||||
break;
|
break;
|
||||||
case ModelItemInfo::Class:
|
case IndexItem::Class:
|
||||||
resultsClasses.append(info);
|
resultsClasses.append(info);
|
||||||
break;
|
break;
|
||||||
case ModelItemInfo::Function:
|
case IndexItem::Function:
|
||||||
resultsFunctions.append(info);
|
resultsFunctions.append(info);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -151,11 +149,11 @@ void CppLocatorData::flushPendingDocument(bool force)
|
|||||||
m_pendingDocuments.reserve(MaxPendingDocuments);
|
m_pendingDocuments.reserve(MaxPendingDocuments);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ModelItemInfo::Ptr> CppLocatorData::allModelItemInfos(const QHash<QString,
|
QList<IndexItem::Ptr> CppLocatorData::allIndexItems(
|
||||||
QList<ModelItemInfo::Ptr>> &items) const
|
const QHash<QString, QList<IndexItem::Ptr>> &items) const
|
||||||
{
|
{
|
||||||
QList<ModelItemInfo::Ptr> result;
|
QList<IndexItem::Ptr> result;
|
||||||
QHashIterator<QString, QList<ModelItemInfo::Ptr> > it(items);
|
QHashIterator<QString, QList<IndexItem::Ptr> > it(items);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
result.append(it.value());
|
result.append(it.value());
|
||||||
|
@@ -49,9 +49,9 @@ class CppLocatorData : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit CppLocatorData(CppModelManager *modelManager);
|
explicit CppLocatorData(CppModelManager *modelManager);
|
||||||
|
|
||||||
QList<ModelItemInfo::Ptr> enums();
|
QList<IndexItem::Ptr> enums();
|
||||||
QList<ModelItemInfo::Ptr> classes();
|
QList<IndexItem::Ptr> classes();
|
||||||
QList<ModelItemInfo::Ptr> functions();
|
QList<IndexItem::Ptr> functions();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDocumentUpdated(const CPlusPlus::Document::Ptr &document);
|
void onDocumentUpdated(const CPlusPlus::Document::Ptr &document);
|
||||||
@@ -59,8 +59,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void flushPendingDocument(bool force);
|
void flushPendingDocument(bool force);
|
||||||
QList<ModelItemInfo::Ptr> allModelItemInfos(
|
QList<IndexItem::Ptr> allIndexItems(const QHash<QString, QList<IndexItem::Ptr>> &items) const;
|
||||||
const QHash<QString, QList<ModelItemInfo::Ptr>> &items) const;
|
|
||||||
|
|
||||||
QString findOrInsertFilePath(const QString &path)
|
QString findOrInsertFilePath(const QString &path)
|
||||||
{ return m_strings.insert(path); }
|
{ return m_strings.insert(path); }
|
||||||
@@ -71,9 +70,9 @@ private:
|
|||||||
StringTable &m_strings; // Used to avoid QString duplication
|
StringTable &m_strings; // Used to avoid QString duplication
|
||||||
|
|
||||||
SearchSymbols m_search;
|
SearchSymbols m_search;
|
||||||
QHash<QString, QList<ModelItemInfo::Ptr> > m_allEnums;
|
QHash<QString, QList<IndexItem::Ptr> > m_allEnums;
|
||||||
QHash<QString, QList<ModelItemInfo::Ptr> > m_allClasses;
|
QHash<QString, QList<IndexItem::Ptr> > m_allClasses;
|
||||||
QHash<QString, QList<ModelItemInfo::Ptr> > m_allFunctions;
|
QHash<QString, QList<IndexItem::Ptr> > m_allFunctions;
|
||||||
|
|
||||||
mutable QMutex m_pendingDocumentsMutex;
|
mutable QMutex m_pendingDocumentsMutex;
|
||||||
QVector<CPlusPlus::Document::Ptr> m_pendingDocuments;
|
QVector<CPlusPlus::Document::Ptr> m_pendingDocuments;
|
||||||
|
@@ -48,11 +48,11 @@ CppLocatorFilter::~CppLocatorFilter()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromModelItemInfo(ModelItemInfo::Ptr info)
|
Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromIndexItem(IndexItem::Ptr info)
|
||||||
{
|
{
|
||||||
const QVariant id = qVariantFromValue(info);
|
const QVariant id = qVariantFromValue(info);
|
||||||
Core::LocatorFilterEntry filterEntry(this, info->scopedSymbolName(), id, info->icon());
|
Core::LocatorFilterEntry filterEntry(this, info->scopedSymbolName(), id, info->icon());
|
||||||
if (info->type() == ModelItemInfo::Class || info->type() == ModelItemInfo::Enum)
|
if (info->type() == IndexItem::Class || info->type() == IndexItem::Enum)
|
||||||
filterEntry.extraInfo = info->shortNativeFilePath();
|
filterEntry.extraInfo = info->shortNativeFilePath();
|
||||||
else
|
else
|
||||||
filterEntry.extraInfo = info->symbolType();
|
filterEntry.extraInfo = info->symbolType();
|
||||||
@@ -65,9 +65,9 @@ void CppLocatorFilter::refresh(QFutureInterface<void> &future)
|
|||||||
Q_UNUSED(future)
|
Q_UNUSED(future)
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QList<CppTools::ModelItemInfo::Ptr> > CppLocatorFilter::itemsToMatchUserInputAgainst() const
|
QList<QList<CppTools::IndexItem::Ptr> > CppLocatorFilter::itemsToMatchUserInputAgainst() const
|
||||||
{
|
{
|
||||||
return QList<QList<CppTools::ModelItemInfo::Ptr> >()
|
return QList<QList<CppTools::IndexItem::Ptr> >()
|
||||||
<< m_data->classes()
|
<< m_data->classes()
|
||||||
<< m_data->functions()
|
<< m_data->functions()
|
||||||
<< m_data->enums();
|
<< m_data->enums();
|
||||||
@@ -94,16 +94,16 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
|
|||||||
bool hasColonColon = entry.contains(QLatin1String("::"));
|
bool hasColonColon = entry.contains(QLatin1String("::"));
|
||||||
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry);
|
||||||
|
|
||||||
const QList<QList<CppTools::ModelItemInfo::Ptr> > itemLists = itemsToMatchUserInputAgainst();
|
const QList<QList<CppTools::IndexItem::Ptr> > itemLists = itemsToMatchUserInputAgainst();
|
||||||
foreach (const QList<CppTools::ModelItemInfo::Ptr> &items, itemLists) {
|
foreach (const QList<CppTools::IndexItem::Ptr> &items, itemLists) {
|
||||||
foreach (ModelItemInfo::Ptr info, items) {
|
foreach (IndexItem::Ptr info, items) {
|
||||||
if (future.isCanceled())
|
if (future.isCanceled())
|
||||||
break;
|
break;
|
||||||
const QString matchString = hasColonColon ? info->scopedSymbolName()
|
const QString matchString = hasColonColon ? info->scopedSymbolName()
|
||||||
: info->symbolName();
|
: info->symbolName();
|
||||||
if ((hasWildcard && regexp.exactMatch(matchString))
|
if ((hasWildcard && regexp.exactMatch(matchString))
|
||||||
|| (!hasWildcard && matcher.indexIn(matchString) != -1)) {
|
|| (!hasWildcard && matcher.indexIn(matchString) != -1)) {
|
||||||
const Core::LocatorFilterEntry filterEntry = filterEntryFromModelItemInfo(info);
|
const Core::LocatorFilterEntry filterEntry = filterEntryFromIndexItem(info);
|
||||||
if (matchString.startsWith(entry, caseSensitivityForPrefix))
|
if (matchString.startsWith(entry, caseSensitivityForPrefix))
|
||||||
betterEntries.append(filterEntry);
|
betterEntries.append(filterEntry);
|
||||||
else
|
else
|
||||||
@@ -123,6 +123,6 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(
|
|||||||
|
|
||||||
void CppLocatorFilter::accept(Core::LocatorFilterEntry selection) const
|
void CppLocatorFilter::accept(Core::LocatorFilterEntry selection) const
|
||||||
{
|
{
|
||||||
ModelItemInfo::Ptr info = qvariant_cast<CppTools::ModelItemInfo::Ptr>(selection.internalData);
|
IndexItem::Ptr info = qvariant_cast<CppTools::IndexItem::Ptr>(selection.internalData);
|
||||||
Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column());
|
Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column());
|
||||||
}
|
}
|
||||||
|
@@ -54,8 +54,8 @@ public:
|
|||||||
void refresh(QFutureInterface<void> &future);
|
void refresh(QFutureInterface<void> &future);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual QList<QList<ModelItemInfo::Ptr> > itemsToMatchUserInputAgainst() const;
|
virtual QList<QList<IndexItem::Ptr> > itemsToMatchUserInputAgainst() const;
|
||||||
virtual Core::LocatorFilterEntry filterEntryFromModelItemInfo(ModelItemInfo::Ptr info);
|
virtual Core::LocatorFilterEntry filterEntryFromIndexItem(IndexItem::Ptr info);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CppLocatorData *m_data;
|
CppLocatorData *m_data;
|
||||||
|
@@ -50,6 +50,7 @@ HEADERS += \
|
|||||||
doxygengenerator.h \
|
doxygengenerator.h \
|
||||||
functionutils.h \
|
functionutils.h \
|
||||||
includeutils.h \
|
includeutils.h \
|
||||||
|
indexitem.h \
|
||||||
insertionpointlocator.h \
|
insertionpointlocator.h \
|
||||||
searchsymbols.h \
|
searchsymbols.h \
|
||||||
stringtable.h \
|
stringtable.h \
|
||||||
@@ -103,6 +104,7 @@ SOURCES += \
|
|||||||
doxygengenerator.cpp \
|
doxygengenerator.cpp \
|
||||||
functionutils.cpp \
|
functionutils.cpp \
|
||||||
includeutils.cpp \
|
includeutils.cpp \
|
||||||
|
indexitem.cpp \
|
||||||
insertionpointlocator.cpp \
|
insertionpointlocator.cpp \
|
||||||
searchsymbols.cpp \
|
searchsymbols.cpp \
|
||||||
stringtable.cpp \
|
stringtable.cpp \
|
||||||
|
@@ -71,6 +71,7 @@ QtcPlugin {
|
|||||||
"doxygengenerator.cpp", "doxygengenerator.h",
|
"doxygengenerator.cpp", "doxygengenerator.h",
|
||||||
"functionutils.cpp", "functionutils.h",
|
"functionutils.cpp", "functionutils.h",
|
||||||
"includeutils.cpp", "includeutils.h",
|
"includeutils.cpp", "includeutils.h",
|
||||||
|
"indexitem.cpp", "indexitem.h",
|
||||||
"insertionpointlocator.cpp", "insertionpointlocator.h",
|
"insertionpointlocator.cpp", "insertionpointlocator.h",
|
||||||
"searchsymbols.cpp", "searchsymbols.h",
|
"searchsymbols.cpp", "searchsymbols.h",
|
||||||
"stringtable.cpp", "stringtable.h",
|
"stringtable.cpp", "stringtable.h",
|
||||||
|
55
src/plugins/cpptools/indexitem.cpp
Normal file
55
src/plugins/cpptools/indexitem.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Digia. For licensing terms and
|
||||||
|
** conditions see http://qt.digia.com/licensing. For further information
|
||||||
|
** use the contact form at http://qt.digia.com/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "indexitem.h"
|
||||||
|
|
||||||
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
|
using namespace CppTools;
|
||||||
|
|
||||||
|
QString IndexItem::shortNativeFilePath() const
|
||||||
|
{
|
||||||
|
return Utils::FileUtils::shortNativePath(Utils::FileName::fromString(m_fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
void IndexItem::squeeze()
|
||||||
|
{
|
||||||
|
m_children.squeeze();
|
||||||
|
for (int i = 0, ei = m_children.size(); i != ei; ++i)
|
||||||
|
m_children[i]->squeeze();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IndexItem::visitAllChildren(std::function<void (const IndexItem::Ptr &)> f) const
|
||||||
|
{
|
||||||
|
foreach (const IndexItem::Ptr &child, m_children) {
|
||||||
|
f(child);
|
||||||
|
if (!child->m_children.isEmpty())
|
||||||
|
child->visitAllChildren(f);
|
||||||
|
}
|
||||||
|
}
|
160
src/plugins/cpptools/indexitem.h
Normal file
160
src/plugins/cpptools/indexitem.h
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Digia. For licensing terms and
|
||||||
|
** conditions see http://qt.digia.com/licensing. For further information
|
||||||
|
** use the contact form at http://qt.digia.com/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CPPTOOLS_INDEXITEM_H
|
||||||
|
#define CPPTOOLS_INDEXITEM_H
|
||||||
|
|
||||||
|
#include "cpptools_global.h"
|
||||||
|
|
||||||
|
#include <utils/function.h>
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
|
namespace CppTools {
|
||||||
|
|
||||||
|
class CPPTOOLS_EXPORT IndexItem
|
||||||
|
{
|
||||||
|
Q_DISABLE_COPY(IndexItem)
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum ItemType { Enum, Class, Function, Declaration };
|
||||||
|
|
||||||
|
private:
|
||||||
|
IndexItem(const QString &symbolName,
|
||||||
|
const QString &symbolType,
|
||||||
|
const QString &symbolScope,
|
||||||
|
ItemType type,
|
||||||
|
const QString &fileName,
|
||||||
|
int line,
|
||||||
|
int column,
|
||||||
|
const QIcon &icon)
|
||||||
|
: m_symbolName(symbolName),
|
||||||
|
m_symbolType(symbolType),
|
||||||
|
m_symbolScope(symbolScope),
|
||||||
|
m_fileName(fileName),
|
||||||
|
m_icon(icon),
|
||||||
|
m_type(type),
|
||||||
|
m_line(line),
|
||||||
|
m_column(column)
|
||||||
|
{}
|
||||||
|
|
||||||
|
IndexItem(const QString &fileName, int sizeHint)
|
||||||
|
: m_fileName(fileName)
|
||||||
|
, m_type(Declaration)
|
||||||
|
, m_line(0)
|
||||||
|
, m_column(0)
|
||||||
|
{ m_children.reserve(sizeHint); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef QSharedPointer<IndexItem> Ptr;
|
||||||
|
static Ptr create(const QString &symbolName,
|
||||||
|
const QString &symbolType,
|
||||||
|
const QString &symbolScope,
|
||||||
|
ItemType type,
|
||||||
|
const QString &fileName,
|
||||||
|
int line,
|
||||||
|
int column,
|
||||||
|
const QIcon &icon)
|
||||||
|
{
|
||||||
|
return Ptr(new IndexItem(
|
||||||
|
symbolName, symbolType, symbolScope, type, fileName, line, column, icon));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Ptr create(const QString &fileName, int sizeHint)
|
||||||
|
{
|
||||||
|
return Ptr(new IndexItem(fileName, sizeHint));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString scopedSymbolName() const
|
||||||
|
{
|
||||||
|
return m_symbolScope.isEmpty()
|
||||||
|
? m_symbolName
|
||||||
|
: m_symbolScope + QLatin1String("::") + m_symbolName;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool unqualifiedNameAndScope(const QString &defaultName, QString *name, QString *scope) const
|
||||||
|
{
|
||||||
|
*name = defaultName;
|
||||||
|
*scope = m_symbolScope;
|
||||||
|
const QString qualifiedName = scopedSymbolName();
|
||||||
|
const int colonColonPosition = qualifiedName.lastIndexOf(QLatin1String("::"));
|
||||||
|
if (colonColonPosition != -1) {
|
||||||
|
*name = qualifiedName.mid(colonColonPosition + 2);
|
||||||
|
*scope = qualifiedName.left(colonColonPosition);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString representDeclaration(const QString &name, const QString &type)
|
||||||
|
{
|
||||||
|
if (type.isEmpty())
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
const QString padding = type.endsWith(QLatin1Char('*'))
|
||||||
|
? QString()
|
||||||
|
: QString(QLatin1Char(' '));
|
||||||
|
return type + padding + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString shortNativeFilePath() const;
|
||||||
|
|
||||||
|
QString symbolName() const { return m_symbolName; }
|
||||||
|
QString symbolType() const { return m_symbolType; }
|
||||||
|
QString symbolScope() const { return m_symbolScope; }
|
||||||
|
QString fileName() const { return m_fileName; }
|
||||||
|
QIcon icon() const { return m_icon; }
|
||||||
|
ItemType type() const { return m_type; }
|
||||||
|
int line() const { return m_line; }
|
||||||
|
int column() const { return m_column; }
|
||||||
|
|
||||||
|
void addChild(IndexItem::Ptr childItem) { m_children.append(childItem); }
|
||||||
|
void squeeze();
|
||||||
|
|
||||||
|
void visitAllChildren(std::function<void (const IndexItem::Ptr &)> f) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_symbolName; // as found in the code, therefore might be qualified
|
||||||
|
QString m_symbolType;
|
||||||
|
QString m_symbolScope;
|
||||||
|
QString m_fileName;
|
||||||
|
QIcon m_icon;
|
||||||
|
ItemType m_type;
|
||||||
|
int m_line;
|
||||||
|
int m_column;
|
||||||
|
QVector<IndexItem::Ptr> m_children;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // CppTools namespace
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(CppTools::IndexItem::Ptr)
|
||||||
|
|
||||||
|
#endif // CPPTOOLS_INDEXITEM_H
|
@@ -38,7 +38,7 @@
|
|||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
|
|
||||||
typedef Utils::ScopedSwap<ModelItemInfo::Ptr> ScopedModelItemInfoPtr;
|
typedef Utils::ScopedSwap<IndexItem::Ptr> ScopedIndexItemPtr;
|
||||||
typedef Utils::ScopedSwap<QString> ScopedScope;
|
typedef Utils::ScopedSwap<QString> ScopedScope;
|
||||||
|
|
||||||
SearchSymbols::SymbolTypes SearchSymbols::AllTypes =
|
SearchSymbols::SymbolTypes SearchSymbols::AllTypes =
|
||||||
@@ -58,19 +58,19 @@ void SearchSymbols::setSymbolsToSearchFor(const SymbolTypes &types)
|
|||||||
symbolsToSearchFor = types;
|
symbolsToSearchFor = types;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelItemInfo::Ptr SearchSymbols::operator()(Document::Ptr doc, int sizeHint, const QString &scope)
|
IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope)
|
||||||
{
|
{
|
||||||
ModelItemInfo::Ptr root = ModelItemInfo::create(findOrInsert(doc->fileName()), sizeHint);
|
IndexItem::Ptr root = IndexItem::create(findOrInsert(doc->fileName()), 100);
|
||||||
|
|
||||||
{ // RAII scope
|
{ // RAII scope
|
||||||
ScopedModelItemInfoPtr parentRaii(_parent, root);
|
ScopedIndexItemPtr parentRaii(_parent, root);
|
||||||
QString newScope = scope;
|
QString newScope = scope;
|
||||||
ScopedScope scopeRaii(_scope, newScope);
|
ScopedScope scopeRaii(_scope, newScope);
|
||||||
|
|
||||||
QTC_ASSERT(_parent, return ModelItemInfo::Ptr());
|
QTC_ASSERT(_parent, return IndexItem::Ptr());
|
||||||
QTC_ASSERT(root, return ModelItemInfo::Ptr());
|
QTC_ASSERT(root, return IndexItem::Ptr());
|
||||||
QTC_ASSERT(_parent->fileName() == findOrInsert(doc->fileName()),
|
QTC_ASSERT(_parent->fileName() == findOrInsert(doc->fileName()),
|
||||||
return ModelItemInfo::Ptr());
|
return IndexItem::Ptr());
|
||||||
|
|
||||||
for (unsigned i = 0, ei = doc->globalSymbolCount(); i != ei; ++i)
|
for (unsigned i = 0, ei = doc->globalSymbolCount(); i != ei; ++i)
|
||||||
accept(doc->globalSymbolAt(i));
|
accept(doc->globalSymbolAt(i));
|
||||||
@@ -89,11 +89,10 @@ bool SearchSymbols::visit(Enum *symbol)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
QString name = overview.prettyName(symbol->name());
|
QString name = overview.prettyName(symbol->name());
|
||||||
ModelItemInfo::Ptr newParent =
|
IndexItem::Ptr newParent = addChildItem(name, QString(), _scope, IndexItem::Enum, symbol);
|
||||||
addChildItem(name, QString(), _scope, ModelItemInfo::Enum, symbol);
|
|
||||||
if (!newParent)
|
if (!newParent)
|
||||||
newParent = _parent;
|
newParent = _parent;
|
||||||
ScopedModelItemInfoPtr parentRaii(_parent, newParent);
|
ScopedIndexItemPtr parentRaii(_parent, newParent);
|
||||||
|
|
||||||
QString newScope = scopedSymbolName(name, symbol);
|
QString newScope = scopedSymbolName(name, symbol);
|
||||||
ScopedScope scopeRaii(_scope, newScope);
|
ScopedScope scopeRaii(_scope, newScope);
|
||||||
@@ -110,7 +109,7 @@ bool SearchSymbols::visit(Function *symbol)
|
|||||||
return false;
|
return false;
|
||||||
QString name = overview.prettyName(symbol->name());
|
QString name = overview.prettyName(symbol->name());
|
||||||
QString type = overview.prettyType(symbol->type());
|
QString type = overview.prettyType(symbol->type());
|
||||||
addChildItem(name, type, _scope, ModelItemInfo::Function, symbol);
|
addChildItem(name, type, _scope, IndexItem::Function, symbol);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,8 +143,8 @@ bool SearchSymbols::visit(Declaration *symbol)
|
|||||||
QString name = overview.prettyName(symbol->name());
|
QString name = overview.prettyName(symbol->name());
|
||||||
QString type = overview.prettyType(symbol->type());
|
QString type = overview.prettyType(symbol->type());
|
||||||
addChildItem(name, type, _scope,
|
addChildItem(name, type, _scope,
|
||||||
symbol->type()->asFunctionType() ? ModelItemInfo::Function
|
symbol->type()->asFunctionType() ? IndexItem::Function
|
||||||
: ModelItemInfo::Declaration,
|
: IndexItem::Declaration,
|
||||||
symbol);
|
symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,12 +155,12 @@ bool SearchSymbols::visit(Class *symbol)
|
|||||||
{
|
{
|
||||||
QString name = overview.prettyName(symbol->name());
|
QString name = overview.prettyName(symbol->name());
|
||||||
|
|
||||||
ModelItemInfo::Ptr newParent;
|
IndexItem::Ptr newParent;
|
||||||
if (symbolsToSearchFor & SymbolSearcher::Classes)
|
if (symbolsToSearchFor & SymbolSearcher::Classes)
|
||||||
newParent = addChildItem(name, QString(), _scope, ModelItemInfo::Class, symbol);
|
newParent = addChildItem(name, QString(), _scope, IndexItem::Class, symbol);
|
||||||
if (!newParent)
|
if (!newParent)
|
||||||
newParent = _parent;
|
newParent = _parent;
|
||||||
ScopedModelItemInfoPtr parentRaii(_parent, newParent);
|
ScopedIndexItemPtr parentRaii(_parent, newParent);
|
||||||
|
|
||||||
QString newScope = scopedSymbolName(name, symbol);
|
QString newScope = scopedSymbolName(name, symbol);
|
||||||
ScopedScope scopeRaii(_scope, newScope);
|
ScopedScope scopeRaii(_scope, newScope);
|
||||||
@@ -291,13 +290,12 @@ QString SearchSymbols::scopeName(const QString &name, const Symbol *symbol) cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelItemInfo::Ptr SearchSymbols::addChildItem(const QString &symbolName, const QString &symbolType,
|
IndexItem::Ptr SearchSymbols::addChildItem(const QString &symbolName, const QString &symbolType,
|
||||||
const QString &symbolScope,
|
const QString &symbolScope, IndexItem::ItemType itemType,
|
||||||
ModelItemInfo::ItemType itemType,
|
Symbol *symbol)
|
||||||
Symbol *symbol)
|
|
||||||
{
|
{
|
||||||
if (!symbol->name() || symbol->isGenerated())
|
if (!symbol->name() || symbol->isGenerated())
|
||||||
return ModelItemInfo::Ptr();
|
return IndexItem::Ptr();
|
||||||
|
|
||||||
QString path = m_paths.value(symbol->fileId(), QString());
|
QString path = m_paths.value(symbol->fileId(), QString());
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
@@ -306,30 +304,14 @@ ModelItemInfo::Ptr SearchSymbols::addChildItem(const QString &symbolName, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QIcon icon = icons.iconForSymbol(symbol);
|
const QIcon icon = icons.iconForSymbol(symbol);
|
||||||
ModelItemInfo::Ptr newItem = ModelItemInfo::create(findOrInsert(symbolName),
|
IndexItem::Ptr newItem = IndexItem::create(findOrInsert(symbolName),
|
||||||
findOrInsert(symbolType),
|
findOrInsert(symbolType),
|
||||||
findOrInsert(symbolScope),
|
findOrInsert(symbolScope),
|
||||||
itemType,
|
itemType,
|
||||||
findOrInsert(path),
|
findOrInsert(path),
|
||||||
symbol->line(),
|
symbol->line(),
|
||||||
symbol->column() - 1, // 1-based vs 0-based column
|
symbol->column() - 1, // 1-based vs 0-based column
|
||||||
icon);
|
icon);
|
||||||
_parent->addChild(newItem);
|
_parent->addChild(newItem);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelItemInfo::squeeze()
|
|
||||||
{
|
|
||||||
m_children.squeeze();
|
|
||||||
for (int i = 0, ei = m_children.size(); i != ei; ++i)
|
|
||||||
m_children[i]->squeeze();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModelItemInfo::visitAllChildren(std::function<void (const ModelItemInfo::Ptr &)> f) const
|
|
||||||
{
|
|
||||||
foreach (const ModelItemInfo::Ptr &child, m_children) {
|
|
||||||
f(child);
|
|
||||||
if (!child->m_children.isEmpty())
|
|
||||||
child->visitAllChildren(f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -32,137 +32,19 @@
|
|||||||
|
|
||||||
#include "cpptools_global.h"
|
#include "cpptools_global.h"
|
||||||
#include "cppindexingsupport.h"
|
#include "cppindexingsupport.h"
|
||||||
|
#include "indexitem.h"
|
||||||
#include "stringtable.h"
|
#include "stringtable.h"
|
||||||
|
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
#include <cplusplus/Icons.h>
|
#include <cplusplus/Icons.h>
|
||||||
#include <cplusplus/Overview.h>
|
#include <cplusplus/Overview.h>
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
|
||||||
#include <utils/function.h>
|
|
||||||
|
|
||||||
#include <QIcon>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
class CPPTOOLS_EXPORT ModelItemInfo
|
|
||||||
{
|
|
||||||
Q_DISABLE_COPY(ModelItemInfo)
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum ItemType { Enum, Class, Function, Declaration };
|
|
||||||
|
|
||||||
private:
|
|
||||||
ModelItemInfo(const QString &symbolName,
|
|
||||||
const QString &symbolType,
|
|
||||||
const QString &symbolScope,
|
|
||||||
ItemType type,
|
|
||||||
const QString &fileName,
|
|
||||||
int line,
|
|
||||||
int column,
|
|
||||||
const QIcon &icon)
|
|
||||||
: m_symbolName(symbolName),
|
|
||||||
m_symbolType(symbolType),
|
|
||||||
m_symbolScope(symbolScope),
|
|
||||||
m_fileName(fileName),
|
|
||||||
m_icon(icon),
|
|
||||||
m_type(type),
|
|
||||||
m_line(line),
|
|
||||||
m_column(column)
|
|
||||||
{}
|
|
||||||
|
|
||||||
ModelItemInfo(const QString &fileName, int sizeHint)
|
|
||||||
: m_fileName(fileName)
|
|
||||||
, m_type(Declaration)
|
|
||||||
, m_line(0)
|
|
||||||
, m_column(0)
|
|
||||||
{ m_children.reserve(sizeHint); }
|
|
||||||
|
|
||||||
public:
|
|
||||||
typedef QSharedPointer<ModelItemInfo> Ptr;
|
|
||||||
static Ptr create(const QString &symbolName,
|
|
||||||
const QString &symbolType,
|
|
||||||
const QString &symbolScope,
|
|
||||||
ItemType type,
|
|
||||||
const QString &fileName,
|
|
||||||
int line,
|
|
||||||
int column,
|
|
||||||
const QIcon &icon)
|
|
||||||
{
|
|
||||||
return Ptr(new ModelItemInfo(
|
|
||||||
symbolName, symbolType, symbolScope, type, fileName, line, column, icon));
|
|
||||||
}
|
|
||||||
|
|
||||||
static Ptr create(const QString &fileName, int sizeHint)
|
|
||||||
{
|
|
||||||
return Ptr(new ModelItemInfo(fileName, sizeHint));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString scopedSymbolName() const
|
|
||||||
{
|
|
||||||
return m_symbolScope.isEmpty()
|
|
||||||
? m_symbolName
|
|
||||||
: m_symbolScope + QLatin1String("::") + m_symbolName;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool unqualifiedNameAndScope(const QString &defaultName, QString *name, QString *scope) const
|
|
||||||
{
|
|
||||||
*name = defaultName;
|
|
||||||
*scope = m_symbolScope;
|
|
||||||
const QString qualifiedName = scopedSymbolName();
|
|
||||||
const int colonColonPosition = qualifiedName.lastIndexOf(QLatin1String("::"));
|
|
||||||
if (colonColonPosition != -1) {
|
|
||||||
*name = qualifiedName.mid(colonColonPosition + 2);
|
|
||||||
*scope = qualifiedName.left(colonColonPosition);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString representDeclaration(const QString &name, const QString &type)
|
|
||||||
{
|
|
||||||
if (type.isEmpty())
|
|
||||||
return QString();
|
|
||||||
|
|
||||||
const QString padding = type.endsWith(QLatin1Char('*'))
|
|
||||||
? QString()
|
|
||||||
: QString(QLatin1Char(' '));
|
|
||||||
return type + padding + name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString shortNativeFilePath() const
|
|
||||||
{ return Utils::FileUtils::shortNativePath(Utils::FileName::fromString(m_fileName)); }
|
|
||||||
|
|
||||||
QString symbolName() const { return m_symbolName; }
|
|
||||||
QString symbolType() const { return m_symbolType; }
|
|
||||||
QString symbolScope() const { return m_symbolScope; }
|
|
||||||
QString fileName() const { return m_fileName; }
|
|
||||||
QIcon icon() const { return m_icon; }
|
|
||||||
ItemType type() const { return m_type; }
|
|
||||||
int line() const { return m_line; }
|
|
||||||
int column() const { return m_column; }
|
|
||||||
|
|
||||||
void addChild(ModelItemInfo::Ptr childItem) { m_children.append(childItem); }
|
|
||||||
void squeeze();
|
|
||||||
|
|
||||||
void visitAllChildren(std::function<void (const ModelItemInfo::Ptr &)> f) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_symbolName; // as found in the code, therefore might be qualified
|
|
||||||
QString m_symbolType;
|
|
||||||
QString m_symbolScope;
|
|
||||||
QString m_fileName;
|
|
||||||
QIcon m_icon;
|
|
||||||
ItemType m_type;
|
|
||||||
int m_line;
|
|
||||||
int m_column;
|
|
||||||
QVector<ModelItemInfo::Ptr> m_children;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SearchSymbols: protected CPlusPlus::SymbolVisitor
|
class SearchSymbols: protected CPlusPlus::SymbolVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -174,10 +56,10 @@ public:
|
|||||||
|
|
||||||
void setSymbolsToSearchFor(const SymbolTypes &types);
|
void setSymbolsToSearchFor(const SymbolTypes &types);
|
||||||
|
|
||||||
ModelItemInfo::Ptr operator()(CPlusPlus::Document::Ptr doc, int sizeHint = 500)
|
IndexItem::Ptr operator()(CPlusPlus::Document::Ptr doc)
|
||||||
{ return operator()(doc, sizeHint, QString()); }
|
{ return operator()(doc, QString()); }
|
||||||
|
|
||||||
ModelItemInfo::Ptr operator()(CPlusPlus::Document::Ptr doc, int sizeHint, const QString &scope);
|
IndexItem::Ptr operator()(CPlusPlus::Document::Ptr doc, const QString &scope);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
using SymbolVisitor::visit;
|
using SymbolVisitor::visit;
|
||||||
@@ -213,11 +95,9 @@ protected:
|
|||||||
QString scopedSymbolName(const QString &symbolName, const CPlusPlus::Symbol *symbol) const;
|
QString scopedSymbolName(const QString &symbolName, const CPlusPlus::Symbol *symbol) const;
|
||||||
QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
|
QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
|
||||||
QString scopeName(const QString &name, const CPlusPlus::Symbol *symbol) const;
|
QString scopeName(const QString &name, const CPlusPlus::Symbol *symbol) const;
|
||||||
ModelItemInfo::Ptr addChildItem(const QString &symbolName,
|
IndexItem::Ptr addChildItem(const QString &symbolName, const QString &symbolType,
|
||||||
const QString &symbolType,
|
const QString &symbolScope, IndexItem::ItemType type,
|
||||||
const QString &symbolScope,
|
CPlusPlus::Symbol *symbol);
|
||||||
ModelItemInfo::ItemType type,
|
|
||||||
CPlusPlus::Symbol *symbol);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString findOrInsert(const QString &s)
|
QString findOrInsert(const QString &s)
|
||||||
@@ -225,7 +105,7 @@ private:
|
|||||||
|
|
||||||
Internal::StringTable &strings; // Used to avoid QString duplication
|
Internal::StringTable &strings; // Used to avoid QString duplication
|
||||||
|
|
||||||
ModelItemInfo::Ptr _parent;
|
IndexItem::Ptr _parent;
|
||||||
QString _scope;
|
QString _scope;
|
||||||
CPlusPlus::Overview overview;
|
CPlusPlus::Overview overview;
|
||||||
CPlusPlus::Icons icons;
|
CPlusPlus::Icons icons;
|
||||||
@@ -236,6 +116,5 @@ private:
|
|||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes)
|
||||||
Q_DECLARE_METATYPE(CppTools::ModelItemInfo::Ptr)
|
|
||||||
|
|
||||||
#endif // SEARCHSYMBOLS_H
|
#endif // SEARCHSYMBOLS_H
|
||||||
|
@@ -181,9 +181,9 @@ void SymbolsFindFilter::finish()
|
|||||||
|
|
||||||
void SymbolsFindFilter::openEditor(const Core::SearchResultItem &item)
|
void SymbolsFindFilter::openEditor(const Core::SearchResultItem &item)
|
||||||
{
|
{
|
||||||
if (!item.userData.canConvert<ModelItemInfo::Ptr>())
|
if (!item.userData.canConvert<IndexItem::Ptr>())
|
||||||
return;
|
return;
|
||||||
ModelItemInfo::Ptr info = item.userData.value<ModelItemInfo::Ptr>();
|
IndexItem::Ptr info = item.userData.value<IndexItem::Ptr>();
|
||||||
EditorManager::openEditorAt(info->fileName(), info->line(), info->column());
|
EditorManager::openEditorAt(info->fileName(), info->line(), info->column());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user