diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-08-04 12:27:02 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-08-05 07:51:51 +0000 |
commit | edb1c204c3bc9ad01ccf7a8abb0e8a02fd89ed72 (patch) | |
tree | 0531a08e8a6df7af2a49b794852eb3023e82634f /src/qml/qml/qqmlpropertycache_p.h | |
parent | 48deab9b69afc8d613e2b22dacd138be7c8c51a8 (diff) |
QML: Change the property data flags into a bit field
This will make it easier in follow-up patches to add or remove flags. It
also shrinks the flags, because each type doesn't need its own bit (as
those are mutually exclusive).
Change-Id: I5ba6de5f330eb20c82aa16b4467ed6c952725979
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlpropertycache_p.h')
-rw-r--r-- | src/qml/qml/qqmlpropertycache_p.h | 259 |
1 files changed, 169 insertions, 90 deletions
diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 52e0fdc3bd..bc2e338348 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -84,91 +84,96 @@ template <typename T> class QQmlPropertyCacheAliasCreator; class QQmlPropertyRawData { public: - enum Flag { - NoFlags = 0x00000000, - ValueTypeFlagMask = 0x0000FFFF, // Flags in valueTypeFlags must fit in this mask + struct Flags { + enum Types { + OtherType = 0, + FunctionType = 1, // Is an invokable + QObjectDerivedType = 2, // Property type is a QObject* derived type + EnumType = 3, // Property type is an enum + QListType = 4, // Property type is a QML list + QmlBindingType = 5, // Property type is a QQmlBinding* + QJSValueType = 6, // Property type is a QScriptValue + V4HandleType = 7, // Property type is a QQmlV4Handle + VarPropertyType = 8, // Property type is a "var" property of VMEMO + ValueTypeVirtualType = 9, // Property is a value type "virtual" property + QVariantType = 10 // Property is a QVariant + }; // Can apply to all properties, except IsFunction - IsConstant = 0x00000001, // Has CONST flag - IsWritable = 0x00000002, // Has WRITE function - IsResettable = 0x00000004, // Has RESET function - IsAlias = 0x00000008, // Is a QML alias to another property - IsFinal = 0x00000010, // Has FINAL flag - IsOverridden = 0x00000020, // Is overridden by a extension property - IsDirect = 0x00000040, // Exists on a C++ QMetaObject - HasAccessors = 0x00000080, // Has property accessors - - // These are mutualy exclusive - IsFunction = 0x00000100, // Is an invokable - IsQObjectDerived = 0x00000200, // Property type is a QObject* derived type - IsEnumType = 0x00000400, // Property type is an enum - IsQList = 0x00000800, // Property type is a QML list - IsQmlBinding = 0x00001000, // Property type is a QQmlBinding* - IsQJSValue = 0x00002000, // Property type is a QScriptValue - IsV4Handle = 0x00004000, // Property type is a QQmlV4Handle - IsVarProperty = 0x00008000, // Property type is a "var" property of VMEMO - IsValueTypeVirtual = 0x00010000, // Property is a value type "virtual" property - IsQVariant = 0x00020000, // Property is a QVariant + unsigned isConstant : 1; // Has CONST flag + unsigned isWritable : 1; // Has WRITE function + unsigned isResettable : 1; // Has RESET function + unsigned isAlias : 1; // Is a QML alias to another property + unsigned isFinal : 1; // Has FINAL flag + unsigned isOverridden : 1; // Is overridden by a extension property + unsigned isDirect : 1; // Exists on a C++ QMetaObject + unsigned hasAccessors : 1; // Has property accessors + + unsigned type : 4; // stores an entry of Types // Apply only to IsFunctions - IsVMEFunction = 0x00040000, // Function was added by QML - HasArguments = 0x00080000, // Function takes arguments - IsSignal = 0x00100000, // Function is a signal - IsVMESignal = 0x00200000, // Signal was added by QML - IsV4Function = 0x00400000, // Function takes QQmlV4Function* args - IsSignalHandler = 0x00800000, // Function is a signal handler - IsOverload = 0x01000000, // Function is an overload of another function - IsCloned = 0x02000000, // The function was marked as cloned - IsConstructor = 0x04000000, // The function was marked is a constructor + unsigned isVMEFunction : 1; // Function was added by QML + unsigned hasArguments : 1; // Function takes arguments + unsigned isSignal : 1; // Function is a signal + unsigned isVMESignal : 1; // Signal was added by QML + unsigned isV4Function : 1; // Function takes QQmlV4Function* args + unsigned isSignalHandler : 1; // Function is a signal handler + unsigned isOverload : 1; // Function is an overload of another function + unsigned isCloned : 1; // The function was marked as cloned + unsigned isConstructor : 1; // The function was marked is a constructor // Internal QQmlPropertyCache flags - NotFullyResolved = 0x08000000, // True if the type data is to be lazily resolved + unsigned notFullyResolved : 1; // True if the type data is to be lazily resolved - // Flags that are set based on the propType field - PropTypeFlagMask = IsQObjectDerived | IsEnumType | IsQList | IsQmlBinding | IsQJSValue | - IsV4Handle | IsQVariant, + unsigned _padding : 10; // align to 32 bits + + inline Flags(); + inline bool operator==(const Flags &other) const; + inline void copyPropertyTypeFlags(Flags from); }; - Q_DECLARE_FLAGS(Flags, Flag) - Flags getFlags() const { return Flag(flags); } + Flags getFlags() const { return flags; } void setFlags(Flags f) { flags = f; } bool isValid() const { return coreIndex != -1; } - bool isConstant() const { return flags & IsConstant; } - bool isWritable() const { return flags & IsWritable; } - bool isResettable() const { return flags & IsResettable; } - bool isAlias() const { return flags & IsAlias; } - bool isFinal() const { return flags & IsFinal; } - bool isOverridden() const { return flags & IsOverridden; } - bool isDirect() const { return flags & IsDirect; } - bool hasAccessors() const { return flags & HasAccessors; } - bool isFunction() const { return flags & IsFunction; } - bool isQObject() const { return flags & IsQObjectDerived; } - bool isEnum() const { return flags & IsEnumType; } - bool isQList() const { return flags & IsQList; } - bool isQmlBinding() const { return flags & IsQmlBinding; } - bool isQJSValue() const { return flags & IsQJSValue; } - bool isV4Handle() const { return flags & IsV4Handle; } - bool isVarProperty() const { return flags & IsVarProperty; } - bool isValueTypeVirtual() const { return flags & IsValueTypeVirtual; } - bool isQVariant() const { return flags & IsQVariant; } - bool isVMEFunction() const { return flags & IsVMEFunction; } - bool hasArguments() const { return flags & HasArguments; } - bool isSignal() const { return flags & IsSignal; } - bool isVMESignal() const { return flags & IsVMESignal; } - bool isV4Function() const { return flags & IsV4Function; } - bool isSignalHandler() const { return flags & IsSignalHandler; } - bool isOverload() const { return flags & IsOverload; } - bool isCloned() const { return flags & IsCloned; } - bool isConstructor() const { return flags & IsConstructor; } - - bool hasOverride() const { return !(flags & IsValueTypeVirtual) && - !(flags & HasAccessors) && + bool isConstant() const { return flags.isConstant; } + bool isWritable() const { return flags.isWritable; } + void setWritable(bool onoff) { flags.isWritable = onoff; } + bool isResettable() const { return flags.isResettable; } + bool isAlias() const { return flags.isAlias; } + bool isFinal() const { return flags.isFinal; } + bool isOverridden() const { return flags.isOverridden; } + bool isDirect() const { return flags.isDirect; } + bool hasAccessors() const { return flags.hasAccessors; } + bool isFunction() const { return flags.type == Flags::FunctionType; } + bool isQObject() const { return flags.type == Flags::QObjectDerivedType; } + bool isEnum() const { return flags.type == Flags::EnumType; } + bool isQList() const { return flags.type == Flags::QListType; } + bool isQmlBinding() const { return flags.type == Flags::QmlBindingType; } + bool isQJSValue() const { return flags.type == Flags::QJSValueType; } + bool isV4Handle() const { return flags.type == Flags::V4HandleType; } + bool isVarProperty() const { return flags.type == Flags::VarPropertyType; } + bool isValueTypeVirtual() const { return flags.type == Flags::ValueTypeVirtualType; } + void setAsValueTypeVirtual() { flags.type = Flags::ValueTypeVirtualType; } + bool isQVariant() const { return flags.type == Flags::QVariantType; } + bool isVMEFunction() const { return flags.isVMEFunction; } + bool hasArguments() const { return flags.hasArguments; } + bool isSignal() const { return flags.isSignal; } + bool isVMESignal() const { return flags.isVMESignal; } + bool isV4Function() const { return flags.isV4Function; } + bool isSignalHandler() const { return flags.isSignalHandler; } + bool isOverload() const { return flags.isOverload; } + void setOverload(bool onoff) { flags.isOverload = onoff; } + bool isCloned() const { return flags.isCloned; } + bool isConstructor() const { return flags.isConstructor; } + + bool hasOverride() const { return flags.type != Flags::ValueTypeVirtualType && + !(flags.hasAccessors) && overrideIndex >= 0; } - bool hasRevision() const { return !(flags & HasAccessors) && revision != 0; } + bool hasRevision() const { return !(flags.hasAccessors) && revision != 0; } - bool isFullyResolved() const { return !(flags & NotFullyResolved); } + bool isFullyResolved() const { return !flags.notFullyResolved; } // Returns -1 if not a value type virtual property inline int getValueTypeCoreIndex() const; @@ -195,8 +200,6 @@ public: union { struct { // When IsValueTypeVirtual - quint16 valueTypeFlags; // flags of the access property on the value type proxy - // object quint16 valueTypePropType; // The QVariant::Type of access property on the value // type proxy object quint16 valueTypeCoreIndex; // The prop index of the access property on the value @@ -215,12 +218,13 @@ public: }; int coreIndex; + Flags valueTypeFlags; // flags of the access property on the value type proxy + // object private: friend class QQmlPropertyData; friend class QQmlPropertyCache; - quint32 flags; + Flags flags; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyRawData::Flags) class QQmlPropertyData : public QQmlPropertyRawData { @@ -272,11 +276,28 @@ public: return true; } + static Flags defaultSignalFlags() + { + Flags f; + f.isSignal = true; + f.type = Flags::FunctionType; + f.isVMESignal = true; + return f; + } + + static Flags defaultSlotFlags() + { + Flags f; + f.type = Flags::FunctionType; + f.isVMEFunction = true; + return f; + } + private: friend class QQmlPropertyCache; void lazyLoad(const QMetaProperty &); void lazyLoad(const QMetaMethod &); - bool notFullyResolved() const { return flags & NotFullyResolved; } + bool notFullyResolved() const { return flags.notFullyResolved; } }; class QQmlPropertyCacheMethodArguments; @@ -295,21 +316,21 @@ public: QQmlPropertyCache *copy(); QQmlPropertyCache *copyAndAppend(const QMetaObject *, - QQmlPropertyData::Flag propertyFlags = QQmlPropertyData::NoFlags, - QQmlPropertyData::Flag methodFlags = QQmlPropertyData::NoFlags, - QQmlPropertyData::Flag signalFlags = QQmlPropertyData::NoFlags); + QQmlPropertyRawData::Flags propertyFlags = QQmlPropertyData::Flags(), + QQmlPropertyRawData::Flags methodFlags = QQmlPropertyData::Flags(), + QQmlPropertyRawData::Flags signalFlags = QQmlPropertyData::Flags()); QQmlPropertyCache *copyAndAppend(const QMetaObject *, int revision, - QQmlPropertyData::Flag propertyFlags = QQmlPropertyData::NoFlags, - QQmlPropertyData::Flag methodFlags = QQmlPropertyData::NoFlags, - QQmlPropertyData::Flag signalFlags = QQmlPropertyData::NoFlags); + QQmlPropertyRawData::Flags propertyFlags = QQmlPropertyData::Flags(), + QQmlPropertyRawData::Flags methodFlags = QQmlPropertyData::Flags(), + QQmlPropertyRawData::Flags signalFlags = QQmlPropertyData::Flags()); QQmlPropertyCache *copyAndReserve(int propertyCount, int methodCount, int signalCount); - void appendProperty(const QString &, - quint32 flags, int coreIndex, int propType, int notifyIndex); - void appendSignal(const QString &, quint32, int coreIndex, const int *types = 0, - const QList<QByteArray> &names = QList<QByteArray>()); - void appendMethod(const QString &, quint32 flags, int coreIndex, + void appendProperty(const QString &, QQmlPropertyRawData::Flags flags, int coreIndex, + int propType, int notifyIndex); + void appendSignal(const QString &, QQmlPropertyRawData::Flags, int coreIndex, + const int *types = 0, const QList<QByteArray> &names = QList<QByteArray>()); + void appendMethod(const QString &, QQmlPropertyData::Flags flags, int coreIndex, const QList<QByteArray> &names = QList<QByteArray>()); const QMetaObject *metaObject() const; @@ -382,9 +403,9 @@ private: inline QQmlPropertyCache *copy(int reserve); void append(const QMetaObject *, int revision, - QQmlPropertyData::Flag propertyFlags = QQmlPropertyData::NoFlags, - QQmlPropertyData::Flag methodFlags = QQmlPropertyData::NoFlags, - QQmlPropertyData::Flag signalFlags = QQmlPropertyData::NoFlags); + QQmlPropertyRawData::Flags propertyFlags = QQmlPropertyRawData::Flags(), + QQmlPropertyRawData::Flags methodFlags = QQmlPropertyData::Flags(), + QQmlPropertyRawData::Flags signalFlags = QQmlPropertyData::Flags()); QQmlPropertyCacheMethodArguments *createArgumentsObject(int count, const QList<QByteArray> &names); @@ -518,6 +539,65 @@ public: int *constructorParameterTypes(int index, ArgTypeStorage *dummy, QByteArray *unknownTypeError) const; }; +QQmlPropertyRawData::Flags::Flags() + : isConstant(false) + , isWritable(false) + , isResettable(false) + , isAlias(false) + , isFinal(false) + , isOverridden(false) + , isDirect(false) + , hasAccessors(false) + , type(OtherType) + , isVMEFunction(false) + , hasArguments(false) + , isSignal(false) + , isVMESignal(false) + , isV4Function(false) + , isSignalHandler(false) + , isOverload(false) + , isCloned(false) + , isConstructor(false) + , notFullyResolved(false) + , _padding(0) +{} + +bool QQmlPropertyRawData::Flags::operator==(const QQmlPropertyRawData::Flags &other) const +{ + return isConstant == other.isConstant && + isWritable == other.isWritable && + isResettable == other.isResettable && + isAlias == other.isAlias && + isFinal == other.isFinal && + isOverridden == other.isOverridden && + hasAccessors == other.hasAccessors && + type == other.type && + isVMEFunction == other.isVMEFunction && + hasArguments == other.hasArguments && + isSignal == other.isSignal && + isVMESignal == other.isVMESignal && + isV4Function == other.isV4Function && + isSignalHandler == other.isSignalHandler && + isOverload == other.isOverload && + isCloned == other.isCloned && + isConstructor == other.isConstructor && + notFullyResolved == other.notFullyResolved; +} + +void QQmlPropertyRawData::Flags::copyPropertyTypeFlags(QQmlPropertyRawData::Flags from) +{ + switch (from.type) { + case QObjectDerivedType: + case EnumType: + case QListType: + case QmlBindingType: + case QJSValueType: + case V4HandleType: + case QVariantType: + type = from.type; + } +} + QQmlPropertyData::QQmlPropertyData() { propType = 0; @@ -527,7 +607,6 @@ QQmlPropertyData::QQmlPropertyData() overrideIndex = -1; revision = 0; metaObjectOffset = -1; - flags = 0; } QQmlPropertyData::QQmlPropertyData(const QQmlPropertyRawData &d) |