Fix leak introduced in 0853343c33e394f35c31c161b019b2aed17f9256.
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlpropertycache_p.h
index 3e87fa3..ad94ed4 100644 (file)
@@ -72,6 +72,7 @@ class QQmlPropertyData;
 class QQmlAccessors;
 class QMetaObjectBuilder;
 class QQmlPropertyCacheMethodArguments;
+class QQmlVMEMetaObject;
 
 // We have this somewhat awful split between RawData and Data so that RawData can be
 // used in unions.  In normal code, you should always use Data which initializes RawData
@@ -89,33 +90,34 @@ public:
         IsResettable       = 0x00000004, // Has RESET function
         IsAlias            = 0x00000008, // Is a QML alias to another property
         IsFinal            = 0x00000010, // Has FINAL flag
-        IsDirect           = 0x00000020, // Exists on a C++ QMetaObject
-        HasAccessors       = 0x00000040, // Has property accessors
+        IsOverridden       = 0x00000020, // Is overridden by a extension property
+        IsDirect           = 0x00000040, // Exists on a C++ QMetaObject
+        HasAccessors       = 0x00000080, // Has property accessors
 
         // These are mutualy exclusive
-        IsFunction         = 0x00000080, // Is an invokable
-        IsQObjectDerived   = 0x00000100, // Property type is a QObject* derived type
-        IsEnumType         = 0x00000200, // Property type is an enum
-        IsQList            = 0x00000400, // Property type is a QML list
-        IsQmlBinding       = 0x00000800, // Property type is a QQmlBinding*
-        IsQJSValue         = 0x00001000, // Property type is a QScriptValue
-        IsV8Handle         = 0x00002000, // Property type is a QQmlV8Handle
-        IsVarProperty      = 0x00004000, // Property type is a "var" property of VMEMO
-        IsValueTypeVirtual = 0x00008000, // Property is a value type "virtual" property
-        IsQVariant         = 0x00010000, // Property is a QVariant
+        IsFunction         = 0x00000100, // Is an invokable
+        IsQObjectDerived   = 0x00000200, // Property type is a QObject* derived type
+        IsEnumType         = 0x00000400, // Property type is an enum
+        IsQList            = 0x00000800, // Property type is a QML list
+        IsQmlBinding       = 0x00001000, // Property type is a QQmlBinding*
+        IsQJSValue         = 0x00002000, // Property type is a QScriptValue
+        IsV8Handle         = 0x00004000, // Property type is a QQmlV8Handle
+        IsVarProperty      = 0x00008000, // Property type is a "var" property of VMEMO
+        IsValueTypeVirtual = 0x00010000, // Property is a value type "virtual" property
+        IsQVariant         = 0x00020000, // Property is a QVariant
 
         // Apply only to IsFunctions
-        IsVMEFunction      = 0x00020000, // Function was added by QML
-        HasArguments       = 0x00040000, // Function takes arguments
-        IsSignal           = 0x00080000, // Function is a signal
-        IsVMESignal        = 0x00100000, // Signal was added by QML
-        IsV8Function       = 0x00200000, // Function takes QQmlV8Function* args
-        IsSignalHandler    = 0x00400000, // Function is a signal handler
-        IsOverload         = 0x00800000, // Function is an overload of another function
-        IsCloned           = 0x01000000, // The function was marked as cloned
+        IsVMEFunction      = 0x00040000, // Function was added by QML
+        HasArguments       = 0x00080000, // Function takes arguments
+        IsSignal           = 0x00100000, // Function is a signal
+        IsVMESignal        = 0x00200000, // Signal was added by QML
+        IsV8Function       = 0x00400000, // Function takes QQmlV8Function* args
+        IsSignalHandler    = 0x00800000, // Function is a signal handler
+        IsOverload         = 0x01000000, // Function is an overload of another function
+        IsCloned           = 0x02000000, // The function was marked as cloned
 
         // Internal QQmlPropertyCache flags
