summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/kernel/qmetaobject.cpp218
-rw-r--r--src/corelib/kernel/qmetaobject.h18
-rw-r--r--src/corelib/kernel/qmetaobject_p.h4
-rw-r--r--src/corelib/kernel/qmetaobjectbuilder.cpp79
-rw-r--r--src/corelib/kernel/qtmetamacros.h2
5 files changed, 116 insertions, 205 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index 032f3cc019..304bfc522f 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -978,8 +978,9 @@ int QMetaObject::indexOfEnumerator(const char *name) const
const QMetaObject *m = this;
while (m) {
const QMetaObjectPrivate *d = priv(m->d.data);
- for (int i = d->enumeratorCount - 1; i >= 0; --i) {
- const char *prop = rawStringData(m, m->d.data[d->enumeratorData + QMetaObjectPrivate::IntsPerEnum * i]);
+ for (int i = 0; i < d->enumeratorCount; ++i) {
+ const QMetaEnum e(m, i);
+ const char *prop = rawStringData(m, e.data.name());
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
i += m->enumeratorOffset();
return i;
@@ -991,8 +992,9 @@ int QMetaObject::indexOfEnumerator(const char *name) const
m = this;
while (m) {
const QMetaObjectPrivate *d = priv(m->d.data);
- for (int i = d->enumeratorCount - 1; i >= 0; --i) {
- const char *prop = rawStringData(m, m->d.data[d->enumeratorData + QMetaObjectPrivate::IntsPerEnum * i + 1]);
+ for (int i = 0; i < d->enumeratorCount; ++i) {
+ const QMetaEnum e(m, i);
+ const char *prop = rawStringData(m, e.data.alias());
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
i += m->enumeratorOffset();
return i;
@@ -1014,8 +1016,9 @@ int QMetaObject::indexOfProperty(const char *name) const
const QMetaObject *m = this;
while (m) {
const QMetaObjectPrivate *d = priv(m->d.data);
- for (int i = d->propertyCount-1; i >= 0; --i) {
- const char *prop = rawStringData(m, m->d.data[d->propertyData + 3*i]);
+ for (int i = 0; i < d->propertyCount; ++i) {
+ const QMetaProperty p(m, i);
+ const char *prop = rawStringData(m, p.data.name());
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
i += m->propertyOffset();
return i;
@@ -1024,7 +1027,6 @@ int QMetaObject::indexOfProperty(const char *name) const
m = m->d.superdata;
}
- Q_ASSERT(priv(this->d.data)->revision >= 3);
if (priv(this->d.data)->flags & DynamicMetaObject) {
QAbstractDynamicMetaObject *me =
const_cast<QAbstractDynamicMetaObject *>(static_cast<const QAbstractDynamicMetaObject *>(this));
@@ -1118,47 +1120,9 @@ QMetaProperty QMetaObject::property(int index) const
if (i < 0 && d.superdata)
return d.superdata->property(index);
- QMetaProperty result;
- if (i >= 0 && i < priv(d.data)->propertyCount) {
- int handle = priv(d.data)->propertyData + 3*i;
- int flags = d.data[handle + 2];
- result.mobj = this;
- result.handle = handle;
- result.idx = i;
-
- if (flags & EnumOrFlag) {
- const char *type = rawTypeNameFromTypeInfo(this, d.data[handle + 1]);
- result.menum = enumerator(indexOfEnumerator(type));
- if (!result.menum.isValid()) {
- const char *enum_name = type;
- const char *scope_name = objectClassName(this);
- char *scope_buffer = nullptr;
-
- const char *colon = strrchr(enum_name, ':');
- // ':' will always appear in pairs
- Q_ASSERT(colon <= enum_name || *(colon-1) == ':');
- if (colon > enum_name) {
- int len = colon-enum_name-1;
- scope_buffer = (char *)malloc(len+1);
- memcpy(scope_buffer, enum_name, len);
- scope_buffer[len] = '\0';
- scope_name = scope_buffer;
- enum_name = colon+1;
- }
-
- const QMetaObject *scope = nullptr;
- if (qstrcmp(scope_name, "Qt") == 0)
- scope = &Qt::staticMetaObject;
- else
- scope = QMetaObject_findMetaObject(this, scope_name);
- if (scope)
- result.menum = scope->enumerator(scope->indexOfEnumerator(enum_name));
- if (scope_buffer)
- free(scope_buffer);
- }
- }
- }
- return result;
+ if (i >= 0 && i < priv(d.data)->propertyCount)
+ return QMetaProperty(this, i);
+ return QMetaProperty();
}
/*!
@@ -2921,13 +2885,9 @@ QMetaEnum::QMetaEnum(const QMetaObject *mobj, int index)
*/
/*!
+ \fn QMetaProperty::QMetaProperty()
\internal
*/
-QMetaProperty::QMetaProperty()
- : mobj(nullptr), handle(0), idx(0)
-{
-}
-
/*!
Returns this property's name.
@@ -2938,8 +2898,7 @@ const char *QMetaProperty::name() const
{
if (!mobj)
return nullptr;
- int handle = priv(mobj->d.data)->propertyData + 3*idx;
- return rawStringData(mobj, mobj->d.data[handle]);
+ return rawStringData(mobj, data.name());
}
/*!
@@ -2951,8 +2910,7 @@ const char *QMetaProperty::typeName() const
{
if (!mobj)
return nullptr;
- int handle = priv(mobj->d.data)->propertyData + 3*idx;
- return rawTypeNameFromTypeInfo(mobj, mobj->d.data[handle + 1]);
+ return rawTypeNameFromTypeInfo(mobj, data.type());
}
/*!
@@ -3049,9 +3007,7 @@ bool QMetaProperty::isEnumType() const
{
if (!mobj)
return false;
- int handle = priv(mobj->d.data)->propertyData + 3*idx;
- int flags = mobj->d.data[handle + 2];
- return (flags & EnumOrFlag) && menum.name();
+ return (data.flags() & EnumOrFlag) && menum.name();
}
/*!
@@ -3067,9 +3023,7 @@ bool QMetaProperty::hasStdCppSet() const
{
if (!mobj)
return false;
- int handle = priv(mobj->d.data)->propertyData + 3*idx;
- int flags = mobj->d.data[handle + 2];
- return (flags & StdCppSet);
+ return (data.flags() & StdCppSet);
}
/*!
@@ -3086,6 +3040,46 @@ int QMetaProperty::registerPropertyType() const
return registerResult == -1 ? QMetaType::UnknownType : registerResult;
}
+QMetaProperty::QMetaProperty(const QMetaObject *mobj, int index)
+ : mobj(mobj),
+ data({ mobj->d.data + priv(mobj->d.data)->propertyData + index * Data::Size }),
+ idx(index)
+{
+ Q_ASSERT(index >= 0 && index < priv(mobj->d.data)->propertyCount);
+
+ if (data.flags() & EnumOrFlag) {
+ const char *type = rawTypeNameFromTypeInfo(mobj, data.type());
+ menum = mobj->enumerator(mobj->indexOfEnumerator(type));
+ if (!menum.isValid()) {
+ const char *enum_name = type;
+ const char *scope_name = objectClassName(mobj);
+ char *scope_buffer = nullptr;
+
+ const char *colon = strrchr(enum_name, ':');
+ // ':' will always appear in pairs
+ Q_ASSERT(colon <= enum_name || *(colon-1) == ':');
+ if (colon > enum_name) {
+ int len = colon-enum_name-1;
+ scope_buffer = (char *)malloc(len+1);
+ memcpy(scope_buffer, enum_name, len);
+ scope_buffer[len] = '\0';
+ scope_name = scope_buffer;
+ enum_name = colon+1;
+ }
+
+ const QMetaObject *scope = nullptr;
+ if (qstrcmp(scope_name, "Qt") == 0)
+ scope = &Qt::staticMetaObject;
+ else
+ scope = QMetaObject_findMetaObject(mobj, scope_name);
+ if (scope)
+ menum = scope->enumerator(scope->indexOfEnumerator(enum_name));
+ if (scope_buffer)
+ free(scope_buffer);
+ }
+ }
+}
+
/*!
Returns the enumerator if this property's type is an enumerator
type; otherwise the returned value is undefined.
@@ -3269,8 +3263,7 @@ bool QMetaProperty::isResettable() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- return flags & Resettable;
+ return data.flags() & Resettable;
}
/*!
@@ -3282,8 +3275,7 @@ bool QMetaProperty::isReadable() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- return flags & Readable;
+ return data.flags() & Readable;
}
/*!
@@ -3296,8 +3288,7 @@ bool QMetaProperty::hasNotifySignal() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- return flags & Notify;
+ return data.notifyIndex() != uint(-1);
}
/*!
@@ -3327,27 +3318,23 @@ QMetaMethod QMetaProperty::notifySignal() const
*/
int QMetaProperty::notifySignalIndex() const
{
- if (hasNotifySignal()) {
- int offset = priv(mobj->d.data)->propertyData +
- priv(mobj->d.data)->propertyCount * 3 + idx;
- int methodIndex = mobj->d.data[offset];
- if (methodIndex & IsUnresolvedSignal) {
- methodIndex &= ~IsUnresolvedSignal;
- const QByteArray signalName = stringData(mobj, methodIndex);
- const QMetaObject *m = mobj;
- const int idx = indexOfMethodRelative<MethodSignal>(&m, signalName, 0, nullptr);
- if (idx >= 0) {
- return idx + m->methodOffset();
- } else {
- qWarning("QMetaProperty::notifySignal: cannot find the NOTIFY signal %s in class %s for property '%s'",
- signalName.constData(), objectClassName(mobj), name());
- return -1;
- }
- }
- return methodIndex + mobj->methodOffset();
- } else {
+ if (!mobj || data.notifyIndex() == std::numeric_limits<uint>::max())
return -1;
+ uint methodIndex = data.notifyIndex();
+ if (methodIndex & IsUnresolvedSignal) {
+ methodIndex &= ~IsUnresolvedSignal;
+ const QByteArray signalName = stringData(mobj, methodIndex);
+ const QMetaObject *m = mobj;
+ const int idx = indexOfMethodRelative<MethodSignal>(&m, signalName, 0, nullptr);
+ if (idx >= 0) {
+ return idx + m->methodOffset();
+ } else {
+ qWarning("QMetaProperty::notifySignal: cannot find the NOTIFY signal %s in class %s for property '%s'",
+ signalName.constData(), objectClassName(mobj), name());
+ return -1;
+ }
}
+ return methodIndex + mobj->methodOffset();
}
// This method has been around for a while, but the documentation was marked \internal until 5.1
@@ -3361,23 +3348,7 @@ int QMetaProperty::revision() const
{
if (!mobj)
return 0;
- int flags = mobj->d.data[handle + 2];
- if (flags & Revisioned) {
- int offset = priv(mobj->d.data)->propertyData +
- priv(mobj->d.data)->propertyCount * 3 + idx;
- // Revision data is placed after NOTIFY data, if present.
- // Iterate through properties to discover whether we have NOTIFY signals.
- for (int i = 0; i < priv(mobj->d.data)->propertyCount; ++i) {
- int handle = priv(mobj->d.data)->propertyData + 3*i;
- if (mobj->d.data[handle + 2] & Notify) {
- offset += priv(mobj->d.data)->propertyCount;
- break;
- }
- }
- return mobj->d.data[offset];
- } else {
- return 0;
- }
+ return data.revision();
}
/*!
@@ -3390,8 +3361,7 @@ bool QMetaProperty::isWritable() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- return flags & Writable;
+ return data.flags() & Writable;
}
@@ -3409,11 +3379,7 @@ bool QMetaProperty::isDesignable() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- bool b = flags & Designable;
- return b;
-
-
+ return data.flags() & Designable;
}
/*!
@@ -3430,9 +3396,7 @@ bool QMetaProperty::isScriptable() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- bool b = flags & Scriptable;
- return b;
+ return data.flags() & Scriptable;
}
/*!
@@ -3449,9 +3413,7 @@ bool QMetaProperty::isStored() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- bool b = flags & Stored;
- return b;
+ return data.flags() & Stored;
}
/*!
@@ -3471,9 +3433,7 @@ bool QMetaProperty::isUser() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- bool b = flags & User;
- return b;
+ return data.flags() & User;
}
/*!
@@ -3487,8 +3447,7 @@ bool QMetaProperty::isConstant() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- return flags & Constant;
+ return data.flags() & Constant;
}
/*!
@@ -3502,8 +3461,7 @@ bool QMetaProperty::isFinal() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- return flags & Final;
+ return data.flags() & Final;
}
/*!
@@ -3517,8 +3475,7 @@ bool QMetaProperty::isRequired() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- return flags & Required;
+ return data.flags() & Required;
}
/*!
@@ -3532,8 +3489,7 @@ bool QMetaProperty::isQProperty() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- return flags & IsQProperty;
+ return data.flags() & IsQProperty;
}
/*!
@@ -3553,9 +3509,7 @@ bool QMetaProperty::isEditable() const
{
if (!mobj)
return false;
- int flags = mobj->d.data[handle + 2];
- bool b = flags & Editable;
- return b;
+ return data.flags() & Editable;
}
#endif
diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h
index c16cdb129a..0dcc74e120 100644
--- a/src/corelib/kernel/qmetaobject.h
+++ b/src/corelib/kernel/qmetaobject.h
@@ -276,7 +276,7 @@ Q_DECLARE_TYPEINFO(QMetaEnum, Q_MOVABLE_TYPE);
class Q_CORE_EXPORT QMetaProperty
{
public:
- QMetaProperty();
+ constexpr QMetaProperty() : mobj(nullptr), data({ nullptr }), idx(-1) {}
const char *name() const;
const char *typeName() const;
@@ -326,8 +326,22 @@ public:
private:
int registerPropertyType() const;
+ struct Data {
+ enum { Size = 5 };
+
+ uint name() const { return d[0]; }
+ uint type() const { return d[1]; }
+ uint flags() const { return d[2]; }
+ uint notifyIndex() const { return d[3]; }
+ uint revision() const { return d[4]; }
+
+ const uint *d;
+ };
+
+ QMetaProperty(const QMetaObject *mobj, int index);
+
const QMetaObject *mobj;
- uint handle;
+ Data data;
int idx;
QMetaEnum menum;
friend struct QMetaObject;
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h
index e9e3e50472..65d2f8f467 100644
--- a/src/corelib/kernel/qmetaobject_p.h
+++ b/src/corelib/kernel/qmetaobject_p.h
@@ -72,7 +72,6 @@ enum PropertyFlags {
Resettable = 0x00000004,
EnumOrFlag = 0x00000008,
StdCppSet = 0x00000100,
-// Override = 0x00000200,
Constant = 0x00000400,
Final = 0x00000800,
Designable = 0x00001000,
@@ -80,8 +79,6 @@ enum PropertyFlags {
Stored = 0x00010000,
Editable = 0x00040000,
User = 0x00100000,
- Notify = 0x00400000,
- Revisioned = 0x00800000,
Required = 0x01000000,
IsQProperty = 0x02000000
};
@@ -176,6 +173,7 @@ struct QMetaObjectPrivate
enum { OutputRevision = 9 }; // Used by moc, qmetaobjectbuilder and qdbus
enum { IntsPerMethod = QMetaMethod::Data::Size};
enum { IntsPerEnum = QMetaEnum::Data::Size };
+ enum { IntsPerProperty = QMetaProperty::Data::Size };
int revision;
int className;
diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp
index 1212f84bf4..086531501f 100644
--- a/src/corelib/kernel/qmetaobjectbuilder.cpp
+++ b/src/corelib/kernel/qmetaobjectbuilder.cpp
@@ -156,13 +156,10 @@ public:
int _revision = 0)
: name(_name),
type(QMetaObject::normalizedType(_type.constData())),
- flags(Readable | Writable | Scriptable), notifySignal(-1),
+ flags(Readable | Writable | Scriptable), notifySignal(notifierIdx),
revision(_revision)
{
- if (notifierIdx >= 0) {
- flags |= Notify;
- notifySignal = notifierIdx;
- }
+
}
QByteArray name;
@@ -213,7 +210,6 @@ public:
staticMetacallFunction = nullptr;
}
- bool hasRevisionedProperties() const;
bool hasRevisionedMethods() const;
QByteArray className;
@@ -229,15 +225,6 @@ public:
int flags;
};
-bool QMetaObjectBuilderPrivate::hasRevisionedProperties() const
-{
- for (const auto &property : properties) {
- if (property.revision)
- return true;
- }
- return false;
-}
-
bool QMetaObjectBuilderPrivate::hasRevisionedMethods() const
{
for (const auto &method : methods) {
@@ -605,7 +592,6 @@ QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QMetaProperty& protot
if (index == -1)
index = addMethod(method).index();
d->properties[property._index].notifySignal = index;
- d->properties[property._index].setFlag(Notify, true);
}
return property;
}
@@ -879,7 +865,6 @@ void QMetaObjectBuilder::removeMethod(int index)
// Adjust the indices of property notify signal references.
if (property.notifySignal == index) {
property.notifySignal = -1;
- property.setFlag(Notify, false);
} else if (property.notifySignal > index)
property.notifySignal--;
}
@@ -1180,8 +1165,6 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
int enumIndex;
int index;
bool hasRevisionedMethods = d->hasRevisionedMethods();
- bool hasRevisionedProperties = d->hasRevisionedProperties();
- bool hasNotifySignals = false;
if (relocatable &&
(d->relatedMetaObjects.size() > 0 || d->staticMetacallFunction))
@@ -1204,12 +1187,6 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
= reinterpret_cast<QMetaObjectPrivate *>(buf + size);
int pmetaSize = size;
dataIndex = MetaObjectPrivateFieldCount;
- for (const auto &property : d->properties) {
- if (property.notifySignal != -1) {
- hasNotifySignals = true;
- break;
- }
- }
int methodParametersDataSize =
((aggregateParameterCount(d->methods)
+ aggregateParameterCount(d->constructors)) * 2) // types and parameter names
@@ -1236,11 +1213,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
pmeta->propertyCount = int(d->properties.size());
pmeta->propertyData = dataIndex;
- dataIndex += 3 * int(d->properties.size());
- if (hasNotifySignals)
- dataIndex += int(d->properties.size());
- if (hasRevisionedProperties)
- dataIndex += int(d->properties.size());
+ dataIndex += QMetaObjectPrivate::IntsPerProperty * int(d->properties.size());
pmeta->enumeratorCount = int(d->enumerators.size());
pmeta->enumeratorData = dataIndex;
@@ -1256,11 +1229,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
dataIndex += int(d->methods.size());
paramsIndex = dataIndex;
dataIndex += methodParametersDataSize;
- dataIndex += 3 * int(d->properties.size());
- if (hasNotifySignals)
- dataIndex += int(d->properties.size());
- if (hasRevisionedProperties)
- dataIndex += int(d->properties.size());
+ dataIndex += QMetaObjectPrivate::IntsPerProperty * int(d->properties.size());
dataIndex += QMetaObjectPrivate::IntsPerEnum * int(d->enumerators.size());
dataIndex += QMetaObjectPrivate::IntsPerMethod * int(d->constructors.size());
}
@@ -1387,26 +1356,10 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
data[dataIndex] = name;
data[dataIndex + 1] = typeInfo;
data[dataIndex + 2] = flags;
+ data[dataIndex + 3] = prop.notifySignal;
+ data[dataIndex + 4] = prop.revision;
}
- dataIndex += 3;
- }
- if (hasNotifySignals) {
- for (const auto &prop : d->properties) {
- if (buf) {
- if (prop.notifySignal != -1)
- data[dataIndex] = prop.notifySignal;
- else
- data[dataIndex] = 0;
- }
- ++dataIndex;
- }
- }
- if (hasRevisionedProperties) {
- for (const auto &prop : d->properties) {
- if (buf)
- data[dataIndex] = prop.revision;
- ++dataIndex;
- }
+ dataIndex += QMetaObjectPrivate::IntsPerProperty;
}
// Output the enumerators in the class.
@@ -1675,8 +1628,7 @@ void QMetaObjectBuilder::serialize(QDataStream& stream) const
stream << property.type;
stream << property.flags;
stream << property.notifySignal;
- if (property.revision)
- stream << property.revision;
+ stream << property.revision;
}
// Write the enumerators.
@@ -1838,8 +1790,7 @@ void QMetaObjectBuilder::deserialize
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
- if (property.flags & Revisioned)
- stream >> property.revision;
+ stream >> property.revision;
}
// Read the enumerators.
@@ -2202,7 +2153,7 @@ bool QMetaPropertyBuilder::hasNotifySignal() const
{
QMetaPropertyBuilderPrivate *d = d_func();
if (d)
- return d->flag(Notify);
+ return d->notifySignal != -1;
else
return false;
}
@@ -2232,10 +2183,8 @@ void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value)
if (d) {
if (value._mobj) {
d->notifySignal = value._index;
- d->setFlag(Notify, true);
} else {
d->notifySignal = -1;
- d->setFlag(Notify, false);
}
}
}
@@ -2248,10 +2197,8 @@ void QMetaPropertyBuilder::setNotifySignal(const QMetaMethodBuilder& value)
void QMetaPropertyBuilder::removeNotifySignal()
{
QMetaPropertyBuilderPrivate *d = d_func();
- if (d) {
+ if (d)
d->notifySignal = -1;
- d->setFlag(Notify, false);
- }
}
/*!
@@ -2604,10 +2551,8 @@ int QMetaPropertyBuilder::revision() const
void QMetaPropertyBuilder::setRevision(int revision)
{
QMetaPropertyBuilderPrivate *d = d_func();
- if (d) {
+ if (d)
d->revision = revision;
- d->setFlag(Revisioned, revision != 0);
- }
}
diff --git a/src/corelib/kernel/qtmetamacros.h b/src/corelib/kernel/qtmetamacros.h
index 432fd8a49b..4214522e98 100644
--- a/src/corelib/kernel/qtmetamacros.h
+++ b/src/corelib/kernel/qtmetamacros.h
@@ -46,7 +46,7 @@
QT_BEGIN_NAMESPACE
#ifndef Q_MOC_OUTPUT_REVISION
-#define Q_MOC_OUTPUT_REVISION 67
+#define Q_MOC_OUTPUT_REVISION 68
#endif
// The following macros can be defined by tools that understand Qt