From 48889e757496961684a8466aaa2c16aad2b4fe05 Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Fri, 12 Mar 2010 11:32:22 +0100
Subject: [PATCH] Changed FindUsages to look into Q_PROPERTYs.

---
 src/libs/cplusplus/FindUsages.cpp | 23 +++++++++++++++++++++--
 src/libs/cplusplus/FindUsages.h   |  3 +++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp
index a7554a14c11..7425fb597a1 100644
--- a/src/libs/cplusplus/FindUsages.cpp
+++ b/src/libs/cplusplus/FindUsages.cpp
@@ -33,6 +33,7 @@
 #include <Control.h>
 #include <Literals.h>
 #include <Names.h>
+#include <Scope.h>
 #include <Symbols.h>
 #include <AST.h>
 #include <TranslationUnit.h>
@@ -47,7 +48,8 @@ FindUsages::FindUsages(Document::Ptr doc, const Snapshot &snapshot)
       _snapshot(snapshot),
       _source(_doc->source()),
       _sem(doc->translationUnit()),
-      _inSimpleDeclaration(0)
+      _inSimpleDeclaration(0),
+      _inQProperty(false)
 {
     _snapshot.insert(_doc);
 }
@@ -70,6 +72,7 @@ void FindUsages::operator()(Symbol *symbol)
     _usages.clear();
     _declSymbol = symbol;
     _inSimpleDeclaration = 0;
+    _inQProperty = false;
 
     _id = 0;
     if (_declSymbol && 0 != (_id = _declSymbol->identifier()))
@@ -204,12 +207,19 @@ LookupContext FindUsages::currentContext(AST *ast)
     getTokenStartPosition(ast->firstToken(), &line, &column);
     Symbol *lastVisibleSymbol = _doc->findSymbolAt(line, column);
 
+    if (_inQProperty && lastVisibleSymbol->isClass()) {
+        Scope *memberScope = lastVisibleSymbol->asClass()->members();
+
+        if (unsigned count = memberScope->symbolCount())
+            lastVisibleSymbol = memberScope->symbolAt(count - 1);
+    }
+
     if (lastVisibleSymbol && lastVisibleSymbol == _previousContext.symbol())
         return _previousContext;
 
     LookupContext ctx(lastVisibleSymbol, _exprDoc, _doc, _snapshot);
     _previousContext = ctx;
-    return ctx;
+    return _previousContext;
 }
 
 void FindUsages::ensureNameIsValid(NameAST *ast)
@@ -476,3 +486,12 @@ bool FindUsages::visit(ObjCSelectorAST *ast)
 
     return false;
 }
+
+bool FindUsages::visit(QtPropertyDeclarationAST *)
+{
+    _inQProperty = true;
+    return true;
+}
+
+void FindUsages::endVisit(QtPropertyDeclarationAST *)
+{ _inQProperty = false; }
diff --git a/src/libs/cplusplus/FindUsages.h b/src/libs/cplusplus/FindUsages.h
index 31f41530b60..176553b8344 100644
--- a/src/libs/cplusplus/FindUsages.h
+++ b/src/libs/cplusplus/FindUsages.h
@@ -100,6 +100,8 @@ protected:
     virtual bool visit(FunctionDeclaratorAST *ast);
     virtual bool visit(SimpleDeclarationAST *);
     virtual bool visit(ObjCSelectorAST *ast);
+    virtual bool visit(QtPropertyDeclarationAST *);
+    virtual void endVisit(QtPropertyDeclarationAST *);
 
 private:
     const Identifier *_id;
@@ -116,6 +118,7 @@ private:
     QList<Usage> _usages;
     LookupContext _previousContext;
     int _inSimpleDeclaration;
+    bool _inQProperty;
     QSet<unsigned> _processed;
 };
 
-- 
GitLab