From 915a07bdbbd5dc65332369a117acde58793a165d Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Tue, 6 Apr 2010 13:30:41 +0200
Subject: [PATCH] CppEditor: Fix context sensitive help for namespaced
 libraries.

If the generated documentation doesn't contain the namespace name,
we failed to look up the correct help page.

Task-number: QTCREATORBUG-946
Reviewed-by: Erik Verbruggen
---
 src/plugins/cppeditor/cpphoverhandler.cpp | 34 +++++++++++++++++------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/plugins/cppeditor/cpphoverhandler.cpp b/src/plugins/cppeditor/cpphoverhandler.cpp
index 1755e925a4f..a4fd089c6a5 100644
--- a/src/plugins/cppeditor/cpphoverhandler.cpp
+++ b/src/plugins/cppeditor/cpphoverhandler.cpp
@@ -307,6 +307,13 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
         }
     }
 
+    if (m_helpEngineNeedsSetup
+        && m_helpEngine->registeredDocumentations().count() > 0) {
+        m_helpEngine->setupData();
+        m_helpEngineNeedsSetup = false;
+    }
+
+    QMap<QString, QUrl> helpLinks;
     if (m_helpId.isEmpty()) {
         // Move to the end of a qualified name
         bool stop = false;
@@ -374,6 +381,24 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
 
                 }
             }
+
+            // Some docs don't contain the namespace in the documentation pages, for instance
+            // there is QtMobility::QContactManager but the help page is for QContactManager.
+            // To show their help anyway, try stripping scopes until we find something.
+            const QString startHelpId = m_helpId;
+            while (!m_helpId.isEmpty()) {
+                helpLinks = m_helpEngine->linksForIdentifier(m_helpId);
+                if (!helpLinks.isEmpty())
+                    break;
+
+                int coloncolonIndex = m_helpId.indexOf(QLatin1String("::"));
+                if (coloncolonIndex == -1) {
+                    m_helpId = startHelpId;
+                    break;
+                }
+
+                m_helpId.remove(0, coloncolonIndex + 2);
+            }
         }
     }
 
@@ -388,13 +413,6 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
         }
     }
 
-    if (m_helpEngineNeedsSetup
-        && m_helpEngine->registeredDocumentations().count() > 0) {
-        m_helpEngine->setupData();
-        m_helpEngineNeedsSetup = false;
-    }
-
-
     if (!formatTooltip.isEmpty()) {
         m_toolTip = formatTooltip;
     }
@@ -402,7 +420,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
     if (!m_toolTip.isEmpty())
         m_toolTip = Qt::escape(m_toolTip);
 
-    if (!m_helpId.isEmpty() && !m_helpEngine->linksForIdentifier(m_helpId).isEmpty()) {
+    if (!m_helpId.isEmpty() && !helpLinks.isEmpty()) {
         if (showF1) {
             m_toolTip = QString(QLatin1String("<table><tr><td valign=middle><nobr>%1</td>"
                                               "<td><img src=\":/cppeditor/images/f1.png\"></td></tr></table>"))
-- 
GitLab