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)); }
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)); }
bool FormDialog::setFaceType(const QString& facetype) { int i = KPageView::staticMetaObject.indexOfEnumerator("FaceType"); Q_ASSERT( i >= 0 ); QMetaEnum e = KPageView::staticMetaObject.enumerator(i); int v = e.keysToValue( facetype.toUtf8() ); if( v < 0 ) return false; KPageDialog::setFaceType( (KPageDialog::FaceType) v ); return true; }
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(); }
bool FormDialog::setButtonText(const QString& button, const QString& text) { int i = metaObject()->indexOfEnumerator("ButtonCode"); Q_ASSERT( i >= 0 ); QMetaEnum e = metaObject()->enumerator(i); int v = e.keysToValue( button.toUtf8() ); if( v < 0 ) return false; KDialog::setButtonText( (KDialog::ButtonCode) v, text); return true; }
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); }
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)); }
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; }
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); }
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)); } }
QScriptClass::QueryFlags QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &name, QScriptClass::QueryFlags flags) { Q_UNUSED(flags); TypeNameData *data = (TypeNameData *)obj; object = 0; type = 0; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); if (data->typeNamespace) { QDeclarativeTypeNameCache::Data *d = data->typeNamespace->data(name); if (d && d->type) { type = d->type; return QScriptClass::HandlesReadAccess; } else { return 0; } } else { Q_ASSERT(data->type); QString strName = toString(name); if (strName.at(0).isUpper()) { // Must be an enum if (data->mode == IncludeEnums) { // ### Optimize QByteArray enumName = strName.toUtf8(); const QMetaObject *metaObject = data->type->baseMetaObject(); for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) { QMetaEnum e = metaObject->enumerator(ii); int value = e.keyToValue(enumName.constData()); if (value != -1) { enumValue = value; return QScriptClass::HandlesReadAccess; } } } return 0; } else if (data->object) { // Must be an attached property object = qmlAttachedPropertiesObjectById(data->type->index(), data->object); if (!object) return 0; return ep->objectClass->queryProperty(object, name, flags, 0); } } return 0; }
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)); } }
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(); }
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); } }
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); } }
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; }
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); } } }
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; } }
QString enumToString(const QMetaEnum &aMetaEnum, const int &aValue) { QString res=qApp->translate("Property", "[No enumeration value]"); for (int i=0; i<aMetaEnum.keyCount(); ++i) { if (aMetaEnum.value(i)==aValue) { res=QString::fromLatin1(aMetaEnum.key(i)); break; } } return res; }
void UpdateInfoPlugin::saveSettings() { QSettings *settings = ICore::settings(); settings->beginGroup(QLatin1String(UpdaterGroup)); settings->setValue(QLatin1String(LastCheckDateKey), d->m_lastCheckDate); settings->setValue(QLatin1String(AutomaticCheckKey), d->m_automaticCheck); // Note: don't save MaintenanceToolKey on purpose! This setting may be set only by installer. // If creator is run not from installed SDK, the setting can be manually created here: // [CREATOR_INSTALLATION_LOCATION]/share/qtcreator/QtProject/QtCreator.ini or // [CREATOR_INSTALLATION_LOCATION]/Qt Creator.app/Contents/Resources/QtProject/QtCreator.ini on OS X const QMetaObject *mo = metaObject(); const QMetaEnum me = mo->enumerator(mo->indexOfEnumerator(CheckIntervalKey)); settings->setValue(QLatin1String(CheckIntervalKey), QLatin1String(me.valueToKey(d->m_checkInterval))); settings->endGroup(); }
QDebug operator<<(QDebug debug, CoapReply *reply) { const QMetaObject &metaObject = CoapPdu::staticMetaObject; QMetaEnum messageTypeEnum = metaObject.enumerator(metaObject.indexOfEnumerator("MessageType")); QMetaEnum contentTypeEnum = metaObject.enumerator(metaObject.indexOfEnumerator("ContentType")); debug.nospace() << "CoapReply(" << messageTypeEnum.valueToKey(reply->messageType()) << ")" << endl; debug.nospace() << " Status code: " << CoapPdu::getStatusCodeString(reply->statusCode()) << endl; debug.nospace() << " Content type: " << contentTypeEnum.valueToKey(reply->contentType()) << endl; debug.nospace() << " Payload size: " << reply->payload().size() << endl; if (!reply->payload().isEmpty()) debug.nospace() << endl << reply->payload() << endl; return debug.space(); }
int ObjectControllerPrivate::intToEnum(const QMetaEnum &metaEnum, int intValue) const { QMap<int, bool> valueMap; // dont show multiple enum values which have the same values QList<int> values; for (int i = 0; i < metaEnum.keyCount(); i++) { int value = metaEnum.value(i); if (!valueMap.contains(value)) { valueMap[value] = true; values.append(value); } } if (intValue >= values.count()) return -1; return values.at(intValue); }
QString RemoteArchiveModel::networkErrorToString(QNetworkReply::NetworkError error) { QString errorValue; QMetaObject meta = QNetworkReply::staticMetaObject; for (int i = 0; i < meta.enumeratorCount(); ++i) { QMetaEnum m = meta.enumerator(i); if (m.name() == QLatin1String("NetworkError")) { errorValue = QLatin1String(m.valueToKey(error)); break; } } return errorValue; }
void SaxsviewProperty::setValue(QObject *obj) { if (!mProperty) { // // Find the meta-property information; the passed object must // provide the Q_PROPERTY name passed to the constructor. // int indexOfProperty = obj->metaObject()->indexOfProperty(qPrintable(mPropertyName)); QMetaProperty metaProperty = obj->metaObject()->property(indexOfProperty); if (metaProperty.isValid()) { // // Create an editor factory if and only if the property is writeable. // if (metaProperty.isWritable()) { mBrowser->setFactoryForManager(mManager, new QtVariantEditorFactory(this)); connect(mManager, SIGNAL(valueChanged(QtProperty*, const QVariant&)), this, SLOT(valueChanged(QtProperty*, const QVariant&))); } if (!mManager->isPropertyTypeSupported(metaProperty.type())) qFatal("internal error: property '%s', property type not supported: '%s'", metaProperty.name(), metaProperty.typeName()); // // Check if this is an enum and handle it specially if yes. // if (metaProperty.isEnumType()) { QStringList enumNames; QMetaEnum metaEnum = metaProperty.enumerator(); // // WARNING: This only builds a list of names in the order // as defined. The combobox to display these names // provides the selected index, not the actual enum // value. // for (int i = 0; i < metaEnum.keyCount(); ++i) enumNames << metaEnum.key(i); setEnumNames(enumNames); } if (mAttributes.contains("enumNames")) mProperty = mManager->addProperty(mManager->enumTypeId(), mPropertyLabel); else mProperty = mManager->addProperty(metaProperty.type(), mPropertyLabel); } else if (obj->dynamicPropertyNames().contains(qPrintable(mPropertyName))) {
void QtScriptEngine::copyEnumsToScriptObject( QScriptEngine *engine, const QMetaObject *metaObject, QScriptValue *object) { for (int enumIndex = 0; enumIndex < metaObject->enumeratorCount(); enumIndex++) { QMetaEnum metaEnum = metaObject->enumerator(enumIndex); QScriptValue enumClass = engine->newObject(); for (int keyIndex = 0; keyIndex < metaEnum.keyCount(); keyIndex++) { enumClass.setProperty(metaEnum.key(keyIndex), metaEnum.value(keyIndex)); } object->setProperty(metaEnum.name(), enumClass); } }
QList<QString> enumToKeys(const QMetaObject o, const QString& name, const QString& strip) { QList<QString> list; int enumIndex = o.indexOfEnumerator(name.toLatin1().data()); QMetaEnum enumerator = o.enumerator(enumIndex); if (enumerator.isValid()) { for (int i = 0; i < enumerator.keyCount(); i++) { QString key(enumerator.valueToKey(i)); list.append(key.remove(strip)); } } return list; }
SignalData::SignalData() { qDebug() << "SignalData ctor" << this; connect(&mSampler, SIGNAL(dataArrived()), SLOT(fetchSamples())); connect(&mSampler, SIGNAL(started()), this, SIGNAL(started())); connect(&mSampler, SIGNAL(finished()), this, SIGNAL(finished())); connect(&mSampler, SIGNAL(terminated()), this, SIGNAL(finished())); connect(&mSampler, SIGNAL(error(QString)), this, SIGNAL(error(QString))); const QMetaObject metaObject = Sample::staticMetaObject; const QMetaEnum metaEnum = metaObject.enumerator(metaObject.indexOfEnumerator("Marker")); for (int i = 0; i < metaEnum.keyCount(); i++) { mSamples.insert((Sample::Marker)metaEnum.value(i), QVector<Sample>()); mBoundingRects.insert((Sample::Marker)metaEnum.value(i), QRectF()); } }
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); } }
int ObjectControllerPrivate::flagToInt(const QMetaEnum &metaEnum, int flagValue) const { if (!flagValue) return 0; int intValue = 0; 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) && isPowerOf2(value)) { if (isSubValue(flagValue, value)) intValue |= (1 << pos); valueMap[value] = pos++; } } return intValue; }
bool QFeedbackSimulator::play(QFeedbackEffect::ThemeEffect theme) { if (mDefaultActuator == -1) return false; const QMetaEnum themeEnum = QFeedbackEffect::staticMetaObject.enumerator( QFeedbackEffect::staticMetaObject.indexOfEnumerator("ThemeEffect")); QString themeString = themeEnum.valueToKey(theme); int effectId = mConnection->startEffect(mDefaultActuator, themeString, 2000); if (effectId != -1) { mActuatorData[mDefaultActuator].state = QFeedbackActuator::Busy; return true; } return false; }