void NodeInstanceSignalSpy::registerObject(QObject *spiedObject, const PropertyName &prefix) { if (m_registeredObjectList.contains(spiedObject)) // prevent cycles return; m_registeredObjectList.append(spiedObject); for (int index = QObject::staticMetaObject.propertyOffset(); index < spiedObject->metaObject()->propertyCount(); index++) { QMetaProperty metaProperty = spiedObject->metaObject()->property(index); // handle dot properties and connect the signals to the object if (metaProperty.isReadable() && !metaProperty.isWritable() && QDeclarativeMetaType::isQObject(metaProperty.userType())) { QObject *propertyObject = QDeclarativeMetaType::toQObject(metaProperty.read(spiedObject)); if (propertyObject) registerObject(propertyObject, prefix + metaProperty.name() + '.'); } else if (metaProperty.hasNotifySignal()) { QMetaMethod metaMethod = metaProperty.notifySignal(); bool isConnecting = QMetaObject::connect(spiedObject, metaMethod.methodIndex(), this, methodeOffset, Qt::DirectConnection); Q_ASSERT(isConnecting); Q_UNUSED(isConnecting); m_indexPropertyHash.insert(methodeOffset, prefix + metaProperty.name()); methodeOffset++; } // search recursive in objects if (metaProperty.isReadable() && metaProperty.isWritable() && QDeclarativeMetaType::isQObject(metaProperty.userType())) { QObject *propertyObject = QDeclarativeMetaType::toQObject(metaProperty.read(spiedObject)); if (propertyObject) registerObject(propertyObject, prefix + metaProperty.name() + '/'); } // search recursive in objects list if (metaProperty.isReadable() && QDeclarativeMetaType::isList(metaProperty.userType())) { QDeclarativeListReference list(spiedObject, metaProperty.name()); if (list.canCount() && list.canAt()) { for (int i = 0; i < list.count(); i++) { QObject *propertyObject = list.at(i); if (propertyObject) registerObject(propertyObject, prefix + metaProperty.name() + '/'); } } } } }
QScriptClass::QueryFlags QDeclarativeValueTypeScriptClass::queryProperty(Object *obj, const Identifier &name, QScriptClass::QueryFlags) { QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj); m_lastIndex = -1; QByteArray propName = toString(name).toUtf8(); m_lastIndex = o->type->metaObject()->indexOfProperty(propName.constData()); if (m_lastIndex == -1) return 0; QScriptClass::QueryFlags rv = 0; if (o->objectType == QDeclarativeValueTypeObject::Reference) { QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(o); if (!ref->object) return 0; QMetaProperty prop = ref->object->metaObject()->property(m_lastIndex); rv = QScriptClass::HandlesReadAccess; if (prop.isWritable()) rv |= QScriptClass::HandlesWriteAccess; } else { rv = QScriptClass::HandlesReadAccess | QScriptClass::HandlesWriteAccess; } return rv; }
extern "C" SEXP qt_qproperties(SEXP x) { const QMetaObject *meta = unwrapSmoke(x, QMetaObject); int n = meta->propertyCount(); SEXP ans, ans_type, ans_name, ans_readable, ans_writable; PROTECT(ans = allocVector(VECSXP, 4)); ans_name = allocVector(STRSXP, n); SET_VECTOR_ELT(ans, 0, ans_name); ans_type = allocVector(STRSXP, n); SET_VECTOR_ELT(ans, 1, ans_type); ans_readable = allocVector(LGLSXP, n); SET_VECTOR_ELT(ans, 2, ans_readable); ans_writable = allocVector(LGLSXP, n); SET_VECTOR_ELT(ans, 3, ans_writable); for (int i = 0; i < n; i++) { QMetaProperty metaProperty = meta->property(i); SET_STRING_ELT(ans_type, i, mkChar(metaProperty.typeName())); SET_STRING_ELT(ans_name, i, mkChar(metaProperty.name())); LOGICAL(ans_readable)[i] = metaProperty.isReadable(); LOGICAL(ans_writable)[i] = metaProperty.isWritable(); } UNPROTECT(1); return ans; }
bool WriteMetaProperty(QObject *pObject, QString pName, const QVariant& pValue) { if (!pObject) return false; const QMetaObject *metaObject = pObject->metaObject(); int index = metaObject->indexOfProperty(pName.toUtf8().constData()); if (index >= 0) { QMetaProperty metaProperty = metaObject->property(index); if (metaProperty.isWritable() && //Value cant Writed metaProperty.read(pObject) != pValue) //Value changed { metaProperty.write(pObject, pValue); return true; } else { return false; } } else { return false; } }
bool UiExtractor::checkProperty(QObject *obj, const QString &prop) const { const QMetaObject *mo = obj->metaObject(); const QMetaProperty mp = mo->property(mo->indexOfProperty(prop.toLatin1())); // TODO come up with some more aggressive filtering if (mp.isValid() && mp.isDesignable(obj) && mp.isStored(obj) && mp.isWritable()) { const QVariant value = mp.read(obj); // try to figure out the default by resetting to it if (mp.isResettable()) { mp.reset(obj); if (mp.read(obj) == value) { return false; } mp.write(obj, value); return true; } // some guessing for non-resettable properties if (value.isNull() || !value.isValid()) { return false; } if (value.type() == QVariant::String) { return !value.toString().isEmpty(); } else if (value.type() == QVariant::Locale) { return value.value<QLocale>() != QLocale::system(); } return true; } return false; }
void CopyMetaProperties(QObject *pObject, QObject *pTarget) { //Temp const QMetaObject *metaOrigin = pObject->metaObject(); const QMetaObject *metaTarget = pTarget->metaObject(); QMetaProperty metaPropertyOrigin; QMetaProperty metaPropertyTarget; QVariant value; int index; int max = metaOrigin->propertyCount(); bool denied; //Read pObject property and Write pTarget property if is writetable for (int i = 0; i < max; i++) { metaPropertyOrigin = metaOrigin->property(i); const char *name = metaPropertyOrigin.name(); index = metaTarget->indexOfProperty(name); denied = QString("selected").split(",").contains(name); if (index >= 0 && !denied) { metaPropertyTarget = metaTarget->property(index); if (metaPropertyTarget.isWritable()) { value = metaPropertyOrigin.read(pObject);//Read metaPropertyTarget.write(pTarget, value);//Write } } } }
QT_BEGIN_NAMESPACE QDeclarativePropertyCache::Data::Flags QDeclarativePropertyCache::Data::flagsForProperty(const QMetaProperty &p, QDeclarativeEngine *engine) { int propType = p.userType(); Flags flags; if (p.isConstant()) flags |= Data::IsConstant; if (p.isWritable()) flags |= Data::IsWritable; if (p.isResettable()) flags |= Data::IsResettable; if (propType == qMetaTypeId<QDeclarativeBinding *>()) { flags |= Data::IsQmlBinding; } else if (propType == qMetaTypeId<QScriptValue>()) { flags |= Data::IsQScriptValue; } else if (p.isEnumType()) { flags |= Data::IsEnumType; } else { QDeclarativeMetaType::TypeCategory cat = engine ? QDeclarativeEnginePrivate::get(engine)->typeCategory(propType) : QDeclarativeMetaType::typeCategory(propType); if (cat == QDeclarativeMetaType::Object) flags |= Data::IsQObjectDerived; else if (cat == QDeclarativeMetaType::List) flags |= Data::IsQList; } return flags; }
void SFIdentityData::deserializeFromMap(QVariantMap map){ const QMetaObject *metaObj = metaObject(); int count = metaObj->propertyCount(); for(int i=0; i<count; i++) { QMetaProperty property = metaObj->property(i); if (!property.isWritable()) { continue; } QVariant value; if (map.contains(property.name())){ value = map[property.name()]; }else if (map.contains("photos") && map["photos"].toMap().contains(property.name())){ value = map["photos"].toMap()[property.name()]; }else if(map.contains("urls") && map["urls"].toMap().contains(property.name())){ value = map["urls"].toMap()[property.name()]; }else if(map.contains("mobile_policy") && map["mobile_policy"].toMap().contains(property.name())){ value = map["mobile_policy"].toMap()[property.name()]; }else{ continue; } if (!const_cast<QVariant&>(value).canConvert(property.type())) { continue; } property.write(this, value); } }
bool Properties::duplicateTo( qps::Properties* destination ) const { if ( destination == nullptr ) return false; if ( getTarget() == nullptr ) return false; // Duplicate static properties int staticPropertyCount = getTarget()->metaObject( )->propertyCount( ); for ( int s = 0; s < staticPropertyCount; s++ ) { QMetaProperty metaProperty = getTarget()->metaObject( )->property( s ); const char* propertyName = metaProperty.name( ); if ( propertyName == nullptr ) continue; if ( std::strcmp( propertyName, "target" ) == 0 ) // Do not modify destination target continue; QVariant srcValue = getTarget()->property( propertyName ); if ( hasProperty( propertyName ) && metaProperty.isWritable( ) ) destination->setProperty( propertyName, srcValue ); else destination->addDynamicProperty( propertyName, srcValue ); } // Duplicate dynamic properties QList< QByteArray > dynamicProperties = getTarget()->dynamicPropertyNames( ); for ( int d = 0; d < dynamicProperties.size( ); d++ ) { QString propertyName = dynamicProperties.at( d ); QVariant srcValue = getTarget()->property( propertyName.toLatin1( ) ); if ( hasProperty( propertyName ) ) destination->setProperty( propertyName, srcValue ); else destination->addDynamicProperty( propertyName, srcValue ); } return true; }
qObjectnode:: qObjectnode(QObject *data, QGraphicsItem *parent, bool autodelete) : GraphicsNode(parent),m_autodelete(autodelete) { m_data=data; if(m_data==0) qWarning("NULL Data Object!"); else { QWidget* tst = dynamic_cast<QWidget*>(data); if(tst!=0) setCentralWidget(tst); const QMetaObject* m = m_data->metaObject(); int property_count = m->propertyCount()-1; for(;property_count>=0;property_count--) { QMetaProperty prop = m->property(property_count); if(prop.isConstant() || !prop.isUser()) continue; if(prop.isReadable() && prop.hasNotifySignal()) { add_source(QString(prop.name()) + "[" +QString(prop.typeName()) +"]",m_data,property_count); } if(prop.isWritable()) add_sink(QString(prop.name()) + "[" +QString(prop.typeName()) +"]",m_data,property_count); } } }
// --------------------------------------------------------------------------- // PosSettingsPushButtonItem:::restore // --------------------------------------------------------------------------- // void PosSettingsPushButtonItem::restore() { HbDataFormViewItem::restore(); if (mWidget) { HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); if(itemType == PushButtonItem) { QModelIndex itemIndex = modelIndex(); HbDataFormModel *model = static_cast<HbDataFormModel*>(itemView()->model());; HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>( model->itemFromIndex(itemIndex)); const QMetaObject *metaObj = mWidget->metaObject(); int count = metaObj->propertyCount(); for (int i = 0; i < count; i++) { QMetaProperty metaProperty = metaObj->property(i); if (metaProperty.isValid() && metaProperty.isWritable()) { metaProperty.write(mWidget,modelItem->contentWidgetData(metaProperty.name())); } } } } }
void NoronJsonBinarySerializer::deserializeQObject(QObject *obj, QVariantMap map) { for(int i = 0; i < obj->metaObject()->propertyCount(); i++){ QMetaProperty property = obj->metaObject()->property(i); if(property.isReadable() && property.isWritable()) property.write(obj, map[property.name()].toString()); } }
bool QObject::setProperty(const char *name, const QVariant &value) { const QMetaObject* metaObj = metaObject(); if (! name || ! metaObj) { return false; } int index = metaObj->indexOfProperty(name); if (index < 0) { const int k = m_extra_propertyNames.indexOf(name); if (value.isValid()) { // add or update dynamic property if (k == -1) { m_extra_propertyNames.append(name); m_extra_propertyValues.append(value); } else { m_extra_propertyValues[k] = value; } } else { // remove dynamic property if (k == -1) { return false; } m_extra_propertyNames.removeAt(k); m_extra_propertyValues.removeAt(k); } QDynamicPropertyChangeEvent event(name); QCoreApplication::sendEvent(this, &event); return false; } QMetaProperty p = metaObj->property(index); if (! p.isWritable()) { qWarning("%s::setProperty() Property \"%s\" is invalid, read only, or does not exist", metaObj->className(), name); } // bool retval = p.write(this, value); if (! retval) { qWarning("%s::setProperty() Set property \"%s\" failed. Passed value is of type %s, property is of type %s", metaObj->className(), name, value.typeName(), p.typeName() ); } return retval; }
void QJnextMainLoop::set(QObject *object, QVariantList& args, QByteArray* retval) { QByteArray property = args.takeFirst().toByteArray(); const QMetaObject * meta = object->metaObject(); int propertyIndex = meta->indexOfProperty(property); if (propertyIndex < 0) { retval->append("No such property " + property); return; } QMetaProperty metaprop = meta->property(propertyIndex); if (!metaprop.isWritable()) { retval->append("Property " + property + " is not writable"); return; } QVariant vValue = args.takeFirst(); /* handle enum inputs as text */ if (metaprop.isEnumType()) { int id; const QMetaEnum &enumerator = metaprop.enumerator(); QByteArray keys; for (int i = 0; i < enumerator.keyCount(); ++i) keys += enumerator.key(i) + QByteArray(" "); #ifdef DEBUG_QJnextMainLoop qDebug() << "[QJnextMainLoop]\tEnumerator" << enumerator.isFlag() << enumerator.scope() << enumerator.name() << keys; #endif if (enumerator.isFlag()) id = enumerator.keyToValue(vValue.toByteArray().constData()); else id = enumerator.keysToValue(vValue.toByteArray().constData()); if (id != -1) vValue = QVariant(id); } #ifdef DEBUG_QJnextMainLoop qDebug() << "[QJnextMainLoop]\tSET" << meta->className() << property << vValue << vValue.canConvert(metaprop.type()); #endif if (!vValue.convert(metaprop.type())) { retval->append( "Unable to convert \"" + vValue.toByteArray() + "\" to " + metaprop.typeName()); return; } if (!metaprop.write(object, vValue)) retval->append( QByteArray("Unable to set property ") + meta->className() + "." + property + " to " + vValue.toByteArray()); else *retval = QByteArray(); }
bool Properties::staticPropertyIsWritable( QString propertyName ) const { if ( getTarget() == nullptr ) return false; int pi = getTarget()->metaObject( )->indexOfProperty( propertyName.toLatin1( ) ); if ( pi == -1 ) return false; QMetaProperty mp = getTarget()->metaObject()->property( pi ); return mp.isWritable(); }
QVariant ObjectStaticPropertyModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || !m_obj || index.row() < 0 || index.row() >= m_obj.data()->metaObject()->propertyCount()) { return QVariant(); } const QMetaProperty prop = m_obj.data()->metaObject()->property(index.row()); if (role == Qt::DisplayRole) { if (index.column() == 0) { return prop.name(); } else if (index.column() == 1) { // QMetaProperty::read sets QVariant::typeName to int for enums, // so we need to handle that separately here const QVariant value = prop.read(m_obj.data()); const QString enumStr = Util::enumToString(value, prop.typeName(), m_obj.data()); if (!enumStr.isEmpty()) { return enumStr; } return VariantHandler::displayString(value); } else if (index.column() == 2) { return prop.typeName(); } else if (index.column() == 3) { const QMetaObject *mo = m_obj.data()->metaObject(); while (mo->propertyOffset() > index.row()) { mo = mo->superClass(); } return mo->className(); } } else if (role == Qt::DecorationRole) { if (index.column() == 1) { return VariantHandler::decoration(prop.read(m_obj.data())); } } else if (role == Qt::EditRole) { if (index.column() == 1) { return prop.read(m_obj.data()); } } else if (role == Qt::ToolTipRole) { const QString toolTip = tr("Constant: %1\nDesignable: %2\nFinal: %3\nResetable: %4\n" "Has notification: %5\nScriptable: %6\nStored: %7\nUser: %8\nWritable: %9"). arg(translateBool(prop.isConstant())). arg(translateBool(prop.isDesignable(m_obj.data()))). arg(translateBool(prop.isFinal())). arg(translateBool(prop.isResettable())). arg(translateBool(prop.hasNotifySignal())). arg(translateBool(prop.isScriptable(m_obj.data()))). arg(translateBool(prop.isStored(m_obj.data()))). arg(translateBool(prop.isUser(m_obj.data()))). arg(translateBool(prop.isWritable())); return toolTip; } return QVariant(); }
void CDiagramItem::fromXml(const QDomElement &n) { QDomElement e; QString type, name, prop; QObject *obj = NULL; QMetaProperty pro; QMetaObject *meta = NULL; CDiagramSerializable *serialItem = NULL; setLibraryCategory(n.attribute( QString("libCategory") ) ); setLibraryName(n.attribute( QString("libName") ) ); setCategory(n.attribute( QString("category") ) ); setName(n.attribute( QString("name") ) ); setId(n.attribute( QString("id") ).toInt() ); obj = dynamic_cast<QObject*>(this); e = n.firstChildElement( QString("property") ); while (!e.isNull()) { QByteArray b; name = e.attribute( QString("name") ); type = e.attribute( QString("type") ); b = QByteArray::fromBase64( e.text().toAscii() ); QDataStream s(&b, QIODevice::ReadOnly); QVariant value(s); if (value.convert( QVariant::nameToType( qPrintable(type) ) ) ) { meta = const_cast<QMetaObject*>( obj->metaObject() ); pro = meta->property( meta->indexOfProperty(qPrintable(name)) ); if (pro.isWritable()) obj->setProperty(qPrintable(name), value); } e = e.nextSiblingElement( QString("property") ); } e = n.firstChildElement( QString("children") ); if (!e.isNull()) { e = e.firstChildElement( QString("child") ); while (!e.isNull()) { prop = e.attribute( QString("dynamicProperty") ); serialItem = RS_PROPERTY(prop.toAscii().constData()); if (serialItem) serialItem->fromXml(e); e = e.nextSiblingElement(QString("child")); } } e = n.firstChildElement( QString("ext" ) ); extFromXml(e); }
void ChangeProperties::on_listProperties_currentItemChanged(QTreeWidgetItem *current) { editValue->setEnabled(current != 0); buttonSet->setEnabled(current != 0); valueLabel->setEnabled(current != 0); if (!current) return; editValue->setText(current->text(2)); QString prop = current->text(0); valueLabel->setText(prop + QLatin1String(" =")); const QMetaObject *mo = activex->metaObject(); const QMetaProperty property = mo->property(mo->indexOfProperty(prop.toLatin1())); valueLabel->setEnabled(property.isWritable()); editValue->setEnabled(property.isWritable()); buttonSet->setEnabled(property.isWritable()); }
void listInterface(const QString &service, const QString &path, const QString &interface) { QDBusInterfacePtr iface(*connection, service, path, interface); if (!iface->isValid()) { QDBusError err(iface->lastError()); fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n", qPrintable(interface), qPrintable(path), qPrintable(service), qPrintable(err.name()), qPrintable(err.message())); exit(1); } const QMetaObject *mo = iface->metaObject(); // properties for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) { QMetaProperty mp = mo->property(i); printf("property "); if (mp.isReadable() && mp.isWritable()) printf("readwrite"); else if (mp.isReadable()) printf("read"); else printf("write"); printf(" %s %s.%s\n", mp.typeName(), qPrintable(interface), mp.name()); } // methods (signals and slots) for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) { QMetaMethod mm = mo->method(i); QByteArray signature = mm.signature(); signature.truncate(signature.indexOf('(')); printf("%s %s%s%s %s.%s(", mm.methodType() == QMetaMethod::Signal ? "signal" : "method", mm.tag(), *mm.tag() ? " " : "", *mm.typeName() ? mm.typeName() : "void", qPrintable(interface), signature.constData()); QList<QByteArray> types = mm.parameterTypes(); QList<QByteArray> names = mm.parameterNames(); bool first = true; for (int i = 0; i < types.count(); ++i) { printf("%s%s", first ? "" : ", ", types.at(i).constData()); if (!names.at(i).isEmpty()) printf(" %s", names.at(i).constData()); first = false; } printf(")\n"); } }
QVariantMap NoronJsonBinarySerializer::serializeQObject(QObject *obj) { QVariantMap map; for(int i = 0; i < obj->metaObject()->propertyCount(); i++){ QMetaProperty property = obj->metaObject()->property(i); if(property.isReadable() && property.isWritable()) map.insert(property.name(), property.read(obj).toString()); } return map; }
static int writeProperty(QObject *obj, const QByteArray &property_name, QVariant value, int propFlags = QDBusConnection::ExportAllProperties) { const QMetaObject *mo = obj->metaObject(); int pidx = mo->indexOfProperty(property_name); if (pidx == -1) { // this object has no property by that name return PropertyNotFound; } QMetaProperty mp = mo->property(pidx); // check if this property is writable if (!mp.isWritable()) return PropertyReadOnly; // check if this property is exported bool isScriptable = mp.isScriptable(); if (!(propFlags & QDBusConnection::ExportScriptableProperties) && isScriptable) return PropertyNotFound; if (!(propFlags & QDBusConnection::ExportNonScriptableProperties) && !isScriptable) return PropertyNotFound; // we found our property // do we have the right type? int id = mp.userType(); if (!id){ // type not registered or invalid / void? qWarning("QDBusConnection: Unable to handle unregistered datatype '%s' for property '%s::%s'", mp.typeName(), mo->className(), property_name.constData()); return PropertyWriteFailed; } if (id != QMetaType::QVariant && value.userType() == QDBusMetaTypeId::argument()) { // we have to demarshall before writing void *null = 0; QVariant other(id, null); if (!QDBusMetaType::demarshall(qvariant_cast<QDBusArgument>(value), id, other.data())) { qWarning("QDBusConnection: type `%s' (%d) is not registered with QtDBus. " "Use qDBusRegisterMetaType to register it", mp.typeName(), id); return PropertyWriteFailed; } value = other; } if (mp.userType() == qMetaTypeId<QDBusVariant>()) value = QVariant::fromValue(QDBusVariant(value)); // the property type here should match return mp.write(obj, value) ? PropertyWriteSuccess : PropertyWriteFailed; }
QStringList propertyNameForWritableProperties(QObject *object, const QString &baseName = QString()) { QStringList propertyNameList; const QMetaObject *metaObject = object->metaObject(); for (int index = 0; index < metaObject->propertyCount(); ++index) { QMetaProperty metaProperty = metaObject->property(index); if (metaProperty.isReadable() && !metaProperty.isWritable()) { QObject *childObject = QDeclarativeMetaType::toQObject(metaProperty.read(object)); if (childObject) propertyNameList.append(propertyNameForWritableProperties(childObject, baseName + QString::fromUtf8(metaProperty.name()) + '.')); } else if (QDeclarativeValueTypeFactory::valueType(metaProperty.userType())) { QDeclarativeValueType *valueType = QDeclarativeValueTypeFactory::valueType(metaProperty.userType()); valueType->setValue(metaProperty.read(object)); propertyNameList.append(propertyNameForWritableProperties(valueType, baseName + QString::fromUtf8(metaProperty.name()) + '.')); } else if (metaProperty.isReadable() && metaProperty.isWritable()) { propertyNameList.append(baseName + QString::fromUtf8(metaProperty.name())); } } return propertyNameList; }
bp::object get_classdef( const QMetaObject* meta ) { pyqbind_info::metaclass_map::const_iterator iter; if( (iter=pyqbind_info.metaclasses_.find( meta )) != pyqbind_info.metaclasses_.end()){ /* This class has been previously exported */ return (*iter).second; } log_debug_stream( "Exporting metaobject " << meta->className() ); const char* classname = meta->className(); //bp::class_<QObject, boost::shared_ptr<QObject>, boost::noncopyable> classdef(classname); bp::class_<QObject, boost::noncopyable> classdef(classname, bp::no_init); classdef.attr("__module__") = "pyqbind"; std::set< std::string > scriptable = get_scriptable_props( meta ); /* Export properties */ for( int i = 0; i < meta->propertyCount(); ++i ){ QMetaProperty prop = meta->property(i); std::string name = prop.name(); if( scriptable.count(name) == 0 ) name = "_" + name; try{ if( prop.isWritable() ){ classdef.add_property( name.c_str(), pyqbind_detail::make_metaproperty_reader(prop), pyqbind_detail::make_metaproperty_writer(prop) ); } else{ classdef.add_property( name.c_str(), pyqbind_detail::make_metaproperty_reader( prop ) ); } } catch( PyQBind::error& e ){ log_warn_stream( "Could not export property " << prop.name() ); } } /* Export slots */ scriptable = get_scriptable_slots( meta ); for( int i = 0; i < meta->methodCount(); ++i ){ QMetaMethod method = meta->method(i); if( method.methodType() != QMetaMethod::Slot ) continue; if( method.access() != QMetaMethod::Public ) continue; std::string name = make_method_name(method); if( name == "deleteLater" ) continue; /* because calling this from python is a bad idea */ if( scriptable.count(name) == 0 ) name = "_" + name; classdef.def( name.c_str(), pyqbind_detail::make_invoker(method) ); } pyqbind_info.metaclasses_[ meta ] = classdef; return classdef; }
void MetaInfoPrivate::parseProperties(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const { Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject"); Q_ASSERT_X(nodeMetaInfo.isValid(), Q_FUNC_INFO, "invalid NodeMetaInfo"); for (int i = qMetaObject->propertyOffset(); i < qMetaObject->propertyCount(); ++i) { QMetaProperty qProperty = qMetaObject->property(i); PropertyMetaInfo propertyInfo; propertyInfo.setName(QLatin1String(qProperty.name())); QString typeName(qProperty.typeName()); QString noStar = typeName; bool star = false; while (noStar.contains('*')) {//strip star noStar.chop(1); star = true; } if (m_QtTypesToQmlTypes.contains(noStar)) { typeName = star ? m_QtTypesToQmlTypes.value(noStar) + '*' : m_QtTypesToQmlTypes.value(noStar); //### versions } propertyInfo.setType(typeName); propertyInfo.setValid(true); propertyInfo.setReadable(qProperty.isReadable()); propertyInfo.setWritable(qProperty.isWritable()); propertyInfo.setResettable(qProperty.isResettable()); propertyInfo.setEnumType(qProperty.isEnumType()); propertyInfo.setFlagType(qProperty.isFlagType()); if (propertyInfo.isEnumType()) { EnumeratorMetaInfo enumerator; QMetaEnum qEnumerator = qProperty.enumerator(); enumerator.setValid(qEnumerator.isValid()); enumerator.setIsFlagType(qEnumerator.isFlag()); enumerator.setScope(qEnumerator.scope()); enumerator.setName(qEnumerator.name()); for (int i = 0 ;i < qEnumerator.keyCount(); i++) { enumerator.addElement(qEnumerator.valueToKey(i), i); } propertyInfo.setEnumerator(enumerator); } nodeMetaInfo.addProperty(propertyInfo); } }
/*! \brief TreeModel::updateItem Updates \a item with the data provided by \a object and \a metaProperty. If \a metaProperty is writable, the data will be stored in Qt::EditRole, otherwise in Qt::DisplayRole. */ void TreeModel::updateItem( QStandardItem* item, QObject* object, const QMetaProperty& metaProperty ) { Q_ASSERT( item ); Q_ASSERT( mp_object ); if ( metaProperty.isWritable() ) { item->setData( object->property( metaProperty.name() ), Qt::EditRole ); } { item->setData( object->property( metaProperty.name() ), Qt::DisplayRole ); } }
Qt::ItemFlags ObjectStaticPropertyModel::flags(const QModelIndex &index) const { const Qt::ItemFlags flags = ObjectPropertyModel::flags(index); if (!index.isValid() || !m_obj || index.column() != 1 || index.row() < 0 || index.row() >= m_obj.data()->metaObject()->propertyCount()) { return flags; } const QMetaProperty prop = m_obj.data()->metaObject()->property(index.row()); if (prop.isWritable()) { return flags | Qt::ItemIsEditable; } return flags; }
void SaxsviewProperty::setValue(QObject *obj) { if (!mProperty) { // // Find the meta-property information; the passed object must // provide the Q_PROPERTY name passed to the constructor. // int indexOfProperty = obj->metaObject()->indexOfProperty(qPrintable(mPropertyName)); QMetaProperty metaProperty = obj->metaObject()->property(indexOfProperty); if (metaProperty.isValid()) { // // Create an editor factory if and only if the property is writeable. // if (metaProperty.isWritable()) { mBrowser->setFactoryForManager(mManager, new QtVariantEditorFactory(this)); connect(mManager, SIGNAL(valueChanged(QtProperty*, const QVariant&)), this, SLOT(valueChanged(QtProperty*, const QVariant&))); } if (!mManager->isPropertyTypeSupported(metaProperty.type())) qFatal("internal error: property '%s', property type not supported: '%s'", metaProperty.name(), metaProperty.typeName()); // // Check if this is an enum and handle it specially if yes. // if (metaProperty.isEnumType()) { QStringList enumNames; QMetaEnum metaEnum = metaProperty.enumerator(); // // WARNING: This only builds a list of names in the order // as defined. The combobox to display these names // provides the selected index, not the actual enum // value. // for (int i = 0; i < metaEnum.keyCount(); ++i) enumNames << metaEnum.key(i); setEnumNames(enumNames); } if (mAttributes.contains("enumNames")) mProperty = mManager->addProperty(mManager->enumTypeId(), mPropertyLabel); else mProperty = mManager->addProperty(metaProperty.type(), mPropertyLabel); } else if (obj->dynamicPropertyNames().contains(qPrintable(mPropertyName))) {
ObjectMapperForwarder::ObjectMapperForwarder(ObjectMapper *m, QObject *o) : QObject(m), m_mapper(m), m_source(o) { for (int i = 0; i < o->metaObject()->propertyCount(); ++i) { QMetaProperty property = o->metaObject()->property(i); if (!property.isStored() || !property.isReadable() || !property.isWritable()) { continue; } if (!property.hasNotifySignal()) { DEBUG << "ObjectMapperForwarder: No notify signal for property " << property.name() << endl; continue; } // Signals can be connected to slots with fewer arguments, so // long as the arguments they do have match. So we connect // the property notify signal to our universal // property-changed slot, and use the sender() of that to // discover which object's property has changed. // Unfortunately, we don't then know which property it was // that changed, as the identity of the signal that activated // the slot is not available to us. The annoying part of this // is that Qt does actually store the identity of the signal // in the same structure as used for the sender() object data; // it just doesn't (at least as of Qt 4.5) make it available // through the public API. QString sig = QString("%1%2").arg(QSIGNAL_CODE) .arg(property.notifySignal().methodSignature().data()); QByteArray ba = sig.toLocal8Bit(); if (!connect(o, ba.data(), this, SLOT(objectModified()))) { std::cerr << "ObjectMapperForwarder: Failed to connect notify signal" << std::endl; } } connect(o, SIGNAL(destroyed(QObject *)), this, SLOT(objectDestroyed())); }
QVariant ObjectStaticPropertyModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || !m_obj || index.row() < 0 || index.row() >= m_obj.data()->metaObject()->propertyCount()) { return QVariant(); } const QMetaProperty prop = m_obj.data()->metaObject()->property(index.row()); if (role == Qt::DisplayRole) { if (index.column() == 0) { return prop.name(); } else if (index.column() == 1) { return Util::variantToString(prop.read(m_obj.data())); } else if (index.column() == 2) { return prop.typeName(); } else if (index.column() == 3) { const QMetaObject *mo = m_obj.data()->metaObject(); while (mo->propertyOffset() > index.row()) { mo = mo->superClass(); } return mo->className(); } } else if (role == Qt::EditRole) { if (index.column() == 1) { return prop.read(m_obj.data()); } } else if (role == Qt::ToolTipRole) { const QString toolTip = tr("Constant: %1\nDesignable: %2\nFinal: %3\nResetable: %4\n" "Has notification: %5\nScriptable: %6\nStored: %7\nUser: %8\nWritable: %9"). arg(translateBool(prop.isConstant())). arg(translateBool(prop.isDesignable(m_obj.data()))). arg(translateBool(prop.isFinal())). arg(translateBool(prop.isResettable())). arg(translateBool(prop.hasNotifySignal())). arg(translateBool(prop.isScriptable(m_obj.data()))). arg(translateBool(prop.isStored(m_obj.data()))). arg(translateBool(prop.isUser(m_obj.data()))). arg(translateBool(prop.isWritable())); return toolTip; } return QVariant(); }
void QObjectHelper::qvariant2qobject(const QVariantMap& variant, QObject* object) { QStringList properies; const QMetaObject *metaobject = object->metaObject(); int count = metaobject->propertyCount(); for (int i=0; i<count; ++i) { QMetaProperty metaproperty = metaobject->property(i); if (metaproperty.isWritable()) { properies << QLatin1String( metaproperty.name()); } } QVariantMap::const_iterator iter; for (iter = variant.constBegin(); iter != variant.end(); iter++) { if (properies.contains(iter.key())) { object->setProperty(iter.key().toAscii(), iter.value()); } } }