src/declarative/qml/qdeclarativepropertycache_p.h
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QDECLARATIVEPROPERTYCACHE_P_H
       
    43 #define QDECLARATIVEPROPERTYCACHE_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include "private/qdeclarativerefcount_p.h"
       
    57 #include "private/qdeclarativecleanup_p.h"
       
    58 #include "private/qdeclarativenotifier_p.h"
       
    59 
       
    60 #include <QtCore/qvector.h>
       
    61 
       
    62 #include <QtScript/private/qscriptdeclarativeclass_p.h>
       
    63 QT_BEGIN_NAMESPACE
       
    64 
       
    65 class QDeclarativeEngine;
       
    66 class QMetaProperty;
       
    67 
       
    68 class QDeclarativePropertyCache : public QDeclarativeRefCount, public QDeclarativeCleanup
       
    69 {
       
    70 public:
       
    71     QDeclarativePropertyCache(QDeclarativeEngine *);
       
    72     QDeclarativePropertyCache(QDeclarativeEngine *, const QMetaObject *);
       
    73     virtual ~QDeclarativePropertyCache();
       
    74 
       
    75     struct Data {
       
    76         inline Data(); 
       
    77         inline bool operator==(const Data &);
       
    78 
       
    79         enum Flag { 
       
    80                     NoFlags           = 0x00000000,
       
    81 
       
    82                     // Can apply to all properties, except IsFunction
       
    83                     IsConstant        = 0x00000001,
       
    84                     IsWritable        = 0x00000002,
       
    85                     IsResettable      = 0x00000004,
       
    86 
       
    87                     // These are mutualy exclusive
       
    88                     IsFunction        = 0x00000010,
       
    89                     IsQObjectDerived  = 0x00000020,
       
    90                     IsEnumType        = 0x00000040,
       
    91                     IsQList           = 0x00000080,
       
    92                     IsQmlBinding      = 0x00000100,
       
    93                     IsQScriptValue    = 0x00000200,
       
    94 
       
    95                     // Apply only to IsFunctions
       
    96                     IsVMEFunction     = 0x00000400,
       
    97                     HasArguments      = 0x00000800
       
    98 
       
    99         };
       
   100         Q_DECLARE_FLAGS(Flags, Flag)
       
   101 
       
   102         bool isValid() const { return coreIndex != -1; } 
       
   103 
       
   104         Flags flags;
       
   105         int propType;
       
   106         int coreIndex;
       
   107         int notifyIndex;
       
   108 
       
   109         static Flags flagsForProperty(const QMetaProperty &, QDeclarativeEngine *engine = 0);
       
   110         void load(const QMetaProperty &, QDeclarativeEngine *engine = 0);
       
   111         void load(const QMetaMethod &);
       
   112         QString name(QObject *);
       
   113         QString name(const QMetaObject *);
       
   114     };
       
   115 
       
   116     struct ValueTypeData {
       
   117         inline ValueTypeData();
       
   118         inline bool operator==(const ValueTypeData &);
       
   119         Data::Flags flags;     // flags of the access property on the value type proxy object
       
   120         int valueTypeCoreIdx;  // The prop index of the access property on the value type proxy object
       
   121         int valueTypePropType; // The QVariant::Type of access property on the value type proxy object
       
   122     };
       
   123 
       
   124     void update(QDeclarativeEngine *, const QMetaObject *);
       
   125 
       
   126     QDeclarativePropertyCache *copy() const;
       
   127     void append(QDeclarativeEngine *, const QMetaObject *, Data::Flag propertyFlags = Data::NoFlags,
       
   128                 Data::Flag methodFlags = Data::NoFlags);
       
   129 
       
   130     static QDeclarativePropertyCache *create(QDeclarativeEngine *, const QMetaObject *);
       
   131     static Data create(const QMetaObject *, const QString &);
       
   132 
       
   133     inline Data *property(const QScriptDeclarativeClass::Identifier &id) const;
       
   134     Data *property(const QString &) const;
       
   135     Data *property(int) const;
       
   136     QStringList propertyNames() const;
       
   137 
       
   138     inline QDeclarativeEngine *qmlEngine() const;
       
   139     static Data *property(QDeclarativeEngine *, QObject *, const QScriptDeclarativeClass::Identifier &, Data &);
       
   140     static Data *property(QDeclarativeEngine *, QObject *, const QString &, Data &);
       
   141 protected:
       
   142     virtual void clear();
       
   143 
       
   144 private:
       
   145     struct RData : public Data, public QDeclarativeRefCount { 
       
   146         QScriptDeclarativeClass::PersistentIdentifier identifier;
       
   147     };
       
   148 
       
   149     typedef QVector<RData *> IndexCache;
       
   150     typedef QHash<QString, RData *> StringCache;
       
   151     typedef QHash<QScriptDeclarativeClass::Identifier, RData *> IdentifierCache;
       
   152 
       
   153     QDeclarativeEngine *engine;
       
   154     IndexCache indexCache;
       
   155     StringCache stringCache;
       
   156     IdentifierCache identifierCache;
       
   157 };
       
   158 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyCache::Data::Flags);
       
   159   
       
   160 QDeclarativePropertyCache::Data::Data()
       
   161 : flags(0), propType(0), coreIndex(-1), notifyIndex(-1) 
       
   162 {
       
   163 }
       
   164 
       
   165 bool QDeclarativePropertyCache::Data::operator==(const QDeclarativePropertyCache::Data &other)
       
   166 {
       
   167     return flags == other.flags &&
       
   168            propType == other.propType &&
       
   169            coreIndex == other.coreIndex &&
       
   170            notifyIndex == other.notifyIndex;
       
   171 }
       
   172 
       
   173 QDeclarativePropertyCache::Data *
       
   174 QDeclarativePropertyCache::property(const QScriptDeclarativeClass::Identifier &id) const 
       
   175 {
       
   176     return identifierCache.value(id);
       
   177 }
       
   178 
       
   179 QDeclarativePropertyCache::ValueTypeData::ValueTypeData()
       
   180 : flags(QDeclarativePropertyCache::Data::NoFlags), valueTypeCoreIdx(-1), valueTypePropType(0) 
       
   181 {
       
   182 }
       
   183 
       
   184 bool QDeclarativePropertyCache::ValueTypeData::operator==(const ValueTypeData &o) 
       
   185 { 
       
   186     return flags == o.flags &&
       
   187            valueTypeCoreIdx == o.valueTypeCoreIdx &&
       
   188            valueTypePropType == o.valueTypePropType; 
       
   189 }
       
   190 
       
   191 QDeclarativeEngine *QDeclarativePropertyCache::qmlEngine() const
       
   192 {
       
   193     return engine;
       
   194 }
       
   195 
       
   196 QT_END_NAMESPACE
       
   197 
       
   198 #endif // QDECLARATIVEPROPERTYCACHE_P_H