void QtInstance::getPropertyNames(ExecState* exec, PropertyNameArray& array) { // This is the enumerable properties, so put: // properties // dynamic properties // slots QObject* obj = getObject(); if (obj) { const QMetaObject* meta = obj->metaObject(); int i; for (i = 0; i < meta->propertyCount(); i++) { QMetaProperty prop = meta->property(i); if (prop.isScriptable()) array.add(Identifier(exec, prop.name())); } #ifndef QT_NO_PROPERTIES QList<QByteArray> dynProps = obj->dynamicPropertyNames(); foreach (const QByteArray& ba, dynProps) array.add(Identifier(exec, ba.constData())); #endif const int methodCount = meta->methodCount(); for (i = 0; i < methodCount; i++) { QMetaMethod method = meta->method(i); if (method.access() != QMetaMethod::Private) { QByteArray sig = method.methodSignature(); array.add(Identifier(exec, String(sig.constData(), sig.length()))); } } } }
inline void qx_save(Archive & ar, const QObject & t, const unsigned int file_version) { Q_UNUSED(file_version); QList<QByteArray> propertyKeyList = t.dynamicPropertyNames(); int iPropertyCount = propertyKeyList.count(); std::pair<std::string, QVariant> pair_string_variant; ar << boost::serialization::make_nvp("propertyCount", iPropertyCount); for (long l = 0; l < iPropertyCount; l++) { pair_string_variant.first = propertyKeyList.at(l).constData(); pair_string_variant.second = t.property(pair_string_variant.first.c_str()); ar << boost::serialization::make_nvp("property", pair_string_variant); } }
// ### we may end up with a different search order than QtScript by not // folding this code into the fallbackMethod above, but Fields propagate out // of the binding code Field* QtClass::fieldNamed(const Identifier& identifier, Instance* instance) const { // Check static properties first QtInstance* qtinst = static_cast<QtInstance*>(instance); QObject* obj = qtinst->getObject(); UString ustring = identifier.ustring(); QString objName(QString::fromUtf16((const ushort*)ustring.rep()->data(),ustring.size())); QByteArray ba = objName.toAscii(); // First check for a cached field QtField* f = qtinst->m_fields.value(objName); if (obj) { if (f) { // We only cache real metaproperties, but we do store the // other types so we can delete them later if (f->fieldType() == QtField::MetaProperty) return f; else if (f->fieldType() == QtField::DynamicProperty) { if (obj->dynamicPropertyNames().indexOf(ba) >= 0) return f; else { // Dynamic property that disappeared qtinst->m_fields.remove(objName); delete f; } } else { QList<QObject*> children = obj->children(); for (int index = 0; index < children.count(); ++index) { QObject *child = children.at(index); if (child->objectName() == objName) return f; } // Didn't find it, delete it from the cache qtinst->m_fields.remove(objName); delete f; } } int index = m_metaObject->indexOfProperty(identifier.ascii()); if (index >= 0) { QMetaProperty prop = m_metaObject->property(index); if (prop.isScriptable(obj)) { f = new QtField(prop); qtinst->m_fields.insert(objName, f); return f; } } // Dynamic properties index = obj->dynamicPropertyNames().indexOf(ba); if (index >= 0) { f = new QtField(ba); qtinst->m_fields.insert(objName, f); return f; } // Child objects QList<QObject*> children = obj->children(); for (index = 0; index < children.count(); ++index) { QObject *child = children.at(index); if (child->objectName() == objName) { f = new QtField(child); qtinst->m_fields.insert(objName, f); return f; } } // Nothing named this return 0; } else { QByteArray ba(identifier.ascii()); // For compatibility with qtscript, cached methods don't cause // errors until they are accessed, so don't blindly create an error // here. if (qtinst->m_methods.contains(ba)) return 0; // deleted qobject, but can't throw an error from here (no exec) // create a fake QtField that will throw upon access if (!f) { f = new QtField(ba); qtinst->m_fields.insert(objName, f); } return f; } }
void PropertiesEditorDialog::canvasSelectionChanged() { // Clear the existing properties. QMap<QtProperty *, QString>::ConstIterator itProp = m_property_to_id.constBegin(); while (itProp != m_property_to_id.constEnd()) { delete itProp.key(); itProp++; } m_property_to_id.clear(); m_id_to_property.clear(); if (!m_canvas) { return; } QList<QGraphicsSvgItem *> list = m_canvas->selectedGeneralItems(); QObject *item = m_canvas; int firstProperty = Canvas::staticMetaObject.propertyOffset(); bool canvasItemProperties = false; if (list.count() > 0) { item = list.front(); canvasItemProperties = true; firstProperty = QGraphicsSvgItem::staticMetaObject.propertyOffset(); } QtVariantProperty *property = NULL; const QMetaObject* metaObject = item->metaObject(); QStringList properties; for(int i = firstProperty; i < metaObject->propertyCount(); ++i) { //qDebug("== %s", metaObject->property(i).name()); // Justin: Get rid of the first 2 special properties for QGraphicsSvgItems; it's meaningless to display them. if (QString(metaObject->property(i).name()).compare(QString("elementId")) == 0 || QString(metaObject->property(i).name()).compare(QString("maximumCacheSize")) == 0) continue; const QMetaProperty& prop = metaObject->property(i); int type = prop.userType(); if (type == QVariant::UInt) { type = QVariant::Int; } //qDebug("## %s, %d, %s", prop.name(), prop.userType(), item->property(prop.name()).typeName()); if (prop.isEnumType()) { property = m_variant_manager->addProperty(QtVariantPropertyManager::enumTypeId(), QLatin1String(prop.name())); QMetaEnum metaEnum = prop.enumerator(); QMap<int, bool> valueMap; // dont show multiple enum values which have the same values QStringList enumNames; for (int i = 0; i < metaEnum.keyCount(); i++) { int value = metaEnum.value(i); if (!valueMap.contains(value)) { valueMap[value] = true; enumNames.append(QLatin1String(metaEnum.key(i))); } } property->setAttribute(QLatin1String("enumNames"), enumNames); //qDebug() << prop.name() << "= " << item->property(prop.name()).value<dunnart::Connector::RoutingType>(); int enumValueIndex = *reinterpret_cast<const int *> (item->property(prop.name()).constData()); property->setValue(metaEnum.value(enumValueIndex)); } else if (m_variant_manager->isPropertyTypeSupported(type)) { if (!prop.isWritable()) { property = m_read_only_manager->addProperty(type, QLatin1String(prop.name()) + QLatin1String(" (read-only)")); } else { property = m_variant_manager->addProperty(type, QLatin1String(prop.name())); } property->setValue(item->property(prop.name())); } else { property = m_read_only_manager->addProperty(QVariant::String, QLatin1String(prop.name())); property->setValue(QLatin1String("< Unknown Type >")); property->setEnabled(false); } Q_ASSERT(property); //property->setAttribute(QLatin1String("minimum"), 0); //property->setAttribute(QLatin1String("maximum"), 100); addProperty(property, prop.name()); } QList<QByteArray> propertyList = item->dynamicPropertyNames(); for (int i = 0; i < propertyList.size(); ++i) { //qDebug("-- %s", propertyList.at(i).constData()); const char *propName = propertyList.at(i).constData(); const QVariant& propVariant = item->property(propName); property = m_variant_manager->addProperty(propVariant.userType(), QString(propName)); //property->setAttribute(QLatin1String("minimum"), 0); //property->setAttribute(QLatin1String("maximum"), 100); property->setValue(propVariant); Q_ASSERT(property); addProperty(property, propName); } }
//void PieceAppearanceWidget::applyCurrentTemplate( QObject * tgt ) void PieceAppearanceWidget::applyCurrentTemplate( QGIPiece * tgt ) { if( !tgt ) return; typedef QList<QGraphicsItem*> QIL; QIL li( impl->gv->scene()->selectedItems() ); impl->pc = 0; // If there are multiple items selected, simply pick the first // selected item which has an associated piece (the order has no // meaning, however). for( QIL::iterator it = li.begin(); li.end() != it; ++it ) { QGIPiece * pvi = dynamic_cast<QGIPiece*>(*it); if( pvi ) { impl->pc = pvi; } } if( ! impl->pc ) return; /** We want to keep certain properties intact: pixmap: b/c the game client normally sets this pos: we don't want to use the template's pos dragDisabled: that property was developed to support this class. The client will almost always expect his pieces to be draggable. */ QVariant pix( tgt->property("pixmap") ); QVariant pos( tgt->property("pos") ); QVariant dragDisabled( tgt->property("dragDisabled") ); { #if 0 QObject * src = impl->pc; typedef QList<QByteArray> QL; QL ql( src->dynamicPropertyNames() ); QL::const_iterator it( ql.begin() ); QL::const_iterator et( ql.end() ); for( ; et != it; ++it ) { char const * key = it->constData(); if( !key || (*key == '_') ) continue; // Qt reserves the "_q_" prefix, so we'll elaborate on that. tgt->setProperty( key, src->property(key) ); } #else S11nNode n; impl->pc->serialize(n); // Lame kludge to ensure that we don't throw // here if tgt is a subclass of QGIType: const QString cn1( S11nNodeTraits::class_name(n).c_str() ); const QString cn2( tgt->s11nClass() ); if( cn1 != cn2 ) { S11nNodeTraits::class_name(n,cn2.toAscii().constData()); } tgt->deserialize(n); #endif } tgt->setProperty("pos", pos ); tgt->setProperty("pixmap", pix ); tgt->setProperty("dragDisabled", dragDisabled ); }