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;
    }
}
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;
}
Exemple #3
0
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;
}
Exemple #4
0
 static inline bool valueFromVariantMap(const QVariantMap &v, const QString &key, T &value) {
     const QVariantMap::const_iterator it = v.constFind(key);
     const bool found = it != v.constEnd();
     if (found)
         value = qVariantValue<T>(it.value());
     return found;
 }
Exemple #5
0
    void doStart(const JavaScriptCommand *cmd, Transformer *transformer)
    {
        m_result.success = true;
        m_result.errorMessage.clear();
        ScriptEngine * const scriptEngine = provideScriptEngine();
        QScriptValue scope = scriptEngine->newObject();
        scope.setPrototype(scriptEngine->globalObject());
        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()));
        }

        scriptEngine->setGlobalObject(scope);
        scriptEngine->evaluate(cmd->sourceCode());
        scriptEngine->setGlobalObject(scope.prototype());
        transformer->propertiesRequestedInCommands
                += scriptEngine->propertiesRequestedInScript();
        transformer->propertiesRequestedFromArtifactInCommands
                = scriptEngine->propertiesRequestedFromArtifact();
        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());
        }
    }
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 TemplateSet :: resolve(const QString& name, const QString& format, QVariantMap* dict)
{
  QVariant result;
  QString resultStr;
  bool found = false;

  if(dict != NULL)
  {
    QVariantMap::const_iterator it = dict->find(name);

    if(it != dict->end())
    {
      result = it.value();
      found = true;
    }
  }

  if(!found)
  {
    StringMap::iterator it = strHash.find(name);
    if(it != strHash.end())
    {
      result = it.value();
    }
    else
      qDebug() << "Variable" << name << "not found";
  }

  if(!format.isEmpty())
  {
    QString formatStr;
    if(format.at(0).toAscii() != '%')
      formatStr = "%";
    formatStr += format;
    switch(formatStr.at(formatStr.size() - 1).toAscii())
    {
    case 'u':
    case 'X':
    case 'x':
      resultStr = QString().sprintf(formatStr.toAscii().constData(), result.toUInt());
      break;
    case 'd':
      resultStr = QString().sprintf(formatStr.toAscii().constData(), result.toInt());
      break;
    case 'f':
      resultStr = QString().sprintf(formatStr.toAscii().constData(), result.toDouble());
      break;
    case 's':
      resultStr = QString().sprintf(formatStr.toAscii().constData(), result.toString().toAscii().constData());
      break;
    default:
      qDebug() << "Format specifier not supported" << format;
      resultStr = result.toString();
      break;
    }
  }
  else
    resultStr = result.toString();
  return resultStr;
}
Exemple #8
0
void toJson(json::ostream_writer_t& os, const QVariant& var)
{
    QVariant::Type type = var.type();

    switch(type)
    {
    case QVariant::Map:
        {
            const QVariantMap map = var.toMap();

            os.object_start();

            for (QVariantMap::const_iterator it = map.begin();
                    it != map.end(); ++it)
            {
                os.new_string(it.key().toStdString().c_str());
                toJson(os, it.value());
            }

            os.object_end();
        }
        break;
    case QVariant::List:
    case QVariant::StringList:
        {
            const QVariantList list = var.toList();

            os.array_start();

            for (int i = 0; i < list.size(); i++)
            {
                toJson(os, list.at(i));
            }

            os.array_end();
        }
        break;
    case QVariant::String:
        {
            os.new_string(var.toString().toStdString().c_str());
        }
        break;
    case QVariant::Bool:
        {
            os.new_bool(var.toBool());
        }
        break;
    default:
        if (var.canConvert< double >())
        {
            os.new_double(var.toDouble());
            break;
        }
        os.new_string("unsupported yet!");
        break;
    }

}
Tileset *VariantToMapConverter::toTileset(const QVariant &variant)
{
    const QVariantMap variantMap = variant.toMap();

    const int firstGid = variantMap["firstgid"].toInt();
    const QString name = variantMap["name"].toString();
    const int tileWidth = variantMap["tilewidth"].toInt();
    const int tileHeight = variantMap["tileheight"].toInt();
    const int spacing = variantMap["spacing"].toInt();
    const int margin = variantMap["margin"].toInt();
    const QVariantMap tileOffset = variantMap["tileoffset"].toMap();
    const int tileOffsetX = tileOffset["x"].toInt();
    const int tileOffsetY = tileOffset["y"].toInt();

    if (tileWidth <= 0 || tileHeight <= 0 || firstGid == 0) {
        mError = tr("Invalid tileset parameters for tileset '%1'").arg(name);
        return 0;
    }

    Tileset *tileset = new Tileset(name,
                                   tileWidth, tileHeight,
                                   spacing, margin);
    tileset->setTileOffset(QPoint(tileOffsetX, tileOffsetY));

    const QString trans = variantMap["transparentcolor"].toString();
    if (!trans.isEmpty())
#if QT_VERSION >= 0x040700
        if (QColor::isValidColor(trans))
#endif
            tileset->setTransparentColor(QColor(trans));

    QString imageSource = variantMap["image"].toString();

    if (QDir::isRelativePath(imageSource))
        imageSource = mMapDir.path() + QLatin1Char('/') + imageSource;

    if (!tileset->loadFromImage(QImage(imageSource), imageSource)) {
        mError = tr("Error loading tileset image:\n'%1'").arg(imageSource);
        delete tileset;
        return 0;
    }

    tileset->setProperties(toProperties(variantMap["properties"]));

    QVariantMap propertiesVariantMap = variantMap["tileproperties"].toMap();
    QVariantMap::const_iterator it = propertiesVariantMap.constBegin();
    for (; it != propertiesVariantMap.constEnd(); ++it) {
        const int tileIndex = it.key().toInt();
        const QVariant propertiesVar = it.value();
        if (tileIndex >= 0 && tileIndex < tileset->tileCount()) {
            const Properties properties = toProperties(propertiesVar);
            tileset->tileAt(tileIndex)->setProperties(properties);
        }
    }

    mGidMapper.insert(firstGid, tileset);
    return tileset;
}
Exemple #10
0
void OgrWriter::_addFeature(OGRLayer* layer, shared_ptr<Feature> f, shared_ptr<Geometry> g)
{
  OGRFeature* poFeature = OGRFeature::CreateFeature( layer->GetLayerDefn() );

  // set all the column values.
  const QVariantMap& vm = f->getValues();

  for (QVariantMap::const_iterator it = vm.constBegin(); it != vm.constEnd(); ++it)
  {
    const QVariant& v = it.value();
    QByteArray ba = it.key().toUtf8();

    // If the field DOESN'T exist in the output layer, skip it.
    if (poFeature->GetFieldIndex(ba.constData()) == -1)
    {
      continue;
    }

    switch (v.type())
    {
    case QVariant::Invalid:
      poFeature->UnsetField(poFeature->GetFieldIndex(ba.constData()));
      break;
    case QVariant::Int:
      poFeature->SetField(ba.constData(), v.toInt());
      break;
    case QVariant::Double:
      poFeature->SetField(ba.constData(), v.toDouble());
      break;
    case QVariant::String:
    {
      QByteArray vba = v.toString().toUtf8();
      poFeature->SetField(ba.constData(), vba.constData());
      break;
    }
    default:
      strictError("Can't convert the provided value into an OGR value. (" + v.toString() + ")");
      return;
    }
  }

  // convert the geometry.
  shared_ptr<GeometryCollection> gc = dynamic_pointer_cast<GeometryCollection>(g);
  if (gc.get() != 0)
  {
    for (size_t i = 0; i < gc->getNumGeometries(); i++)
    {
      const Geometry* child = gc->getGeometryN(i);
      _addFeatureToLayer(layer, f, child, poFeature);
    }
  }
  else
  {
    _addFeatureToLayer(layer, f, g.get(), poFeature);
  }

  OGRFeature::DestroyFeature(poFeature);
}
Exemple #11
0
QScriptValue JSONData::createValue(const QVariant& value)
{
    if(value.type() == QVariant::Map)
    {
        QScriptValue obj = this->engine.newObject();

        QVariantMap map = value.toMap();
        QVariantMap::const_iterator it = map.begin();
        QVariantMap::const_iterator end = map.end();
        while(it != end)
        {
            obj.setProperty( it.key(), this->createValue(it.value()) );
            ++it;
        }

        return obj;
    }

    switch(value.type())
    {
    case QVariant::String:
        return QScriptValue(value.toString());
    case QVariant::Int:
        return QScriptValue(value.toInt());
    case QVariant::UInt:
        return QScriptValue(value.toUInt());
    case QVariant::LongLong:
        return QScriptValue((qsreal)value.toLongLong());
    case QVariant::Bool:
        return QScriptValue(value.toBool());
    case QVariant::ByteArray:
        return QScriptValue(QLatin1String(value.toByteArray()));
    case QVariant::Double:
        return QScriptValue((qsreal)value.toDouble());
    case QVariant::StringList: {
        QStringList stringList = value.toStringList();
        QScriptValue array = this->engine.newArray(stringList.length());
        for(int i=0; i<stringList.count(); i++)
            array.setProperty(i, stringList.at(i));
        return array;
    } break;
    case QVariant::List: {
        QList<QVariant> list = value.toList();
        QScriptValue array = this->engine.newArray(list.length());
        for(int i=0; i<list.count(); i++)
            array.setProperty(i, this->createValue(list.at(i)));
        return array;
    } break;
    default:
        break;
    }

    if(value.isNull())
        return QScriptValue(QScriptValue::NullValue);

    return this->engine.newVariant(value);
}
/*!
    Converts the variant map \a map to a QJsonObject.

    The keys in \a map will be used as the keys in the JSON object,
    and the QVariant values will be converted to JSON values.

    \sa fromVariantHash(), toVariantMap(), QJsonValue::fromVariant()
 */
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map)
{
    // ### this is implemented the trivial way, not the most efficient way

    QJsonObject object;
    for (QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it)
        object.insert(it.key(), QJsonValue::fromVariant(it.value()));
    return object;
}
Exemple #13
0
void
CredentialsManager::keychainJobFinished( QKeychain::Job* j )
{
    tDebug() << Q_FUNC_INFO;
    if ( QKeychain::ReadPasswordJob* readJob = qobject_cast< QKeychain::ReadPasswordJob* >( j ) )
    {
        if ( readJob->error() == QKeychain::NoError )
        {
            tDebug() << "QtKeychain readJob for" << readJob->service() << "/"
                     << readJob->key() << "finished without errors";

            QVariant creds;
            QJson::Parser parser;
            bool ok;

            creds = parser.parse( readJob->textData().toLatin1(), &ok );

            QVariantMap map = creds.toMap();
            QVariantHash hash;
            for ( QVariantMap::const_iterator it = map.constBegin();
                  it != map.constEnd(); ++it )
            {
                hash.insert( it.key(), it.value() );
            }
            creds = QVariant( hash );

            if ( !ok || creds.toHash().isEmpty() )
            {
                creds = QVariant( readJob->textData() );
            }

            m_credentials.insert( CredentialsStorageKey( readJob->service(), readJob->key() ), creds );
        }
        else
        {
            tDebug() << "QtKeychain readJob for" << readJob->service() << "/" << readJob->key() << "finished with error:" << j->error() << j->errorString();
        }

        m_readJobs[ readJob->service() ].removeOne( readJob );

        if ( m_readJobs[ readJob->service() ].isEmpty() )
        {
            emit serviceReady( readJob->service() );
        }
    }
    else if ( QKeychain::WritePasswordJob* writeJob = qobject_cast< QKeychain::WritePasswordJob* >( j ) )
    {
        tLog() << Q_FUNC_INFO << "QtKeychain writeJob for" << writeJob->service() << "/" << writeJob->key() << "finished"
               << ( ( j->error() == QKeychain::NoError ) ? "without error" : j->errorString() );
    }
    else if ( QKeychain::DeletePasswordJob* deleteJob = qobject_cast< QKeychain::DeletePasswordJob* >( j ) )
    {
        tLog() << Q_FUNC_INFO << "QtKeychain deleteJob for" << deleteJob->service() << "/" << deleteJob->key() << "finished"
               << ( ( j->error() == QKeychain::NoError ) ? "without error" : j->errorString() );
    }
    j->deleteLater();
}
Exemple #14
0
void FaceDetector::setParameters(const QVariantMap& parameters)
{
    for (QVariantMap::const_iterator it = parameters.begin(); it != parameters.end(); ++it)
    {
        d->m_parameters.insert(it.key(), it.value());
    }

    d->applyParameters();
}
Exemple #15
0
void VRosterPrivate::onGetTagListRequestFinished(const QVariant &var, bool error)
{
	Q_Q(VRoster);
	Q_UNUSED(error);
	QVariantMap tagData = var.toMap();
	QVariantMap::const_iterator it = tagData.constBegin();
	for (; it != tagData.constEnd(); it++)
		tags.insert(it.key(), it.value().toString());
	q->getFriendList();
}
Exemple #16
0
void QPpsObjectPrivate::encodeObject(pps_encoder_t *encoder, const QVariantMap &data, bool *ok)
{
    for (QVariantMap::const_iterator it = data.constBegin(); it != data.constEnd(); ++it) {
        encodeData(encoder, it.key().toUtf8().constData(), it.value(), ok);
        if (!(*ok))
            return;
    }
    // if the passed data is empty, nothing went wrong and ok is set to true
    *ok = true;
}
Exemple #17
0
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();
        }
    }
}
/*!
 * Set the overridden values of the build configuration.
 */
