forked from qt-creator/qt-creator
		
	C++: pass ModelItemInfo around wrapped in a QSharedPointer.
Change-Id: I36162ea589ad01cf2ba79fc931732422fc1e6983 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
		| @@ -125,19 +125,19 @@ public: | ||||
|                 break; | ||||
|             if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->fileName())) { | ||||
|                 QVector<Core::SearchResultItem> resultItems; | ||||
|                 QList<ModelItemInfo> modelInfos = search(it.value()); | ||||
|                 foreach (const ModelItemInfo &info, modelInfos) { | ||||
|                     int index = matcher.indexIn(info.symbolName); | ||||
|                 QList<ModelItemInfo::Ptr> modelInfos = search(it.value()); | ||||
|                 foreach (const ModelItemInfo::Ptr &info, modelInfos) { | ||||
|                     int index = matcher.indexIn(info->symbolName()); | ||||
|                     if (index != -1) { | ||||
|                         QString text = info.symbolName; | ||||
|                         QString scope = info.symbolScope; | ||||
|                         if (info.type == ModelItemInfo::Function) { | ||||
|                         QString text = info->symbolName(); | ||||
|                         QString scope = info->symbolScope(); | ||||
|                         if (info->type() == ModelItemInfo::Function) { | ||||
|                             QString name; | ||||
|                             info.unqualifiedNameAndScope(info.symbolName, &name, &scope); | ||||
|                             text = name + info.symbolType; | ||||
|                         } else if (info.type == ModelItemInfo::Declaration){ | ||||
|                             text = ModelItemInfo::representDeclaration(info.symbolName, | ||||
|                                                                        info.symbolType); | ||||
|                             info->unqualifiedNameAndScope(info->symbolName(), &name, &scope); | ||||
|                             text = name + info->symbolType(); | ||||
|                         } else if (info->type() == ModelItemInfo::Declaration){ | ||||
|                             text = ModelItemInfo::representDeclaration(info->symbolName(), | ||||
|                                                                        info->symbolType()); | ||||
|                         } | ||||
|  | ||||
|                         Core::SearchResultItem item; | ||||
| @@ -145,7 +145,7 @@ public: | ||||
|                         item.text = text; | ||||
|                         item.textMarkPos = -1; | ||||
|                         item.textMarkLength = 0; | ||||
|                         item.icon = info.icon; | ||||
|                         item.icon = info->icon(); | ||||
|                         item.lineNumber = -1; | ||||
|                         item.userData = qVariantFromValue(info); | ||||
|                         resultItems << item; | ||||
|   | ||||
| @@ -45,18 +45,18 @@ CppClassesFilter::~CppClassesFilter() | ||||
| { | ||||
| } | ||||
|  | ||||
| QList<QList<CppTools::ModelItemInfo> > CppClassesFilter::itemsToMatchUserInputAgainst() const | ||||
| QList<QList<ModelItemInfo::Ptr> > CppClassesFilter::itemsToMatchUserInputAgainst() const | ||||
| { | ||||
|     return QList<QList<CppTools::ModelItemInfo> >() << m_data->classes(); | ||||
|     return QList<QList<CppTools::ModelItemInfo::Ptr> >() << m_data->classes(); | ||||
| } | ||||
|  | ||||
| Core::LocatorFilterEntry CppClassesFilter::filterEntryFromModelItemInfo(const ModelItemInfo &info) | ||||
| Core::LocatorFilterEntry CppClassesFilter::filterEntryFromModelItemInfo(ModelItemInfo::Ptr info) | ||||
| { | ||||
|     const QVariant id = qVariantFromValue(info); | ||||
|     Core::LocatorFilterEntry filterEntry(this, info.symbolName, id, info.icon); | ||||
|     filterEntry.extraInfo = info.symbolScope.isEmpty() | ||||
|         ? info.shortNativeFilePath() | ||||
|         : info.symbolScope; | ||||
|     Core::LocatorFilterEntry filterEntry(this, info->symbolName(), id, info->icon()); | ||||
|     filterEntry.extraInfo = info->symbolScope().isEmpty() | ||||
|         ? info->shortNativeFilePath() | ||||
|         : info->symbolScope(); | ||||
|  | ||||
|     return filterEntry; | ||||
| } | ||||
|   | ||||
| @@ -45,8 +45,8 @@ public: | ||||
|     ~CppClassesFilter(); | ||||
|  | ||||
| private: | ||||
|     QList<QList<CppTools::ModelItemInfo> > itemsToMatchUserInputAgainst() const; | ||||
|     Core::LocatorFilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); | ||||
|     QList<QList<CppTools::ModelItemInfo::Ptr> > itemsToMatchUserInputAgainst() const; | ||||
|     Core::LocatorFilterEntry filterEntryFromModelItemInfo(ModelItemInfo::Ptr info); | ||||
| }; | ||||
|  | ||||
| } // namespace CppTools | ||||
|   | ||||
| @@ -84,28 +84,28 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor( | ||||
|  | ||||
|     const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); | ||||
|  | ||||
|     foreach (const ModelItemInfo & info, m_itemsOfCurrentDoc) | ||||
|     { | ||||
|     foreach (ModelItemInfo::Ptr info, m_itemsOfCurrentDoc) { | ||||
|         if (future.isCanceled()) | ||||
|             break; | ||||
|  | ||||
|         QString matchString = info.symbolName; | ||||
|         if (info.type == ModelItemInfo::Declaration) | ||||
|             matchString = ModelItemInfo::representDeclaration(info.symbolName, info.symbolType); | ||||
|         else if (info.type == ModelItemInfo::Function) | ||||
|             matchString += info.symbolType; | ||||
|         QString matchString = info->symbolName(); | ||||
|         if (info->type() == ModelItemInfo::Declaration) | ||||
|             matchString = ModelItemInfo::representDeclaration(info->symbolName(), | ||||
|                                                               info->symbolType()); | ||||
|         else if (info->type() == ModelItemInfo::Function) | ||||
|             matchString += info->symbolType(); | ||||
|  | ||||
|         if ((hasWildcard && regexp.exactMatch(matchString)) | ||||
|             || (!hasWildcard && matcher.indexIn(matchString) != -1)) | ||||
|         { | ||||
|             QVariant id = qVariantFromValue(info); | ||||
|             QString name = matchString; | ||||
|             QString extraInfo = info.symbolScope; | ||||
|             if (info.type == ModelItemInfo::Function) { | ||||
|                 if (info.unqualifiedNameAndScope(matchString, &name, &extraInfo)) | ||||
|                     name += info.symbolType; | ||||
|             QString extraInfo = info->symbolScope(); | ||||
|             if (info->type() == ModelItemInfo::Function) { | ||||
|                 if (info->unqualifiedNameAndScope(matchString, &name, &extraInfo)) | ||||
|                     name += info->symbolType(); | ||||
|             } | ||||
|             Core::LocatorFilterEntry filterEntry(this, name, id, info.icon); | ||||
|             Core::LocatorFilterEntry filterEntry(this, name, id, info->icon()); | ||||
|             filterEntry.extraInfo = extraInfo; | ||||
|  | ||||
|             if (matchString.startsWith(entry, caseSensitivityForPrefix)) | ||||
| @@ -123,8 +123,8 @@ QList<Core::LocatorFilterEntry> CppCurrentDocumentFilter::matchesFor( | ||||
|  | ||||
| void CppCurrentDocumentFilter::accept(Core::LocatorFilterEntry selection) const | ||||
| { | ||||
|     ModelItemInfo info = qvariant_cast<CppTools::ModelItemInfo>(selection.internalData); | ||||
|     Core::EditorManager::openEditorAt(info.fileName, info.line, info.column); | ||||
|     ModelItemInfo::Ptr info = qvariant_cast<CppTools::ModelItemInfo::Ptr>(selection.internalData); | ||||
|     Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column()); | ||||
| } | ||||
|  | ||||
| void CppCurrentDocumentFilter::refresh(QFutureInterface<void> &future) | ||||
|   | ||||
| @@ -61,7 +61,7 @@ private slots: | ||||
| private: | ||||
|     CppModelManager * m_modelManager; | ||||
|     QString m_currentFileName; | ||||
|     QList<ModelItemInfo> m_itemsOfCurrentDoc; | ||||
|     QList<ModelItemInfo::Ptr> m_itemsOfCurrentDoc; | ||||
|     SearchSymbols search; | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -44,22 +44,22 @@ CppFunctionsFilter::~CppFunctionsFilter() | ||||
| { | ||||
| } | ||||
|  | ||||
| QList<QList<CppTools::ModelItemInfo> > CppFunctionsFilter::itemsToMatchUserInputAgainst() const | ||||
| QList<QList<CppTools::ModelItemInfo::Ptr> > CppFunctionsFilter::itemsToMatchUserInputAgainst() const | ||||
| { | ||||
|     return QList<QList<CppTools::ModelItemInfo> >() << m_data->functions(); | ||||
|     return QList<QList<CppTools::ModelItemInfo::Ptr> >() << m_data->functions(); | ||||
| } | ||||
|  | ||||
| Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info) | ||||
| Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(ModelItemInfo::Ptr info) | ||||
| { | ||||
|     const QVariant id = qVariantFromValue(info); | ||||
|  | ||||
|     QString name = info.symbolName; | ||||
|     QString extraInfo = info.symbolScope; | ||||
|     info.unqualifiedNameAndScope(name, &name, &extraInfo); | ||||
|     QString name = info->symbolName(); | ||||
|     QString extraInfo = info->symbolScope(); | ||||
|     info->unqualifiedNameAndScope(name, &name, &extraInfo); | ||||
|     if (extraInfo.isEmpty()) | ||||
|         extraInfo = info.shortNativeFilePath(); | ||||
|         extraInfo = info->shortNativeFilePath(); | ||||
|  | ||||
|     Core::LocatorFilterEntry filterEntry(this, name + info.symbolType, id, info.icon); | ||||
|     Core::LocatorFilterEntry filterEntry(this, name + info->symbolType(), id, info->icon()); | ||||
|     filterEntry.extraInfo = extraInfo; | ||||
|  | ||||
|     return filterEntry; | ||||
|   | ||||
| @@ -45,8 +45,8 @@ public: | ||||
|     ~CppFunctionsFilter(); | ||||
|  | ||||
| private: | ||||
|     QList<QList<ModelItemInfo> > itemsToMatchUserInputAgainst() const; | ||||
|     Core::LocatorFilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); | ||||
|     QList<QList<ModelItemInfo::Ptr> > itemsToMatchUserInputAgainst() const; | ||||
|     Core::LocatorFilterEntry filterEntryFromModelItemInfo(ModelItemInfo::Ptr info); | ||||
| }; | ||||
|  | ||||
| } // namespace Internal | ||||
|   | ||||
| @@ -53,19 +53,19 @@ CppLocatorData::CppLocatorData(CppModelManager *modelManager) | ||||
|             this, SLOT(onAboutToRemoveFiles(QStringList))); | ||||
| } | ||||
|  | ||||
| QList<ModelItemInfo> CppLocatorData::enums() | ||||
| QList<ModelItemInfo::Ptr> CppLocatorData::enums() | ||||
| { | ||||
|     flushPendingDocument(true); | ||||
|     return allModelItemInfos(m_allEnums); | ||||
| } | ||||
|  | ||||
| QList<ModelItemInfo> CppLocatorData::classes() | ||||
| QList<ModelItemInfo::Ptr> CppLocatorData::classes() | ||||
| { | ||||
|     flushPendingDocument(true); | ||||
|     return allModelItemInfos(m_allClasses); | ||||
| } | ||||
|  | ||||
| QList<ModelItemInfo> CppLocatorData::functions() | ||||
| QList<ModelItemInfo::Ptr> CppLocatorData::functions() | ||||
| { | ||||
|     flushPendingDocument(true); | ||||
|     return allModelItemInfos(m_allFunctions); | ||||
| @@ -120,15 +120,15 @@ void CppLocatorData::flushPendingDocument(bool force) | ||||
|     foreach (CPlusPlus::Document::Ptr doc, m_pendingDocuments) { | ||||
|         const QString fileName = findOrInsertFilePath(doc->fileName()); | ||||
|  | ||||
|         QList<ModelItemInfo> resultsEnums; | ||||
|         QList<ModelItemInfo> resultsClasses; | ||||
|         QList<ModelItemInfo> resultsFunctions; | ||||
|         QList<ModelItemInfo::Ptr> resultsEnums; | ||||
|         QList<ModelItemInfo::Ptr> resultsClasses; | ||||
|         QList<ModelItemInfo::Ptr> resultsFunctions; | ||||
|  | ||||
|         const int sizeHint = m_allEnums[fileName].size() + m_allClasses[fileName].size() | ||||
|                 + m_allFunctions[fileName].size() + 10; | ||||
|         const QList<ModelItemInfo> results = m_search(doc, sizeHint); | ||||
|         foreach (const ModelItemInfo &info, results) { | ||||
|             switch (info.type) { | ||||
|         const QList<ModelItemInfo::Ptr> results = m_search(doc, sizeHint); | ||||
|         foreach (ModelItemInfo::Ptr info, results) { | ||||
|             switch (info->type()) { | ||||
|             case ModelItemInfo::Enum: | ||||
|                 resultsEnums.append(info); | ||||
|                 break; | ||||
| @@ -152,11 +152,11 @@ void CppLocatorData::flushPendingDocument(bool force) | ||||
|     m_pendingDocuments.reserve(MaxPendingDocuments); | ||||
| } | ||||
|  | ||||
| QList<ModelItemInfo> CppLocatorData::allModelItemInfos(const QHash<QString, | ||||
|                                                        QList<ModelItemInfo> > &items) const | ||||
| QList<ModelItemInfo::Ptr> CppLocatorData::allModelItemInfos(const QHash<QString, | ||||
|                                                             QList<ModelItemInfo::Ptr>> &items) const | ||||
| { | ||||
|     QList<ModelItemInfo> result; | ||||
|     QHashIterator<QString, QList<ModelItemInfo> > it(items); | ||||
|     QList<ModelItemInfo::Ptr> result; | ||||
|     QHashIterator<QString, QList<ModelItemInfo::Ptr> > it(items); | ||||
|     while (it.hasNext()) { | ||||
|         it.next(); | ||||
|         result.append(it.value()); | ||||
|   | ||||
| @@ -49,9 +49,9 @@ class CppLocatorData : public QObject | ||||
| public: | ||||
|     explicit CppLocatorData(CppModelManager *modelManager); | ||||
|  | ||||
|     QList<ModelItemInfo> enums(); | ||||
|     QList<ModelItemInfo> classes(); | ||||
|     QList<ModelItemInfo> functions(); | ||||
|     QList<ModelItemInfo::Ptr> enums(); | ||||
|     QList<ModelItemInfo::Ptr> classes(); | ||||
|     QList<ModelItemInfo::Ptr> functions(); | ||||
|  | ||||
| private slots: | ||||
|     void onDocumentUpdated(const CPlusPlus::Document::Ptr &document); | ||||
| @@ -59,8 +59,8 @@ private slots: | ||||
|  | ||||
| private: | ||||
|     void flushPendingDocument(bool force); | ||||
|     QList<ModelItemInfo> allModelItemInfos(const QHash<QString, | ||||
|                                            QList<ModelItemInfo> > &items) const; | ||||
|     QList<ModelItemInfo::Ptr> allModelItemInfos( | ||||
|             const QHash<QString, QList<ModelItemInfo::Ptr>> &items) const; | ||||
|  | ||||
|     QString findOrInsertFilePath(const QString &path) | ||||
|     { return m_strings.insert(path); } | ||||
| @@ -71,9 +71,9 @@ private: | ||||
|     StringTable &m_strings; // Used to avoid QString duplication | ||||
|  | ||||
|     SearchSymbols m_search; | ||||
|     QHash<QString, QList<ModelItemInfo> > m_allEnums; | ||||
|     QHash<QString, QList<ModelItemInfo> > m_allClasses; | ||||
|     QHash<QString, QList<ModelItemInfo> > m_allFunctions; | ||||
|     QHash<QString, QList<ModelItemInfo::Ptr> > m_allEnums; | ||||
|     QHash<QString, QList<ModelItemInfo::Ptr> > m_allClasses; | ||||
|     QHash<QString, QList<ModelItemInfo::Ptr> > m_allFunctions; | ||||
|  | ||||
|     mutable QMutex m_pendingDocumentsMutex; | ||||
|     QVector<CPlusPlus::Document::Ptr> m_pendingDocuments; | ||||
|   | ||||
| @@ -47,13 +47,14 @@ CppLocatorFilter::~CppLocatorFilter() | ||||
| { | ||||
| } | ||||
|  | ||||
| Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info) | ||||
| Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromModelItemInfo(ModelItemInfo::Ptr info) | ||||
| { | ||||
|     const QVariant id = qVariantFromValue(info); | ||||
|     Core::LocatorFilterEntry filterEntry(this, info.scopedSymbolName(), id, info.icon); | ||||
|     filterEntry.extraInfo = info.type == ModelItemInfo::Class || info.type == ModelItemInfo::Enum | ||||
|         ? info.shortNativeFilePath() | ||||
|         : info.symbolType; | ||||
|     Core::LocatorFilterEntry filterEntry(this, info->scopedSymbolName(), id, info->icon()); | ||||
|     if (info->type() == ModelItemInfo::Class || info->type() == ModelItemInfo::Enum) | ||||
|         filterEntry.extraInfo = info->shortNativeFilePath(); | ||||
|     else | ||||
|         filterEntry.extraInfo = info->symbolType(); | ||||
|  | ||||
|     return filterEntry; | ||||
| } | ||||
| @@ -63,9 +64,9 @@ void CppLocatorFilter::refresh(QFutureInterface<void> &future) | ||||
|     Q_UNUSED(future) | ||||
| } | ||||
|  | ||||
| QList<QList<CppTools::ModelItemInfo> > CppLocatorFilter::itemsToMatchUserInputAgainst() const | ||||
| QList<QList<CppTools::ModelItemInfo::Ptr> > CppLocatorFilter::itemsToMatchUserInputAgainst() const | ||||
| { | ||||
|     return QList<QList<CppTools::ModelItemInfo> >() | ||||
|     return QList<QList<CppTools::ModelItemInfo::Ptr> >() | ||||
|         << m_data->classes() | ||||
|         << m_data->functions() | ||||
|         << m_data->enums(); | ||||
| @@ -77,7 +78,8 @@ static bool compareLexigraphically(const Core::LocatorFilterEntry &a, | ||||
|     return a.displayName < b.displayName; | ||||
| } | ||||
|  | ||||
| QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &origEntry) | ||||
| QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor( | ||||
|         QFutureInterface<Core::LocatorFilterEntry> &future, const QString &origEntry) | ||||
| { | ||||
|     QString entry = trimWildcards(origEntry); | ||||
|     QList<Core::LocatorFilterEntry> goodEntries; | ||||
| @@ -91,12 +93,13 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Co | ||||
|     bool hasColonColon = entry.contains(QLatin1String("::")); | ||||
|     const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); | ||||
|  | ||||
|     const QList<QList<CppTools::ModelItemInfo> > itemLists = itemsToMatchUserInputAgainst(); | ||||
|     foreach (const QList<CppTools::ModelItemInfo> &items, itemLists) { | ||||
|         foreach (const ModelItemInfo &info, items) { | ||||
|     const QList<QList<CppTools::ModelItemInfo::Ptr> > itemLists = itemsToMatchUserInputAgainst(); | ||||
|     foreach (const QList<CppTools::ModelItemInfo::Ptr> &items, itemLists) { | ||||
|         foreach (ModelItemInfo::Ptr info, items) { | ||||
|             if (future.isCanceled()) | ||||
|                 break; | ||||
|             const QString matchString = hasColonColon ? info.scopedSymbolName() : info.symbolName; | ||||
|             const QString matchString = hasColonColon ? info->scopedSymbolName() | ||||
|                                                       : info->symbolName(); | ||||
|             if ((hasWildcard && regexp.exactMatch(matchString)) | ||||
|                 || (!hasWildcard && matcher.indexIn(matchString) != -1)) { | ||||
|                 const Core::LocatorFilterEntry filterEntry = filterEntryFromModelItemInfo(info); | ||||
| @@ -119,6 +122,6 @@ QList<Core::LocatorFilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Co | ||||
|  | ||||
| void CppLocatorFilter::accept(Core::LocatorFilterEntry selection) const | ||||
| { | ||||
|     ModelItemInfo info = qvariant_cast<CppTools::ModelItemInfo>(selection.internalData); | ||||
|     Core::EditorManager::openEditorAt(info.fileName, info.line, info.column); | ||||
|     ModelItemInfo::Ptr info = qvariant_cast<CppTools::ModelItemInfo::Ptr>(selection.internalData); | ||||
|     Core::EditorManager::openEditorAt(info->fileName(), info->line(), info->column()); | ||||
| } | ||||
|   | ||||
| @@ -48,13 +48,14 @@ public: | ||||
|     CppLocatorFilter(CppLocatorData *locatorData); | ||||
|     ~CppLocatorFilter(); | ||||
|  | ||||
|     QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry); | ||||
|     QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, | ||||
|                                                const QString &entry); | ||||
|     void accept(Core::LocatorFilterEntry selection) const; | ||||
|     void refresh(QFutureInterface<void> &future); | ||||
|  | ||||
| private: | ||||
|     virtual QList<QList<ModelItemInfo> > itemsToMatchUserInputAgainst() const; | ||||
|     virtual Core::LocatorFilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); | ||||
| protected: | ||||
|     virtual QList<QList<ModelItemInfo::Ptr> > itemsToMatchUserInputAgainst() const; | ||||
|     virtual Core::LocatorFilterEntry filterEntryFromModelItemInfo(ModelItemInfo::Ptr info); | ||||
|  | ||||
| protected: | ||||
|     CppLocatorData *m_data; | ||||
|   | ||||
| @@ -53,7 +53,8 @@ void SearchSymbols::setSymbolsToSearchFor(const SymbolTypes &types) | ||||
|     symbolsToSearchFor = types; | ||||
| } | ||||
|  | ||||
| QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, int sizeHint, const QString &scope) | ||||
| QList<ModelItemInfo::Ptr> SearchSymbols::operator()(Document::Ptr doc, int sizeHint, | ||||
|                                                     const QString &scope) | ||||
| { | ||||
|     QString previousScope = switchScope(scope); | ||||
|     items.clear(); | ||||
| @@ -62,7 +63,7 @@ QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, int sizeHint, | ||||
|         accept(doc->globalSymbolAt(i)); | ||||
|     } | ||||
|     (void) switchScope(previousScope); | ||||
|     QList<ModelItemInfo> result = items; | ||||
|     QList<ModelItemInfo::Ptr> result = items; | ||||
|     strings.scheduleGC(); | ||||
|     items.clear(); | ||||
|     m_paths.clear(); | ||||
| @@ -288,12 +289,12 @@ void SearchSymbols::appendItem(const QString &symbolName, const QString &symbolT | ||||
|     } | ||||
|  | ||||
|     const QIcon icon = icons.iconForSymbol(symbol); | ||||
|     items.append(ModelItemInfo(findOrInsert(symbolName), | ||||
|                                findOrInsert(symbolType), | ||||
|                                findOrInsert(symbolScope), | ||||
|                                itemType, | ||||
|                                findOrInsert(path), | ||||
|                                symbol->line(), | ||||
|                                symbol->column() - 1, // 1-based vs 0-based column | ||||
|                                icon)); | ||||
|     items.append(ModelItemInfo::create(findOrInsert(symbolName), | ||||
|                                        findOrInsert(symbolType), | ||||
|                                        findOrInsert(symbolScope), | ||||
|                                        itemType, | ||||
|                                        findOrInsert(path), | ||||
|                                        symbol->line(), | ||||
|                                        symbol->column() - 1, // 1-based vs 0-based column | ||||
|                                        icon)); | ||||
| } | ||||
|   | ||||
| @@ -43,22 +43,21 @@ | ||||
| #include <QIcon> | ||||
| #include <QString> | ||||
| #include <QSet> | ||||
| #include <QSharedPointer> | ||||
| #include <QHash> | ||||
|  | ||||
| #include <functional> | ||||
|  | ||||
| namespace CppTools { | ||||
|  | ||||
| struct CPPTOOLS_EXPORT ModelItemInfo | ||||
| class CPPTOOLS_EXPORT ModelItemInfo | ||||
| { | ||||
|     Q_DISABLE_COPY(ModelItemInfo) | ||||
|  | ||||
| public: | ||||
|     enum ItemType { Enum, Class, Function, Declaration }; | ||||
|  | ||||
|     ModelItemInfo() | ||||
|         : type(Declaration), | ||||
|           line(0), | ||||
|           column(0) | ||||
|     { } | ||||
|  | ||||
| private: | ||||
|     ModelItemInfo(const QString &symbolName, | ||||
|                   const QString &symbolType, | ||||
|                   const QString &symbolScope, | ||||
| @@ -67,38 +66,42 @@ struct CPPTOOLS_EXPORT ModelItemInfo | ||||
|                   int line, | ||||
|                   int column, | ||||
|                   const QIcon &icon) | ||||
|         : symbolName(symbolName), | ||||
|           symbolType(symbolType), | ||||
|           symbolScope(symbolScope), | ||||
|           fileName(fileName), | ||||
|           icon(icon), | ||||
|           type(type), | ||||
|           line(line), | ||||
|           column(column) | ||||
|     { } | ||||
|         : 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 ModelItemInfo &otherInfo) | ||||
|         : symbolName(otherInfo.symbolName), | ||||
|           symbolType(otherInfo.symbolType), | ||||
|           symbolScope(otherInfo.symbolScope), | ||||
|           fileName(otherInfo.fileName), | ||||
|           icon(otherInfo.icon), | ||||
|           type(otherInfo.type), | ||||
|           line(otherInfo.line), | ||||
|           column(otherInfo.column) | ||||
|     { } | ||||
| 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)); | ||||
|     } | ||||
|  | ||||
|     QString scopedSymbolName() const | ||||
|     { | ||||
|         return symbolScope.isEmpty() | ||||
|                 ? symbolName | ||||
|                 : symbolScope +  QLatin1String("::") + symbolName; | ||||
|         return m_symbolScope.isEmpty() | ||||
|                 ? m_symbolName | ||||
|                 : m_symbolScope +  QLatin1String("::") + m_symbolName; | ||||
|     } | ||||
|  | ||||
|     bool unqualifiedNameAndScope(const QString &defaultName, QString *name, QString *scope) const | ||||
|     { | ||||
|         *name = defaultName; | ||||
|         *scope = symbolScope; | ||||
|         *scope = m_symbolScope; | ||||
|         const QString qualifiedName = scopedSymbolName(); | ||||
|         const int colonColonPosition = qualifiedName.lastIndexOf(QLatin1String("::")); | ||||
|         if (colonColonPosition != -1) { | ||||
| @@ -121,16 +124,26 @@ struct CPPTOOLS_EXPORT ModelItemInfo | ||||
|     } | ||||
|  | ||||
|     QString shortNativeFilePath() const | ||||
|     { return Utils::FileUtils::shortNativePath(Utils::FileName::fromString(fileName)); } | ||||
|     { return Utils::FileUtils::shortNativePath(Utils::FileName::fromString(m_fileName)); } | ||||
|  | ||||
|     QString symbolName; // as found in the code, therefore might be qualified | ||||
|     QString symbolType; | ||||
|     QString symbolScope; | ||||
|     QString fileName; | ||||
|     QIcon icon; | ||||
|     ItemType type; | ||||
|     int line; | ||||
|     int column; | ||||
|     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; } | ||||
|  | ||||
| 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; | ||||
| }; | ||||
|  | ||||
| class SearchSymbols: public std::binary_function<CPlusPlus::Document::Ptr, int, QList<ModelItemInfo> >, | ||||
| @@ -145,10 +158,11 @@ public: | ||||
|  | ||||
|     void setSymbolsToSearchFor(const SymbolTypes &types); | ||||
|  | ||||
|     QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc, int sizeHint = 500) | ||||
|     QList<ModelItemInfo::Ptr> operator()(CPlusPlus::Document::Ptr doc, int sizeHint = 500) | ||||
|     { return operator()(doc, sizeHint, QString()); } | ||||
|  | ||||
|     QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc, int sizeHint, const QString &scope); | ||||
|     QList<ModelItemInfo::Ptr> operator()(CPlusPlus::Document::Ptr doc, int sizeHint, | ||||
|                                          const QString &scope); | ||||
|  | ||||
| protected: | ||||
|     using SymbolVisitor::visit; | ||||
| @@ -201,7 +215,7 @@ private: | ||||
|     QString _scope; | ||||
|     CPlusPlus::Overview overview; | ||||
|     CPlusPlus::Icons icons; | ||||
|     QList<ModelItemInfo> items; | ||||
|     QList<ModelItemInfo::Ptr> items; | ||||
|     SymbolTypes symbolsToSearchFor; | ||||
|     QHash<const CPlusPlus::StringLiteral *, QString> m_paths; | ||||
| }; | ||||
| @@ -209,6 +223,6 @@ private: | ||||
| } // namespace CppTools | ||||
|  | ||||
| Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes) | ||||
| Q_DECLARE_METATYPE(CppTools::ModelItemInfo) | ||||
| Q_DECLARE_METATYPE(CppTools::ModelItemInfo::Ptr) | ||||
|  | ||||
| #endif // SEARCHSYMBOLS_H | ||||
|   | ||||
| @@ -181,10 +181,10 @@ void SymbolsFindFilter::finish() | ||||
|  | ||||
| void SymbolsFindFilter::openEditor(const Core::SearchResultItem &item) | ||||
| { | ||||
|     if (!item.userData.canConvert<ModelItemInfo>()) | ||||
|     if (!item.userData.canConvert<ModelItemInfo::Ptr>()) | ||||
|         return; | ||||
|     ModelItemInfo info = item.userData.value<ModelItemInfo>(); | ||||
|     EditorManager::openEditorAt(info.fileName, info.line, info.column); | ||||
|     ModelItemInfo::Ptr info = item.userData.value<ModelItemInfo::Ptr>(); | ||||
|     EditorManager::openEditorAt(info->fileName(), info->line(), info->column()); | ||||
| } | ||||
|  | ||||
| QWidget *SymbolsFindFilter::createConfigWidget() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user