std::map<QString, double> ScriptMatch::getFeatures(const ConstOsmMapPtr& map) const { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; // removing these two lines causes a crash when checking for conflicts. WTF? Handle<Object> global = _script->getContext()->Global(); global->Get(String::NewSymbol("plugin")); std::map<QString, double> result; Handle<Value> v = _callGetMatchFeatureDetails(map); if (v.IsEmpty() || v->IsObject() == false) { throw IllegalArgumentException( "Expected getMatchFeatureDetails to return an associative array."); } QVariantMap vm = toCpp<QVariantMap>(v); for (QVariantMap::const_iterator it = vm.begin(); it != vm.end(); ++it) { if (it.value().isNull() == false) { double d = it.value().toDouble(); result[it.key()] = d; if (isnan(result[it.key()])) { LOG_WARN("found NaN feature value for: " << it.key()); } } } return result; }
QStringList FindKeyOperation::findKey(const QVariant &in, const QString &key, const QString &prefix) { QStringList result; if (in.type() == QVariant::Map) { QVariantMap map = in.toMap(); for (QVariantMap::const_iterator i = map.begin(); i != map.end(); ++i) { QString pfx = prefix; if (!pfx.isEmpty()) pfx.append(QLatin1Char('/')); if (i.key() == key) { result << pfx + key; } else { pfx.append(i.key()); result.append(findKey(i.value(), key, pfx)); } } } else if (in.type() == QVariant::List) { QVariantList list = in.toList(); for (int pos = 0; pos < list.count(); ++pos) { QString pfx = prefix + QLatin1Char('[') + QString::number(pos) + QLatin1Char(']'); result.append(findKey(list.at(pos), key, pfx)); } } return result; }
void ExternalObjectInterface::updateLocalProperties(const QVariantMap& properties, bool callOnLocalPropertiesChanged) { LOG(Trace, "updateLocalProperties"); QVariantMap changedProperties; QVariantMap::const_iterator it = properties.begin(); QVariantMap::const_iterator itend = properties.end(); for (; it != itend; ++it){ QVariantMap::const_iterator jt = m_localProperties.find(it.key()); if (jt != m_localProperties.end()){ if (jt.value() == it.value()){ // no change }else{ m_localProperties[it.key()] = it.value(); changedProperties.insert(it.key(), it.value()); } }else{ // key not found m_localProperties[it.key()] = it.value(); changedProperties.insert(it.key(), it.value()); } } if (callOnLocalPropertiesChanged && !changedProperties.empty()){ onLocalPropertiesChanged(changedProperties); } }
void StatusManager::restore(const QString& filename) { QVariant var; // Try to Read a JSON file bool res = fromJsonFile(filename.toStdString().c_str(), var); if (res) { const QVariantMap map = var.toMap(); for (QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it) { Holder holder(status(it.key())); if (holder.is_valid()) { res = fromQVariant(holder.get_type_descriptor(), holder, it.value()); if (res) { setStatus(it.key(), holder); } } } } else { emit error(QString("Unable to load file '%1'").arg(filename)); } }
Properties VariantToMapConverter::toProperties(const QVariant &propertiesVariant, const QVariant &propertyTypesVariant) const { const QVariantMap propertiesMap = propertiesVariant.toMap(); const QVariantMap propertyTypesMap = propertyTypesVariant.toMap(); Properties properties; QVariantMap::const_iterator it = propertiesMap.constBegin(); QVariantMap::const_iterator it_end = propertiesMap.constEnd(); for (; it != it_end; ++it) { int type = nameToType(propertyTypesMap.value(it.key()).toString()); if (type == QVariant::Invalid) type = QVariant::String; QVariant value = it.value(); if (type == filePathTypeId()) value = resolvePath(mMapDir, value); value = fromExportValue(value, type); properties[it.key()] = value; } return properties; }
QVariantMap MprisPlayer::typeMetadata(const QVariantMap &aMetadata) { QVariantMap metadata; QVariantMap::const_iterator i = aMetadata.constBegin(); while (i != aMetadata.constEnd()) { switch (Mpris::enumerationFromString<Mpris::Metadata>(i.key())) { case Mpris::TrackId: metadata.insert(i.key(), QVariant::fromValue(QDBusObjectPath(i.value().toString()))); break; case Mpris::Length: metadata.insert(i.key(), QVariant::fromValue(i.value().toLongLong())); break; case Mpris::ArtUrl: case Mpris::Url: metadata.insert(i.key(), QVariant::fromValue(i.value().toUrl().toString())); break; case Mpris::Album: case Mpris::AsText: case Mpris::Title: metadata.insert(i.key(), QVariant::fromValue(i.value().toString())); break; case Mpris::AlbumArtist: case Mpris::Artist: case Mpris::Comment: case Mpris::Composer: case Mpris::Genre: case Mpris::Lyricist: metadata.insert(i.key(), QVariant::fromValue(i.value().toStringList())); break; case Mpris::AudioBPM: case Mpris::DiscNumber: case Mpris::TrackNumber: case Mpris::UseCount: metadata.insert(i.key(), QVariant::fromValue(i.value().toInt())); break; case Mpris::AutoRating: case Mpris::UserRating: metadata.insert(i.key(), QVariant::fromValue(i.value().toFloat())); break; case Mpris::ContentCreated: case Mpris::FirstUsed: case Mpris::LastUsed: metadata.insert(i.key(), QVariant::fromValue(i.value().toDate().toString(Qt::ISODate))); break; case Mpris::InvalidMetadata: // Passing with the original type and hoping the user used // a type supported by DBus metadata.insert(i.key(), i.value()); break; default: // Nothing to do break; } ++i; } return metadata; }
void TreeJsonModel::setupModelData(const QVariant& newdata, TreeJsonItem* parent) { QMetaType::Type type = (QMetaType::Type)newdata.type(); if (type == QMetaType::QVariantMap) { QVariantMap map = newdata.toMap(); QVariantMap::const_iterator it; for (it = map.constBegin(); it != map.constEnd(); it++) { type = (QMetaType::Type)it.value().type(); if (type == QMetaType::QString || type == QMetaType::ULongLong) { QList<QVariant> value; value << it.key() << it.value(); TreeJsonItem* item = new TreeJsonItem(value,parent); parent->appendChild(item); } else if (type == QMetaType::QVariantMap) { QList<QVariant> value; value << it.key() << "{"; TreeJsonItem* item = new TreeJsonItem(value,parent); parent->appendChild(item); setupModelData(it.value(),item); item->setData(1,QString("{%1}").arg(item->childCount())); } else if (type == QMetaType::QVariantList) { QList<QVariant> value; value << it.key() << "["; TreeJsonItem* item = new TreeJsonItem(value,parent); parent->appendChild(item); setupModelData(it.value(),item); item->setData(1,QString("[%1]").arg(item->childCount())); } } } else if (type == QMetaType::QVariantList) { QVariantList list = newdata.toList(); int len = list.size(); for (int i=0;i<len;i++) { type = (QMetaType::Type)list.value(i).type(); if (type == QMetaType::QString || type == QMetaType::ULongLong) { QList<QVariant> value; value << i << list.value(i); TreeJsonItem* item = new TreeJsonItem(value,parent); parent->appendChild(item); } else if (type == QMetaType::QVariantMap) { QList<QVariant> value; value << i << "{"; TreeJsonItem* item = new TreeJsonItem(value,parent); parent->appendChild(item); setupModelData(list.value(i),item); item->setData(1,QString("{%1}").arg(item->childCount())); } else if (type == QMetaType::QVariantList) { QList<QVariant> value; value << i << "["; TreeJsonItem* item = new TreeJsonItem(value,parent); parent->appendChild(item); setupModelData(list.value(i),item); item->setData(1,QString("[%1]").arg(item->childCount())); } } } }
bool ccObject::toFile(QFile& out) const { assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly)); //class ID (dataVersion>=20) //DGM: on 64 bits since version 34 uint64_t classID = static_cast<uint64_t>(getClassID()); if (out.write((const char*)&classID,8) < 0) return WriteError(); //unique ID (dataVersion>=20) //DGM: this ID will be useful to recreate dynamic links between entities! uint32_t uniqueID = (uint32_t)m_uniqueID; if (out.write((const char*)&uniqueID,4) < 0) return WriteError(); //name (dataVersion>=22) { QDataStream outStream(&out); outStream << m_name; } //flags (dataVersion>=20) uint32_t objFlags = (uint32_t)m_flags; if (out.write((const char*)&objFlags,4) < 0) return WriteError(); //meta data (dataVersion>=30) { //check for valid pieces of meta-data //DGM: some pieces of meta-data can't be properly streamed (the ones relying on 'Q_DECLARE_METATYPE' calls typically) uint32_t validMetaDataCount = 0; for (QVariantMap::const_iterator it = m_metaData.begin(); it != m_metaData.end(); ++it) { if (!it.key().contains(".nosave")) { ++validMetaDataCount; } } //count if (out.write((const char*)&validMetaDataCount, 4) < 0) return WriteError(); //"key + value" pairs QDataStream outStream(&out); for (QVariantMap::const_iterator it = m_metaData.begin(); it != m_metaData.end(); ++it) { if (!it.key().contains(".nosave")) { outStream << it.key(); outStream << it.value(); } } } return true; }
ApiTraceState::ApiTraceState(const QVariantMap &parsedJson) { m_parameters = parsedJson[QLatin1String("parameters")].toMap(); QVariantMap attachedShaders = parsedJson[QLatin1String("shaders")].toMap(); QVariantMap::const_iterator itr; for (itr = attachedShaders.constBegin(); itr != attachedShaders.constEnd(); ++itr) { QString type = itr.key(); QString source = itr.value().toString(); m_shaderSources[type] = source; } m_uniforms = parsedJson[QLatin1String("uniforms")].toMap(); m_buffers = parsedJson[QLatin1String("buffers")].toMap(); { QVariantMap textures = parsedJson[QLatin1String("textures")].toMap(); for (itr = textures.constBegin(); itr != textures.constEnd(); ++itr) { m_textures.append(getTextureFrom(itr.value().toMap(), itr.key())); } } QVariantMap fbos = parsedJson[QLatin1String("framebuffer")].toMap(); for (itr = fbos.constBegin(); itr != fbos.constEnd(); ++itr) { QVariantMap buffer = itr.value().toMap(); QSize size(buffer[QLatin1String("__width__")].toInt(), buffer[QLatin1String("__height__")].toInt()); QString cls = buffer[QLatin1String("__class__")].toString(); int depth = buffer[QLatin1String("__depth__")].toInt(); QString formatName = buffer[QLatin1String("__format__")].toString(); QByteArray dataArray = buffer[QLatin1String("__data__")].toByteArray(); QString label = itr.key(); QString userLabel = buffer[QLatin1String("__label__")].toString(); if (!userLabel.isEmpty()) { label += QString(", \"%1\"").arg(userLabel); } ApiFramebuffer fbo; fbo.setSize(size); fbo.setDepth(depth); fbo.setFormatName(formatName); fbo.setType(label); fbo.setData(dataArray); m_framebuffers.append(fbo); } }
void ccObject::setMetaData(const QVariantMap& dataset, bool overwrite/*=false*/) { for (QVariantMap::const_iterator it = dataset.begin(); it != dataset.end(); ++it) { if (overwrite || !m_metaData.contains(it.key())) { m_metaData[it.key()] = it.value(); } } }
void expand_map(QStringList & keys, const QString & k, const QVariant & v){ if(v.type() == QVariant::Map){ const QVariantMap & map = asMap(v); for(QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it){ expand_map(keys, k.isEmpty() ? it.key() : k +"." + it.key(), it.value()); } } if(!k.isEmpty()){ keys.append(k); } }
std::map<QString, double> ScriptMatch::getFeatures(const ConstOsmMapPtr& map) const { Isolate* current = v8::Isolate::GetCurrent(); HandleScope handleScope(current); Context::Scope context_scope(_script->getContext(current)); // removing these two lines causes a crash when checking for conflicts. WTF? Handle<Object> global = _script->getContext(current)->Global(); global->Get(String::NewFromUtf8(current, "plugin")); std::map<QString, double> result; LOG_TRACE("Calling getMatchFeatureDetails..."); Handle<Value> v = _callGetMatchFeatureDetails(map); if (v.IsEmpty() || v->IsObject() == false) { throw IllegalArgumentException( "Expected getMatchFeatureDetails to return an associative array."); } QVariantMap vm = toCpp<QVariantMap>(v); long valCtr = 0; LOG_VART(vm.size()); for (QVariantMap::const_iterator it = vm.begin(); it != vm.end(); ++it) { if (it.value().isNull() == false) { double d = it.value().toDouble(); result[it.key()] = d; if (::qIsNaN(result[it.key()])) { if (logWarnCount < Log::getWarnMessageLimit()) { LOG_WARN("found NaN feature value for: " << it.key()); } else if (logWarnCount == Log::getWarnMessageLimit()) { LOG_WARN(className() << ": " << Log::LOG_WARN_LIMIT_REACHED_MESSAGE); } logWarnCount++; } } valCtr++; } if (vm.size() > 0) { LOG_DEBUG("Processed " << vm.size() << " sample values."); } return result; }
void RecognitionDatabase::Private::applyParameters() { if (recognizerConst()) { for (QVariantMap::const_iterator it = parameters.constBegin(); it != parameters.constEnd(); ++it) { if (it.key() == QString::fromLatin1("threshold") || it.key() == QString::fromLatin1("accuracy")) { recognizer()->setThreshold(it.value().toFloat()); } } } }
bool tLibs3::UploadFile( tTransfer* pTransfer ) { bool success = false; if( m_Process.state() == QProcess::NotRunning ) { QString archiveFilename = pTransfer->GetTransferGroup()->GetDirectoryToString() + QDir::separator() + pTransfer->GetArchiveFilename(); QVariantMap metaData = pTransfer->GetMetaData(); for(QVariantMap::const_iterator iter = metaData.begin(); iter != metaData.end(); ++iter) { DbgPrintf( QString("%1 = %2").arg(iter.key()).arg(iter.value().toString()) ); } QString uploadName; { uploadName = "navicomerlintest/"; // TODO uploadName += "support."; uploadName += tUploadAWS::CreateFilename(metaData["brand"].toString(), metaData["model"].toString(), metaData["serialnumber"].toString(), metaData["time"].toString()); } QStringList args; args << "-f" << "put" << QString("%1").arg(uploadName); args << QString("filename=%1").arg(archiveFilename); for(QVariantMap::const_iterator iter = metaData.begin(); iter != metaData.end(); ++iter) { QString value; if (iter.value().isValid() == true) { value = iter.value().toString(); } if (value.isEmpty() == false) { // x-amz-meta-serial=123456 args << QString("x-amz-meta-%1=%2").arg(iter.key()).arg(value); } } QString command = ""; #ifdef Q_WS_WIN command = QString( "..\\..\\ThirdParty\\libs3\\s3.exe" ); #else command = QString( "s3" ); #endif #ifdef DATATRANSFERMANAGER_DBG DbgPrintf(command); foreach (QString arg, args) { DbgPrintf( QString(" \"%1\"").arg(arg) ); }
QVariantMap AddQtOperation::addQt(const QVariantMap &map, const QString &id, const QString &displayName, const QString &type, const QString &qmake, const KeyValuePairList &extra) { QString sdkId = extendId(id); // Sanity check: Make sure autodetection source is not in use already: if (exists(map, sdkId)) { std::cerr << "Error: Id " << qPrintable(id) << " already defined as Qt versions." << std::endl; return QVariantMap(); } // Find position to insert: int versionCount = 0; for (QVariantMap::const_iterator i = map.begin(); i != map.end(); ++i) { if (!i.key().startsWith(QLatin1String(PREFIX))) continue; QString number = i.key().mid(QString::fromLatin1(PREFIX).count()); bool ok; int count = number.toInt(&ok); if (ok && count >= versionCount) versionCount = count + 1; } const QString qt = QString::fromLatin1(PREFIX) + QString::number(versionCount); // Sanity check: Make sure displayName is unique. QStringList nameKeys = FindKeyOperation::findKey(map, QLatin1String(DISPLAYNAME)); QStringList nameList; foreach (const QString &nameKey, nameKeys) nameList << GetOperation::get(map, nameKey).toString(); const QString uniqueName = makeUnique(displayName, nameList); // Sanitize qmake path: QString saneQmake = QDir::cleanPath(QDir::fromNativeSeparators(qmake)); // insert data: KeyValuePairList data; data << KeyValuePair(QStringList() << qt << QLatin1String(ID), QVariant(-1)); data << KeyValuePair(QStringList() << qt << QLatin1String(DISPLAYNAME), QVariant(uniqueName)); data << KeyValuePair(QStringList() << qt << QLatin1String(AUTODETECTED), QVariant(true)); data << KeyValuePair(QStringList() << qt << QLatin1String(AUTODETECTION_SOURCE), QVariant(sdkId)); data << KeyValuePair(QStringList() << qt << QLatin1String(QMAKE), QVariant(saneQmake)); data << KeyValuePair(QStringList() << qt << QLatin1String(TYPE), QVariant(type)); KeyValuePairList qtExtraList; foreach (const KeyValuePair &pair, extra) qtExtraList << KeyValuePair(QStringList() << qt << pair.key, pair.value); data.append(qtExtraList); return AddKeysOperation::addKeys(map, data); }
void Feature::validate(StrictChecking strict) { // make sure we didn't get more fields than necessary for (QVariantMap::const_iterator it = _values.begin(); it != _values.end(); ++it) { if (_definition->hasField(it.key()) == false) { QString error = QString("Returned a field name that isn't appropriate for this layer. %1") .arg(it.key()); if (strict == StrictOn) { throw FieldDefinition::InvalidValueException(it.key(), error); } else if (strict == StrictWarn) { LOG_WARN(error); } } } for (size_t i = 0; i < _definition->getFieldCount(); ++i) { // is shared_ptr<const FieldDefinition> d = _definition->getFieldDefinition(i); if (_values.contains(d->getName()) == false) { if (d->hasDefaultValue() == false) { QString error = QString("Field has no default value and no value was specified. (%1)") .arg(d->getName()); if (strict == StrictOn) { throw FieldDefinition::InvalidValueException(d->getName(), error); } else if (strict == StrictWarn) { LOG_WARN(error); } } else { _values[d->getName()] = d->getDefaultValue(); } } else { d->validate(_values[d->getName()], strict); } } }
QString debugDumpJson(QVariantMap json, QString name, QString indent) { QString ret = "{"; QVariantMap::const_iterator it = json.constBegin(); for (; it != json.constEnd(); ++it) { ret += "\n" + indent + " " + it.key() + ": "; ret += debugDumpJson(it.value(), it.key(), indent); } ret += "\n" + indent + "}"; if (!name.isEmpty()) ret += " // end of " + name; return ret; }
QStringList FindKeyOperation::findKey(const QVariantMap &map, const QString &key) { QStringList result; for (QVariantMap::const_iterator i = map.begin(); i != map.end(); ++i) { if (i.key() == key) { result << key; continue; } if (i.value().type() == QVariant::Map) { QStringList subKeyList = findKey(i.value().toMap(), key); foreach (const QString &subKey, subKeyList) result << i.key() + QLatin1Char('/') + subKey; } }
void jsonparser::getMap(QVariantMap* depmap,QVariantMap* totalMap,ActiveOptionsContainer* activeOpts, JasonCore* jCore){ QStringList excludes = jCore->getCoreElements(); for(QVariantMap::const_iterator it = depmap->begin(); it!=depmap->end(); it++){ if(!excludes.contains(it.key())){ activeOpts->addOption(it.key(),it.value()); continue; } if(it.key()=="imports") for(QVariant el : it.value().toList()){ getMap(new QVariantMap(jsonOpenFile(el.toMap().value("file").toString()).object().toVariantMap()),totalMap,activeOpts,jCore); continue; } totalMap->insertMulti(it.key(),it.value()); //We want to generate a complete map of all values from all files. We'll deal with conflicts later. } }
void GaugeView::guiUpdateTimerTick() { QVariantMap::const_iterator i = m_valueMap.constBegin(); while (i != m_valueMap.constEnd()) { if (propertiesInUse.contains(i.key())) { widget->propertyMap.setProperty(i.key().toAscii(),i.value()); } //ui.tableWidget->item(m_nameToIndexMap[i.key()],1)->setText(QString::number(i.value())); i++; } }
void BridgeSettingTest::testSetting() { QFETCH(QString, interfaceName); QFETCH(bool, stp); QFETCH(quint16, priority); QFETCH(quint16, forwardDelay); QFETCH(quint16, helloTime); QFETCH(quint16, maxAge); QFETCH(quint32, ageintTime); QVariantMap map; #if NM_CHECK_VERSION(1, 0, 0) map.insert(QLatin1String("interface-name"), interfaceName); #else map.insert(QLatin1String(NM_SETTING_BRIDGE_INTERFACE_NAME), interfaceName); #endif map.insert(QLatin1String(NM_SETTING_BRIDGE_STP), stp); map.insert(QLatin1String(NM_SETTING_BRIDGE_PRIORITY), priority); map.insert(QLatin1String(NM_SETTING_BRIDGE_FORWARD_DELAY), forwardDelay); map.insert(QLatin1String(NM_SETTING_BRIDGE_HELLO_TIME), helloTime); map.insert(QLatin1String(NM_SETTING_BRIDGE_MAX_AGE), maxAge); map.insert(QLatin1String(NM_SETTING_BRIDGE_AGEING_TIME), ageintTime); NetworkManager::BridgeSetting setting; setting.fromMap(map); QVariantMap map1 = setting.toMap(); QVariantMap::const_iterator it = map.constBegin(); while (it != map.constEnd()) { QCOMPARE(it.value(), map1.value(it.key())); ++it; } }
QString QstMessage::toString() const { QString ret; if (!isUnpacked()) { ret = QLatin1String("(packed)\n"); return ret; } QVariantMap::const_iterator i = m_map.constBegin(); while (i != m_map.constEnd()) { if (!i.value().isValid()) { i++; continue; } ret += i.key() + QLatin1String(": "); if (i.value().canConvert<QStringList>()) ret += QLatin1String("'") + i.value().toStringList().join(QLatin1String("','")) + QLatin1String("'"); else if (i.value().canConvert<QString>()) ret += QLatin1String("'") + i.value().toString() + QLatin1String("'"); else ret += QLatin1String("(data)"); ret += QLatin1Char('\n'); ++i; } if (ret.endsWith(QLatin1Char('\n'))) ret.chop(1); return ret; }
void TransactionObjectBuilder::setExtraData(const QVariantMap &data) { for(QVariantMap::const_iterator it = data.begin(), end = data.end(); it!=end; ++it) { _data.insert(it.key(), QJsonValue::fromVariant(it.value())); } }
QVariantMap RemoteControl::get_conference_room_infos() { QVariantMap args; XletConference* conference_xlet = this->get_xlet<XletConference>("conference"); QAbstractItemModel* conflist_model = conference_xlet->findChild<QAbstractItemModel*>("conflist_model"); args["conference_xlet"] = conference_xlet != NULL; args["conflist_model"] = conflist_model != NULL; QVariantList content; QVariantMap header_data; header_data["name"] = ConfListModel::NAME; header_data["number"] = ConfListModel::NUMBER; header_data["pin_required"] = ConfListModel::PIN_REQUIRED; header_data["member_count"] = ConfListModel::MEMBER_COUNT; header_data["started_since"] = ConfListModel::STARTED_SINCE; int nb_rows = conflist_model->rowCount(QModelIndex()); for (int row = 0; row < nb_rows; row++) { QVariantMap header_value; QVariantMap::const_iterator i; for(i = header_data.begin(); i != header_data.end(); ++i) { header_value[i.key()] = getValueInModel(conflist_model, row, i.value().toInt()); } content.append(header_value); } args["content"] = content; return args; }
Var Var::fromQVariant(QVariant qvar) { Var var; if(qvar.type()==QVariant::List) { QVariantList qlist = qvar.toList(); var.setType("list"); for(int i=0;i<qlist.size();i++) var.append(fromQVariant(qlist[i])); } if(qvar.type()==QVariant::Map) { QVariantMap qmap = qvar.toMap(); var.setType("map"); for(QVariantMap::const_iterator i = qmap.constBegin();i != qmap.constEnd();i++) var.insert(i.key(),fromQVariant(i.value())); } if(qvar.type()==QVariant::String) { var.setType("string"); var.setString(qvar.toString()); } if(qvar.type()==QVariant::Int) { var.setType("string"); var.setString(QString::number(qvar.toInt())); } if(qvar.type()==QVariant::Double) { var.setType("string"); var.setString(QString::number(qvar.toDouble())); } return var; }
void JsonDbSortingListModel::setScriptableRoleNames(const QVariant &vroles) { Q_D(JsonDbSortingListModel); d->properties.clear(); d->roleNames.clear(); if (vroles.type() == QVariant::Map) { QVariantMap roles = vroles.toMap(); d->roleMap = roles; int i = 0; for (QVariantMap::const_iterator it = roles.begin(); it != roles.end(); ++it) { d->roleNames.insert(i, it.key().toLatin1()); d->properties.insert(i, removeArrayOperator(it.value().toString()).split('.')); i++; } } else { QVariantList roleList = vroles.toList(); d->roleMap.clear(); for (int i = 0; i < roleList.size(); i++) { QString role = roleList[i].toString(); d->roleMap[role] = role; d->roleNames.insert(i, role.toLatin1()); d->properties.insert(i, removeArrayOperator(role).split('.')); } } }
QString Utilities::prettyPrint(const QVariantMap & map) { QString res; res.append("{\n"); QVariantMap::const_iterator itr = map.begin(); res.append(QString("%1=%2").arg(itr.key(), prettyPrint(itr.value()))); for (++itr; itr != map.end(); ++itr) { res.append(QString("; %1=%2").arg(itr.key(), prettyPrint(itr.value()))); } res.append("}\n"); return res; }
void VlanSettingTest::testSetting() { QFETCH(QString, interfaceName); QFETCH(QString, parent); QFETCH(quint32, id); QFETCH(quint32, flags); QFETCH(QStringList, ingressPriorityMap); QFETCH(QStringList, egressPriorityMap); QVariantMap map; #if NM_CHECK_VERSION(1, 0, 0) map.insert(QLatin1String("interface-name"), interfaceName); #else map.insert(QLatin1String(NM_SETTING_VLAN_INTERFACE_NAME), interfaceName); #endif map.insert(QLatin1String(NM_SETTING_VLAN_PARENT), parent); map.insert(QLatin1String(NM_SETTING_VLAN_ID), id); map.insert(QLatin1String(NM_SETTING_VLAN_FLAGS), flags); map.insert(QLatin1String(NM_SETTING_VLAN_INGRESS_PRIORITY_MAP), ingressPriorityMap); map.insert(QLatin1String(NM_SETTING_VLAN_EGRESS_PRIORITY_MAP), egressPriorityMap); NetworkManager::VlanSetting setting; setting.fromMap(map); QVariantMap map1 = setting.toMap(); QVariantMap::const_iterator it = map.constBegin(); while (it != map.constEnd()) { QCOMPARE(it.value(), map1.value(it.key())); ++it; } }
QgsExpressionContextScope* QgsExpressionContextUtils::projectScope( const QgsProject* project ) { QgsExpressionContextScope* scope = new QgsExpressionContextScope( QObject::tr( "Project" ) ); if ( !project ) return scope; const QVariantMap vars = project->customVariables(); QVariantMap::const_iterator it = vars.constBegin(); for ( ; it != vars.constEnd(); ++it ) { scope->setVariable( it.key(), it.value() ); } //add other known project variables scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_title" ), project->title(), true ) ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_path" ), project->fileInfo().filePath(), true ) ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_folder" ), project->fileInfo().dir().path(), true ) ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_filename" ), project->fileInfo().fileName(), true ) ); QgsCoordinateReferenceSystem projectCrs = project->crs(); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs" ), projectCrs.authid(), true ) ); scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "project_crs_definition" ), projectCrs.toProj4(), true ) ); scope->addFunction( QStringLiteral( "project_color" ), new GetNamedProjectColor() ); return scope; }
void doStart(const JavaScriptCommand *cmd, Transformer *transformer) { m_result.success = true; m_result.errorMessage.clear(); ScriptEngine * const scriptEngine = provideScriptEngine(); QScriptValue scope = scriptEngine->newObject(); PrepareScriptObserver observer(scriptEngine); setupScriptEngineForFile(scriptEngine, transformer->rule->prepareScript->fileContext, scope); setupScriptEngineForProduct(scriptEngine, transformer->product(), transformer->rule->module, scope, &observer); transformer->setupInputs(scope); transformer->setupOutputs(scriptEngine, scope); for (QVariantMap::const_iterator it = cmd->properties().constBegin(); it != cmd->properties().constEnd(); ++it) { scope.setProperty(it.key(), scriptEngine->toScriptValue(it.value())); } QScriptContext *ctx = scriptEngine->currentContext(); ctx->pushScope(scope); scriptEngine->evaluate(cmd->sourceCode()); ctx->popScope(); transformer->propertiesRequestedInCommands += scriptEngine->propertiesRequestedInScript(); scriptEngine->clearRequestedProperties(); if (scriptEngine->hasUncaughtException()) { // ### We don't know the line number of the command's sourceCode property assignment. setError(scriptEngine->uncaughtException().toString(), cmd->codeLocation()); } }