-        NotFullyResolved   = 0x02000000, // True if the type data is to be lazily resolved
+        NotFullyResolved   = 0x04000000, // True if the type data is to be lazily resolved
 
         // Flags that are set based on the propType field
         PropTypeFlagMask = IsQObjectDerived | IsEnumType | IsQList | IsQmlBinding | IsQJSValue |
@@ -133,6 +135,7 @@ public:
     bool isResettable() const { return flags & IsResettable; }
     bool isAlias() const { return flags & IsAlias; }
     bool isFinal() const { return flags & IsFinal; }
+    bool isOverridden() const { return flags & IsOverridden; }
     bool isDirect() const { return flags & IsDirect; }
     bool hasAccessors() const { return flags & HasAccessors; }
     bool isFunction() const { return flags & IsFunction; }
@@ -163,7 +166,7 @@ public:
     inline int getValueTypeCoreIndex() const;
 
     // Returns the "encoded" index for use with bindings.  Encoding is:
-    //     coreIndex | (valueTypeCoreIndex << 24)
+    //     coreIndex | (valueTypeCoreIndex << 16)
     inline int encodedIndex() const;
 
     union {
@@ -187,10 +190,10 @@ public:
                 struct { // When IsValueTypeVirtual
                     quint16 valueTypeFlags; // flags of the access property on the value type proxy
                                             // object
-                    quint8 valueTypePropType; // The QVariant::Type of access property on the value
-                                              // type proxy object
-                    quint8 valueTypeCoreIndex; // The prop index of the access property on the value
+                    quint16 valueTypePropType; // The QVariant::Type of access property on the value
                                                // type proxy object
+                    quint16 valueTypeCoreIndex; // The prop index of the access property on the value
+                                                // type proxy object
                 };
 
                 struct { // When !IsValueTypeVirtual
@@ -226,6 +229,8 @@ public:
     QString name(QObject *);
     QString name(const QMetaObject *);
 
+    void markAsOverrideOf(QQmlPropertyData *predecessor);
+
 private:
     friend class QQmlPropertyCache;
     void lazyLoad(const QMetaProperty &, QQmlEngine *engine = 0);
@@ -272,13 +277,15 @@ public:
     const QMetaObject *createMetaObject();
     const QMetaObject *firstCppMetaObject() const;
 
-    inline QQmlPropertyData *property(const QHashedV8String &) const;
-    QQmlPropertyData *property(const QHashedStringRef &) const;
-    QQmlPropertyData *property(const QHashedCStringRef &) const;
-    QQmlPropertyData *property(const QString &) const;
+    template<typename K>
+    QQmlPropertyData *property(const K &key, QObject *object, QQmlContextData *context) const
+    {
+        return findProperty(stringCache.find(key), object, context);
+    }
+
     QQmlPropertyData *property(int) const;
     QQmlPropertyData *method(int) const;
-    QQmlPropertyData *signal(int) const;
+    QQmlPropertyData *signal(int index) const { return signal(index, 0); }
     int methodIndexToSignalIndex(int) const;
     QStringList propertyNames() const;
 
@@ -291,14 +298,20 @@ public:
 
     inline QQmlEngine *qmlEngine() const;
     static QQmlPropertyData *property(QQmlEngine *, QObject *, const QString &,
-                                              QQmlPropertyData &);
+                                              QQmlContextData *, QQmlPropertyData &);
     static QQmlPropertyData *property(QQmlEngine *, QObject *, const QHashedV8String &,
-                                              QQmlPropertyData &);
+                                              QQmlContextData *, QQmlPropertyData &);
     static int *methodParameterTypes(QObject *, int index, QVarLengthArray<int, 9> &dummy,
                                      QByteArray *unknownTypeError);
     static int methodReturnType(QObject *, const QQmlPropertyData &data,
                                 QByteArray *unknownTypeError);
-    static QList<QByteArray> signalParameterNames(QObject *, int index);
+
+    //see QMetaObjectPrivate::originalClone
+    int originalClone(int index);
+    static int originalClone(QObject *, int index);
+
+    QList<QByteArray> signalParameterNames(int index) const;
+    QString signalParameterStringForJS(int index, int *count = 0, QString *errorString = 0);
 
     const char *className() const;
 
