本文整理汇总了C++中QMetaEnum::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QMetaEnum::isValid方法的具体用法?C++ QMetaEnum::isValid怎么用?C++ QMetaEnum::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMetaEnum
的用法示例。
在下文中一共展示了QMetaEnum::isValid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fixError
void QgsGeometryGapCheck::fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> & /*mergeAttributeIndices*/, Changes &changes ) const
{
QMetaEnum metaEnum = QMetaEnum::fromType<QgsGeometryGapCheck::ResolutionMethod>();
if ( !metaEnum.isValid() || !metaEnum.valueToKey( method ) )
{
error->setFixFailed( tr( "Unknown method" ) );
}
else
{
ResolutionMethod methodValue = static_cast<ResolutionMethod>( method );
switch ( methodValue )
{
case NoChange:
error->setFixed( method );
break;
case MergeLongestEdge:
QString errMsg;
if ( mergeWithNeighbor( featurePools, static_cast<QgsGeometryGapCheckError *>( error ), changes, errMsg ) )
{
error->setFixed( method );
}
else
{
error->setFixFailed( tr( "Failed to merge with neighbor: %1" ).arg( errMsg ) );
}
break;
}
}
}
示例2: enumToString
QString Util::enumToString(const QVariant &value, const char *typeName, const QObject *object)
{
QByteArray enumTypeName(typeName);
if (enumTypeName.isEmpty()) {
enumTypeName = value.typeName();
}
// strip of class name and namespace
const int pos = enumTypeName.lastIndexOf("::");
if (pos >= 0) {
enumTypeName = enumTypeName.mid(pos + 2);
}
const QMetaObject *mo = &ProtectedExposer::staticQtMetaObject;
int enumIndex = mo->indexOfEnumerator(enumTypeName);
if (enumIndex < 0 && object) {
mo = object->metaObject();
enumIndex = mo->indexOfEnumerator(enumTypeName);
}
if (enumIndex < 0) {
return QString();
}
const QMetaEnum me = mo->enumerator(enumIndex);
if (!me.isValid()) {
return QString();
}
return me.valueToKeys(value.toInt());
}
示例3: QObject
AmarokPlaylistManagerScript::AmarokPlaylistManagerScript( AmarokScriptEngine* engine )
: QObject( engine )
{
QScriptValue scriptObject = engine->newQObject( this, QScriptEngine::AutoOwnership,
QScriptEngine::ExcludeSuperClassContents );
engine->globalObject().property( "Amarok" ).setProperty( "PlaylistManager", scriptObject );
const QMetaObject *metaObject = &PlaylistManager::staticMetaObject;
const QMetaEnum categoryEnum = metaObject->enumerator( metaObject->indexOfEnumerator("PlaylistCategory") );
Q_ASSERT( categoryEnum.isValid() );
scriptObject.setProperty( "PlaylistCategory", engine->enumObject( categoryEnum ) );
PlaylistPrototype::init( engine );
PlaylistProviderPrototype::init( engine );
PlaylistManager *instance = PlaylistManager::instance();
connect( instance, SIGNAL(categoryAdded(int)), SIGNAL(categoryAdded(int)) );
connect( instance, SIGNAL(playlistAdded(Playlists::PlaylistPtr,int)), SIGNAL(playlistAdded(Playlists::PlaylistPtr,int)) );
connect( instance, SIGNAL(playlistRemoved(Playlists::PlaylistPtr,int)), SIGNAL(playlistRemoved(Playlists::PlaylistPtr,int)) );
connect( instance, SIGNAL(playlistUpdated(Playlists::PlaylistPtr,int)), SIGNAL(playlistUpdated(Playlists::PlaylistPtr,int)) );
connect( instance, SIGNAL(providerAdded(Playlists::PlaylistProvider*,int)), SIGNAL(providerAdded(Playlists::PlaylistProvider*,int)) );
connect( instance, SIGNAL(providerRemoved(Playlists::PlaylistProvider*,int)), SIGNAL(providerRemoved(Playlists::PlaylistProvider*,int)) );
connect( instance, SIGNAL(renamePlaylist(Playlists::PlaylistPtr)), SIGNAL(renamePlaylist(Playlists::PlaylistPtr)) );
connect( instance, SIGNAL(updated(int)), SIGNAL(updated(int)) );
}
示例4: parseProperties
void MetaInfoPrivate::parseProperties(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const
{
Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject");
Q_ASSERT_X(nodeMetaInfo.isValid(), Q_FUNC_INFO, "invalid NodeMetaInfo");
for (int i = qMetaObject->propertyOffset(); i < qMetaObject->propertyCount(); ++i) {
QMetaProperty qProperty = qMetaObject->property(i);
PropertyMetaInfo propertyInfo;
propertyInfo.setName(QLatin1String(qProperty.name()));
QString typeName(qProperty.typeName());
QString noStar = typeName;
bool star = false;
while (noStar.contains('*')) {//strip star
noStar.chop(1);
star = true;
}
if (m_QtTypesToQmlTypes.contains(noStar)) {
typeName = star ? m_QtTypesToQmlTypes.value(noStar) + '*' : m_QtTypesToQmlTypes.value(noStar);
//### versions
}
propertyInfo.setType(typeName);
propertyInfo.setValid(true);
propertyInfo.setReadable(qProperty.isReadable());
propertyInfo.setWritable(qProperty.isWritable());
propertyInfo.setResettable(qProperty.isResettable());
propertyInfo.setEnumType(qProperty.isEnumType());
propertyInfo.setFlagType(qProperty.isFlagType());
if (propertyInfo.isEnumType()) {
EnumeratorMetaInfo enumerator;
QMetaEnum qEnumerator = qProperty.enumerator();
enumerator.setValid(qEnumerator.isValid());
enumerator.setIsFlagType(qEnumerator.isFlag());
enumerator.setScope(qEnumerator.scope());
enumerator.setName(qEnumerator.name());
for (int i = 0 ;i < qEnumerator.keyCount(); i++)
{
enumerator.addElement(qEnumerator.valueToKey(i), i);
}
propertyInfo.setEnumerator(enumerator);
}
nodeMetaInfo.addProperty(propertyInfo);
}
}
示例5: loadSettings
void UpdateInfoPlugin::loadSettings() const
{
QSettings *settings = ICore::settings();
const QString updaterKey = QLatin1String(UpdaterGroup) + QLatin1Char('/');
d->m_maintenanceTool = settings->value(updaterKey + QLatin1String(MaintenanceToolKey)).toString();
d->m_lastCheckDate = settings->value(updaterKey + QLatin1String(LastCheckDateKey), QDate()).toDate();
d->m_automaticCheck = settings->value(updaterKey + QLatin1String(AutomaticCheckKey), true).toBool();
const QString checkInterval = settings->value(updaterKey + QLatin1String(CheckIntervalKey)).toString();
const QMetaObject *mo = metaObject();
const QMetaEnum me = mo->enumerator(mo->indexOfEnumerator(CheckIntervalKey));
if (me.isValid()) {
bool ok = false;
const int newValue = me.keyToValue(checkInterval.toUtf8(), &ok);
if (ok)
d->m_checkInterval = static_cast<CheckUpdateInterval>(newValue);
}
}
示例6: save
/******************************************************************************
* Saves the settings to the given settings store.
******************************************************************************/
void ViewportSettings::save(QSettings& store) const
{
store.setValue("UpDirection", (int)_upDirection);
store.setValue("RestrictVerticalRotation", _restrictVerticalRotation);
store.remove("Colors");
store.beginGroup("Colors");
QMetaEnum colorEnum;
for(int i = 0; i < ViewportSettings::staticMetaObject.enumeratorCount(); i++) {
if(qstrcmp(ViewportSettings::staticMetaObject.enumerator(i).name(), "ViewportColor") == 0) {
colorEnum = ViewportSettings::staticMetaObject.enumerator(i);
break;
}
}
OVITO_ASSERT(colorEnum.isValid());
for(size_t i = 0; i < _viewportColors.size(); i++) {
store.setValue(colorEnum.key(i), QVariant::fromValue((QColor)_viewportColors[i]));
}
store.endGroup();
}
示例7: load
/******************************************************************************
* Loads the settings from the given settings store.
******************************************************************************/
void ViewportSettings::load(QSettings& store)
{
_upDirection = (UpDirection)store.value("UpDirection", qVariantFromValue((int)_upDirection)).toInt();
_restrictVerticalRotation = store.value("RestrictVerticalRotation", qVariantFromValue(_restrictVerticalRotation)).toBool();
store.beginGroup("Colors");
QMetaEnum colorEnum;
for(int i = 0; i < ViewportSettings::staticMetaObject.enumeratorCount(); i++) {
if(qstrcmp(ViewportSettings::staticMetaObject.enumerator(i).name(), "ViewportColor") == 0) {
colorEnum = ViewportSettings::staticMetaObject.enumerator(i);
break;
}
}
OVITO_ASSERT(colorEnum.isValid());
for(const QString& key : store.childKeys()) {
QColor c = store.value(key).value<QColor>();
bool ok;
int index = colorEnum.keyToValue(key.toLatin1().constData(), &ok);
if(ok && index >= 0 && index < NUMBER_OF_COLORS) {
_viewportColors[index] = Color(c);
}
}
store.endGroup();
}
示例8: initDB
void LogEngine::initDB()
{
m_db.close();
m_db.open();
QSqlQuery query;
if (!m_db.tables().contains("metadata")) {
query.exec("CREATE TABLE metadata (key varchar(10), data varchar(40));");
query.exec(QString("INSERT INTO metadata (key, data) VALUES('version', '%1');").arg(DB_SCHEMA_VERSION));
}
query.exec("SELECT data FROM metadata WHERE key = 'version';");
if (query.next()) {
int version = query.value("data").toInt();
if (version != DB_SCHEMA_VERSION) {
qCWarning(dcLogEngine) << "Log schema version not matching! Schema upgrade not implemented yet. Logging might fail.";
} else {
qCDebug(dcLogEngine) << QString("Log database schema version \"%1\" matches").arg(DB_SCHEMA_VERSION);
}
} else {
qCWarning(dcLogEngine) << "Broken log database. Version not found in metadata table.";
}
if (!m_db.tables().contains("sourceTypes")) {
query.exec("CREATE TABLE sourceTypes (id int, name varchar(20), PRIMARY KEY(id));");
//qCDebug(dcLogEngine) << query.lastError().databaseText();
QMetaEnum logTypes = Logging::staticMetaObject.enumerator(Logging::staticMetaObject.indexOfEnumerator("LoggingSource"));
Q_ASSERT_X(logTypes.isValid(), "LogEngine", "Logging has no enum LoggingSource");
for (int i = 0; i < logTypes.keyCount(); i++) {
query.exec(QString("INSERT INTO sourceTypes (id, name) VALUES(%1, '%2');").arg(i).arg(logTypes.key(i)));
}
}
if (!m_db.tables().contains("loggingEventTypes")) {
query.exec("CREATE TABLE loggingEventTypes (id int, name varchar(20), PRIMARY KEY(id));");
//qCDebug(dcLogEngine) << query.lastError().databaseText();
QMetaEnum logTypes = Logging::staticMetaObject.enumerator(Logging::staticMetaObject.indexOfEnumerator("LoggingEventType"));
Q_ASSERT_X(logTypes.isValid(), "LogEngine", "Logging has no enum LoggingEventType");
for (int i = 0; i < logTypes.keyCount(); i++) {
query.exec(QString("INSERT INTO loggingEventTypes (id, name) VALUES(%1, '%2');").arg(i).arg(logTypes.key(i)));
}
}
if (!m_db.tables().contains("entries")) {
query.exec("CREATE TABLE entries "
"("
"timestamp int,"
"loggingLevel int,"
"sourceType int,"
"typeId varchar(38),"
"deviceId varchar(38),"
"value varchar(100),"
"loggingEventType int,"
"active bool,"
"errorCode int,"
"FOREIGN KEY(sourceType) REFERENCES sourceTypes(id),"
"FOREIGN KEY(loggingEventType) REFERENCES loggingEventTypes(id)"
");");
if (query.lastError().isValid()) {
qCWarning(dcLogEngine) << "Error creating log table in database. Driver error:" << query.lastError().driverText() << "Database error:" << query.lastError().databaseText();
}
}
qCDebug(dcLogEngine) << "Initialized logging DB successfully. (maximum DB size:" << m_dbMaxSize << ")";
}