src/tools/moc/generator.cpp
changeset 37 758a864f9613
parent 30 5dc02b23752f
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   480     }
   480     }
   481 }
   481 }
   482 
   482 
   483 void Generator::generateProperties()
   483 void Generator::generateProperties()
   484 {
   484 {
   485     //
       
   486     // specify get function, for compatibiliy we accept functions
       
   487     // returning pointers, or const char * for QByteArray.
       
   488     //
       
   489     for (int i = 0; i < cdef->propertyList.count(); ++i) {
       
   490         PropertyDef &p = cdef->propertyList[i];
       
   491         if (p.read.isEmpty())
       
   492             continue;
       
   493         for (int j = 0; j < cdef->publicList.count(); ++j) {
       
   494             const FunctionDef &f = cdef->publicList.at(j);
       
   495             if (f.name != p.read)
       
   496                 continue;
       
   497             if (!f.isConst) // get  functions must be const
       
   498                 continue;
       
   499             if (f.arguments.size()) // and must not take any arguments
       
   500                 continue;
       
   501             PropertyDef::Specification spec = PropertyDef::ValueSpec;
       
   502             QByteArray tmp = f.normalizedType;
       
   503             if (p.type == "QByteArray" && tmp == "const char *")
       
   504                     tmp = "QByteArray";
       
   505             if (tmp.left(6) == "const ")
       
   506                 tmp = tmp.mid(6);
       
   507             if (p.type != tmp && tmp.endsWith('*')) {
       
   508                 tmp.chop(1);
       
   509                 spec = PropertyDef::PointerSpec;
       
   510             } else if (f.type.name.endsWith('&')) { // raw type, not normalized type
       
   511                 spec = PropertyDef::ReferenceSpec;
       
   512             }
       
   513             if (p.type != tmp)
       
   514                 continue;
       
   515             p.gspec = spec;
       
   516             break;
       
   517         }
       
   518         if(!p.notify.isEmpty()) {
       
   519             int notifyId = -1;
       
   520             for (int j = 0; j < cdef->signalList.count(); ++j) {
       
   521                 const FunctionDef &f = cdef->signalList.at(j);
       
   522                 if(f.name != p.notify) {
       
   523                     continue;
       
   524                 } else {
       
   525                     notifyId = j /* Signal indexes start from 0 */;
       
   526                     break;
       
   527                 }
       
   528             }
       
   529             p.notifyId = notifyId;
       
   530         }
       
   531     }
       
   532 
       
   533     //
   485     //
   534     // Create meta data
   486     // Create meta data
   535     //
   487     //
   536 
   488 
   537     if (cdef->propertyList.count())
   489     if (cdef->propertyList.count())