src/declarative/qml/qdeclarativepropertycache.cpp
changeset 37 758a864f9613
parent 30 5dc02b23752f
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   132     clear();
   132     clear();
   133 }
   133 }
   134 
   134 
   135 void QDeclarativePropertyCache::clear()
   135 void QDeclarativePropertyCache::clear()
   136 {
   136 {
   137     for (int ii = 0; ii < indexCache.count(); ++ii) 
   137     for (int ii = 0; ii < indexCache.count(); ++ii) {
   138         indexCache.at(ii)->release();
   138         if (indexCache.at(ii)) indexCache.at(ii)->release();
       
   139     }
   139 
   140 
   140     for (StringCache::ConstIterator iter = stringCache.begin(); 
   141     for (StringCache::ConstIterator iter = stringCache.begin(); 
   141             iter != stringCache.end(); ++iter)
   142             iter != stringCache.end(); ++iter)
   142         (*iter)->release();
   143         (*iter)->release();
   143 
   144 
   154                                                                   const QString &property)
   155                                                                   const QString &property)
   155 {
   156 {
   156     Q_ASSERT(metaObject);
   157     Q_ASSERT(metaObject);
   157 
   158 
   158     QDeclarativePropertyCache::Data rv;
   159     QDeclarativePropertyCache::Data rv;
   159     int idx = metaObject->indexOfProperty(property.toUtf8());
   160     {
   160     if (idx != -1) {
   161         const QMetaObject *cmo = metaObject;
   161         rv.load(metaObject->property(idx));
   162         while (cmo) {
   162         return rv;
   163             int idx = metaObject->indexOfProperty(property.toUtf8());
       
   164             if (idx != -1) {
       
   165                 QMetaProperty p = metaObject->property(idx);
       
   166                 if (p.isScriptable()) {
       
   167                     rv.load(metaObject->property(idx));
       
   168                     return rv;
       
   169                 } else {
       
   170                     while (cmo && cmo->propertyOffset() >= idx)
       
   171                         cmo = cmo->superClass();
       
   172                 }
       
   173             } else {
       
   174                 cmo = 0;
       
   175             }
       
   176         }
   163     }
   177     }
   164 
   178 
   165     int methodCount = metaObject->methodCount();
   179     int methodCount = metaObject->methodCount();
   166     for (int ii = methodCount - 1; ii >= 2; --ii) { // >=2 to block the destroyed signal
   180     for (int ii = methodCount - 1; ii >= 3; --ii) { // >=3 to block the destroyed signal and deleteLater() slot
   167         QMetaMethod m = metaObject->method(ii);
   181         QMetaMethod m = metaObject->method(ii);
   168         if (m.access() == QMetaMethod::Private)
   182         if (m.access() == QMetaMethod::Private)
   169             continue;
   183             continue;
   170         QString methodName = QString::fromUtf8(m.signature());
   184         QString methodName = QString::fromUtf8(m.signature());
   171 
   185 
   187     QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(engine);
   201     QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(engine);
   188     cache->indexCache = indexCache;
   202     cache->indexCache = indexCache;
   189     cache->stringCache = stringCache;
   203     cache->stringCache = stringCache;
   190     cache->identifierCache = identifierCache;
   204     cache->identifierCache = identifierCache;
   191 
   205 
   192     for (int ii = 0; ii < indexCache.count(); ++ii)
   206     for (int ii = 0; ii < indexCache.count(); ++ii) {
   193         indexCache.at(ii)->addref();
   207         if (indexCache.at(ii)) indexCache.at(ii)->addref();
       
   208     }
   194     for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
   209     for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
   195         (*iter)->addref();
   210         (*iter)->addref();
   196     for (IdentifierCache::ConstIterator iter = identifierCache.begin(); iter != identifierCache.end(); ++iter)
   211     for (IdentifierCache::ConstIterator iter = identifierCache.begin(); iter != identifierCache.end(); ++iter)
   197         (*iter)->addref();
   212         (*iter)->addref();
   198 
   213 
   208     int propOffset = metaObject->propertyOffset();
   223     int propOffset = metaObject->propertyOffset();
   209 
   224 
   210     indexCache.resize(propCount);
   225     indexCache.resize(propCount);
   211     for (int ii = propOffset; ii < propCount; ++ii) {
   226     for (int ii = propOffset; ii < propCount; ++ii) {
   212         QMetaProperty p = metaObject->property(ii);
   227         QMetaProperty p = metaObject->property(ii);
       
   228         if (!p.isScriptable()) 
       
   229             continue;
       
   230         
   213         QString propName = QString::fromUtf8(p.name());
   231         QString propName = QString::fromUtf8(p.name());
   214 
   232 
   215         RData *data = new RData;
   233         RData *data = new RData;
   216         data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName);
   234         data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName);
   217 
   235 
   273     int propCount = metaObject->propertyCount();
   291     int propCount = metaObject->propertyCount();
   274 
   292 
   275     indexCache.resize(propCount);
   293     indexCache.resize(propCount);
   276     for (int ii = propCount - 1; ii >= 0; --ii) {
   294     for (int ii = propCount - 1; ii >= 0; --ii) {
   277         QMetaProperty p = metaObject->property(ii);
   295         QMetaProperty p = metaObject->property(ii);
       
   296         if (!p.isScriptable()) {
       
   297             indexCache[ii] = 0;
       
   298             continue;
       
   299         }
   278         QString propName = QString::fromUtf8(p.name());
   300         QString propName = QString::fromUtf8(p.name());
   279 
   301 
   280         RData *data = new RData;
   302         RData *data = new RData;
   281         data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName);
   303         data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName);
   282 
   304 
   292         data->addref();
   314         data->addref();
   293         data->addref();
   315         data->addref();
   294     }
   316     }
   295 
   317 
   296     int methodCount = metaObject->methodCount();
   318     int methodCount = metaObject->methodCount();
   297     for (int ii = methodCount - 1; ii >= 2; --ii) { // >=2 to block the destroyed signal
   319     for (int ii = methodCount - 1; ii >= 3; --ii) { // >=3 to block the destroyed signal and deleteLater() slot
   298         QMetaMethod m = metaObject->method(ii);
   320         QMetaMethod m = metaObject->method(ii);
   299         if (m.access() == QMetaMethod::Private)
   321         if (m.access() == QMetaMethod::Private)
   300             continue;
   322             continue;
   301         QString methodName = QString::fromUtf8(m.signature());
   323         QString methodName = QString::fromUtf8(m.signature());
   302 
   324