本文整理汇总了C++中qvariantmap::const_iterator类的典型用法代码示例。如果您正苦于以下问题:C++ const_iterator类的具体用法?C++ const_iterator怎么用?C++ const_iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了const_iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testSetting
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;
}
}
示例2: findKey
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;
}
示例3: valueFromVariantMap
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;
}
示例4: testSetting
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;
}
}
示例5: resolve
/*----------------------------------------------------------------------------*/
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;
}
示例6: toJson
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;
}
}
示例7: tr
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;
}
示例8: _addFeature
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);
}
示例9: createValue
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);
}
示例10: fromVariantMap
/*!
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;
}
示例11: serviceReady
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();
}
示例12: setParameters
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();
}
示例13: onGetTagListRequestFinished
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();
}
示例14: encodeObject
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;
}
示例15: setMetaData
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();
}
}
}