void SetupProjectParameters::setOverriddenValues(const QVariantMap &values)
{
    // warn if somebody tries to set a build configuration tree:
    for (QVariantMap::const_iterator i = values.constBegin();
            i != values.constEnd(); ++i) {
        QBS_ASSERT(i.value().type() != QVariant::Map, return);
    }
    d->overriddenValues = values;
    d->overriddenValuesTree.clear();
    d->finalBuildConfigTree.clear();
}
Exemple #19
0
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);
    }
}
Exemple #20
0
/*!
  Streams the \a collection to the given debug stream \a dbg, and returns the stream.
  \since 1.1
 */
QDebug operator<<(QDebug dbg, const QOrganizerCollection& collection)
{
    dbg.nospace() << "QOrganizerCollection(id=" << collection.id();
    QVariantMap metadata = collection.metaData();
    QVariantMap::const_iterator it;
    for (it = metadata.constBegin(); it != metadata.constEnd(); ++it) {
        dbg.nospace() << ", " << it.key() << '=' << it.value();
    }
    dbg.nospace() << ')';
    return dbg.maybeSpace();
}
QScriptValue variantMapToScriptValue(QVariantMap& variantMap, QScriptEngine& scriptEngine) {
    QScriptValue scriptValue = scriptEngine.newObject();

    for (QVariantMap::const_iterator iter = variantMap.begin(); iter != variantMap.end(); ++iter) {
        QString key = iter.key();
        QVariant qValue = iter.value();
        scriptValue.setProperty(key, variantToScriptValue(qValue, scriptEngine));
    }

    return scriptValue;
}
Exemple #22
0
QDebug operator<<(QDebug dbg, const QContactDetail& detail)
{
    dbg.nospace() << "QContactDetail(name=" << detail.definitionName() << ", key=" << detail.key();
    QVariantMap fields = detail.variantValues();
    QVariantMap::const_iterator it;
    for (it = fields.constBegin(); it != fields.constEnd(); ++it) {
        dbg.nospace() << ", " << it.key() << '=' << it.value();
    }
    dbg.nospace() << ')';
    return dbg.maybeSpace();
}
Exemple #23
0
/*! Returns the hash value for \a key.
  \since 1.1
*/
uint qHash(const QOrganizerCollection &key)
{
    uint hash = qHash(key.id());
    QVariantMap metadata = key.metaData();
    QVariantMap::const_iterator it;
    for (it = metadata.constBegin(); it != metadata.constEnd(); ++it) {
        hash += qHash(it.key())
                + QT_PREPEND_NAMESPACE(qHash)(it.value().toString());
    }

    return hash;
}
void JsonDbSortingListModelPrivate::generateCustomData(QVariantMap &valMap)
{
    Q_Q(JsonDbSortingListModel);
    QJSValueList args;
    args << injectCallback.engine()->toScriptValue(valMap);
    QJSValue retVal = injectCallback.call(args);
    QVariantMap customData = qjsvalue_cast<QVariant>(retVal).toMap();
    QVariantMap::const_iterator it = customData.constBegin(), e = customData.constEnd();
    for (; it != e; ++it) {
        valMap.insert(it.key(), it.value());
    }
}
void WirelessSecuritySetting::testSetting()
{
    QFETCH(QString, keyMgmt);
    QFETCH(quint32, wepTxKeyidx);
    QFETCH(QString, authAlg);
    QFETCH(QStringList, proto);
    QFETCH(QStringList, pairwise);
    QFETCH(QStringList, group);
    QFETCH(QString, leapUsername);
    QFETCH(QString, wepKey0);
    QFETCH(QString, wepKey1);
    QFETCH(QString, wepKey2);
    QFETCH(QString, wepKey3);
    QFETCH(quint32, wepKeyFlags);
    QFETCH(quint32, wepKeyType);
    QFETCH(QString, psk);
    QFETCH(quint32, pskFlags);
    QFETCH(QString, leapPassword);
    QFETCH(quint32, leapPasswordFlags);

    QVariantMap map;

    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), keyMgmt);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), wepTxKeyidx);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), authAlg);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO), proto);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE), pairwise);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP), group);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), leapUsername);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), wepKey0);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), wepKey1);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), wepKey2);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), wepKey3);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), wepKeyFlags);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), wepKeyType);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), psk);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), pskFlags);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), leapPassword);
    map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), leapPasswordFlags);

    NetworkManager::WirelessSecuritySetting setting;
    setting.fromMap(map);

    QVariantMap map1 = setting.toMap();

    // Will fail if set some default values, because they are skipped in toMap() method
    QVariantMap::const_iterator it = map.constBegin();
    while (it != map.constEnd()) {
        QCOMPARE(it.value(), map1.value(it.key()));
        ++it;
    }
}
Exemple #26
0
void StatusChecker::statusDownloadFinished()
{
	QLOG_DEBUG() << "Finished loading status JSON.";

	QByteArray data;
	{
		ByteArrayDownloadPtr dl = std::dynamic_pointer_cast<ByteArrayDownload>(m_statusNetJob->first());
		data = dl->m_data;
		m_statusNetJob.reset();
	}

	QJsonParseError jsonError;
	QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);

	if (jsonError.error != QJsonParseError::NoError)
	{
		fail("Error parsing status JSON:" + jsonError.errorString());
		return;
	}

	if (!jsonDoc.isArray())
	{
		fail("Error parsing status JSON: JSON root is not an array");
		return;
	}

	QJsonArray root = jsonDoc.array();

	for(auto status = root.begin(); status != root.end(); ++status)
	{
		QVariantMap map = (*status).toObject().toVariantMap();

		for (QVariantMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
		{
			QString key = iter.key();
			QVariant value = iter.value();

			if(value.type() == QVariant::Type::String)
			{
				m_statusEntries.insert(key, value.toString());
				//QLOG_DEBUG() << "Status JSON object: " << key << m_statusEntries[key];
			}
			else
			{
				fail("Malformed status JSON: expected status type to be a string.");
				return;
			}
		}
	}

	succeed();
}
Exemple #27
0
void PppSetting::testSetting()
{
    QFETCH(bool, noAuth);
    QFETCH(bool, refuseEap);
    QFETCH(bool, refusePap);
    QFETCH(bool, refuseChap);
    QFETCH(bool, refuseMschap);
    QFETCH(bool, refuseMschapv2);
    QFETCH(bool, noBsdComp);
    QFETCH(bool, noDeflate);
    QFETCH(bool, noVjCompare);
    QFETCH(bool, requireMppe);
    QFETCH(bool, requireMppe128);
    QFETCH(bool, mppeStateful);
    QFETCH(bool, cRtsCts);
    QFETCH(quint32, baud);
    QFETCH(quint32, mru);
    QFETCH(quint32, mtu);
    QFETCH(quint32, lcpEchoFailure);
    QFETCH(quint32, lcpEchoInterval);

    QVariantMap map;

    map.insert(QLatin1String(NM_SETTING_PPP_NOAUTH), noAuth);
    map.insert(QLatin1String(NM_SETTING_PPP_REFUSE_EAP), refuseEap);
    map.insert(QLatin1String(NM_SETTING_PPP_REFUSE_PAP), refusePap);
    map.insert(QLatin1String(NM_SETTING_PPP_REFUSE_CHAP), refuseChap);
    map.insert(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP), refuseMschap);
    map.insert(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2), refuseMschapv2);
    map.insert(QLatin1String(NM_SETTING_PPP_NOBSDCOMP), noBsdComp);
    map.insert(QLatin1String(NM_SETTING_PPP_NODEFLATE), noDeflate);
    map.insert(QLatin1String(NM_SETTING_PPP_NO_VJ_COMP), noVjCompare);
    map.insert(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE), requireMppe);
    map.insert(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128), requireMppe128);
    map.insert(QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL), mppeStateful);
    map.insert(QLatin1String(NM_SETTING_PPP_CRTSCTS), cRtsCts);
    map.insert(QLatin1String(NM_SETTING_PPP_BAUD), baud);
    map.insert(QLatin1String(NM_SETTING_PPP_MRU), mru);
    map.insert(QLatin1String(NM_SETTING_PPP_MTU), mtu);
    map.insert(QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE), lcpEchoFailure);
    map.insert(QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL), lcpEchoInterval);

    NetworkManager::PppSetting 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;
    }
}
Exemple #28
0
/*!
    Converts the variant map \a map to a QJsonObject.

    The keys in \a map will be used as the keys in the JSON object,
    and the QVariant values will be converted to JSON values.

    \sa fromVariantHash(), toVariantMap(), QJsonValue::fromVariant()
 */
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map)
{
    QJsonObject object;
    if (map.isEmpty())
        return object;

    object.detach2(1024);

    QVector<QJsonPrivate::offset> offsets;
    QJsonPrivate::offset currentOffset;
    currentOffset = sizeof(QJsonPrivate::Base);

    // the map is already sorted, so we can simply append one entry after the other and
    // write the offset table at the end
    for (QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it) {
        QString key = it.key();
        QJsonValue val = QJsonValue::fromVariant(it.value());

        bool latinOrIntValue;
        int valueSize = QJsonPrivate::Value::requiredStorage(val, &latinOrIntValue);

        bool latinKey = QJsonPrivate::useCompressed(key);
        int valueOffset = sizeof(QJsonPrivate::Entry) + QJsonPrivate::qStringSize(key, latinKey);
        int requiredSize = valueOffset + valueSize;

        if (!object.detach2(requiredSize + sizeof(QJsonPrivate::offset))) // offset for the new index entry
            return QJsonObject();

        QJsonPrivate::Entry *e = reinterpret_cast<QJsonPrivate::Entry *>(reinterpret_cast<char *>(object.o) + currentOffset);
        e->value.type = val.t;
        e->value.latinKey = latinKey;
        e->value.latinOrIntValue = latinOrIntValue;
        e->value.value = QJsonPrivate::Value::valueToStore(val, (char *)e - (char *)object.o + valueOffset);
        QJsonPrivate::copyString((char *)(e + 1), key, latinKey);
        if (valueSize)
            QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);

        offsets << currentOffset;
        currentOffset += requiredSize;
        object.o->size = currentOffset;
    }

    // write table
    object.o->tableOffset = currentOffset;
    if (!object.detach2(sizeof(QJsonPrivate::offset)*offsets.size()))
        return QJsonObject();
    memcpy(object.o->table(), offsets.constData(), offsets.size()*sizeof(uint));
    object.o->length = offsets.size();
    object.o->size = currentOffset + sizeof(QJsonPrivate::offset)*offsets.size();

    return object;
}
Properties VariantToMapConverter::toProperties(const QVariant &variant)
{
    const QVariantMap variantMap = variant.toMap();

    Properties properties;

    QVariantMap::const_iterator it = variantMap.constBegin();
    QVariantMap::const_iterator it_end = variantMap.constEnd();
    for (; it != it_end; ++it)
        properties[it.key()] = it.value().toString();

    return properties;
}
void MetaModel::setMetaData(const QVariantMap &metaData)
{
	//delete old metadata in key
	foreach(MetaItem* item, m_model)
		deleteKeyMetaData(item->metaName());

	//delete old metadata in model
	clear();

	for(QVariantMap::const_iterator iter = metaData.begin(); iter != metaData.end(); iter++) {
		insertRow(m_model.count(), new MetaItem(iter.key(), iter.value()));
	}
}