@@ -332,13 +345,34 @@ private:
     // Implemented in v8/qv8qobjectwrapper.cpp
     v8::Local<v8::Object> newQObject(QObject *, QV8Engine *);
 
+    QQmlPropertyData *signal(int, QQmlPropertyCache **) const;
+
     typedef QVector<QQmlPropertyData> IndexCache;
-    typedef QStringHash<QQmlPropertyData *> StringCache;
+    typedef QStringMultiHash<QPair<int, QQmlPropertyData *> > StringCache;
     typedef QVector<int> AllowedRevisionCache;
 
+    QQmlPropertyData *findProperty(StringCache::ConstIterator it, QObject *, QQmlContextData *) const;
+    QQmlPropertyData *findProperty(StringCache::ConstIterator it, const QQmlVMEMetaObject *, QQmlContextData *) const;
+
+    QQmlPropertyData *ensureResolved(QQmlPropertyData*) const;
+
     void resolve(QQmlPropertyData *) const;
     void updateRecur(QQmlEngine *, const QMetaObject *);
 
+    template<typename K>
+    QQmlPropertyData *findNamedProperty(const K &key)
+    {
+        StringCache::mapped_type *it = stringCache.value(key);
+        return it ? it->second : 0;
+    }
+
+    template<typename K>
+    void setNamedProperty(const K &key, int index, QQmlPropertyData *data, bool isOverride)
+    {
+        stringCache.insert(key, qMakePair(index, data));
+        _hasPropertyOverrides |= isOverride;
+    }
+
     QQmlEngine *engine;
 
     QQmlPropertyCache *_parent;
@@ -353,7 +387,8 @@ private:
     AllowedRevisionCache allowedRevisionCache;
     v8::Persistent<v8::Function> constructor;
 
-    bool _ownMetaObject;
+    bool _hasPropertyOverrides : 1;
+    bool _ownMetaObject : 1;
     const QMetaObject *_metaObject;
     QByteArray _dynamicClassName;
     QByteArray _dynamicStringData;
@@ -394,7 +429,7 @@ public:
 private:
     QBiPointer<QQmlPropertyCache, const QMetaObject> _m;
 };
-  
+
 QQmlPropertyData::QQmlPropertyData()
 {
     propType = 0;
@@ -403,7 +438,7 @@ QQmlPropertyData::QQmlPropertyData()
     overrideIndexIsProperty = false;
     overrideIndex = -1;
     revision = 0;
-    metaObjectOffset = -1; 
+    metaObjectOffset = -1;
     flags = 0;
 }
 
@@ -419,8 +454,8 @@ bool QQmlPropertyData::operator==(const QQmlPropertyRawData &other)
            coreIndex == other.coreIndex &&
            notifyIndex == other.notifyIndex &&
            revision == other.revision &&
-           (!isValueTypeVirtual() || 
-            (valueTypeCoreIndex == other.valueTypeCoreIndex && 
+           (!isValueTypeVirtual() ||
+            (valueTypeCoreIndex == other.valueTypeCoreIndex &&
              valueTypePropType == other.valueTypePropType));
 }
 
@@ -431,7 +466,7 @@ int QQmlPropertyRawData::getValueTypeCoreIndex() const
 
 int QQmlPropertyRawData::encodedIndex() const
 {
-    return isValueTypeVirtual()?(coreIndex | (valueTypeCoreIndex << 24)):coreIndex;
+    return isValueTypeVirtual()?(coreIndex | (valueTypeCoreIndex << 16)):coreIndex;
 }
 
 QQmlPropertyData *
@@ -457,13 +492,6 @@ QQmlEngine *QQmlPropertyCache::qmlEngine() const
     return engine;
 }
 
-QQmlPropertyData *QQmlPropertyCache::property(const QHashedV8String &str) const
-{
-    QQmlPropertyData **rv = stringCache.value(str);
-    if (rv && (*rv)->notFullyResolved()) resolve(*rv);
-    return rv?*rv:0;
-}
-
 int QQmlPropertyCache::propertyCount() const
 {
     return propertyIndexCacheStart + propertyIndexCache.count();