void QConnectedReplicaPrivate::initializeMetaObject(const QMetaObjectBuilder &builder, const QVariantList &values)
{
    QRemoteObjectReplicaPrivate::initializeMetaObject(builder, values);
    foreach (QRemoteObjectReplica *obj, m_parentsNeedingConnect)
        configurePrivate(obj);
    m_parentsNeedingConnect.clear();

    //initialized and validChanged need to be sent manually, since they are not in the derived classes
    //We should emit initialized before emitting any changed signals in case connections are made in a
    //Slot responding to initialized/validChanged.
    if (isSet.fetchAndStoreRelease(2) > 0) {
        //We are already initialized, now we are valid again
        emitValidChanged();
    } else {
        //We need to send the initialized signal, too
        emitInitialized();
        emitValidChanged();
    }

    void *args[] = {Q_NULLPTR, Q_NULLPTR};
    for (int index = m_metaObject->propertyOffset(); index < m_metaObject->propertyCount(); ++index) {
        const QMetaProperty mp = m_metaObject->property(index);
        if (mp.hasNotifySignal()) {
            qCDebug(QT_REMOTEOBJECT) << " Before activate" << index << m_metaObject->property(index).name();
            args[1] = this->m_propertyStorage[index-m_propertyOffset].data();
            QMetaObject::activate(this, metaObject(), mp.notifySignalIndex(), args);
        }
    }

    qCDebug(QT_REMOTEOBJECT) << "isSet = true for" << m_objectName;
}
void QDeclarativePropertyCache::Data::load(const QMetaProperty &p, QDeclarativeEngine *engine)
{
    propType = p.userType();
    coreIndex = p.propertyIndex();
    notifyIndex = p.notifySignalIndex();
    flags = flagsForProperty(p, engine);
    revision = p.revision();
}
DialogCallbacks::DialogCallbacks(QWidget* dialog, QDeclarativeView* declarative, QObject* view) :
    QObject(dialog),
    m_dialog(dialog),
    m_declarative(declarative),
    m_view(view)
{
    int index = view->metaObject()->indexOfProperty("dialogFullScreen");
    if (index != -1)
    {
        QMetaProperty metaProperty = view->metaObject()->property(index);
        if (metaProperty.hasNotifySignal())
        {
            QMetaObject::connect(view, metaProperty.notifySignalIndex(),
                                 this, metaObject()->indexOfSlot("viewFullScreenChanged()"));
        }
    }

    index = view->metaObject()->indexOfSignal("dialogCloseRequested()");
    if (index != -1)
        QObject::connect(view, SIGNAL(dialogCloseRequested()), dialog, SLOT(close()));

    index = view->metaObject()->indexOfProperty("width");
    if (index != -1)
    {
        QMetaProperty metaProperty = view->metaObject()->property(index);
        if (metaProperty.hasNotifySignal())
        {
            QMetaObject::connect(view, metaProperty.notifySignalIndex(),
                                 this, metaObject()->indexOfSlot("widthChanged()"));
        }
    }

    index = view->metaObject()->indexOfProperty("height");
    if (index != -1)
    {
        QMetaProperty metaProperty = view->metaObject()->property(index);
        if (metaProperty.hasNotifySignal())
        {
            QMetaObject::connect(view, metaProperty.notifySignalIndex(),
                                 this, metaObject()->indexOfSlot("heightChanged()"));
        }
    }

    dialog->installEventFilter(this);
}
示例#4
0
void QDeclarativePropertyCache::Data::load(const QMetaProperty &p, QDeclarativeEngine *engine)
{
    propType = p.userType();
    if (QVariant::Type(propType) == QVariant::LastType)
        propType = qMetaTypeId<QVariant>();
    coreIndex = p.propertyIndex();
    notifyIndex = p.notifySignalIndex();
    flags = flagsForProperty(p, engine);
    revision = p.revision();
}
示例#5
0
void MonitoredDataMapper::addChangeMonitor(QWidget *widget)
{
	// Watch user property of widget for changes, and connect
	//  the signal to our viewModified signal.
	QMetaProperty prop = widget->metaObject()->userProperty();
	int signal = prop.notifySignalIndex();
	int method = this->metaObject()->indexOfMethod("viewModified()");
	if (signal != -1 && method != -1) {
		QMetaObject::connect(widget, signal, this, method);
	}
}
示例#6
0
void QmlProfilerCanvas::componentComplete()
{
    const QMetaObject *metaObject = this->metaObject();
    int propertyCount = metaObject->propertyCount();
    int requestPaintMethod = metaObject->indexOfMethod("requestPaint()");
    for (int ii = QmlProfilerCanvas::staticMetaObject.propertyCount(); ii < propertyCount; ++ii) {
        QMetaProperty p = metaObject->property(ii);
        if (p.hasNotifySignal())
            QMetaObject::connect(this, p.notifySignalIndex(), this, requestPaintMethod, 0, 0);
    }
    QDeclarativeItem::componentComplete();
}
示例#7
0
/*!
    Connects the property's change notifier signal to the
    specified \a method of the \a dest object and returns
    true. Returns false if this metaproperty does not
    represent a regular Qt property or if it has no
    change notifier signal, or if the \a dest object does
    not have the specified \a method.
*/
bool QDeclarativeProperty::connectNotifySignal(QObject *dest, int method) const
{
    if (!(type() & Property) || !d->object)
        return false;

    QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex);
    if (prop.hasNotifySignal()) {
        return QMetaObject::connect(d->object, prop.notifySignalIndex(), dest, method, Qt::DirectConnection);
    } else {
        return false;
    }
}
示例#8
0
/*!
   \brief TreeModel::propertyChanged
   This function is responsible to propagade the changes in the data to
   the GUI.
 */
void TreeModel::propertyChanged()
{
    int propCount   = QObject::sender()->metaObject()->propertyCount();
    int signalIndex = QObject::senderSignalIndex();
    for ( int i = 0; i < propCount; ++i )
    {
        QMetaProperty metaProperty = mp_object->metaObject()->property( i );
        if ( metaProperty.notifySignalIndex() == signalIndex )
        {
            QStandardItem* item = m_propertyIndexToItemMap.value( i );
            updateItem( item, mp_object, metaProperty );
            return;
        }
    }
}
void ObjectStaticPropertyModel::monitorObject(QObject* obj)
{
  for (int i = 0; i < obj->metaObject()->propertyCount(); ++i) {
    const QMetaProperty prop = obj->metaObject()->property(i);
    if (prop.hasNotifySignal()) {
      connect(obj, QByteArray("2") +
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
      prop.notifySignal().signature()
#else
      prop.notifySignal().methodSignature()
#endif
      , this, SLOT(propertyUpdated()));
      m_notifyToPropertyMap.insert(prop.notifySignalIndex(), i);
    }
  }
}
void QDeclarativePropertyCache::Data::lazyLoad(const QMetaProperty &p, QDeclarativeEngine *engine)
{
    Q_UNUSED(engine);

    coreIndex = p.propertyIndex();
    notifyIndex = p.notifySignalIndex();
    revision = p.revision();

    flags = fastFlagsForProperty(p);

    int type = p.type();
    if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) {
        propType = type;
        flags |= QDeclarativePropertyCache::Data::IsQObjectDerived;
    } else if (type == QVariant::UserType || type == -1) {
        propTypeName = p.typeName();
        flags |= QDeclarativePropertyCache::Data::NotFullyResolved;
    } else {
        propType = type;
    }
}
void QMetaPropertyAdaptor::doSetObject(const ObjectInstance& oi)
{
    auto mo = oi.metaObject();
    if (!mo || oi.type() != ObjectInstance::QtObject || !oi.qtObject())
        return;

    connect(oi.qtObject(), SIGNAL(destroyed(QObject*)), this, SIGNAL(objectInvalidated()));

    for (int i = 0; i < mo->propertyCount(); ++i) {
        const QMetaProperty prop = mo->property(i);
        if (prop.hasNotifySignal()) {
            connect(oi.qtObject(), QByteArray("2") +
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
                prop.notifySignal().signature()
#else
                prop.notifySignal().methodSignature()
#endif
                , this, SLOT(propertyUpdated()));
            m_notifyToPropertyMap.insert(prop.notifySignalIndex(), i);
        }
    }
}
示例#12
0
void QDeclarativeVMEMetaObject::connectAlias(int aliasId)
{
    if (!aConnected.testBit(aliasId)) {
        aConnected.setBit(aliasId);

        QDeclarativeContext *context = ctxt->asQDeclarativeContext();
        QDeclarativeContextPrivate *ctxtPriv = QDeclarativeContextPrivate::get(context);

        QDeclarativeVMEMetaData::AliasData *d = metaData->aliasData() + aliasId;

        QObject *target = ctxtPriv->data->idValues[d->contextIdx].data();
        if (!target) 
            return;

        int sigIdx = methodOffset + aliasId + metaData->propertyCount;
        QMetaObject::connect(context, d->contextIdx + ctxtPriv->notifyIndex, object, sigIdx);

        if (!d->isObjectAlias()) {
            QMetaProperty prop = target->metaObject()->property(d->propertyIndex());
            if (prop.hasNotifySignal())
                QDeclarativePropertyPrivate::connect(target, prop.notifySignalIndex(), object, sigIdx);
        }
    }
}
void tst_QQmlMetaObject::property()
{
    QFETCH(QString, testFile);
    QFETCH(QByteArray, cppTypeName);
    QFETCH(int, cppType);
    QFETCH(bool, isDefault);
    QFETCH(QVariant, expectedValue);
    QFETCH(bool, isWritable);
    QFETCH(QVariant, newValue);

    QQmlEngine engine;
    QQmlComponent component(&engine, testFileUrl(testFile));
    QObject *object = component.create();
    QVERIFY(object != 0);

    const QMetaObject *mo = object->metaObject();
    QVERIFY(mo->superClass() != 0);
    QVERIFY(QByteArray(mo->className()).contains("_QML_"));
    QCOMPARE(mo->propertyOffset(), mo->superClass()->propertyCount());
    QCOMPARE(mo->propertyCount(), mo->superClass()->propertyCount() + 1);

    QMetaProperty prop = mo->property(mo->propertyOffset());
    QCOMPARE(prop.name(), "test");

    QCOMPARE(QByteArray(prop.typeName()), cppTypeName);
    if (prop.userType() < QMetaType::User)
        QCOMPARE(prop.type(), QVariant::Type(cppType));
    else
        QCOMPARE(prop.type(), QVariant::UserType);
    QCOMPARE(prop.userType(), cppType);

    QVERIFY(!prop.isConstant());
    QVERIFY(!prop.isDesignable());
    QVERIFY(!prop.isEnumType());
    QVERIFY(!prop.isFinal());
    QVERIFY(!prop.isFlagType());
    QVERIFY(prop.isReadable());
    QVERIFY(!prop.isResettable());
    QVERIFY(prop.isScriptable());
    QVERIFY(!prop.isStored());
    QVERIFY(!prop.isUser());
    QVERIFY(prop.isValid());
    QCOMPARE(prop.isWritable(), isWritable);

    QCOMPARE(mo->classInfoOffset(), mo->superClass()->classInfoCount());
    QCOMPARE(mo->classInfoCount(), mo->superClass()->classInfoCount() + (isDefault ? 1 : 0));
    if (isDefault) {
        QMetaClassInfo info = mo->classInfo(mo->classInfoOffset());
        QCOMPARE(info.name(), "DefaultProperty");
        QCOMPARE(info.value(), "test");
    }

    QCOMPARE(mo->methodOffset(), mo->superClass()->methodCount());
    QCOMPARE(mo->methodCount(), mo->superClass()->methodCount() + 1); // the signal

    QVERIFY(prop.notifySignalIndex() != -1);
    QMetaMethod signal = prop.notifySignal();
    QCOMPARE(signal.methodType(), QMetaMethod::Signal);
    QCOMPARE(signal.name(), QByteArray("testChanged"));
    QCOMPARE(signal.methodSignature(), QByteArray("testChanged()"));
    QCOMPARE(signal.access(), QMetaMethod::Public);
    QCOMPARE(signal.parameterCount(), 0);
    QCOMPARE(signal.parameterTypes(), QList<QByteArray>());
    QCOMPARE(signal.parameterNames(), QList<QByteArray>());
    QCOMPARE(signal.tag(), "");
    QCOMPARE(signal.typeName(), "void");
    QCOMPARE(signal.returnType(), int(QMetaType::Void));

    QSignalSpy changedSpy(object, SIGNAL(testChanged()));
    QObject::connect(object, SIGNAL(testChanged()), object, SLOT(deleteLater()));

    if (expectedValue.isValid())
        QCOMPARE(prop.read(object), expectedValue);
    else
        QVERIFY(prop.read(object).isValid());
    QCOMPARE(changedSpy.count(), 0);

    if (isWritable) {
        QVERIFY(prop.write(object, newValue));
        QCOMPARE(changedSpy.count(), 1);
        QCOMPARE(prop.read(object), newValue);
    } else {
        QVERIFY(!prop.write(object, prop.read(object)));
        QCOMPARE(changedSpy.count(), 0);
    }

    delete object;
}
void serializeInitDynamicPacket(DataStreamPacket &ds, const QRemoteObjectSource *object)
{
    const QMetaObject *meta = object->m_object->metaObject();
    const QMetaObject *adapterMeta = Q_NULLPTR;
    if (object->hasAdapter())
        adapterMeta = object->m_adapter->metaObject();
    const SourceApiMap *api = object->m_api;

    ds.setId(InitDynamicPacket);
    ds << api->name();

    //Now copy the property data
    const int numSignals = api->signalCount();
    ds << quint32(numSignals);  //Number of signals
    const int numMethods = api->methodCount();
    ds << quint32(numMethods);  //Number of methods

    for (int i = 0; i < numSignals; ++i) {
        const int index = api->sourceSignalIndex(i);
        if (index < 0) {
            qCWarning(QT_REMOTEOBJECT) << "QInitDynamicPacketEncoder - Found invalid signal.  Index not found:" << i << "Dropping invalid packet.";
            ds.size = 0;
            return;
        }
        ds << api->signalSignature(i);
    }

    for (int i = 0; i < numMethods; ++i) {
        const int index = api->sourceMethodIndex(i);
        if (index < 0) {
            qCWarning(QT_REMOTEOBJECT) << "QInitDynamicPacketEncoder - Found invalid method.  Index not found:" << i << "Dropping invalid packet.";
            ds.size = 0;
            return;
        }
        ds << api->methodSignature(i);
        ds << api->typeName(i);
    }

    const int numProperties = api->propertyCount();
    ds << quint32(numProperties);  //Number of properties

    for (int i = 0; i < numProperties; ++i) {
        const int index = api->sourcePropertyIndex(i);
        if (index < 0) {
            qCWarning(QT_REMOTEOBJECT) << "QInitDynamicPacketEncoder - Found invalid method.  Index not found:" << i << "Dropping invalid packet.";
            ds.size = 0;
            return;
        }
        if (api->isAdapterProperty(i)) {
            const QMetaProperty mp = adapterMeta->property(index);
            ds << mp.name();
            ds << mp.typeName();
            if (mp.notifySignalIndex() == -1)
                ds << QByteArray();
            else
                ds << mp.notifySignal().methodSignature();
            ds << mp.read(object->m_adapter);
        } else {
            const QMetaProperty mp = meta->property(index);
            ds << mp.name();
            ds << mp.typeName();
            if (mp.notifySignalIndex() == -1)
                ds << QByteArray();
            else
                ds << mp.notifySignal().methodSignature();
            ds << mp.read(object->m_object);
        }
    }
    ds.finishPacket();
}