本文整理汇总了C++中QMetaEnum::keysToValue方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaEnum::keysToValue方法的具体用法?C++ QMetaEnum::keysToValue怎么用?C++ QMetaEnum::keysToValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMetaEnum
的用法示例。
在下文中一共展示了QMetaEnum::keysToValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setUnit
void QEther::setUnit(QString const& _unit)
{
try
{
QMetaEnum units = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("EtherUnit"));
for (int k = 0; k < units.keyCount(); k++)
{
if (QString(units.key(k)).toLower() == _unit.toLower())
{
m_currentUnit = static_cast<EtherUnit>(units.keysToValue(units.key(k)));
return;
}
}
}
catch (...)
{
manageException();
}
}
示例2: domPropertyToVariant
// Convert complex DOM types with the help of QAbstractFormBuilder
QVariant domPropertyToVariant(QAbstractFormBuilder *afb,const QMetaObject *meta,const DomProperty *p)
{
// Complex types that need functions from QAbstractFormBuilder
switch(p->kind()) {
case DomProperty::String: {
const int index = meta->indexOfProperty(p->attributeName().toUtf8());
if (index != -1 && meta->property(index).type() == QVariant::KeySequence)
return QVariant::fromValue(QKeySequence(p->elementString()->text()));
}
break;
case DomProperty::Palette: {
const DomPalette *dom = p->elementPalette();
QPalette palette;
if (dom->elementActive())
afb->setupColorGroup(palette, QPalette::Active, dom->elementActive());
if (dom->elementInactive())
afb->setupColorGroup(palette, QPalette::Inactive, dom->elementInactive());
if (dom->elementDisabled())
afb->setupColorGroup(palette, QPalette::Disabled, dom->elementDisabled());
palette.setCurrentColorGroup(QPalette::Active);
return QVariant::fromValue(palette);
}
case DomProperty::Set: {
const QByteArray pname = p->attributeName().toUtf8();
const int index = meta->indexOfProperty(pname);
if (index == -1) {
uiLibWarning(QCoreApplication::translate("QFormBuilder", "The set-type property %1 could not be read.").arg(p->attributeName()));
return QVariant();
}
const QMetaEnum e = meta->property(index).enumerator();
Q_ASSERT(e.isFlag() == true);
return QVariant(e.keysToValue(p->elementSet().toUtf8()));
}
case DomProperty::Enum: {
const QByteArray pname = p->attributeName().toUtf8();
const int index = meta->indexOfProperty(pname);
QString enumValue = p->elementEnum();
// Triggers in case of objects in Designer like Spacer/Line for which properties
// are serialized using language introspection. On preview, however, these objects are
// emulated by hacks in the formbuilder (size policy/orientation)
fixEnum(enumValue);
if (index == -1) {
// ### special-casing for Line (QFrame) -- fix for 4.2. Jambi hack for enumerations
if (!qstrcmp(meta->className(), "QFrame")
&& (pname == QByteArray("orientation"))) {
return QVariant(enumValue == QFormBuilderStrings::instance().horizontalPostFix ? QFrame::HLine : QFrame::VLine);
} else {
uiLibWarning(QCoreApplication::translate("QFormBuilder", "The enumeration-type property %1 could not be read.").arg(p->attributeName()));
return QVariant();
}
}
const QMetaEnum e = meta->property(index).enumerator();
return QVariant(e.keyToValue(enumValue.toUtf8()));
}
case DomProperty::Brush:
return QVariant::fromValue(afb->setupBrush(p->elementBrush()));
default:
if (afb->resourceBuilder()->isResourceProperty(p)) {
return afb->resourceBuilder()->loadResource(afb->workingDirectory(), p);
}
break;
}
// simple type
return domPropertyToVariant(p);
}
示例3: standardContainer
MenuBarContainer::StandardContainer MenuBarContainer::standardContainer(const char *name)
{
const QMetaObject &mo = MenuBarContainer::staticMetaObject;
QMetaEnum me = mo.enumerator(mo.indexOfEnumerator("StandardContainer"));
return StandardContainer(me.keysToValue(name));
}