当前位置: 首页>>代码示例>>C++>>正文


C++ QMetaEnum::keysToValue方法代码示例

本文整理汇总了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();
	}
}
开发者ID:EarthDollar,项目名称:farmer,代码行数:19,代码来源:QEther.cpp

示例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);
}
开发者ID:hkahn,项目名称:qt5-qttools-nacl,代码行数:77,代码来源:properties.cpp

示例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));
}
开发者ID:denosauro,项目名称:Andromeda,代码行数:6,代码来源:menubarcontainer.cpp


注:本文中的QMetaEnum::keysToValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。