本文整理汇总了C++中QMetaEnum类的典型用法代码示例。如果您正苦于以下问题:C++ QMetaEnum类的具体用法?C++ QMetaEnum怎么用?C++ QMetaEnum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QMetaEnum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qtscript_construct_QAbstractSpinBox_CorrectionMode
static QScriptValue qtscript_construct_QAbstractSpinBox_CorrectionMode(QScriptContext *context, QScriptEngine *engine)
{
int arg = context->argument(0).toInt32();
const QMetaObject *meta = qtscript_QAbstractSpinBox_metaObject();
int idx = meta->indexOfEnumerator("CorrectionMode");
Q_ASSERT(idx != -1);
QMetaEnum menum = meta->enumerator(idx);
if (menum.valueToKey(arg) != 0)
return qScriptValueFromValue(engine, static_cast<QAbstractSpinBox::CorrectionMode>(arg));
return context->throwError(QString::fromLatin1("CorrectionMode(): invalid enum value (%0)").arg(arg));
}
示例2: qtscript_construct_QFontDialog_FontDialogOption
static QScriptValue qtscript_construct_QFontDialog_FontDialogOption(QScriptContext *context, QScriptEngine *engine)
{
int arg = context->argument(0).toInt32();
const QMetaObject *meta = qtscript_QFontDialog_metaObject();
int idx = meta->indexOfEnumerator("FontDialogOption");
Q_ASSERT(idx != -1);
QMetaEnum menum = meta->enumerator(idx);
if (menum.valueToKey(arg) != 0)
return qScriptValueFromValue(engine, static_cast<QFontDialog::FontDialogOption>(arg));
return context->throwError(QString::fromLatin1("FontDialogOption(): invalid enum value (%0)").arg(arg));
}
示例3: rowCount
int ObjectEnumModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid()) {
return SuperClass::rowCount(parent);
}
if (parent.parent().isValid()) {
return 0;
}
const QMetaEnum e = m_object.data()->metaObject()->enumerator(parent.row());
return e.keyCount();
}
示例4: indexForFormat
int BookStyleItem::indexForFormat(Format::Type type)
{
static const int foregroundsIndex = staticMetaObject.indexOfEnumerator("ForegroundColorType");
static const QMetaEnum foregrounds = staticMetaObject.enumerator(foregroundsIndex);
static const int typesIndex = Format::staticMetaObject.indexOfEnumerator("Type");
static const QMetaEnum types = Format::staticMetaObject.enumerator(typesIndex);
const char *key = types.valueToKey(type);
return foregrounds.keyToValue(key);
}
示例5: qtscript_construct_QComboBox_SizeAdjustPolicy
static QScriptValue qtscript_construct_QComboBox_SizeAdjustPolicy(QScriptContext *context, QScriptEngine *engine)
{
int arg = context->argument(0).toInt32();
const QMetaObject *meta = qtscript_QComboBox_metaObject();
int idx = meta->indexOfEnumerator("SizeAdjustPolicy");
Q_ASSERT(idx != -1);
QMetaEnum menum = meta->enumerator(idx);
if (menum.valueToKey(arg) != 0)
return qScriptValueFromValue(engine, static_cast<QComboBox::SizeAdjustPolicy>(arg));
return context->throwError(QString::fromLatin1("SizeAdjustPolicy(): invalid enum value (%0)").arg(arg));
}
示例6: mp
QStringList Country::getCountryNames() {
if (sCountryNames.isEmpty()) {
Country cc;
QMetaProperty mp(cc.metaProperty("val"));
QMetaEnum qmen = mp.enumerator();
for (int i=0; i<qmen.keyCount(); ++i) {
sCountryNames += qmen.valueToKey(i);
}
}
return sCountryNames;
}
示例7: rulesTypeFromString
static core::WorldRules::Type rulesTypeFromString(const char* str)
{
const QMetaEnum metaEnum{QMetaEnum::fromType<core::WorldRules::Type>()};
bool ok{true};
auto e = metaEnum.keyToValue(str, &ok);
if (!ok)
throw utils::ValueError("Failed to unserialize RulesType");
return static_cast<core::WorldRules::Type>(e);
}
示例8: QAbstractTableModel
PaletteModel::PaletteModel(QObject *parent) :
QAbstractTableModel(parent),
m_compute(true)
{
const QMetaObject *meta = metaObject();
const int index = meta->indexOfProperty("colorRole");
const QMetaProperty p = meta->property(index);
const QMetaEnum e = p.enumerator();
for (int r = QPalette::WindowText; r < QPalette::NColorRoles; r++) {
m_roleNames[static_cast<QPalette::ColorRole>(r)] = QLatin1String(e.key(r));
}
}
示例9: settingsValueChanged
void Terrain3D::loadUserSettings()
{
const QMetaObject &mo = Settings::staticMetaObject;
const QMetaEnum me = mo.enumerator(mo.indexOfEnumerator("Key"));
//loop through every Settings::Key and tell ourself that a value has
//changed to effectively load the value
for (int i=0; i<me.keyCount(); i++)
{
Settings::Key key = static_cast<Settings::Key>(me.value(i));
settingsValueChanged(key, mMainSettings->value(key));
}
}
示例10: metaData
QVariant ObjectEnumModel::metaData(const QModelIndex &index,
const QMetaEnum &enumerator, int role) const
{
if (role == Qt::DisplayRole) {
if (index.column() == 0) {
return QString::fromLatin1(enumerator.name());
}
if (index.column() == 1) {
return tr("%n element(s)", "", enumerator.keyCount());
}
}
return QVariant();
}
示例11: pix
void Window::createCurveIcons()
{
QPixmap pix(m_iconSize);
QPainter painter(&pix);
QLinearGradient gradient(0,0, 0, m_iconSize.height());
gradient.setColorAt(0.0, QColor(240, 240, 240));
gradient.setColorAt(1.0, QColor(224, 224, 224));
QBrush brush(gradient);
const QMetaObject &mo = QEasingCurve::staticMetaObject;
QMetaEnum metaEnum = mo.enumerator(mo.indexOfEnumerator("Type"));
// Skip QEasingCurve::Custom
for (int i = 0; i < QEasingCurve::NCurveTypes - 1; ++i) {
painter.fillRect(QRect(QPoint(0, 0), m_iconSize), brush);
QEasingCurve curve((QEasingCurve::Type)i);
painter.setPen(QColor(0, 0, 255, 64));
qreal xAxis = m_iconSize.height()/1.5;
qreal yAxis = m_iconSize.width()/3;
painter.drawLine(0, xAxis, m_iconSize.width(), xAxis);
painter.drawLine(yAxis, 0, yAxis, m_iconSize.height());
qreal curveScale = m_iconSize.height()/2;
painter.setPen(Qt::NoPen);
// start point
painter.setBrush(Qt::red);
QPoint start(yAxis, xAxis - curveScale * curve.valueForProgress(0));
painter.drawRect(start.x() - 1, start.y() - 1, 3, 3);
// end point
painter.setBrush(Qt::blue);
QPoint end(yAxis + curveScale, xAxis - curveScale * curve.valueForProgress(1));
painter.drawRect(end.x() - 1, end.y() - 1, 3, 3);
QPainterPath curvePath;
curvePath.moveTo(start);
for (qreal t = 0; t <= 1.0; t+=1.0/curveScale) {
QPoint to;
to.setX(yAxis + curveScale * t);
to.setY(xAxis - curveScale * curve.valueForProgress(t));
curvePath.lineTo(to);
}
painter.setRenderHint(QPainter::Antialiasing, true);
painter.strokePath(curvePath, QColor(32, 32, 32));
painter.setRenderHint(QPainter::Antialiasing, false);
QListWidgetItem *item = new QListWidgetItem;
item->setIcon(QIcon(pix));
item->setText(metaEnum.key(i));
m_ui.easingCurvePicker->addItem(item);
}
}
示例12: QString
void GCF::Components::EnumEditorCreator::initialize(QWidget* editor, QMetaEnum enumStruct)
{
QComboBox* combo = qobject_cast<QComboBox*>(editor);
if(!combo)
return;
for(int i=enumStruct.keyCount()-1; i>=0; i--)
{
QString key = QString("%1").arg(enumStruct.key(i));
int value = enumStruct.value(i);
combo->insertItem(0, key);
combo->setItemData(0, value);
}
}
示例13: enumToInt
int ObjectControllerPrivate::enumToInt(const QMetaEnum &metaEnum, int enumValue) const
{
QMap<int, int> valueMap; // dont show multiple enum values which have the same values
int pos = 0;
for (int i = 0; i < metaEnum.keyCount(); i++) {
int value = metaEnum.value(i);
if (!valueMap.contains(value)) {
if (value == enumValue)
return pos;
valueMap[value] = pos++;
}
}
return -1;
}
示例14: metaObject
void SimpleLoggerRoutingInfo::setRouting(MessageRoutings messageRoutings, bool state)
{
const QMetaObject* metaObj = metaObject();
QMetaEnum metaEnum = metaObj->enumerator(metaObj->indexOfEnumerator("MessageRouting"));
for (int i=0; i<metaEnum.keyCount(); ++i)
{
MessageRouting messageRouting = static_cast<MessageRouting>(metaEnum.value(i));
if ((messageRoutings & messageRouting) == messageRouting)
{
m_routing->insert(messageRouting, state);
}
}
}
示例15: QObject
QQnxButtonEventNotifier::QQnxButtonEventNotifier(QObject *parent)
: QObject(parent),
m_fd(-1),
m_readNotifier(0)
{
// Set initial state of buttons to ButtonUp and
// fetch the new button ids
int enumeratorIndex = QQnxButtonEventNotifier::staticMetaObject.indexOfEnumerator(QByteArrayLiteral("ButtonId"));
QMetaEnum enumerator = QQnxButtonEventNotifier::staticMetaObject.enumerator(enumeratorIndex);
for (int buttonId = bid_minus; buttonId < ButtonCount; ++buttonId) {
m_buttonKeys.append(enumerator.valueToKey(buttonId));
m_state[buttonId] = ButtonUp;
}
}