![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qmetaobject.h>
Public Member Functions | |
constexpr | QMetaEnum () |
const char * | name () const |
Returns the name of the type (without the scope). | |
const char * | enumName () const |
Returns the enum name of the flag (without the scope). | |
QMetaType | metaType () const |
Returns the meta type of the enum. | |
bool | isFlag () const |
Returns true if this enumerator is used as a flag; otherwise returns false. | |
bool | isScoped () const |
int | keyCount () const |
Returns the number of keys. | |
const char * | key (int index) const |
Returns the key with the given index, or \nullptr if no such key exists. | |
int | value (int index) const |
Returns the value with the given index; or returns -1 if there is no such value. | |
const char * | scope () const |
Returns the scope this enumerator was declared in. | |
int | keyToValue (const char *key, bool *ok=nullptr) const |
Returns the integer value of the given enumeration key, or -1 if key is not defined. | |
const char * | valueToKey (int value) const |
Returns the string that is used as the name of the given enumeration value, or \nullptr if value is not defined. | |
int | keysToValue (const char *keys, bool *ok=nullptr) const |
Returns the value derived from combining together the values of the keys using the OR operator, or -1 if keys is not defined. | |
QByteArray | valueToKeys (int value) const |
Returns a byte array of '|'-separated keys that represents the given value. | |
const QMetaObject * | enclosingMetaObject () const |
bool | isValid () const |
Returns true if this enum is valid (has a name); otherwise returns false. | |
Static Public Member Functions | |
template<typename T > | |
static QMetaEnum | fromType () |
Friends | |
struct | QMetaObject |
struct | QMetaObjectPrivate |
\inmodule QtCore
The QMetaEnum class provides meta-data about an enumerator.
Use name() for the enumerator's name. The enumerator's keys (names of each enumerated item) are returned by key(); use keyCount() to find the number of keys. isFlag() returns whether the enumerator is meant to be used as a flag, meaning that its values can be combined using the OR operator.
The conversion functions keyToValue(), valueToKey(), keysToValue(), and valueToKeys() allow conversion between the integer representation of an enumeration or set value and its literal representation. The scope() function returns the class scope this enumerator was declared in.
Definition at line 261 of file qmetaobject.h.
|
inlineconstexpr |
Definition at line 264 of file qmetaobject.h.
|
inline |
Definition at line 284 of file qmetaobject.h.
const char * QMetaEnum::enumName | ( | ) | const |
Returns the enum name of the flag (without the scope).
For example, the Qt::AlignmentFlag flag has AlignmentFlag
as the enum name, but Alignment
as the type name. Non flag enums has the same type and enum names.
Enum names have the same scope as the type name.
Definition at line 3036 of file qmetaobject.cpp.
References rawStringData().
Referenced by QMetaObjectBuilder::addEnumerator(), qt_QMetaEnum_debugOperator(), and qt_QMetaEnum_flagDebugOperator().
|
inlinestatic |
Returns the QMetaEnum corresponding to the type in the template parameter. The enum needs to be declared with Q_ENUM.
Definition at line 289 of file qmetaobject.h.
References metaObject().
bool QMetaEnum::isFlag | ( | ) | const |
Returns true
if this enumerator is used as a flag; otherwise returns false.
When used as flags, enumerators can be combined using the OR operator.
Definition at line 3120 of file qmetaobject.cpp.
References EnumIsFlag.
Referenced by QMetaObjectBuilder::addEnumerator(), convertFromEnum(), and QMetaProperty::isFlagType().
bool QMetaEnum::isScoped | ( | ) | const |
Returns true
if this enumerator is declared as a C++11 enum class; otherwise returns false.
Definition at line 3133 of file qmetaobject.cpp.
References EnumIsScoped.
Referenced by QMetaObjectBuilder::addEnumerator(), qt_QMetaEnum_debugOperator(), and qt_QMetaEnum_flagDebugOperator().
|
inline |
Returns true
if this enum is valid (has a name); otherwise returns false.
Definition at line 286 of file qmetaobject.h.
Referenced by convertFromEnum(), convertToEnum(), and QQuickRectangle::setGradient().
const char * QMetaEnum::key | ( | int | index | ) | const |
Returns the key with the given index, or \nullptr if no such key exists.
Definition at line 3087 of file qmetaobject.cpp.
References QMetaObject::d, QMetaObject::Data::data, and rawStringData().
Referenced by QQmlJS::Dom::PathEls::Current::Current(), QQmlJS::Dom::PathEls::Root::Root(), and QMetaObjectBuilder::addEnumerator().
int QMetaEnum::keyCount | ( | ) | const |
Returns the number of keys.
Definition at line 3075 of file qmetaobject.cpp.
Referenced by QQmlJS::Dom::PathEls::Current::Current(), QQmlJS::Dom::PathEls::Root::Root(), QMetaObjectBuilder::addEnumerator(), and queryInputMethod().
int QMetaEnum::keysToValue | ( | const char * | keys, |
bool * | ok = nullptr |
||
) | const |
Returns the value derived from combining together the values of the keys using the OR operator, or -1 if keys is not defined.
Note that the strings in keys must be '|'-separated.
If keys is not defined, *{ok} is set to false; otherwise {ok} is set to true.
Definition at line 3232 of file qmetaobject.cpp.
References QMetaObjectPrivate::className, className, QMetaObject::d, QMetaObject::Data::data, i, keys, ok, parse_scope(), priv(), qTokenize(), and stringDataView().
Referenced by convertToEnum(), QMetaProperty::write(), and QQmlPropertyPrivate::writeEnumProperty().
int QMetaEnum::keyToValue | ( | const char * | key, |
bool * | ok = nullptr |
||
) | const |
Returns the integer value of the given enumeration key, or -1 if key is not defined.
If key is not defined, *{ok} is set to false; otherwise {ok} is set to true.
For flag types, use keysToValue().
Definition at line 3164 of file qmetaobject.cpp.
References QMetaObjectPrivate::className, className, QMetaObject::d, QMetaObject::Data::data, i, ok, priv(), qstrlen(), rawStringData(), scope(), and stringData().
Referenced by QGeoServiceProviderPrivate::features(), QQmlPrivate::AOTCompiledContext::initGetEnumLookup(), QQuickRectangle::setGradient(), toEnumValue(), toEnumValue(), QMetaProperty::write(), and QQmlPropertyPrivate::writeEnumProperty().
QMetaType QMetaEnum::metaType | ( | ) | const |
Returns the meta type of the enum.
If the QMetaObject this enum is part of was generated with Qt 6.5 or earlier this will be the invalid metatype.
Definition at line 3056 of file qmetaobject.cpp.
References QMetaObject::d, QMetaObject::Data::data, QMetaObject::Data::metaTypes, and priv().
Referenced by QMetaObjectBuilder::addEnumerator(), and QQmlPrivate::AOTCompiledContext::initGetEnumLookup().
const char * QMetaEnum::name | ( | ) | const |
Returns the name of the type (without the scope).
For example, the Qt::Key enumeration has Key
as the type name and \l Qt as the scope.
For flags this returns the name of the flag type, not the name of the enum type.
Definition at line 3017 of file qmetaobject.cpp.
References rawStringData().
Referenced by QMetaObjectBuilder::addEnumerator(), QQmlMetaType::clone(), and QMetaProperty::isEnumType().
const char * QMetaEnum::scope | ( | ) | const |
Returns the scope this enumerator was declared in.
For example, the Qt::AlignmentFlag enumeration has Qt
as the scope and AlignmentFlag
as the name.
Definition at line 3148 of file qmetaobject.cpp.
References objectClassName().
Referenced by keyToValue(), qt_QMetaEnum_debugOperator(), and qt_QMetaEnum_flagDebugOperator().
int QMetaEnum::value | ( | int | index | ) | const |
Returns the value with the given index; or returns -1 if there is no such value.
Definition at line 3102 of file qmetaobject.cpp.
References QMetaObject::d, and QMetaObject::Data::data.
Referenced by QQmlJS::Dom::PathEls::Current::Current(), QQmlJS::Dom::PathEls::Root::Root(), QMetaObjectBuilder::addEnumerator(), and queryInputMethod().
const char * QMetaEnum::valueToKey | ( | int | value | ) | const |
Returns the string that is used as the name of the given enumeration value, or \nullptr if value is not defined.
For flag types, use valueToKeys().
Definition at line 3199 of file qmetaobject.cpp.
References QMetaObject::d, QMetaObject::Data::data, i, and rawStringData().
Referenced by QPdfBookmarkModel::QPdfBookmarkModel(), QPdfLinkModel::QPdfLinkModel(), QPdfPageModel::QPdfPageModel(), QPdfSearchModel::QPdfSearchModel(), QQnxButtonEventNotifier::QQnxButtonEventNotifier(), convertFromEnum(), QtDebugUtils::formatQEnum(), formatWidgetAttributes(), QXcbWindow::handleXIMouseEvent(), QTest::Internal::QCborValueFormatter::innerFormat(), QPdfDocument::metaData(), qt_QMetaEnum_debugOperator(), QQuickRectangle::setGradient(), QQmlJS::Dom::FormatTextStatus::stateToString(), QTest::toString(), QTest::Internal::toString(), and QTest::Internal::toString().
QByteArray QMetaEnum::valueToKeys | ( | int | value | ) | const |
Returns a byte array of '|'-separated keys that represents the given value.
Definition at line 3291 of file qmetaobject.cpp.
References QMetaObject::d, QMetaObject::Data::data, i, keys, and stringDataView().
Referenced by convertFromEnum(), QtDebugUtils::formatQFlags(), qt_QMetaEnum_flagDebugOperator(), QTest::Internal::toString(), and QTest::Internal::toString().
|
friend |
Definition at line 316 of file qmetaobject.h.
|
friend |
Definition at line 317 of file qmetaobject.h.