Qt 4.8
Public Functions | Properties | Friends | List of all members
QMetaEnum Class Reference

The QMetaEnum class provides meta-data about an enumerator. More...

#include <qmetaobject.h>

Public Functions

const QMetaObjectenclosingMetaObject () const
 
bool isFlag () const
 Returns true if this enumerator is used as a flag; otherwise returns false. More...
 
bool isValid () const
 Returns true if this enum is valid (has a name); otherwise returns false. More...
 
const char * key (int index) const
 Returns the key with the given index, or 0 if no such key exists. More...
 
int keyCount () const
 Returns the number of keys. More...
 
int keysToValue (const char *keys) const
 Returns the value derived from combining together the values of the keys using the OR operator, or -1 if keys is not defined. More...
 
int keyToValue (const char *key) const
 Returns the integer value of the given enumeration key, or -1 if key is not defined. More...
 
const char * name () const
 Returns the name of the enumerator (without the scope). More...
 
 QMetaEnum ()
 
const char * scope () const
 Returns the scope this enumerator was declared in. More...
 
int value (int index) const
 Returns the value with the given index; or returns -1 if there is no such value. More...
 
const char * valueToKey (int value) const
 Returns the string that is used as the name of the given enumeration value, or 0 if value is not defined. More...
 
QByteArray valueToKeys (int value) const
 Returns a byte array of '|'-separated keys that represents the given value. More...
 

Properties

uint handle
 
const QMetaObjectmobj
 

Friends

struct QMetaObject
 

Detailed Description

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.

See also
QMetaObject, QMetaMethod, QMetaProperty

Definition at line 147 of file qmetaobject.h.

Constructors and Destructors

◆ QMetaEnum()

QMetaEnum::QMetaEnum ( )
inline
Warning
This function is not part of the public interface.

Definition at line 150 of file qmetaobject.h.

150 : mobj(0),handle(0) {}
uint handle
Definition: qmetaobject.h:171
const QMetaObject * mobj
Definition: qmetaobject.h:170

Functions

◆ enclosingMetaObject()

const QMetaObject * QMetaEnum::enclosingMetaObject ( ) const
inline
Warning
This function is not part of the public interface.

Definition at line 166 of file qmetaobject.h.

166 { return mobj; }
const QMetaObject * mobj
Definition: qmetaobject.h:170

◆ isFlag()

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.

See also
keysToValue(), valueToKeys()

Definition at line 1935 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addEnumerator(), classIDL(), and QMetaProperty::isFlagType().

1936 {
1937  return mobj && mobj->d.data[handle + 1];
1938 }
uint handle
Definition: qmetaobject.h:171
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * mobj
Definition: qmetaobject.h:170
struct QMetaObject::@38 d

◆ isValid()

bool QMetaEnum::isValid ( ) const
inline

Returns true if this enum is valid (has a name); otherwise returns false.

See also
name()

Definition at line 168 of file qmetaobject.h.

Referenced by QScript::callQtMethod(), and QMetaObject::property().

168 { return name() != 0; }
const char * name() const
Returns the name of the enumerator (without the scope).

◆ key()

const char * QMetaEnum::key ( int  index) const

Returns the key with the given index, or 0 if no such key exists.

See also
keyCount(), value(), valueToKey()

Definition at line 1897 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addEnumerator(), classIDL(), QScript::QMetaObjectWrapperObject::deleteProperty(), QScript::QMetaObjectWrapperObject::getOwnPropertyDescriptor(), QScript::QMetaObjectWrapperObject::getOwnPropertyNames(), QScript::QMetaObjectWrapperObject::getOwnPropertySlot(), QScript::QMetaObjectWrapperObject::put(), and qax_generateDocumentation().

1898 {
1899  if (!mobj)
1900  return 0;
1901  int count = mobj->d.data[handle + 2];
1902  int data = mobj->d.data[handle + 3];
1903  if (index >= 0 && index < count)
1904  return mobj->d.stringdata + mobj->d.data[data + 2*index];
1905  return 0;
1906 }
const char * stringdata
Definition: qobjectdefs.h:470
static const char * data(const QByteArray &arr)
uint handle
Definition: qmetaobject.h:171
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * mobj
Definition: qmetaobject.h:170
struct QMetaObject::@38 d
quint16 index

◆ keyCount()

int QMetaEnum::keyCount ( ) const

◆ keysToValue()

int QMetaEnum::keysToValue ( const char *  keys) 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.

See also
isFlag(), valueToKey(), valueToKeys()

Definition at line 2011 of file qmetaobject.cpp.

Referenced by QDeclarativeCompiler::genLiteralAssignment(), QDeclarativeCompiler::testLiteralAssignment(), QDeclarativeCompiler::testQualifiedEnumAssignment(), QMetaProperty::write(), and QDeclarativePropertyPrivate::writeEnumProperty().

