📄 qmetaobject.cpp
字号:
if (!mobj) return 0; int handle = priv(mobj->d.data)->propertyData + 3*idx; return mobj->d.stringdata + mobj->d.data[handle + 1];}/*! Returns this property's type. The return value is one of the values of the QVariant::Type enumeration. \sa userType(), typeName(), name()*/QVariant::Type QMetaProperty::type() const{ if (!mobj) return QVariant::Invalid; int handle = priv(mobj->d.data)->propertyData + 3*idx; uint flags = mobj->d.data[handle + 2]; uint type = flags >> 24; if (type == 0xff) // special value for QVariant type = QVariant::LastType; if (type) return QVariant::Type(type); if (isEnumType()) return QVariant::Int; return QVariant::UserType;}/*! \since 4.2 Returns this property's user type. The return value is one of the values that are registered with QMetaType, or 0 if the type is not registered. \sa type(), QMetaType, typeName() */int QMetaProperty::userType() const{ QVariant::Type tp = type(); if (tp != QVariant::UserType) return tp; return QMetaType::type(typeName());}/*! Returns true if the property's type is an enumeration value that is used as a flag; otherwise returns false. Flags can be combined using the OR operator. A flag type is implicitly also an enum type. \sa isEnumType(), enumerator(), QMetaEnum::isFlag()*/bool QMetaProperty::isFlagType() const{ return isEnumType() && menum.isFlag();}/*! Returns true if the property's type is an enumeration value; otherwise returns false. \sa enumerator(), isFlagType()*/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();}/*! \internal Returns true if the property has a C++ setter function that follows Qt's standard "name" / "setName" pattern. Designer and uic query hasStdCppSet() in order to avoid expensive QObject::setProperty() calls. All properties in Qt [should] follow this pattern.*/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);}/*! Returns the enumerator if this property's type is an enumerator type; otherwise the returned value is undefined. \sa isEnumType(), isFlagType()*/QMetaEnum QMetaProperty::enumerator() const{ return menum;}/*! Reads the property's value from the given \a object. Returns the value if it was able to read it; otherwise returns an invalid variant. \sa write(), reset(), isReadable()*/QVariant QMetaProperty::read(const QObject *object) const{ if (!object || !mobj) return QVariant(); uint t = QVariant::Int; if (!isEnumType()) { int handle = priv(mobj->d.data)->propertyData + 3*idx; uint flags = mobj->d.data[handle + 2]; const char *typeName = mobj->d.stringdata + mobj->d.data[handle + 1]; t = (flags >> 24); if (t == 0xff) // special value for QVariant t = QVariant::LastType; if (t == QVariant::Invalid) t = QMetaType::type(typeName); if (t == QVariant::Invalid) t = QVariant::nameToType(typeName); if (t == QVariant::Invalid || t == QVariant::UserType) { if (t == QVariant::Invalid) qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property '%s::%s'", typeName, mobj->className(), name()); return QVariant(); } } QVariant value; void *argv[1]; if (t == QVariant::LastType) { argv[0] = &value; } else { value = QVariant(t, (void*)0); argv[0] = value.data(); } const_cast<QObject*>(object)->qt_metacall(QMetaObject::ReadProperty, idx + mobj->propertyOffset(), argv); if (t != QVariant::LastType && argv[0] != value.data()) return QVariant((QVariant::Type)t, argv[0]); return value;}/*! Writes \a value as the property's value to the given \a object. Returns true if the write succeeded; otherwise returns false. \sa read(), reset(), isWritable()*/bool QMetaProperty::write(QObject *object, const QVariant &value) const{ if (!object || !isWritable()) return false; QVariant v = value; uint t = QVariant::Invalid; if (isEnumType()) { if (v.type() == QVariant::String#ifdef QT3_SUPPORT || v.type() == QVariant::CString#endif ) { if (isFlagType()) v = QVariant(menum.keysToValue(value.toByteArray())); else v = QVariant(menum.keyToValue(value.toByteArray())); } else if (v.type() != QVariant::Int && v.type() != QVariant::UInt) { return false; } v.convert(QVariant::Int); } else { int handle = priv(mobj->d.data)->propertyData + 3*idx; uint flags = mobj->d.data[handle + 2]; const char *typeName = mobj->d.stringdata + mobj->d.data[handle + 1]; t = flags >> 24; if (t == 0xff) // special value for QVariant t = QVariant::LastType; if (t == QVariant::Invalid) { const char *vtypeName = value.typeName(); if (vtypeName && strcmp(typeName, vtypeName) == 0) t = value.userType(); else t = QVariant::nameToType(typeName); } if (t == QVariant::Invalid) return false; if (t != QVariant::LastType && t != (uint)value.userType() && (t < QMetaType::User && !v.convert((QVariant::Type)t))) return false; } void *argv[1]; if (t == QVariant::LastType) argv[0] = &v; else argv[0] = v.data(); object->qt_metacall(QMetaObject::WriteProperty, idx + mobj->propertyOffset(), argv); return true;}/*! Resets the property for the given \a object with a reset method. Returns true if the reset worked; otherwise returns false. Reset methods are optional; only a few properties support them. \sa read(), write()*/bool QMetaProperty::reset(QObject *object) const{ if (!object || !mobj || !isResettable()) return false; void *argv[] = { 0 }; object->qt_metacall(QMetaObject::ResetProperty, idx + mobj->propertyOffset(), argv); return true;}/*! Returns true if this property can be reset to a default value; otherwise returns false. \sa reset()*/bool QMetaProperty::isResettable() const{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; return flags & Resettable;}/*! Returns true if this property is readable; otherwise returns false. \sa isWritable(), read(), isValid() */bool QMetaProperty::isReadable() const{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; return flags & Readable;}/*! Returns true if this property is writable; otherwise returns false. \sa isReadable(), write() */bool QMetaProperty::isWritable() const{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; return flags & Writable;}/*! Returns true if this property is designable for the given \a object; otherwise returns false. If no \a object is given, the function returns false if the \c{Q_PROPERTY()}'s \c DESIGNABLE attribute is false; otherwise returns true (if the attribute is true or is a function or expression). \sa isScriptable(), isStored()*/bool QMetaProperty::isDesignable(const QObject *object) const{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; bool b = flags & Designable; if (object) { void *argv[] = { &b }; const_cast<QObject*>(object)->qt_metacall(QMetaObject::QueryPropertyDesignable, idx + mobj->propertyOffset(), argv); } return b;}/*! Returns true if the property is scriptable for the given \a object; otherwise returns false. If no \a object is given, the function returns false if the \c{Q_PROPERTY()}'s \c SCRIPTABLE attribute is false; otherwise returns true (if the attribute is true or is a function or expression). \sa isDesignable(), isStored()*/bool QMetaProperty::isScriptable(const QObject *object) const{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; bool b = flags & Scriptable; if (object) { void *argv[] = { &b }; const_cast<QObject*>(object)->qt_metacall(QMetaObject::QueryPropertyScriptable, idx + mobj->propertyOffset(), argv); } return b;}/*! Returns true if the property is stored for \a object; otherwise returns false. If no \a object is given, the function returns false if the \c{Q_PROPERTY()}'s \c STORED attribute is false; otherwise returns true (if the attribute is true or is a function or expression). \sa isDesignable(), isScriptable()*/bool QMetaProperty::isStored(const QObject *object) const{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; bool b = flags & Stored; if (object) { void *argv[] = { &b }; const_cast<QObject*>(object)->qt_metacall(QMetaObject::QueryPropertyStored, idx + mobj->propertyOffset(), argv); } return b;}/*! Returns true if this is the property that the user can editable for \a object; otherwise returns false. I.e. the text property is the user editable property of a QLineEdit. If no \a object is given, the function returns false if the \c{Q_PROPERTY()}'s \c USER attribute is false; otherwise returns true (if the attribute is true or is a function or expression). \sa QMetaObject::userProperty(), isDesignable(), isScriptable()*/bool QMetaProperty::isUser(const QObject *object) const{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; bool b = flags & User; if (object) { void *argv[] = { &b }; const_cast<QObject*>(object)->qt_metacall(QMetaObject::QueryPropertyUser, idx + mobj->propertyOffset(), argv); } return b;}/*! \obsolete Returns true if the property is editable for the given \a object; otherwise returns false. If no \a object is given, the function returns false if the \c{Q_PROPERTY()}'s \c EDITABLE attribute is false; otherwise returns true (if the attribute is true or is a function or expression). \sa isDesignable(), isScriptable(), isStored()*/bool QMetaProperty::isEditable(const QObject *object) const{ if (!mobj) return false; int flags = mobj->d.data[handle + 2]; bool b = flags & Editable; if (object) { void *argv[] = { &b }; const_cast<QObject*>(object)->qt_metacall(QMetaObject::QueryPropertyEditable, idx + mobj->propertyOffset(), argv); } return b;}/*! \class QMetaClassInfo \brief The QMetaClassInfo class provides additional information about a class. \ingroup objectmodel Class information items are simple \e{name}--\e{value} pairs that are specified using Q_CLASSINFO() in the source code. The information can be retrieved using name() and value(). For example: \code class MyClass { Q_OBJECT Q_CLASSINFO("author", "Sabrina Schweinsteiger") Q_CLASSINFO("url", "http://doc.moosesoft.co.uk/1.0/") public: ... }; \endcode This mechanism is free for you to use in your Qt applications. Qt doesn't use it for any of its classes. \sa QMetaObject*//*! \fn QMetaClassInfo::QMetaClassInfo() \internal*//*! Returns the name of this item. \sa value()*/const char *QMetaClassInfo::name() const{ if (!mobj) return 0; return mobj->d.stringdata + mobj->d.data[handle];}/*! Returns the value of this item. \sa name()*/const char* QMetaClassInfo::value() const{ if (!mobj) return 0; return mobj->d.stringdata + mobj->d.data[handle + 1];}/*! \macro QGenericArgument Q_ARG(Type, const Type &value) \relates QMetaObject This macro takes a \a Type and a \a value of that type and returns a \l QGenericArgument object that can be passed to QMetaObject::invokeMethod(). \sa Q_RETURN_ARG()*//*! \macro QGenericReturnArgument Q_RETURN_ARG(Type, Type &value) \relates QMetaObject This macro takes a \a Type and a non-const reference to a \a value of that type and returns a QGenericReturnArgument object that can be passed to QMetaObject::invokeMethod(). \sa Q_ARG()*//*! \class QGenericArgument \brief The QGenericArgument class is an internal helper class for marshalling arguments. This class should never be used directly. Please use the \l Q_ARG() macro instead. \sa Q_ARG(), QMetaObject::invokeMethod(), QGenericReturnArgument*//*! \fn QGenericArgument::QGenericArgument(const char *name, const void *data) Constructs a QGenericArgument object with the given \a name and \a data.*//*! \fn QGenericArgument::data () const Returns the data set in the constructor.*//*! \fn QGenericArgument::name () const Returns the name set in the constructor.*//*! \class QGenericReturnArgument \brief The QGenericReturnArgument class is an internal helper class for marshalling arguments. This class should never be used directly. Please use the Q_RETURN_ARG() macro instead. \sa Q_RETURN_ARG(), QMetaObject::invokeMethod(), QGenericArgument*//*! \fn QGenericReturnArgument::QGenericReturnArgument(const char *name, void *data) Constructs a QGenericReturnArgument object with the given \a name and \a data.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -