aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-03-05 08:31:00 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-13 12:58:48 +0100
commit4dd4c442e15a155ff3784f28d6c1ebc68fe8382e (patch)
treee3220da00e3cc22a3a0cfad855db69e2adf8a376 /src/qml
parent4338b35c71060c33e7b0dd026a52b8d845d0b8d4 (diff)
Adapt to Qt5 meta-object changes
QMetaMethod::signature() has been renamed to methodSignature(), and it now returns a QByteArray. Also, the new function QMetaMethod::isValid() should be used to determine whether a method is valid, instead of relying on signature() returning a 0 pointer. Where it makes sense, the existing code that was using signature() and parameterTypes() has been changed to use the new API QMetaMethod::name(), parameterCount(), and parameterType(int). Also, in the new meta-object revision (7), the QMetaObject stringdata member is now of type QByteArrayData*. QFastMetaBuilder will be ported to generate the new format, but for now it's sufficient to reinterpret_cast the stringdata assignment to keep it compiling. Change-Id: Ie340ef17bcebc3afa4aae6450dfe2d06e4d881a4 Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/debugger/qqmlenginedebugservice.cpp6
-rw-r--r--src/qml/qml/ftw/qfastmetabuilder.cpp2
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp4
-rw-r--r--src/qml/qml/qqmlmetatype.cpp9
-rw-r--r--src/qml/qml/qqmlproperty.cpp9
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp79
-rw-r--r--src/qml/qml/qqmlvme.cpp9
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp2
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper.cpp16
9 files changed, 57 insertions, 79 deletions
diff --git a/src/qml/debugger/qqmlenginedebugservice.cpp b/src/qml/debugger/qqmlenginedebugservice.cpp
index 114d7ef63f..76a88029ea 100644
--- a/src/qml/debugger/qqmlenginedebugservice.cpp
+++ b/src/qml/debugger/qqmlenginedebugservice.cpp
@@ -247,10 +247,8 @@ void QQmlEngineDebugService::buildObjectDump(QDataStream &message,
prop.value = expr->expression();
QObject *scope = expr->scopeObject();
if (scope) {
- QString sig = QLatin1String(scope->metaObject()->method(signal->index()).signature());
- int lparen = sig.indexOf(QLatin1Char('('));
- if (lparen >= 0) {
- QString methodName = sig.mid(0, lparen);
+ QString methodName = QLatin1String(scope->metaObject()->method(signal->index()).name().constData());
+ if (!methodName.isEmpty()) {
prop.name = QLatin1String("on") + methodName[0].toUpper()
+ methodName.mid(1);
}
diff --git a/src/qml/qml/ftw/qfastmetabuilder.cpp b/src/qml/qml/ftw/qfastmetabuilder.cpp
index 08ea76b37e..00685f8b28 100644
--- a/src/qml/qml/ftw/qfastmetabuilder.cpp
+++ b/src/qml/qml/ftw/qfastmetabuilder.cpp
@@ -306,7 +306,7 @@ void QFastMetaBuilder::allocateStringData()
void QFastMetaBuilder::fromData(QMetaObject *output, const QMetaObject *parent, const QByteArray &data)
{
output->d.superdata = parent;
- output->d.stringdata = data.constData() + header(data)->fieldCount * sizeof(uint);
+ output->d.stringdata = reinterpret_cast<const QByteArrayData *>(data.constData() + header(data)->fieldCount * sizeof(uint));
output->d.data = fieldPointer(data);
output->d.extradata = 0;
}
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index ca6b13e7f8..02f4941236 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -172,11 +172,11 @@ int QQmlBoundSignal::qt_metacall(QMetaObject::Call c, int id, void **a)
return -1;
if (QQmlDebugService::isDebuggingEnabled())
- QV8DebugService::instance()->signalEmitted(QString::fromAscii(m_signal.signature()));
+ QV8DebugService::instance()->signalEmitted(QString::fromAscii(m_signal.methodSignature().constData()));
QQmlHandlingSignalProfiler prof;
if (prof.enabled) {
- prof.setSignalInfo(QString::fromLatin1(m_signal.signature()),
+ prof.setSignalInfo(QString::fromLatin1(m_signal.methodSignature().constData()),
m_expression->expression());
prof.setLocation(m_expression->sourceFile(), m_expression->lineNumber(),
m_expression->columnNumber());
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 2061530dc5..5b80f57d01 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -340,9 +340,7 @@ static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
QMetaMethod method = mo->method(ii);
// More complex - need to search name
- QByteArray name = method.signature();
- int parenIdx = name.indexOf('(');
- if (parenIdx != -1) name = name.left(parenIdx);
+ QByteArray name = method.name();
bool found = false;
@@ -352,11 +350,8 @@ static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
++ii) {
QMetaMethod other = ignoreEnd->method(ii);
- QByteArray othername = other.signature();
- int parenIdx = othername.indexOf('(');
- if (parenIdx != -1) othername = othername.left(parenIdx);
- found = name == othername;
+ found = name == other.name();
}
QMetaMethodBuilder m = builder.addMethod(method);
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 00cb65d106..86e18229ef 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -333,7 +333,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
signalName[0] = signalName.at(0).toLower();
QMetaMethod method = findSignalByName(currentObject->metaObject(), signalName.toLatin1().constData());
- if (method.signature()) {
+ if (method.isValid()) {
object = currentObject;
core.load(method);
return;
@@ -1707,7 +1707,7 @@ bool QQmlProperty::connectNotifySignal(QObject *dest, const char *slot) const
QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex);
if (prop.hasNotifySignal()) {
- QByteArray signal(QByteArray("2") + prop.notifySignal().signature());
+ QByteArray signal(QByteArray("2") + prop.notifySignal().methodSignature());
return QObject::connect(d->object, signal.constData(), dest, slot);
} else {
return false;
@@ -1813,11 +1813,8 @@ QMetaMethod QQmlPropertyPrivate::findSignalByName(const QMetaObject *mo, const Q
int methods = mo->methodCount();
for (int ii = methods - 1; ii >= 2; --ii) { // >= 2 to block the destroyed signal
QMetaMethod method = mo->method(ii);
- QByteArray methodName = method.signature();
- int idx = methodName.indexOf('(');
- methodName = methodName.left(idx);
- if (methodName == name)
+ if (method.name() == name)
return method;
}
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index 93c6aa1f00..af6cd9285b 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -176,19 +176,11 @@ void QQmlPropertyData::load(const QMetaMethod &m)
flags |= IsFunction;
if (m.methodType() == QMetaMethod::Signal)
flags |= IsSignal;
- propType = QVariant::Invalid;
-
- const char *returnType = m.typeName();
- if (returnType)
- propType = QMetaType::type(returnType);
+ propType = m.returnType();
- const char *signature = m.signature();
- while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
-
- ++signature;
- if (*signature != ')') {
+ if (m.parameterCount()) {
flags |= HasArguments;
- if (0 == ::strcmp(signature, "QQmlV8Function*)")) {
+ if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) {
flags |= IsV8Function;
}
}
@@ -212,13 +204,9 @@ void QQmlPropertyData::lazyLoad(const QMetaMethod &m)
flags |= NotFullyResolved;
}
- const char *signature = m.signature();
- while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
-
- ++signature;
- if (*signature != ')') {
+ if (m.parameterCount()) {
flags |= HasArguments;
- if (0 == ::strcmp(signature, "QQmlV8Function*)")) {
+ if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) {
flags |= IsV8Function;
}
}
@@ -414,10 +402,17 @@ void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject
continue;
// Extract method name
- const char *signature = m.signature();
+ const char *signature;
+ if (QMetaObjectPrivate::get(metaObject)->revision >= 7) {
+ // Safe to use the raw name pointer
+ signature = m.name().constData();
+ } else {
+ // Safe to use the raw signature pointer
+ signature = m.methodSignature().constData();
+ }
const char *cptr = signature;
char utf8 = 0;
- while (*cptr != '(') {
+ while (*cptr && *cptr != '(') {
Q_ASSERT(*cptr != 0);
utf8 |= *cptr & 0x80;
++cptr;
@@ -663,11 +658,7 @@ QString QQmlPropertyData::name(const QMetaObject *metaObject)
if (flags & IsFunction) {
QMetaMethod m = metaObject->method(coreIndex);
- QString name = QString::fromUtf8(m.signature());
- int parenIdx = name.indexOf(QLatin1Char('('));
- if (parenIdx != -1)
- name = name.left(parenIdx);
- return name;
+ return QString::fromUtf8(m.name().constData());
} else {
QMetaProperty p = metaObject->property(coreIndex);
return QString::fromUtf8(p.name());
@@ -727,15 +718,19 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
const QMetaObject *metaObject = object->metaObject();
QMetaMethod m = metaObject->method(index);
- QList<QByteArray> argTypeNames = m.parameterTypes();
- A *args = static_cast<A *>(malloc(sizeof(A) + (argTypeNames.count() + 1) * sizeof(int)));
- args->arguments[0] = argTypeNames.count();
+ int argc = m.parameterCount();
+ A *args = static_cast<A *>(malloc(sizeof(A) + (argc + 1) * sizeof(int)));
+ args->arguments[0] = argc;
+ QList<QByteArray> argTypeNames; // Only loaded if needed
- for (int ii = 0; ii < argTypeNames.count(); ++ii) {
- int type = QMetaType::type(argTypeNames.at(ii));
- if (type == QVariant::Invalid)
+ for (int ii = 0; ii < argc; ++ii) {
+ int type = m.parameterType(ii);
+ if (type == QVariant::Invalid) {
+ if (argTypeNames.isEmpty())
+ argTypeNames = m.parameterTypes();
type = EnumType(object->metaObject(), argTypeNames.at(ii));
+ }
if (type == QVariant::Invalid) {
if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
free(args);
@@ -751,14 +746,18 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
} else {
QMetaMethod m = object->metaObject()->method(index);
- QList<QByteArray> argTypeNames = m.parameterTypes();
- dummy.resize(argTypeNames.count() + 1);
- dummy[0] = argTypeNames.count();
+ int argc = m.parameterCount();
+ dummy.resize(argc + 1);
+ dummy[0] = argc;
+ QList<QByteArray> argTypeNames; // Only loaded if needed
- for (int ii = 0; ii < argTypeNames.count(); ++ii) {
- int type = QMetaType::type(argTypeNames.at(ii));
- if (type == QVariant::Invalid)
+ for (int ii = 0; ii < argc; ++ii) {
+ int type = m.parameterType(ii);
+ if (type == QVariant::Invalid) {
+ if (argTypeNames.isEmpty())
+ argTypeNames = m.parameterTypes();
type = EnumType(object->metaObject(), argTypeNames.at(ii));
+ }
if (type == QVariant::Invalid) {
if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
return 0;
@@ -804,13 +803,9 @@ QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject,
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
continue;
- QString methodName = QString::fromUtf8(m.signature());
-
- int parenIdx = methodName.indexOf(QLatin1Char('('));
- Q_ASSERT(parenIdx != -1);
- QStringRef methodNameRef = methodName.leftRef(parenIdx);
+ QString methodName = QString::fromUtf8(m.name().constData());
- if (methodNameRef == property) {
+ if (methodName == property) {
rv.load(m);
return rv;
}
diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp
index 2b66e00bad..9ef9ca96ef 100644
--- a/src/qml/qml/qqmlvme.cpp
+++ b/src/qml/qml/qqmlvme.cpp
@@ -690,11 +690,14 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
if (prop.type() & QQmlProperty::SignalProperty) {
QMetaMethod method = QQmlMetaType::defaultMethod(assign);
- if (method.signature() == 0)
+ if (!method.isValid())
VME_EXCEPTION(tr("Cannot assign object type %1 with no default method").arg(QString::fromLatin1(assign->metaObject()->className())), instr.line);
- if (!QMetaObject::checkConnectArgs(prop.method().signature(), method.signature()))
- VME_EXCEPTION(tr("Cannot connect mismatched signal/slot %1 %vs. %2").arg(QString::fromLatin1(method.signature())).arg(QString::fromLatin1(prop.method().signature())), instr.line);
+ if (!QMetaObject::checkConnectArgs(prop.method(), method)) {
+ VME_EXCEPTION(tr("Cannot connect mismatched signal/slot %1 %vs. %2")
+ .arg(QString::fromLatin1(method.methodSignature().constData()))
+ .arg(QString::fromLatin1(prop.method().methodSignature().constData())), instr.line);
+ }
QQmlPropertyPrivate::connect(target, prop.index(), assign, method.methodIndex());
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index 7ea89a4a2d..a7af2db837 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -738,7 +738,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
// performance reasons; see QTBUG-24064) and thus compilation will have failed.
QQmlError e;
e.setDescription(QString(QLatin1String("Exception occurred during compilation of function: %1")).
- arg(QLatin1String(QMetaObject::method(_id).signature())));
+ arg(QLatin1String(QMetaObject::method(_id).methodSignature().constData())));
ep->warning(e);
return -1; // The dynamic method with that id is not available.
}
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp
index 4be93d111d..d61ca8b64f 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp
@@ -1673,16 +1673,6 @@ static inline int QMetaObject_methods(const QMetaObject *metaObject)
return reinterpret_cast<const Private *>(metaObject->d.data)->methodCount;
}
-static QByteArray QMetaMethod_name(const QMetaMethod &m)
-{
- QByteArray sig = m.signature();
- int paren = sig.indexOf('(');
- if (paren == -1)
- return sig;
- else
- return sig.left(paren);
-}
-
/*!
Returns the next related method, if one, or 0.
*/
@@ -1711,9 +1701,9 @@ static const QQmlPropertyData * RelatedMethod(QObject *object,
dummy.load(method);
// Look for overloaded methods
- QByteArray methodName = QMetaMethod_name(method);
+ QByteArray methodName = method.name();
for (int ii = current->overrideIndex - 1; ii >= methodOffset; --ii) {
- if (methodName == QMetaMethod_name(mo->method(ii))) {
+ if (methodName == mo->method(ii).name()) {
dummy.setFlags(dummy.getFlags() | QQmlPropertyData::IsOverload);
dummy.overrideIndexIsProperty = 0;
dummy.overrideIndex = ii;
@@ -1827,7 +1817,7 @@ static v8::Handle<v8::Value> CallOverloaded(QObject *object, const QQmlPropertyD
const QQmlPropertyData *candidate = &data;
while (candidate) {
error += QLatin1String("\n ") +
- QString::fromUtf8(object->metaObject()->method(candidate->coreIndex).signature());
+ QString::fromUtf8(object->metaObject()->method(candidate->coreIndex).methodSignature().constData());
candidate = RelatedMethod(object, candidate, dummy);
}