OSDN Git Service

FileInProjectFinder: Try to find path in list of files even if project directory...
authorKai Koehne <kai.koehne@nokia.com>
Wed, 1 Jun 2011 14:03:45 +0000 (16:03 +0200)
committerChristiaan Janssen <christiaan.janssen@nokia.com>
Mon, 6 Jun 2011 13:38:44 +0000 (15:38 +0200)
Change-Id: I4c7e783b7fc43fc3ff68a04fcb2ff3b2cf14e109
Reviewed-on: http://codereview.qt.nokia.com/310
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Christiaan Janssen <christiaan.janssen@nokia.com>
src/libs/utils/fileinprojectfinder.cpp

index c0394d8..8f2671c 100644 (file)
@@ -97,37 +97,36 @@ void FileInProjectFinder::setProjectFiles(const QStringList &projectFiles)
   */
 QString FileInProjectFinder::findFile(const QString &originalPath, bool *success) const
 {
-    if (m_projectDir.isEmpty())
-        return originalPath;
-
-    const QChar separator = QLatin1Char('/');
-    if (originalPath.startsWith(m_projectDir + separator)) {
-        if (success)
-            *success = true;
-        return originalPath;
-    }
+    if (!m_projectDir.isEmpty()) {
+        const QChar separator = QLatin1Char('/');
+        if (originalPath.startsWith(m_projectDir + separator)) {
+            if (success)
+                *success = true;
+            return originalPath;
+        }
 
-    if (m_cache.contains(originalPath)) {
-        if (success)
-            *success = true;
-        return m_cache.value(originalPath);
-    }
+        if (m_cache.contains(originalPath)) {
+            if (success)
+                *success = true;
+            return m_cache.value(originalPath);
+        }
 
-    // Strip directories one by one from the beginning of the path,
-    // and see if the new relative path exists in the build directory.
-    if (originalPath.contains(separator)) {
-        for (int pos = originalPath.indexOf(separator); pos != -1;
-             pos = originalPath.indexOf(separator, pos + 1)) {
-            QString candidate = originalPath;
-            candidate.remove(0, pos);
-            candidate.prepend(m_projectDir);
-            QFileInfo candidateInfo(candidate);
-            if (candidateInfo.exists() && candidateInfo.isFile()) {
-                if (success)
-                    *success = true;
-
-                m_cache.insert(originalPath, candidate);
-                return candidate;
+        // Strip directories one by one from the beginning of the path,
+        // and see if the new relative path exists in the build directory.
+        if (originalPath.contains(separator)) {
+            for (int pos = originalPath.indexOf(separator); pos != -1;
+                 pos = originalPath.indexOf(separator, pos + 1)) {
+                QString candidate = originalPath;
+                candidate.remove(0, pos);
+                candidate.prepend(m_projectDir);
+                QFileInfo candidateInfo(candidate);
+                if (candidateInfo.exists() && candidateInfo.isFile()) {
+                    if (success)
+                        *success = true;
+
+                    m_cache.insert(originalPath, candidate);
+                    return candidate;
+                }
             }
         }
     }