From bf8c0b8a223165325a9eee1044e8bcdda316f9e1 Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Tue, 26 Jan 2010 10:19:42 +0100
Subject: [PATCH] Complete signals, slots and generate slots of QML items.

---
 src/libs/qmljs/qmljsinterpreter.cpp           | 34 ++++++++++++-------
 src/libs/qmljs/qmljsinterpreter.h             |  1 +
 src/plugins/qmljseditor/qmlcodecompletion.cpp | 14 ++++++++
 3 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp
index 5f9cd189a11..65b311bf40c 100644
--- a/src/libs/qmljs/qmljsinterpreter.cpp
+++ b/src/libs/qmljs/qmljsinterpreter.cpp
@@ -77,25 +77,30 @@ public:
 
         for (int index = 0; index < _metaObject->methodCount(); ++index) {
             QMetaMethod meth = _metaObject->method(index);
-            if (meth.methodType() != QMetaMethod::Signal)
-                continue;
-            if (meth.access() == QMetaMethod::Private)
-                continue;
 
             const QString signature = QString::fromUtf8(meth.signature());
 
-            int indexOfParen = signature.indexOf(QLatin1Char('('));
+            const int indexOfParen = signature.indexOf(QLatin1Char('('));
             if (indexOfParen == -1)
                 continue; // skip it, invalid signature.
 
-            const QString signalName = signature.left(indexOfParen);
-            QString slotName;
-            slotName += QLatin1String("on");
-            slotName += signalName.at(0).toUpper();
-            slotName += signalName.midRef(1);
+            const QString methodName = signature.left(indexOfParen);
 
-            processor->processSignal(signalName, engine()->undefinedValue()); // ### FIXME: assign a decent type to the signal
-            processor->processSlot(slotName, engine()->undefinedValue()); // ### FIXME: assign a decent type to the slot
+            if (meth.methodType() == QMetaMethod::Slot && meth.access() == QMetaMethod::Public) {
+                processor->processSlot(methodName, engine()->undefinedValue());
+
+            } else if (meth.methodType() == QMetaMethod::Signal && meth.access() != QMetaMethod::Private) {
+                // process the signal
+                processor->processSignal(methodName, engine()->undefinedValue()); // ### FIXME: assign a decent type to the signal
+
+                QString slotName;
+                slotName += QLatin1String("on");
+                slotName += methodName.at(0).toUpper();
+                slotName += methodName.midRef(1);
+
+                // process the generated slot
+                processor->processGeneratedSlot(slotName, engine()->undefinedValue()); // ### FIXME: assign a decent type to the slot
+            }
         }
 
         ObjectValue::processMembers(processor);
@@ -584,6 +589,11 @@ bool MemberProcessor::processSlot(const QString &, const Value *)
     return true;
 }
 
+bool MemberProcessor::processGeneratedSlot(const QString &, const Value *)
+{
+    return true;
+}
+
 ObjectValue::ObjectValue(Engine *engine)
     : _engine(engine), _prototype(0), _scope(0)
 {
diff --git a/src/libs/qmljs/qmljsinterpreter.h b/src/libs/qmljs/qmljsinterpreter.h
index b8bdb46d9fd..27a34806dd3 100644
--- a/src/libs/qmljs/qmljsinterpreter.h
+++ b/src/libs/qmljs/qmljsinterpreter.h
@@ -205,6 +205,7 @@ public:
     virtual bool processProperty(const QString &name, const Value *value);
     virtual bool processSignal(const QString &name, const Value *value);
     virtual bool processSlot(const QString &name, const Value *value);
+    virtual bool processGeneratedSlot(const QString &name, const Value *value);
 };
 
 class QMLJS_EXPORT ObjectValue: public Value, public Environment
diff --git a/src/plugins/qmljseditor/qmlcodecompletion.cpp b/src/plugins/qmljseditor/qmlcodecompletion.cpp
index 820d14e49ea..45bfbe866a2 100644
--- a/src/plugins/qmljseditor/qmlcodecompletion.cpp
+++ b/src/plugins/qmljseditor/qmlcodecompletion.cpp
@@ -410,7 +410,21 @@ private:
         return true;
     }
 
+    virtual bool processSignal(const QString &name, const Interpreter::Value *value)
+    {
+        if (! _globalCompletion)
+            _properties.insert(name, value);
+        return true;
+    }
+
     virtual bool processSlot(const QString &name, const Interpreter::Value *value)
+    {
+        if (! _globalCompletion)
+            _properties.insert(name, value);
+        return true;
+    }
+
+    virtual bool processGeneratedSlot(const QString &name, const Interpreter::Value *value)
     {
         if (_globalCompletion)
             _properties.insert(name, value);
-- 
GitLab