diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index d580c89c0e1e45cf87ae20e38923c7fd8221425c..8758a9f4b4a8e150c8768a40bd850ce337ba0767 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -68,15 +68,15 @@ namespace { class ProcessFile: public std::unary_function<QString, QList<Usage> > { - const QHash<QString, QString> workingList; + const CppTools::CppModelManagerInterface::WorkingCopy workingCopy; const Snapshot snapshot; Symbol *symbol; public: - ProcessFile(const QHash<QString, QString> workingList, - const Snapshot snapshot, - Symbol *symbol) - : workingList(workingList), snapshot(snapshot), symbol(symbol) + ProcessFile(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy, + const Snapshot snapshot, + Symbol *symbol) + : workingCopy(workingCopy), snapshot(snapshot), symbol(symbol) { } QList<Usage> operator()(const QString &fileName) @@ -92,8 +92,8 @@ public: QByteArray source; - if (workingList.contains(fileName)) - source = snapshot.preprocessedCode(workingList.value(fileName), fileName); + if (workingCopy.contains(fileName)) + source = snapshot.preprocessedCode(workingCopy.source(fileName), fileName); else { QFile file(fileName); if (! file.open(QFile::ReadOnly)) @@ -168,7 +168,7 @@ QList<int> CppFindReferences::references(Symbol *symbol, } static void find_helper(QFutureInterface<Usage> &future, - const QHash<QString, QString> workingList, + const CppTools::CppModelManagerInterface::WorkingCopy workingCopy, Snapshot snapshot, Symbol *symbol) { @@ -199,7 +199,7 @@ static void find_helper(QFutureInterface<Usage> &future, future.setProgressRange(0, files.size()); - ProcessFile process(workingList, snapshot, symbol); + ProcessFile process(workingCopy, snapshot, symbol); UpdateUI reduce(&future); QtConcurrent::blockingMappedReduced<QList<Usage> > (files, process, reduce); diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 4c60a5d312d7469132c68b89256cfc1647a0cbf4..8a947f1205adf3aa0b1674df219809b7501c9f20 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -171,7 +171,7 @@ public: virtual ~CppPreprocessor(); void setRevision(unsigned revision); - void setWorkingCopy(const QHash<QString, QString> &workingCopy); + void setWorkingCopy(const CppModelManagerInterface::WorkingCopy &workingCopy); void setIncludePaths(const QStringList &includePaths); void setFrameworkPaths(const QStringList &frameworkPaths); void setProjectFiles(const QStringList &files); @@ -215,7 +215,7 @@ private: Preprocessor preprocess; QStringList m_includePaths; QStringList m_systemIncludePaths; - QHash<QString, QString> m_workingCopy; + CppModelManagerInterface::WorkingCopy m_workingCopy; QStringList m_projectFiles; QStringList m_frameworkPaths; QSet<QString> m_included; @@ -241,7 +241,7 @@ CppPreprocessor::~CppPreprocessor() void CppPreprocessor::setRevision(unsigned revision) { m_revision = revision; } -void CppPreprocessor::setWorkingCopy(const QHash<QString, QString> &workingCopy) +void CppPreprocessor::setWorkingCopy(const CppTools::CppModelManagerInterface::WorkingCopy &workingCopy) { m_workingCopy = workingCopy; } void CppPreprocessor::setIncludePaths(const QStringList &includePaths) @@ -263,13 +263,13 @@ class Process: public std::unary_function<Document::Ptr, void> { QPointer<CppModelManager> _modelManager; Snapshot _snapshot; - QHash<QString, QString> _workingCopy; + CppModelManager::WorkingCopy _workingCopy; Document::Ptr _doc; public: Process(QPointer<CppModelManager> modelManager, Snapshot snapshot, - const QHash<QString, QString> &workingCopy) + const CppModelManager::WorkingCopy &workingCopy) : _modelManager(modelManager), _snapshot(snapshot), _workingCopy(workingCopy) @@ -335,7 +335,7 @@ bool CppPreprocessor::includeFile(const QString &absoluteFilePath, QString *resu if (m_workingCopy.contains(absoluteFilePath)) { m_included.insert(absoluteFilePath); - *result = m_workingCopy.value(absoluteFilePath); + *result = m_workingCopy.source(absoluteFilePath); return true; } @@ -797,19 +797,19 @@ CppModelManager::WorkingCopy CppModelManager::buildWorkingCopyList() TextEditor::ITextEditor *textEditor = it.key(); CppEditorSupport *editorSupport = it.value(); QString fileName = textEditor->file()->fileName(); - workingCopy[fileName] = editorSupport->contents(); + workingCopy.insert(fileName, editorSupport->contents()); } QSetIterator<AbstractEditorSupport *> jt(m_addtionalEditorSupport); while (jt.hasNext()) { AbstractEditorSupport *es = jt.next(); - workingCopy[es->fileName()] = es->contents(); + workingCopy.insert(es->fileName(), es->contents()); } // add the project configuration file QByteArray conf(pp_configuration); conf += definedMacros(); - workingCopy[pp_configuration_file] = conf; + workingCopy.insert(pp_configuration_file, conf); return workingCopy; } diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h index f0327fb631ee759daec98decc567cb1440a64747..77ed5f8e73e0b473cd6c1ce6860803d7b61e1c05 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ b/src/plugins/cpptools/cppmodelmanagerinterface.h @@ -78,7 +78,30 @@ public: QStringList frameworkPaths; }; - typedef QHash<QString, QString> WorkingCopy; + class WorkingCopy + { + public: + typedef QHash<QString, QString> Table; + + typedef Table::const_iterator iterator; + typedef Table::const_iterator const_iterator; + + public: + const_iterator begin() const { return _elements.begin(); } + const_iterator end() const { return _elements.end(); } + + void insert(const QString &fileName, const QString &source) + { _elements.insert(fileName, source); } + + bool contains(const QString &fileName) const + { return _elements.contains(fileName); } + + QString source(const QString &fileName) const + { return _elements.value(fileName); } + + private: + Table _elements; + }; public: CppModelManagerInterface(QObject *parent = 0) : QObject(parent) {}