Code model: Fix Windows issues (duplicate matches).

Ensure the code model receives file names with clean paths ('/')
and fix paths in the relevant places of the code model. Pass on clean
paths from Cpp reference find and display them correctly in the search
window tooltip.

Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
Friedemann Kleint
2009-11-09 13:53:28 +01:00
parent 6320b06b7c
commit d2bd092b47
6 changed files with 16 additions and 10 deletions

View File

@@ -42,6 +42,7 @@
#include <QtCore/QByteArray> #include <QtCore/QByteArray>
#include <QtCore/QBitArray> #include <QtCore/QBitArray>
#include <QtCore/QDir>
#include <QtCore/QtDebug> #include <QtCore/QtDebug>
/*! /*!
@@ -108,7 +109,7 @@ private:
Document::Document(const QString &fileName) Document::Document(const QString &fileName)
: _fileName(fileName), : _fileName(QDir::cleanPath(fileName)),
_globalNamespace(0), _globalNamespace(0),
_revision(0) _revision(0)
{ {
@@ -173,7 +174,7 @@ QStringList Document::includedFiles() const
void Document::addIncludeFile(const QString &fileName, unsigned line) void Document::addIncludeFile(const QString &fileName, unsigned line)
{ {
_includes.append(Include(fileName, line)); _includes.append(Include(QDir::cleanPath(fileName), line));
} }
void Document::appendMacro(const Macro &macro) void Document::appendMacro(const Macro &macro)
@@ -569,3 +570,8 @@ QStringList Snapshot::dependsOn(const QString &fileName) const
return deps; return deps;
} }
Document::Ptr Snapshot::value(const QString &fileName) const
{
return QMap<QString, Document::Ptr>::value(QDir::cleanPath(fileName));
}

View File

@@ -341,6 +341,7 @@ public:
QStringList dependsOn(const QString &fileName) const; QStringList dependsOn(const QString &fileName) const;
void insert(Document::Ptr doc); void insert(Document::Ptr doc);
Document::Ptr value(const QString &fileName) const;
using _Base::insert; using _Base::insert;

View File

@@ -121,8 +121,7 @@ void FindUsages::reportResult(unsigned tokenIndex)
const int len = tk.f.length; const int len = tk.f.length;
if (_future) { if (_future) {
const QString path = QDir::toNativeSeparators(_doc->fileName()); _future->reportResult(Usage(_doc->fileName(), line, lineText, col, len));
_future->reportResult(Usage(path, line, lineText, col, len));
} }
_references.append(tokenIndex); _references.append(tokenIndex);

View File

@@ -110,7 +110,6 @@ static void find_helper(QFutureInterface<Usage> &future,
Q_ASSERT(symbolId != 0); Q_ASSERT(symbolId != 0);
const QString sourceFile = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()); const QString sourceFile = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
QStringList files(sourceFile); QStringList files(sourceFile);
if (symbol->isClass() || symbol->isForwardClassDeclaration()) { if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
@@ -126,9 +125,7 @@ static void find_helper(QFutureInterface<Usage> &future,
} else { } else {
files += snapshot.dependsOn(sourceFile); files += snapshot.dependsOn(sourceFile);
} }
files.removeDuplicates(); files.removeDuplicates();
//qDebug() << "done in:" << tm.elapsed() << "number of files to parse:" << files.size(); //qDebug() << "done in:" << tm.elapsed() << "number of files to parse:" << files.size();
future.setProgressRange(0, files.size()); future.setProgressRange(0, files.size());
@@ -232,7 +229,6 @@ void CppFindReferences::findAll_helper(Symbol *symbol)
const QMap<QString, QString> wl = _modelManager->workingCopy(); const QMap<QString, QString> wl = _modelManager->workingCopy();
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
QFuture<Usage> result = QtConcurrent::run(&find_helper, wl, snapshot, symbol); QFuture<Usage> result = QtConcurrent::run(&find_helper, wl, snapshot, symbol);
m_watcher.setFuture(result); m_watcher.setFuture(result);

View File

@@ -532,7 +532,7 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
return; return;
QString contents = tryIncludeFile(fileName, type); QString contents = tryIncludeFile(fileName, type);
fileName = QDir::cleanPath(fileName);
if (m_currentDoc) { if (m_currentDoc) {
m_currentDoc->addIncludeFile(fileName, line); m_currentDoc->addIncludeFile(fileName, line);

View File

@@ -243,7 +243,7 @@ QVariant SearchResultTreeModel::data(const SearchResultFile *file, int role) con
break; break;
case ItemDataRoles::FileNameRole: case ItemDataRoles::FileNameRole:
case Qt::ToolTipRole: case Qt::ToolTipRole:
result = file->fileName(); result = QDir::toNativeSeparators(file->fileName());
break; break;
case ItemDataRoles::ResultLinesCountRole: case ItemDataRoles::ResultLinesCountRole:
result = file->childrenCount(); result = file->childrenCount();
@@ -270,6 +270,10 @@ QVariant SearchResultTreeModel::headerData(int section, Qt::Orientation orientat
void SearchResultTreeModel::appendResultFile(const QString &fileName) void SearchResultTreeModel::appendResultFile(const QString &fileName)
{ {
#ifdef Q_OS_WIN
if (fileName.contains(QLatin1Char('\\')))
qWarning("SearchResultTreeModel::appendResultFile: File name with native separators added %s.\n", qPrintable(fileName));
#endif
m_lastAppendedResultFile = new SearchResultFile(fileName, m_rootItem); m_lastAppendedResultFile = new SearchResultFile(fileName, m_rootItem);
if (m_showReplaceUI) { if (m_showReplaceUI) {