QVariant BluetoothDevicesModel::data(const QModelIndex &index, int role) const { qDebug()<<"requested role: "<<roleNames()[role]; if(!index.isValid() || index.row() < 0) { qDebug()<<"index is not valid: "<<index.row()<<","<<index.column(); return QVariant(); ///this is retarded but it has to be done. } if(roleNames()[role] == "bluetoothDevice") { return QVariant::fromValue<QObject*>((QObject*)m_devices[index.row()]); } QString roleName = roleNames()[role]; QMetaObject object = BluetoothDevice::staticMetaObject; for(int i=0; i<object.propertyCount(); i++) { if(object.property(i).name() == roleName) { return object.property(i).read(m_devices[index.row()]); } } return QVariant(); }
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; }
BluetoothDevicesModel::BluetoothDevicesModel(QObject *parent) : QAbstractListModel(parent), m_connected(false), adapter(NULL) { manager = new OrgBluezManagerInterface( "org.bluez", "/", QDBusConnection::systemBus(), this); connect(manager,SIGNAL(DefaultAdapterChanged(QDBusObjectPath)), this,SLOT(defaultAdapterChanged(QDBusObjectPath))); connect(manager,SIGNAL(AdapterRemoved(QDBusObjectPath)),this,SLOT(adapterRemoved(QDBusObjectPath))); defaultAdapterChanged(manager->DefaultAdapter()); QMetaObject properties = BluetoothDevice::staticMetaObject; for(int i=0; i<properties.propertyCount();i++) { m_roleNames[i]=properties.property(i).name(); } m_roleNames[m_roleNames.keys().count()+1] = "bluetoothDevice"; #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) setRoleNames(m_roleNames); #endif }
QWidget *KasTaskItem::createTaskProps( QObject *target, QWidget *parent, bool recursive ) { QVBox *vb = new QVBox( parent ); vb->setSpacing( KDialog::spacingHint() ); vb->setMargin( KDialog::marginHint() ); // Create List View KListView *taskprops = new KListView( vb, "props_view" ); taskprops->setResizeMode( QListView::LastColumn ); taskprops->addColumn( i18n("Property"), 0 ); taskprops->addColumn( i18n("Type"), 0 ); taskprops->addColumn( i18n("Value") ); // Create List Items QMetaObject *mo = target->metaObject(); for ( int i = 0; i < mo->numProperties( recursive ); i++ ) { const QMetaProperty *p = mo->property(i, recursive); (void) new KListViewItem( taskprops, p->name(), p->type(), target->property( p->name() ).toString() ); } return vb; }
void ImportQMetaObject::import(const QMetaObject& t) { Analitza::BuiltinMethods* b=m_a->builtinMethods(); QByteArray classname(t.className()); classname.replace("::", "_"); for(int p=0; p<t.propertyCount(); p++) { QMetaProperty prop=t.property(p); QByteArray name(prop.name()); if(prop.isReadable()) { QObjectGet* getter=new QObjectGet(name); b->insertFunction(QString(classname+'_'+name), getter->type(classname, prop), getter); } if(prop.isWritable()) { QObjectSet* setter=new QObjectSet(name); b->insertFunction(QString(classname+"_set_"+name), setter->type(classname, prop), setter); } } if(t.superClass()) { QObjectCastToParent *cast = new QObjectCastToParent(t.className(), t.superClass()->className()); b->insertFunction(classname+QStringLiteral("_toParent"), cast->type(), cast); } }
void QtMetaUtilities::setValue(const QMetaObject &metaObject, QObject *object, const QString &propertyName, const QVariant &value) { QString className = QLatin1String(metaObject.className()); if (className == "QObject") return ; int idx = metaObject.indexOfProperty(propertyName.toUtf8().data()); if (idx != -1) metaObject.property(idx).write(object, value); }
QStringList Utils::propertyNames(const QMetaObject& meta) { QStringList names; for (int i = meta.propertyOffset(); i < meta.propertyCount(); ++i) { names << meta.property(i).name(); } return names; }
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; }
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); }
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; }
QVariant QtMetaUtilities::getValue(const QMetaObject &metaObject, const QObject *object, const QString &propertyName) { QVariant retour; QString className = QLatin1String(metaObject.className()); if (className == "QObject") return retour; int idx = metaObject.indexOfProperty(propertyName.toUtf8().data()); if (idx != -1) return metaObject.property(idx).read(object); return retour; }
void JSObjectProxy::put( KJS::ExecState *exec, const KJS::Identifier &p, const KJS::Value &v, int attr ) { if ( !isAllowed( exec->interpreter() ) ) { kdWarning() << "JS put request from unknown interpreter, ignoring" << endl; return ; } if ( !policy->hasCapability( JSSecurityPolicy::CapabilitySetProperties ) ) { ObjectImp::put( exec, p, v, attr ); return ; } if ( !obj ) { kdDebug( 80001 ) << "JS setting '" << p.ascii() << "' but qobj has died" << endl; ObjectImp::put( exec, p, v, attr ); return ; } // Properties QMetaObject *meta = obj->metaObject(); int propIndex = meta->findProperty( p.ascii(), true ); if ( propIndex != -1 ) { QVariant val = convertToVariant( exec, v ); if ( meta->property(propIndex, true)->isEnumType() ) { obj->setProperty( p.ascii(), val.toUInt() ); } else if ( val.isValid() ) { obj->setProperty( p.ascii(), val ); } else { kdWarning(80001) << "Error setting value." << endl; } } else { ObjectImp::put( exec, p, v, attr ); } if ( jspart->factory() ->eventMapper() ->isEventHandler( p ) ) { if ( evproxy.isNull() ) evproxy = new KJSEmbed::JSObjectEventProxy( this ); evproxy->addFilter( jspart->factory() ->eventMapper() ->findEventType( p ) ); kdDebug( 80001 ) << "Adding event handler " << p.ascii() << endl; } }
void CDiagramItem::toXml(QDomElement &n) { QMetaObject *meta = NULL; QMetaProperty prop; QDomDocument doc; QDomElement ext, childNode; QList<QByteArray> props; QStringList filtersOut, filtersIn; CDiagramSerializable *inst = NULL; filtersIn = filterProperties(); filtersOut << "width" << "height" << "x" << "y" << "z" << "pos" << "size" << "parent" << "effect" << "children" << "layout" << "palette"; doc = n.ownerDocument(); ext = doc.createElement( QString("ext") ); childNode = doc.createElement( QString("children") ); n.setAttribute( QString("type"), interType()); n.setAttribute( QString("category"), category() ); n.setAttribute( QString("name"), name() ); n.setAttribute( QString("libCategory"), libraryCategory() ); n.setAttribute( QString("libName"), libraryName() ); n.setAttribute( QString("id"), QString::number(id()) ); meta = const_cast<QMetaObject*>(metaObject()); for (int i = 0; i < meta->propertyCount(); ++i) { QString propName; QByteArray b; QDataStream s(&b, QIODevice::WriteOnly); prop = meta->property(i); propName = QString(prop.name()); if (filtersIn.isEmpty()) { if (filtersOut.contains(propName, Qt::CaseInsensitive) || prop.userType() == 0) { continue; } } else { if (!filtersIn.contains(propName, Qt::CaseInsensitive)) { continue; } } if (prop.isValid() && prop.isReadable()) { s << prop.read(this); QDomElement e = doc.createElement(QString("property")); e.setAttribute( QString("name"), QString(prop.name()) ); e.setAttribute( QString("type"), QString(prop.typeName()) ); e.appendChild( doc.createTextNode( QString(b.toBase64() ) ) ); n.appendChild(e); // qDebug() << "save->name:" << prop.name() << " value:" << prop.read(this); } } props = dynamicPropertyNames(); for (int i = 0; i < props.length(); ++i) { inst = RS_PROPERTY(props.at(i).constData()); // inst = property(props.at(i).constData()).value<CDiagramSerializable*>(); if (inst) { QDomElement c = doc.createElement(QString("child")); c.setAttribute( QString("dynamicProperty"), QString(props.at(i).constData()) ); inst->toXml(c); childNode.appendChild(c); } } n.appendChild(childNode); extToXml( ext ); n.appendChild( ext ); }
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; }
/*!\internal */ void QMetaObject::resolveProperty( QMetaProperty* prop ) { QMetaObject* super = superclass; while ( super ) { const QMetaProperty* p = super->property( prop->n ); if( p ) { if ( qstrcmp( prop->type(), p->type() ) != 0 ) { #if defined(CHECK_STATE) qWarning( "QMetaObject::resolveProperty: Attempt to override property type: %s %s::%s clashes with %s %s::%s", p->type(), super->className(), p->name(), prop->type(), className(), prop->name() ); #endif } if ( prop->get == 0 ) { if ( p->get != 0 ) { prop->get = p->get; prop->gspec = p->gspec; } } if ( prop->set == 0 ) { if ( p->set != 0 ) { prop->set = p->set; prop->sspec = p->sspec; } } if ( prop->testFlags( QMetaProperty::UnresolvedStored ) ) { if ( !p->testFlags( QMetaProperty::UnresolvedStored ) ) { prop->clearFlags( QMetaProperty::UnresolvedStored ); if ( p->testFlags( QMetaProperty::NotStored ) ) prop->setFlags( QMetaProperty::NotStored ); prop->store = p->store; } } if ( prop->testFlags( QMetaProperty::UnresolvedDesignable ) ) { if ( !p->testFlags( QMetaProperty::UnresolvedDesignable ) ) { prop->clearFlags( QMetaProperty::UnresolvedDesignable ); if ( p->testFlags( QMetaProperty::NotDesignable ) ) prop->setFlags( QMetaProperty::NotDesignable ); } } } if ( prop->testFlags( QMetaProperty::UnresolvedEnum | QMetaProperty::UnresolvedSet | QMetaProperty::UnresolvedEnumOrSet ) ) { QMetaEnum* e = super->enumerator( prop->t); if ( e && e->set ) { if ( !prop->testFlags( QMetaProperty::UnresolvedSet | QMetaProperty::UnresolvedEnumOrSet ) ) { #if defined(CHECK_STATE) qWarning("QMetaObject::resolveProperty: The property %s %s::%s assumed that '%s' was listed in Q_ENUMS, but it was listed in Q_SETS", prop->type(), className(), prop->name(), prop->type() ); #endif } prop->enumData = e; prop->clearFlags( QMetaProperty::UnresolvedEnum ); } else if ( e && !e->set ) { if ( !prop->testFlags( QMetaProperty::UnresolvedEnum | QMetaProperty::UnresolvedEnumOrSet ) ) { #if defined(CHECK_STATE) qWarning("QMetaObject::resolveProperty: The property %s %s::%s assumed that '%s' was listed in Q_SETS, but it was listed in Q_ENUMS", prop->type(), className(), prop->name(), prop->type() ); #endif } prop->enumData = e; prop->clearFlags( QMetaProperty::UnresolvedEnum ); } } super = super->superclass; } if ( !prop->isValid() ) { #if defined(CHECK_STATE) qWarning("QMetaObject::resolveProperty: Could not resolve property %s::%s. Property not available.", className(), prop->name() ); #endif } }