2012 {
2013  if (!mobj)
2014  return -1;
2016  //#### TODO write proper code, do not use QStringList
2017  int value = 0;
2018  int count = mobj->d.data[handle + 2];
2019  int data = mobj->d.data[handle + 3];
2020  for (int li = 0; li < l.size(); ++li) {
2021  QString trimmed = l.at(li).trimmed();
2022  QByteArray qualified_key = trimmed.toLatin1();
2023  const char *key = qualified_key.constData();
2024  uint scope = 0;
2025  const char *s = key + qstrlen(key);
2026  while (s > key && *s != ':')
2027  --s;
2028  if (s > key && *(s-1)==':') {
2029  scope = s - key - 1;
2030  key += scope + 2;
2031  }
2032  int i;
2033  for (i = count-1; i >= 0; --i)
2034  if ((!scope || (qstrlen(mobj->d.stringdata) == scope && strncmp(qualified_key.constData(), mobj->d.stringdata, scope) == 0))
2035  && strcmp(key, mobj->d.stringdata + mobj->d.data[data + 2*i]) == 0) {
2036  value |= mobj->d.data[data + 2*i + 1];
2037  break;
2038  }
2039  if (i < 0)
2040  value |= -1;
2041  }
2042  return value;
2043 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * key(int index) const
Returns the key with the given index, or 0 if no such key exists.
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * stringdata
Definition: qobjectdefs.h:470
const char * scope() const
Returns the scope this enumerator was declared in.
QStringList keys
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
uint handle
Definition: qmetaobject.h:171
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * mobj
Definition: qmetaobject.h:170
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
uint qstrlen(const char *str)
Definition: qbytearray.h:79
QString trimmed(QString source)
Definition: generator.cpp:233
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
struct QMetaObject::@38 d
QFactoryLoader * l
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
int value(int index) const
Returns the value with the given index; or returns -1 if there is no such value.

◆ keyToValue()

int QMetaEnum::keyToValue ( const char *  key) const

Returns the integer value of the given enumeration key, or -1 if key is not defined.

For flag types, use keysToValue().

See also
valueToKey(), isFlag(), keysToValue()

Definition at line 1962 of file qmetaobject.cpp.

Referenced by QScript::callQtMethod(), QAxBase::dynamicCallHelper(), QDeclarativeCompiler::evaluateEnum(), QDeclarativeCompiler::genLiteralAssignment(), QDeclarativeTypeNameScriptClass::queryProperty(), QDeclarativeCompiler::testLiteralAssignment(), QDeclarativeCompiler::testQualifiedEnumAssignment(), QMetaProperty::write(), and QDeclarativePropertyPrivate::writeEnumProperty().

1963 {
1964  if (!mobj || !key)
1965  return -1;
1966  uint scope = 0;
1967  const char *qualified_key = key;
1968  const char *s = key + qstrlen(key);
1969  while (s > key && *s != ':')
1970  --s;
1971  if (s > key && *(s-1)==':') {
1972  scope = s - key - 1;
1973  key += scope + 2;
1974  }
1975  int count = mobj->d.data[handle + 2];
1976  int data = mobj->d.data[handle + 3];
1977  for (int i = 0; i < count; ++i)
1978  if ((!scope || (qstrlen(mobj->d.stringdata) == scope && strncmp(qualified_key, mobj->d.stringdata, scope) == 0))
1979  && strcmp(key, mobj->d.stringdata + mobj->d.data[data + 2*i]) == 0)
1980  return mobj->d.data[data + 2*i + 1];
1981  return -1;
1982 }
const char * key(int index) const
Returns the key with the given index, or 0 if no such key exists.
const char * stringdata
Definition: qobjectdefs.h:470
const char * scope() const
Returns the scope this enumerator was declared in.
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
uint handle
Definition: qmetaobject.h:171
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * mobj
Definition: qmetaobject.h:170
uint qstrlen(const char *str)
Definition: qbytearray.h:79
struct QMetaObject::@38 d

◆ name()

const char * QMetaEnum::name ( ) const

Returns the name of the enumerator (without the scope).

For example, the Qt::AlignmentFlag enumeration has AlignmentFlag as the name and Qt as the scope.

See also
isValid(), scope()

Definition at line 1872 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addEnumerator(), classIDL(), QDeclarativeObjectMethodScriptClass::enumType(), for(), QScript::indexOfMetaEnum(), QMetaProperty::isEnumType(), qax_generateDocumentation(), QDeclarativeBoundSignalParameters::QDeclarativeBoundSignalParameters(), qualifiedName(), and QDeclarativePropertyPrivate::writeEnumProperty().

1873 {
1874  if (!mobj)
1875  return 0;
1876  return mobj->d.stringdata + mobj->d.data[handle];
1877 }
const char * stringdata
Definition: qobjectdefs.h:470
uint handle
Definition: qmetaobject.h:171
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * mobj
Definition: qmetaobject.h:170
struct QMetaObject::@38 d

◆ scope()

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.

See also
name()

Definition at line 1949 of file qmetaobject.cpp.

Referenced by QDeclarativeObjectMethodScriptClass::enumType(), QScript::indexOfMetaEnum(), QDeclarativeBoundSignalParameters::QDeclarativeBoundSignalParameters(), qualifiedName(), and QDeclarativePropertyPrivate::writeEnumProperty().

1950 {
1951  return mobj?mobj->d.stringdata : 0;
1952 }
const char * stringdata
Definition: qobjectdefs.h:470
const QMetaObject * mobj
Definition: qmetaobject.h:170
struct QMetaObject::@38 d

◆ value()

int QMetaEnum::value ( int  index) const

Returns the value with the given index; or returns -1 if there is no such value.

See also
keyCount(), key(), keyToValue()

Definition at line 1914 of file qmetaobject.cpp.

Referenced by QMetaObjectBuilder::addEnumerator(), classIDL(), QScript::QMetaObjectWrapperObject::getOwnPropertyDescriptor(), QScript::QMetaObjectWrapperObject::getOwnPropertySlot(), and qax_generateDocumentation().

1915 {
1916  if (!mobj)
1917  return 0;
1918  int count = mobj->d.data[handle + 2];
1919  int data = mobj->d.data[handle + 3];
1920  if (index >= 0 && index < count)
1921  return mobj->d.data[data + 2*index + 1];
1922  return -1;
1923 }
static const char * data(const QByteArray &arr)
uint handle
Definition: qmetaobject.h:171
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * mobj
Definition: qmetaobject.h:170
struct QMetaObject::@38 d
quint16 index

◆ valueToKey()

const char * QMetaEnum::valueToKey ( int  value) const

Returns the string that is used as the name of the given enumeration value, or 0 if value is not defined.

For flag types, use valueToKeys().

See also
isFlag(), valueToKeys()

Definition at line 1992 of file qmetaobject.cpp.

Referenced by QScript::callQtMethod(), QAxBase::dynamicCallHelper(), QBBButtonEventNotifier::QBBButtonEventNotifier(), QmlJSDebugger::InspectorProtocol::toString(), and QGLEngineSharedShaders::~QGLEngineSharedShaders().

1993 {
1994  if (!mobj)
1995  return 0;
1996  int count = mobj->d.data[handle + 2];
1997  int data = mobj->d.data[handle + 3];
1998  for (int i = 0; i < count; ++i)
1999  if (value == (int)mobj->d.data[data + 2*i + 1])
2000  return mobj->d.stringdata + mobj->d.data[data + 2*i];
2001  return 0;
2002 }
const char * stringdata
Definition: qobjectdefs.h:470
static const char * data(const QByteArray &arr)
uint handle
Definition: qmetaobject.h:171
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * mobj
Definition: qmetaobject.h:170
struct QMetaObject::@38 d
int value(int index) const
Returns the value with the given index; or returns -1 if there is no such value.

◆ valueToKeys()

QByteArray QMetaEnum::valueToKeys ( int  value) const

Returns a byte array of '|'-separated keys that represents the given value.

See also
isFlag(), valueToKey(), keysToValue()

Definition at line 2051 of file qmetaobject.cpp.

2052 {
2053  QByteArray keys;
2054  if (!mobj)
2055  return keys;
2056  int count = mobj->d.data[handle + 2];
2057  int data = mobj->d.data[handle + 3];
2058  int v = value;
2059  for(int i = 0; i < count; i++) {
2060  int k = mobj->d.data[data + 2*i + 1];
2061  if ((k != 0 && (v & k) == k ) || (k == value)) {
2062  v = v & ~k;
2063  if (!keys.isEmpty())
2064  keys += '|';
2065  keys += mobj->d.stringdata + mobj->d.data[data + 2*i];
2066  }
2067  }
2068  return keys;
2069 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const char * stringdata
Definition: qobjectdefs.h:470
QStringList keys
static const char * data(const QByteArray &arr)
uint handle
Definition: qmetaobject.h:171
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * mobj
Definition: qmetaobject.h:170
struct QMetaObject::@38 d
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int value(int index) const
Returns the value with the given index; or returns -1 if there is no such value.

Friends and Related Functions

◆ QMetaObject

friend struct QMetaObject
friend

Definition at line 172 of file qmetaobject.h.

Properties

◆ handle

uint QMetaEnum::handle
private

Definition at line 171 of file qmetaobject.h.

Referenced by QMetaObject::enumerator().

◆ mobj

const QMetaObject* QMetaEnum::mobj
private

Definition at line 170 of file qmetaobject.h.

Referenced by QMetaObject::enumerator().


The documentation for this class was generated from the following files: