void QpBelongsToOneBase::setObject(const QSharedPointer<QObject> newObject) const
{
    QSharedPointer<QObject> previousObject = object();
    data->cleared = newObject.isNull();
    if(previousObject == newObject)
        return;

    QpMetaProperty reverse = data->metaProperty.reverseRelation();
    data->object = newObject.toWeakRef();
    QSharedPointer<QObject> shared = Qp::sharedFrom(data->parent);

    if(previousObject) {
        if(reverse.isToOneRelationProperty()) {
            QString className = data->metaProperty.metaObject().className();
            reverse.write(previousObject.data(), Qp::Private::variantCast(QSharedPointer<QObject>(), className));
        }
        else {
            QVariant wrapper = Qp::Private::variantCast(shared);

            const QMetaObject *mo = previousObject->metaObject();
            QByteArray methodName = reverse.metaObject().removeObjectMethod(reverse).methodSignature();
            int index = mo->indexOfMethod(methodName);

            Q_ASSERT_X(index > 0, Q_FUNC_INFO,
                       QString("You have to add a public slot with the signature '%1' to your '%2' class!")
                       .arg(QString::fromLatin1(methodName))
                       .arg(mo->className())
                       .toLatin1());

            QMetaMethod method = mo->method(index);

            Q_ASSERT(method.invoke(previousObject.data(), Qt::DirectConnection,
                                   QGenericArgument(data->metaProperty.typeName().toLatin1(), wrapper.data())));
        }
    }

    if(newObject) {
        if(reverse.isToOneRelationProperty()) {
            reverse.write(newObject.data(), Qp::Private::variantCast(shared));
        }
        else {
            QVariant wrapper = Qp::Private::variantCast(shared);

            const QMetaObject *mo = newObject->metaObject();
            QByteArray methodName = reverse.metaObject().addObjectMethod(reverse).methodSignature();
            int index = mo->indexOfMethod(methodName);

            Q_ASSERT_X(index > 0, Q_FUNC_INFO,
                       QString("You have to add a public slot with the signature '%1' to your '%2' class!")
                       .arg(QString::fromLatin1(methodName))
                       .arg(mo->className())
                       .toLatin1());

            QMetaMethod method = mo->method(index);

            Q_ASSERT(method.invoke(newObject.data(), Qt::DirectConnection,
                                   QGenericArgument(data->metaProperty.typeName().toLatin1(), wrapper.data())));
        }
    }

    // Set again, because it may happen, that resetting the previousObjects relation has also reset this value.
    data->object = newObject.toWeakRef();
}
Exemplo n.º 2
0
bool
TwitterPlugin::connectPlugin( bool startup )
{
    qDebug() << Q_FUNC_INFO;

    m_cachedPeers = twitterCachedPeers();
    QList<QString> peerlist = m_cachedPeers.keys();
    qStableSort( peerlist.begin(), peerlist.end() );
    foreach( QString screenName, peerlist )
    {
        QHash< QString, QVariant > cachedPeer = m_cachedPeers[screenName].toHash();
        foreach( QString prop, cachedPeer.keys() )
            qDebug() << "TwitterPlugin : " << screenName << ", key " << prop << ", value " << ( cachedPeer[prop].canConvert< QString >() ? cachedPeer[prop].toString() : QString::number( cachedPeer[prop].toInt() ) );
        QMetaObject::invokeMethod( this, "registerOffer", Q_ARG( QString, screenName ), QGenericArgument( "QHash< QString, QVariant >", (const void*)&cachedPeer ) );
    }
Exemplo n.º 3
0
 foreach (const QVariant &ar, args) {
     vargs.append(QGenericArgument(ar.typeName(), ar.data()));
 }
Exemplo n.º 4
0
void QMetaObjectInvokeMethod(QObject* o, const char *signature, const QList<QVariant>& args){
	QList<QGenericArgument> temp;
	foreach (const QVariant& a, args)
		temp << QGenericArgument(a.typeName(), a.data());
	QMetaObjectInvokeMethod(o, signature, temp);
}
Exemplo n.º 5
0
/*
taken from http://delta.affinix.com/2006/08/14/invokemethodwithvariants/
thanks to Justin Karneges once again :)
*/
bool MaiaXmlRpcServerConnection::invokeMethodWithVariants( QObject *obj,
                                                           const QByteArray &method,
                                                           const QVariantList &args,
                                                           QVariant *ret,
                                                           Qt::ConnectionType type )
{
    // QMetaObject::invokeMethod() has a 10 argument maximum
    if( args.count() > 10 ) {
        return false;
    }

    QList<QByteArray> argTypes;
    for( int n = 0; n < args.count(); ++n ) {
        argTypes += args[n].typeName();
    }

    // get return type
    int metatype = 0;
    QByteArray retTypeName = getReturnType(obj->metaObject(), method, argTypes);
    if( !retTypeName.isEmpty() && retTypeName != "QVariant" ) {
        metatype = QMetaType::type(retTypeName.data());
        if( metatype == 0 ) {
            // lookup failed
            return false;
        }
    }

    QGenericArgument arg[10];
    for( int n = 0; n < args.count(); ++n ) {
        arg[n] = QGenericArgument(args[n].typeName(), args[n].constData());
    }

    QGenericReturnArgument retarg;
    QVariant retval;
    if( metatype != 0 && retTypeName != "void" ) {
        retval = QVariant(metatype, (const void *)0);
        retarg = QGenericReturnArgument(retval.typeName(), retval.data());
    }
    else {
        /* QVariant */
        retarg = QGenericReturnArgument("QVariant", &retval);
    }

    if( retTypeName.isEmpty() || retTypeName == "void" ) {
        /* void */
        if( !QMetaObject::invokeMethod(obj, method.data(), type,
                                       arg[0], arg[1], arg[2], arg[3], arg[4],
                                       arg[5], arg[6], arg[7], arg[8], arg[9]) ) {
            return false;
        }
    }
    else {
        if( !QMetaObject::invokeMethod(obj, method.data(), type, retarg,
                                       arg[0], arg[1], arg[2], arg[3], arg[4],
                                       arg[5], arg[6], arg[7], arg[8], arg[9]) ) {
            return false;
        }
    }

    if( retval.isValid() && ret ) {
        *ret = retval;
    }
    return true;

} // bool invokeMethodWithVariants( QObject *obj, const QByteArray &method, const QVariantList &args, QVariant *ret, Qt::ConnectionType type )
Exemplo n.º 6
0
QVariant QXmppInvokable::dispatch( const QByteArray & method, const QList< QVariant > & args )
{
    buildMethodHash();

    if( !m_methodHash.contains(method))
        return QVariant();

    int idx = m_methodHash[method];
    if( paramTypes( args) != metaObject()->method(idx).parameterTypes ())
        return QVariant();

    const char *typeName = metaObject()->method(idx).typeName();
    int resultType = QMetaType::type(typeName);
    void *result = QMetaType::construct(resultType, 0);

    QGenericReturnArgument ret( typeName, result );
    QList<QGenericArgument> genericArgs;
    QList<QVariant>::ConstIterator iter = args.begin();
    while( iter != args.end())
    {
        const void *data = iter->data();
        const char *name = iter->typeName();
        genericArgs << QGenericArgument(name,data);
        ++iter;
    }

    if( QMetaObject::invokeMethod ( this, method.constData(), ret,
                                    genericArgs.value(0, QGenericArgument() ),
                                    genericArgs.value(1, QGenericArgument() ),
                                    genericArgs.value(2, QGenericArgument() ),
                                    genericArgs.value(3, QGenericArgument() ),
                                    genericArgs.value(4, QGenericArgument() ),
                                    genericArgs.value(5, QGenericArgument() ),
                                    genericArgs.value(6, QGenericArgument() ),
                                    genericArgs.value(7, QGenericArgument() ),
                                    genericArgs.value(8, QGenericArgument() ),
                                    genericArgs.value(9, QGenericArgument() )) )
    {
        QVariant returnValue( resultType, result);
        QMetaType::destroy(resultType, result);
        return returnValue;
    }
    else
    {
        qDebug("No such method '%s'", method.constData() );
        return QVariant();
    }
}
Exemplo n.º 7
0
void CLogisticMainWindow::execAction(const QString &stored, const QVariant &arg)
{
    QGenericArgument genericArgument;

    if (arg.isValid()){
        genericArgument = QGenericArgument(arg.typeName(), arg.data());
    }

    if (activeMdiWindow()){

        if ( CLogisticApplication::instance()->position != nullptr ){
            if ( activeMdiWindow()->accessibleDescription() == CLogisticApplication::instance()->position->metaObject()->className() ) {
                QMetaObject::invokeMethod(CLogisticApplication::instance()->position,
                                          QString("%1").arg(stored).toUtf8().constData(), genericArgument);
            }
        }

        if ( CLogisticApplication::instance()->tasktype != nullptr ) {
            if ( activeMdiWindow()->accessibleDescription() == CLogisticApplication::instance()->tasktype->metaObject()->className() ) {
                QMetaObject::invokeMethod(CLogisticApplication::instance()->tasktype,
                                          QString("%1").arg(stored).toUtf8().constData(), genericArgument);
            }
        }

        if ( CLogisticApplication::instance()->contractortype != nullptr ) {
            if ( activeMdiWindow()->accessibleDescription() == CLogisticApplication::instance()->contractortype->metaObject()->className() ) {
                QMetaObject::invokeMethod(CLogisticApplication::instance()->contractortype,
                                          QString("%1").arg(stored).toUtf8().constData(), genericArgument);
            }
        }

        if ( CLogisticApplication::instance()->status != nullptr ) {
            if ( activeMdiWindow()->accessibleDescription() == CLogisticApplication::instance()->status->metaObject()->className() ) {
                QMetaObject::invokeMethod(CLogisticApplication::instance()->status,
                                          QString("%1").arg(stored).toUtf8().constData(), genericArgument);
            }
        }

        if ( CLogisticApplication::instance()->priority != nullptr ) {
            if ( activeMdiWindow()->accessibleDescription() == CLogisticApplication::instance()->priority->metaObject()->className() ) {
                QMetaObject::invokeMethod(CLogisticApplication::instance()->priority,
                                          QString("%1").arg(stored).toUtf8().constData(), genericArgument);
            }
        }

        if ( CLogisticApplication::instance()->countrycity != nullptr ) {
            if ( activeMdiWindow()->accessibleDescription() == CLogisticApplication::instance()->countrycity->metaObject()->className() ) {
                QMetaObject::invokeMethod(CLogisticApplication::instance()->countrycity,
                                          QString("%1").arg(stored).toUtf8().constData(), genericArgument);
            }
        }

        if ( CLogisticApplication::instance()->customer != nullptr ) {
            if ( activeMdiWindow()->accessibleDescription() == CLogisticApplication::instance()->customer->metaObject()->className() ) {
                QMetaObject::invokeMethod(CLogisticApplication::instance()->customer,
                                          QString("%1").arg(stored).toUtf8().constData(), genericArgument);
            }
        }

        if ( CLogisticApplication::instance()->supplier != nullptr ) {
            if ( activeMdiWindow()->accessibleDescription() == CLogisticApplication::instance()->supplier->metaObject()->className() ) {
                QMetaObject::invokeMethod(CLogisticApplication::instance()->supplier,
                                          QString("%1").arg(stored).toUtf8().constData(), genericArgument);
            }
        }
    }
}