QStringList Utils::propertyNames(const QMetaObject& meta) { QStringList names; for (int i = meta.propertyOffset(); i < meta.propertyCount(); ++i) { names << meta.property(i).name(); } return names; }
QMetaObject *GoValue::metaObjectFor(GoTypeInfo *typeInfo) { if (typeInfo->metaObject) { return reinterpret_cast<QMetaObject *>(typeInfo->metaObject); } QMetaObjectBuilder mob; mob.setSuperClass(&QObject::staticMetaObject); mob.setClassName(typeInfo->typeName); mob.setFlags(QMetaObjectBuilder::DynamicMetaObject); GoMemberInfo *memberInfo; memberInfo = typeInfo->fields; int relativePropIndex = mob.propertyCount(); for (int i = 0; i < typeInfo->fieldsLen; i++) { mob.addSignal("__" + QByteArray::number(relativePropIndex) + "()"); QMetaPropertyBuilder propb = mob.addProperty(memberInfo->memberName, "QVariant", relativePropIndex); propb.setWritable(true); memberInfo->metaIndex = relativePropIndex; memberInfo++; relativePropIndex++; } memberInfo = typeInfo->methods; int relativeMethodIndex = mob.methodCount(); for (int i = 0; i < typeInfo->methodsLen; i++) { if (*memberInfo->resultSignature) { mob.addMethod(memberInfo->methodSignature, memberInfo->resultSignature); } else { mob.addMethod(memberInfo->methodSignature); } memberInfo->metaIndex = relativeMethodIndex; memberInfo++; relativeMethodIndex++; } QMetaObject *mo = mob.toMetaObject(); // Turn the relative indexes into absolute indexes. memberInfo = typeInfo->fields; int propOffset = mo->propertyOffset(); for (int i = 0; i < typeInfo->fieldsLen; i++) { memberInfo->metaIndex += propOffset; memberInfo++; } memberInfo = typeInfo->methods; int methodOffset = mo->methodOffset(); for (int i = 0; i < typeInfo->methodsLen; i++) { memberInfo->metaIndex += methodOffset; memberInfo++; } typeInfo->metaObject = mo; return mo; }
QStringList QtMetaUtilities::getNames(const QMetaObject &metaObject) { QStringList retour; QString className = QLatin1String(metaObject.className()); if (className == "QObject") return retour; for (int idx = metaObject.propertyOffset(); idx < metaObject.propertyCount(); idx++) retour <<metaObject.property(idx).name(); return retour; }
QList<QVariant> QtMetaUtilities::getValues(const QMetaObject &metaObject, const QObject *object) { QList<QVariant> retour; QString className = QLatin1String(metaObject.className()); if (className == "QObject") return retour; for (int idx = metaObject.propertyOffset(); idx < metaObject.propertyCount(); idx++) retour << metaObject.property(idx).read(object); return retour; }
QList<QPair<QString, QVariant::Type> >QtMetaUtilities::getNamesNTypes(const QMetaObject &metaObject) { QList<QPair<QString, QVariant::Type> >retour; QString className = QLatin1String(metaObject.className()); if (className == "QObject") return retour; for (int idx = metaObject.propertyOffset(); idx < metaObject.propertyCount(); idx++) { QMetaProperty prop = metaObject.property(idx); retour.append(QPair<QString, QVariant::Type>(prop.name(), prop.type())); } return retour; }
void QDeclarative1OpenMetaObjectTypePrivate::init(const QMetaObject *metaObj) { if (!mem) { mob.setSuperClass(metaObj); mob.setClassName(metaObj->className()); mob.setFlags(QMetaObjectBuilder::DynamicMetaObject); mem = mob.toMetaObject(); propertyOffset = mem->propertyOffset(); signalOffset = mem->methodOffset(); } }
QString QtMetaUtilities::toString(const QMetaObject &metaObject, const QObject *object) { QString retour; QString className = QLatin1String(metaObject.className()); if (className == "QObject") return retour; for (int idx = metaObject.propertyOffset(); idx < metaObject.propertyCount(); idx++) { retour += QString("[ %1 = %2 ]") .arg(metaObject.property(idx).name()) .arg(metaObject.property(idx).read(object).toString()); } return retour; }
QMetaObject *metaObjectFor(GoTypeInfo *typeInfo) { if (typeInfo->metaObject) { return reinterpret_cast<QMetaObject *>(typeInfo->metaObject); } QMetaObjectBuilder mob; if (typeInfo->paint) { mob.setSuperClass(&QQuickPaintedItem::staticMetaObject); } else { mob.setSuperClass(&QObject::staticMetaObject); } mob.setClassName(typeInfo->typeName); mob.setFlags(QMetaObjectBuilder::DynamicMetaObject); GoMemberInfo *memberInfo; memberInfo = typeInfo->fields; int relativePropIndex = mob.propertyCount(); for (int i = 0; i < typeInfo->fieldsLen; i++) { mob.addSignal("__" + QByteArray::number(relativePropIndex) + "()"); const char *typeName = "QVariant"; if (memberInfo->memberType == DTListProperty) { typeName = "QQmlListProperty<QObject>"; } QMetaPropertyBuilder propb = mob.addProperty(memberInfo->memberName, typeName, relativePropIndex); propb.setWritable(true); memberInfo->metaIndex = relativePropIndex; memberInfo++; relativePropIndex++; } memberInfo = typeInfo->methods; int relativeMethodIndex = mob.methodCount(); for (int i = 0; i < typeInfo->methodsLen; i++) { if (*memberInfo->resultSignature) { mob.addMethod(memberInfo->methodSignature, memberInfo->resultSignature); } else { mob.addMethod(memberInfo->methodSignature); } memberInfo->metaIndex = relativeMethodIndex; memberInfo++; relativeMethodIndex++; } // TODO Support default properties. //mob.addClassInfo("DefaultProperty", "objects"); QMetaObject *mo = mob.toMetaObject(); // Turn the relative indexes into absolute indexes. memberInfo = typeInfo->fields; int propOffset = mo->propertyOffset(); for (int i = 0; i < typeInfo->fieldsLen; i++) { memberInfo->metaIndex += propOffset; memberInfo++; } memberInfo = typeInfo->methods; int methodOffset = mo->methodOffset(); for (int i = 0; i < typeInfo->methodsLen; i++) { memberInfo->metaIndex += methodOffset; memberInfo++; } typeInfo->metaObject = mo; return mo; }
QString QtMetaUtilities::getName(const QMetaObject &metaObject, int pos) { return metaObject.property(pos + metaObject.propertyOffset()).name(); }
QString AsemanQtTools::exportItem(const QString &module, int major, int minor, const QString &component, bool store) { QString result; aseman_qt_tools_indexCache << component; QMetaObject meta = T::staticMetaObject; QString inherits = fixType(meta.superClass()? meta.superClass()->className() : ""); bool isModel = component.toLower().contains("model"); result += QString("# %1\n\n").arg(component); QString headers; headers += QString(" * [Component details](#component-details)\n"); QString details = QString("\n### Component details:\n\n"); details += QString("|Detail|Value|\n" "|------|-----|\n"); details += QString("|%1|%2 %3.%4|\n").arg("Import").arg(module).arg(major).arg(minor); details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Component").arg(component); details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("C++ class").arg(meta.className()); details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Inherits").arg(inherits); details += QString("|%1|<font color='#074885'>%2</font>|\n").arg("Model").arg(isModel?"Yes":"No"); QString resultProperties; QStringList propertiesSignals; for(int i=0; i<meta.propertyCount(); i++) { QMetaProperty property = meta.property(i); const QString &propertyName = property.name(); const QString &propertyType = fixType(property.typeName()); propertiesSignals << property.notifySignal().name(); QString text = QString("* <font color='#074885'><b>%1</b></font>: %2").arg(propertyName).arg(propertyType); if(!property.isWritable()) text += " (readOnly)"; text += "\n"; if(meta.propertyOffset()<=i) resultProperties += text; } QString enumResults; for(int i=meta.enumeratorOffset(); i<meta.enumeratorCount(); i++) { QMetaEnum enumerator = meta.enumerator(i); const QString &enumName = enumerator.name(); enumResults += QString("\n##### %1\n\n").arg(enumName); enumResults += QString("|Key|Value|\n" "|---|-----|\n"); for(int j=0; j<enumerator.keyCount(); j++) enumResults += QString("|%1|%2|\n").arg(enumerator.key(j)).arg(enumerator.value(j)); } QString resultSlots; QString resultSignals; for(int i=meta.methodOffset(); i<meta.methodCount(); i++) { QMetaMethod method = meta.method(i); if(method.access() != QMetaMethod::Public) continue; const QString &methodName = method.name(); if(propertiesSignals.contains(methodName)) continue; const QString &methodType = fixType(method.typeName()); QString args; const QList<QByteArray> ¶mNames = method.parameterNames(); const QList<QByteArray> ¶mTypes = method.parameterTypes(); for(int j=0; j<paramNames.count(); j++) { if(j != 0) args += ", "; args += fixType(paramTypes[j]) + " " + paramNames[j]; } QString text = QString(" * %1 <font color='#074885'><b>%2</b></font>(%3)\n").arg(methodType).arg(methodName).arg(args); switch(static_cast<int>(method.methodType())) { case QMetaMethod::Slot: resultSlots += text; break; case QMetaMethod::Signal: resultSignals += text; break; } } if(!resultProperties.isEmpty()) { headers += QString(" * [Normal Properties](#normal-properties)\n"); resultProperties = QString("\n### Normal Properties\n\n") + resultProperties; } if(!enumResults.isEmpty()) { headers += QString(" * [Enumerator](#enumerator)\n"); enumResults = QString("\n### Enumerator\n\n") + enumResults; } if(!resultSlots.isEmpty()) { headers += QString(" * [Methods](#methods)\n"); resultSlots = QString("\n### Methods\n\n") + resultSlots; } if(!resultSignals.isEmpty()) { headers += QString(" * [Signals](#signals)\n"); resultSignals = QString("\n### Signals\n\n") + resultSignals; } if(isModel) headers += QString(" * [Roles](#roles)\n"); result += headers + "\n"; result += details + "\n"; result += resultProperties + "\n"; result += resultSlots + "\n"; result += resultSignals + "\n"; result += enumResults + "\n"; if(!store) return result; QString path = aseman_qt_tools_destination + "/" + component.toLower() + ".md"; QFile file(path); if(!file.open(QFile::WriteOnly)) return result; file.write(result.toUtf8()); file.close(); return result; }