Esempio n. 1
0
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;
}
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;
}
Esempio n. 3
0
void ShaderDialog::copyParametersToDialog(QVariantMap const& map)
{
   QString name;
   double val;
   bool ok;

   hideOptionControls();
   int sliderCount(0);
   int checkBoxCount(0);
   int lightBoxCount(0);

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

       if (name.startsWith("user_light_")) {
          // lights are either on or off, no dimmers here
          name.replace("user_light_","");
          name.replace("_"," ");
          m_dialog.lightBox->show();
          if (lightBoxCount < s_maxLightBoxes) {
             m_lightBoxes[lightBoxCount]->show();
             m_lightBoxes[lightBoxCount]->setText(name);
             m_lightBoxes[lightBoxCount]->setChecked(iter.value().toBool());
             ++lightBoxCount;
          }

       } else if (name.startsWith("user_")) {
          name.replace("user_","");
          name.replace("_"," ");

          switch (iter.value().type()) {
             case QVariant::Bool:
                if (checkBoxCount < s_maxCheckBoxes) {
                   m_dialog.optionBox->show();
                   m_checkBoxes[checkBoxCount]->show();
                   m_checkBoxes[checkBoxCount]->setText(name);
                   m_checkBoxes[checkBoxCount]->setChecked(iter.value().toBool());
                   ++checkBoxCount;
                }
             break;
             case QVariant::Double:
             case QMetaType::Float:
                val = iter.value().toDouble(&ok);  
                if (ok && val <= 1.0 && sliderCount < s_maxSliders) {  
                   m_labels[sliderCount]->show();
                   m_labels[sliderCount]->setText(name);
                   m_sliders[sliderCount]->show();
                   m_sliders[sliderCount]->setValue(100*val);
                   ++sliderCount;
                }
             break;
             default:
                qDebug() << "Unsupported QVariant type in ShaderDialog" << iter.value().type();
             break;
          }
      }
   }  
}
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()));
            }
        }
    }
}
Esempio n. 5
0
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);
    }
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
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) );
        }
Esempio n. 9
0
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;
        }
    }
Esempio n. 10
0
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.
    }
}
Esempio n. 11
0
/*----------------------------------------------------------------------------*/
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;
}
Esempio n. 12
0
/*
 * This function builds a map of hostname -> [ "region" -> regionName, "service" -> serviceName ]
 * for every host AWS supports (as gleaned from Amazons' endpoints.xml file).
 */
QVariantMap AwsEndpointTestData::hostInfoMap()
{
    QVariantMap hosts;
    const QVariantMap regions = AwsEndpointTestData::regionServiceHosts();
    for (QVariantMap::const_iterator region = regions.constBegin(); region != regions.constEnd(); ++region) {
        const QVariantMap services = region.value().toMap();
        for (QVariantMap::const_iterator service = services.constBegin(); service != services.constEnd(); ++service) {
            QVariantMap hostInfo;
            hostInfo.insert(QLatin1String("region"),
                hosts.contains(service.value().toString()) ? QString::fromLatin1("us-east-1") : region.key());
            hostInfo.insert(QLatin1String("service"), service.key());
            hosts.insert(service.value().toString(), hostInfo);
       }
    }
    return hosts;
}
Esempio n. 13
0
	void MprisPlayer::onPropertiesChanged(const QDBusMessage &msg)
	{
		QDBusArgument arg = msg.arguments().at(1).value<QDBusArgument>();
		QVariantMap map = qdbus_cast<QVariantMap>(arg);
		QVariantMap::const_iterator it = map.find(QLatin1String("Metadata"));
		if (it != map.end()) {
			arg = it.value().value<QDBusArgument>();
			onTrackChanged(qdbus_cast<QVariantMap>(arg));
		}
		it = map.find(QLatin1String("PlaybackStatus"));
		if (it != map.end()) {
			DBusMprisPlayerStatus status;
			status.Play = it.value().toString() == QLatin1String("Playing") ? 0 : 1;
			onStatusChanged(status);
		}
	}
Esempio n. 14
0
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;
    }
}
Esempio n. 15
0
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;
}
Esempio n. 16
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;
}
Esempio n. 17
0
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;
}
Esempio n. 19
0
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;
    }
}
Esempio n. 20
0
File: var.cpp Progetto: Aspenka/SSD
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 ModemManager::ModemLocationInterface::propertiesChanged(const QString & interface, const QVariantMap & properties)
{
    mmDebug() << interface << properties.keys();

    if (interface == QString("org.freedesktop.ModemManager.Modem.Location")) {
        QLatin1String capabilities("Capabilities");
        QLatin1String enabled("Enabled");
        QLatin1String signalsLocation("SignalsLocation");
        QLatin1String location("Location");

        QVariantMap::const_iterator it = properties.find(capabilities);
        if ( it != properties.end()) {
            emit capabilitiesChanged((ModemManager::ModemLocationInterface::Capability)it->toUInt());
        }
        it = properties.find(enabled);
        if ( it != properties.end()) {
            emit enabledChanged(it->toBool());
        }
        it = properties.find(signalsLocation);
        if ( it != properties.end()) {
            emit signalsLocationChanged(it->toBool());
        }
        it = properties.find(location);
        if ( it != properties.end()) {
            QVariant v = it.value();
            LocationInformationMap map;
            if (v.canConvert<LocationInformationMap>()) {
                map = v.value<LocationInformationMap>();
            } else {
                mmDebug() << "Error converting LocationInformationMap property";
            }
            emit locationChanged(map);
        }
    }
}
Esempio n. 22
0
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;
}
Esempio n. 23
0
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;
}
Esempio n. 24
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;
 }
Esempio n. 25
0
    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());
        }
    }
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('.'));
        }
    }
}
Esempio n. 27
0
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));
    }
}
Esempio n. 28
0
void TableView::guiUpdateTimerTick()
{
	QVariantMap::const_iterator i = m_valueMap.constBegin();
	while (i != m_valueMap.constEnd())
	{
		if (i.value().type() == QVariant::Double)
		{
			//widget->propertyMap.setProperty(i.key().toAscii(),QVariant::fromValue(i.value()));
			double val = i.value().toDouble();
			QString valstr = QString::number(val,'f',2);
			ui.tableWidget->item(m_nameToIndexMap[i.key()],1)->setText(valstr);
		}
		//qDebug() << i.key() << m_nameToIndexMap[i.key()] << i.value();
		i++;
	}

}
Esempio n. 29
0
/*
 * This function builds a map of serivceName -> regionNames -> (int)transports for every
 * service and region AWS supports (as gleaned from Amazons' endpoints.xml file).
 */
QVariantMap AwsEndpointTestData::supportedRegionsMap()
{
    QVariantMap supportedRegions;

    // Transpose the supportedServicesMap output.
    const QVariantMap regions = AwsEndpointTestData::supportedServicesMap();
    for (QVariantMap::const_iterator region = regions.constBegin(); region != regions.constEnd(); ++region) {
        const QVariantMap services = region.value().toMap();
        for (QVariantMap::const_iterator service = services.constBegin(); service != services.constEnd(); ++service) {
            QVariantMap map = supportedRegions.value(service.key()).toMap();
            map.insert(region.key(), service.value());
            supportedRegions.insert(service.key(), map);
        }
    }

    return supportedRegions;
}
Esempio n. 30
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;
    }

}