本文整理汇总了C++中QVariantMap::insertMulti方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariantMap::insertMulti方法的具体用法?C++ QVariantMap::insertMulti怎么用?C++ QVariantMap::insertMulti使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariantMap
的用法示例。
在下文中一共展示了QVariantMap::insertMulti方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: actionOriginate
QString AsteriskManager::actionOriginate(QString channel,
QString exten,
QString context,
uint priority,
QString application,
QString data,
uint timeout,
QString callerID,
QVariantMap variables,
QString account,
boolean earlyMedia,
boolean async,
QStringList codecs)
{
QVariantMap headers;
headers["Channel"] = channel;
insertNotEmpty(&headers, "Exten", exten);
insertNotEmpty(&headers, "Context", context);
insertNotEmpty(&headers, "Priority", priority);
insertNotEmpty(&headers, "Application", application);
insertNotEmpty(&headers, "Data", data);
insertNotEmpty(&headers, "Timeout", timeout);
insertNotEmpty(&headers, "CallerID", callerID);
insertNotEmpty(&headers, "Account", account);
insertNotEmpty(&headers, "EarlyMedia", earlyMedia);
insertNotEmpty(&headers, "Async", async);
insertNotEmpty(&headers, "Codecs", codecs.join(","));
qDebug() << "Headers:" << headers;
if (!variables.isEmpty()) {
QMapIterator<QString, QVariant> variable(variables);
while (variable.hasNext()) {
variable.next();
headers.insertMulti("Variable", QString("%1=%2").arg(variable.key(), valueToString(variable.value())));
}
}
return action("Originate", headers);
}
示例2: mergeCLParametersWithJSONConfig
QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringList& argumentList) {
QVariantMap mergedMap;
// Add anything in the CL parameter list to the variant map.
// Take anything with a dash in it as a key, and the values after it as the value.
const QString DASHED_KEY_REGEX_STRING = "(^-{1,2})([\\w-]+)";
QRegExp dashedKeyRegex(DASHED_KEY_REGEX_STRING);
int keyIndex = argumentList.indexOf(dashedKeyRegex);
int nextKeyIndex = 0;
// check if there is a config file to read where we can pull config info not passed on command line
const QString CONFIG_FILE_OPTION = "--config";
while (keyIndex != -1) {
if (argumentList[keyIndex] != CONFIG_FILE_OPTION) {
// we have a key - look forward to see how many values associate to it
QString key = dashedKeyRegex.cap(2);
nextKeyIndex = argumentList.indexOf(dashedKeyRegex, keyIndex + 1);
if (nextKeyIndex == keyIndex + 1) {
// there's no value associated with this option, it's a boolean
// so add it to the variant map with NULL as value
mergedMap.insertMulti(key, QVariant());
} else {
int maxIndex = (nextKeyIndex == -1) ? argumentList.size() : nextKeyIndex;
// there's at least one value associated with the option
// pull the first value to start
QString value = argumentList[keyIndex + 1];
// for any extra values, append them, with a space, to the value string
for (int i = keyIndex + 2; i < maxIndex; i++) {
value += " " + argumentList[i];
}
// add the finalized value to the merged map
mergedMap.insert(key, value);
}
keyIndex = nextKeyIndex;
} else {
keyIndex = argumentList.indexOf(dashedKeyRegex, keyIndex + 1);
}
}
int configIndex = argumentList.indexOf(CONFIG_FILE_OPTION);
if (configIndex != -1) {
// we have a config file - try and read it
QString configFilePath = argumentList[configIndex + 1];
QFile configFile(configFilePath);
if (configFile.exists()) {
qDebug() << "Reading JSON config file at" << configFilePath;
configFile.open(QIODevice::ReadOnly);
QJsonDocument configDocument = QJsonDocument::fromJson(configFile.readAll());
QJsonObject rootObject = configDocument.object();
// enumerate the keys of the configDocument object
foreach(const QString& key, rootObject.keys()) {
if (!mergedMap.contains(key)) {
// no match in existing list, add it
mergedMap.insert(key, QVariant(rootObject[key]));
}
}
} else {
示例3: toVariant
/**
* @brief Convert an XML stream to a hierarchical QVariantMap.
*
* This function is used internally to embed opaque XML structures, such as the
* SQS service's ErrorResponse::Error::Detail, which the SQS schema defines as
* an arbitrary complex type.
*
* @note This static function exists within the AwsAbstractResponse for
* historic reasons. It should probably be moved our of this class, and
* into a more generic utility space at some point.
*
* @param xml XML stream to convert.
* @param prefix Prefix to apply to special (non-element) child entry names.
* @param maxDepth Maximum depth to traverse before truncating the tree.
*
* @return A QVariantMap representing the \a xml XML fragment.
*
* @todo Move this toVariant function to somewhere more generic.
*/
QVariantMap AwsAbstractResponse::toVariant(
QXmlStreamReader &xml, const QString &prefix, const int maxDepth)
{
if (maxDepth < 0) {
qWarning() << QObject::tr("max depth exceeded");
return QVariantMap();
}
if (xml.hasError()) {
qWarning() << xml.errorString();
return QVariantMap();
}
if (xml.tokenType() == QXmlStreamReader::NoToken)
xml.readNext();
if ((xml.tokenType() != QXmlStreamReader::StartDocument) &&
(xml.tokenType() != QXmlStreamReader::StartElement)) {
qWarning() << QObject::tr("unexpected XML tokenType %1 (%2)")
.arg(xml.tokenString()).arg(xml.tokenType());
return QVariantMap();
}
QVariantMap map;
if (xml.tokenType() == QXmlStreamReader::StartDocument) {
map.insert(prefix + QLatin1String("DocumentEncoding"), xml.documentEncoding().toString());
map.insert(prefix + QLatin1String("DocumentVersion"), xml.documentVersion().toString());
map.insert(prefix + QLatin1String("StandaloneDocument"), xml.isStandaloneDocument());
} else {
if (!xml.namespaceUri().isEmpty())
map.insert(prefix + QLatin1String("NamespaceUri"), xml.namespaceUri().toString());
foreach (const QXmlStreamAttribute &attribute, xml.attributes()) {
QVariantMap attributeMap;
attributeMap.insert(QLatin1String("Value"), attribute.value().toString());
if (!attribute.namespaceUri().isEmpty())
attributeMap.insert(QLatin1String("NamespaceUri"), attribute.namespaceUri().toString());
if (!attribute.prefix().isEmpty())
attributeMap.insert(QLatin1String("Prefix"), attribute.prefix().toString());
attributeMap.insert(QLatin1String("QualifiedName"), attribute.qualifiedName().toString());
map.insertMulti(prefix + attribute.name().toString(), attributeMap);
}
}
for (xml.readNext(); (!xml.atEnd()) && (xml.tokenType() != QXmlStreamReader::EndElement)
&& (xml.tokenType() != QXmlStreamReader::EndDocument); xml.readNext()) {
switch (xml.tokenType()) {
case QXmlStreamReader::Characters:
case QXmlStreamReader::Comment:
case QXmlStreamReader::DTD:
case QXmlStreamReader::EntityReference:
map.insertMulti(prefix + xml.tokenString(), xml.text().toString());
break;
case QXmlStreamReader::ProcessingInstruction:
map.insertMulti(prefix + xml.processingInstructionTarget().toString(),
xml.processingInstructionData().toString());
break;
case QXmlStreamReader::StartElement: {
const QString elementName = xml.name().toString();
map.insertMulti(elementName, toVariant(xml, prefix, maxDepth-1));
break;
}
default:
qWarning() << QObject::tr("unexpected XML tokenType %1 (%2)")
.arg(xml.tokenString()).arg(xml.tokenType());
}
}
return map;
}
示例4: mergeCLParametersWithJSONConfig
QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringList& argumentList) {
QVariantMap mergedMap;
// Add anything in the CL parameter list to the variant map.
// Take anything with a dash in it as a key, and the values after it as the value.
const QString DASHED_KEY_REGEX_STRING = "(^-{1,2})([\\w-]+)";
QRegExp dashedKeyRegex(DASHED_KEY_REGEX_STRING);
int keyIndex = argumentList.indexOf(dashedKeyRegex);
int nextKeyIndex = 0;
// check if there is a config file to read where we can pull config info not passed on command line
const QString CONFIG_FILE_OPTION = "--config";
while (keyIndex != -1) {
if (argumentList[keyIndex] != CONFIG_FILE_OPTION) {
// we have a key - look forward to see how many values associate to it
QString key = dashedKeyRegex.cap(2);
nextKeyIndex = argumentList.indexOf(dashedKeyRegex, keyIndex + 1);
if (nextKeyIndex == keyIndex + 1 || keyIndex == argumentList.size() - 1) {
// this option is simply a switch, so add it to the map with a value of `true`
mergedMap.insertMulti(key, QVariant(true));
} else {
int maxIndex = (nextKeyIndex == -1) ? argumentList.size() : nextKeyIndex;
// there's at least one value associated with the option
// pull the first value to start
QString value = argumentList[keyIndex + 1];
// for any extra values, append them, with a space, to the value string
for (int i = keyIndex + 2; i < maxIndex; i++) {
value += " " + argumentList[i];
}
// add the finalized value to the merged map
mergedMap.insert(key, value);
}
keyIndex = nextKeyIndex;
} else {
keyIndex = argumentList.indexOf(dashedKeyRegex, keyIndex + 1);
}
}
int configIndex = argumentList.indexOf(CONFIG_FILE_OPTION);
QString configFilePath;
if (configIndex != -1) {
// we have a config file - try and read it
configFilePath = argumentList[configIndex + 1];
} else {
// no config file - try to read a file config.json at the system config path
configFilePath = QString("%1/%2/%3/config.json").arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation),
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
}
return mergedMap;
}