Example #1
0
QMetaMethod QpMetaObject::method(QString signature, const QpMetaProperty &property) const
{
    QString propertyName = property.name();
    propertyName[0] = propertyName.at(0).toTitleCase();
    QString reverseClassName = property.reverseClassName();
    QMetaMethod method = findMethod(signature.arg(propertyName).arg(reverseClassName));


    if (method.isValid())
        return method;

    QString reverseClassNameWithoutNamespaces = removeNamespaces(reverseClassName);
    if (reverseClassNameWithoutNamespaces == reverseClassName)
        return QMetaMethod();


    method = findMethod(signature.arg(propertyName).arg(reverseClassNameWithoutNamespaces));
    if (method.isValid())
        return method;

    Q_ASSERT_X(false, Q_FUNC_INFO,
               QString("No such method '%1::%2'")
               .arg(data->metaObject.className())

               .arg(signature.arg(propertyName).arg(reverseClassName)).toLatin1());
    return QMetaMethod();
}
void tst_QMetaMethod::comparisonOperators()
{
    static const QMetaObject *mo = &MethodTestObject::staticMetaObject;
    for (int x = 0; x < 2; ++x) {
        int count = x ? mo->constructorCount() : mo->methodCount();
        for (int i = 0; i < count; ++i) {
            QMetaMethod method = x ? mo->constructor(i) : mo->method(i);
            const QMetaObject *methodMo = method.enclosingMetaObject();
            for (int j = 0; j < count; ++j) {
                QMetaMethod other = x ? mo->constructor(j) : mo->method(j);
                bool expectedEqual = ((methodMo == other.enclosingMetaObject())
                                      && (i == j));
                QCOMPARE(method == other, expectedEqual);
                QCOMPARE(method != other, !expectedEqual);
                QCOMPARE(other == method, expectedEqual);
                QCOMPARE(other != method, !expectedEqual);
            }

            QVERIFY(method != QMetaMethod());
            QVERIFY(QMetaMethod() != method);
            QVERIFY(!(method == QMetaMethod()));
            QVERIFY(!(QMetaMethod() == method));
        }
    }

    // Constructors and normal methods with identical index should not
    // compare equal
    for (int i = 0; i < qMin(mo->methodCount(), mo->constructorCount()); ++i) {
        QMetaMethod method = mo->method(i);
        QMetaMethod constructor = mo->constructor(i);
        QVERIFY(method != constructor);
        QVERIFY(!(method == constructor));
    }
}
Example #3
0
/*!
    Return the QMetaMethod for this property if it is a SignalProperty, 
    otherwise returns an invalid QMetaMethod.
*/
QMetaMethod QDeclarativeProperty::method() const
{
    if (type() & SignalProperty && d->object)
        return d->object->metaObject()->method(d->core.coreIndex);
    else
        return QMetaMethod();
}
Example #4
0
QMetaMethod QpMetaObject::findMethod(QString signature) const
{
    QByteArray normalized = QMetaObject::normalizedSignature(signature.toUtf8());
    int index = data->metaObject.indexOfMethod(normalized);

    if (index > 0)
        return data->metaObject.method(index);

    // Remove a possible trailing 's' to match 'many' relations
    signature.remove(signature.indexOf('(') - 1, 1);
    normalized = QMetaObject::normalizedSignature(signature.toUtf8());
    index = data->metaObject.indexOfMethod(normalized);

    if (index > 0)
        return data->metaObject.method(index);

    // Remove a possible trailing 's' to match 'many' relations
    signature.remove(signature.indexOf('(') - 1, 1);
    normalized = QMetaObject::normalizedSignature(signature.toUtf8());
    index = data->metaObject.indexOfMethod(normalized);

    if (index > 0)
        return data->metaObject.method(index);

    // Remove all 's' to even better match 'many' relations
    signature.remove('s');
    normalized = QMetaObject::normalizedSignature(signature.toUtf8());
    index = data->metaObject.indexOfMethod(normalized);

    if (index > 0)
        return data->metaObject.method(index);

    return QMetaMethod();
}
Example #5
0
QMetaMethod QQmlMetaType::defaultMethod(const QMetaObject *metaObject)
{
    int idx = metaObject->indexOfClassInfo("DefaultMethod");
    if (-1 == idx)
        return QMetaMethod();

    QMetaClassInfo info = metaObject->classInfo(idx);
    if (!info.value())
        return QMetaMethod();

    idx = metaObject->indexOfMethod(info.value());
    if (-1 == idx)
        return QMetaMethod();

    return metaObject->method(idx);
}
Example #6
0
QMetaMethod QQmlMetaType::defaultMethod(QObject *obj)
{
    if (!obj)
        return QMetaMethod();

    const QMetaObject *metaObject = obj->metaObject();
    return defaultMethod(metaObject);
}
Example #7
0
QMetaMethod DosQMetaObject::writeSlot(const char *propertyName) const
{
    const auto index = m_propertySlots.value(QString::fromUtf8(propertyName), qMakePair(-1, -1)).second;
    if (index != -1)
        return metaObject()->method(metaObject()->methodOffset() + index);
    if (auto superMetaObject = superClassDosMetaObject())
        return superMetaObject->writeSlot(propertyName);
    return QMetaMethod();
}
Example #8
0
QMetaMethod DosQMetaObject::signal(const QString &signalName) const
{
    const int index = m_signalIndexByName.value(signalName, -1);
    if (index != -1)
        return metaObject()->method(metaObject()->methodOffset() + index);
    if (auto superMetaObject = superClassDosMetaObject())
        return superMetaObject->signal(signalName);
    return QMetaMethod();
}
Example #9
0
QMetaMethod Game::getMetaMethod(QObject *object, QString methodSignature) const
{
    int methodIndex = object->metaObject()->indexOfMethod(QMetaObject::normalizedSignature(methodSignature.toLocal8Bit()));

    if(!object || methodIndex == -1)
        return QMetaMethod();

    return object->metaObject()->method(methodIndex);
}
Example #10
0
QMetaMethod BaseDosQMetaObject::writeSlot(const char *propertyName) const
{
    return QMetaMethod();
}
Example #11
0
QMetaMethod BaseDosQMetaObject::signal(const QString &signalName) const
{
    return QMetaMethod();
}