本文整理汇总了C++中QVariantMap::size方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariantMap::size方法的具体用法?C++ QVariantMap::size怎么用?C++ QVariantMap::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariantMap
的用法示例。
在下文中一共展示了QVariantMap::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_map
void MixedTest::test_map()
{
QVariantMap map;
map.insert(QString("%1").QString::arg(0, 5), "v");
QByteArray arr = MsgPack::pack(map);
QVERIFY(arr.size() == map.size() * 8 + 1);
quint8 *p = (quint8 *)arr.data();
QVERIFY(p[0] == (0x80 | map.size()));
QVariantMap m2 = MsgPack::unpack(arr).toMap();
QVERIFY(m2 == map);
for (int i = 1; i < 16; ++i)
map.insert(QString("%1").QString::arg(i, 5), "v");
arr = MsgPack::pack(map);
QVERIFY(arr.size() == map.size() * 8 + 3);
p = (quint8 *)arr.data();
QVERIFY(p[0] == 0xde);
QVERIFY(p[1] == 0x00);
QVERIFY(p[2] == 0x10);
m2 = MsgPack::unpack(arr).toMap();
QVERIFY(m2 == map);
for (int i = 16; i < 65536; ++i)
map.insert(QString("%1").QString::arg(i, 5), "v");
arr = MsgPack::pack(map);
QVERIFY(arr.size() == map.size() * 8 + 5);
p = (quint8 *)arr.data();
QVERIFY(p[0] == 0xdf);
QVERIFY(p[1] == 0x00);
QVERIFY(p[2] == 0x01);
QVERIFY(p[3] == 0x00);
QVERIFY(p[4] == 0x00);
m2 = MsgPack::unpack(arr).toMap();
QVERIFY(m2 == map);
}
示例2: parseResponseListFolders
void DBTalker::parseResponseListFolders(const QByteArray& data)
{
//added root in list at constructor and call getfolderslist after calling list folders in dbwindow
QJson::Parser parser;
bool ok;
QVariant result = parser.parse(data,&ok);
if(!ok)
{
emit signalBusy(false);
emit signalListAlbumsFailed(i18n("Failed to list folders"));
return;
}
QList<QPair<QString, QString> > list;
list.clear();
list.append(qMakePair(QString("/"),QString("root")));
QVariantMap rmap = result.toMap();
QList<QString> a = rmap.uniqueKeys();
for(int i=0;i<rmap.size();i++)
{
if(a[i] == "contents")
{
QVariantList qwe = rmap[a[i]].toList();
foreach(QVariant abc, qwe)
{
QVariantMap qwer = abc.toMap();
QList<QString> b = qwer.uniqueKeys();
QString path("");
QString isDir("");
int temp = 0;
for(int i=0;i<qwer.size();i++)
{
if(b[i] == "is_dir")
isDir = qwer[b[i]].value<QString>();
if(b[i] == "path")
{
path = qwer[b[i]].value<QString>();
temp = i;
}
}
if(QString::compare(isDir, QString("true"), Qt::CaseInsensitive) == 0)
{
kDebug() << temp << " " << b[temp] << " : " << qwer[b[temp]] << " " << qwer[b[temp]].value<QString>() << endl;
QString name = qwer[b[temp]].value<QString>().section('/',-2);
kDebug() << "str " << name;
list.append(qMakePair(qwer[b[temp]].value<QString>(),name));
queue.enqueue(qwer[b[temp]].value<QString>());
}
}
}
示例3: handleScope
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;
}
示例4: convertArgs
bool JsonRpcServer::convertArgs(const QMetaMethod& meta_method,
const QVariantMap& args,
QVariantList& converted_args)
{
QList<QByteArray> param_types = meta_method.parameterTypes();
if (args.size() != param_types.size()) {
logError(QString("wrong number of arguments to method %1 -- "
"expected %2 arguments, but got %3")
.arg(QString(meta_method.methodSignature()))
.arg(meta_method.parameterCount())
.arg(args.size()));
return false;
}
for (int i = 0; i < param_types.size(); i++) {
QByteArray param_name = meta_method.parameterNames().at(i);
if (args.find(param_name) == args.end()) {
// no arg with param name found
return false;
}
const QVariant& arg = args.value(param_name);
if (!arg.isValid()) {
logError(QString("argument %1 of %2 to method %3 is invalid")
.arg(i + 1)
.arg(param_types.size())
.arg(QString(meta_method.methodSignature())));
return false;
}
QByteArray arg_type_name = arg.typeName();
QByteArray param_type_name = param_types.at(i);
QVariant::Type param_type = QVariant::nameToType(param_type_name);
QVariant copy = QVariant(arg);
if (copy.type() != param_type) {
if (copy.canConvert(param_type)) {
if (!copy.convert(param_type)) {
// qDebug() << "cannot convert" << arg_type_name
// << "to" << param_type_name;
return false;
}
}
}
converted_args << copy;
}
return true;
}
示例5: addFlow
QStringList WorkflowModel::addFlow(int vertexFrom, int vertexTo, const QVariantMap& flowpoints, int rectFrom, int rectTo)
{
QStringList* parameterEntrySet = new QStringList();
if ( vertexFrom >= 0 && vertexTo >= 0 && flowpoints.size() == 2) {
try {
const OVertex& fromOperationVertex = vertexFrom;
const OVertex& toOperationVertex = vertexTo;
int outParamIndex = flowpoints["fromParameterIndex"].toInt();
int inParamIndex = flowpoints["toParameterIndex"].toInt();
int parameterIndex = _workflow->getWorkflowParameterIndex(toOperationVertex, inParamIndex);
parameterEntrySet->push_back(QString::number(parameterIndex) + "|remove");
--_inputParameterCount;
EdgeProperties flowPoperties(
outParamIndex, inParamIndex,
rectFrom, rectTo
);
_workflow->addOperationFlow(fromOperationVertex,toOperationVertex,flowPoperties);
} catch (std::out_of_range e) {
qDebug() << "False operation";
}
}
return *parameterEntrySet;
}
示例6: parseResponseAddPhoto
void DBTalker::parseResponseAddPhoto(const QByteArray& data)
{
bool success = false;
QJson::Parser parser;
bool ok;
QVariant result = parser.parse(data, &ok);
QVariantMap rmap = result.toMap();
QList<QString> keys = rmap.uniqueKeys();
for(int i=0;i<rmap.size();i++)
{
if(keys[i] == "bytes")
{
success = true;
break;
}
}
emit signalBusy(false);
if(!success)
{
emit signalAddPhotoFailed(i18n("Failed to upload photo"));
}
else
{
emit signalAddPhotoSucceeded();
}
}
示例7: prepareSetFieldsUpdateQuery
void DatabaseUtilities::prepareSetFieldsUpdateQuery(QSqlQuery& query, QString const& queryString, QVariantMap const& fieldsAndValues) {
if (fieldsAndValues.size() > 0) {
QString setString;
setString.reserve(512);
auto it = fieldsAndValues.constBegin();
auto const end = fieldsAndValues.constEnd();
int keyIndex = 1;
for (; it != end; ++it) {
if (!setString.isEmpty()) {
setString.append(QStringLiteral(", "));
}
setString.append(QStringLiteral("`%1` = :value%2").arg(it.key()).arg(keyIndex, 4, 10, QChar('0')));
++keyIndex;
}
query.prepare(queryString.arg(setString));
it = fieldsAndValues.constBegin();
keyIndex = 1;
for (; it != end; ++it) {
query.bindValue(QStringLiteral(":value%1").arg(keyIndex, 4, 10, QChar('0')), it.value());
++keyIndex;
}
} else {
throw openmittsu::exceptions::InternalErrorException() << "Can not build setFields update query part with empty field/value map, this should never happen!";
}
}
示例8: parse
static Task::List parse(const QVariant &data)
{
const QVariantMap results = data.toMap();
Task::List tasks;
tasks.reserve(results.size());
for (auto iter = results.cbegin(), end = results.cend(); iter != end; ++iter) {
const QVariantMap d = iter.value().toMap();
Task task;
task.d_ptr->phid = iter.key().toLatin1();
task.d_ptr->id = d[QStringLiteral("id")].toUInt();
task.d_ptr->authorPHID = d[QStringLiteral("authorPHID")].toByteArray();
task.d_ptr->ownerPHID = d[QStringLiteral("ownerPHID")].toByteArray();
const QVariantList ccPHIDs = d[QStringLiteral("ccPHIDs")].toList();
task.d_ptr->ccPHIDs.reserve(ccPHIDs.size());
Q_FOREACH (const QVariant &ccPHID, ccPHIDs) {
task.d_ptr->ccPHIDs.push_back(ccPHID.toByteArray());
}
task.d_ptr->status = d[QStringLiteral("status")].toString();
task.d_ptr->statusName = d[QStringLiteral("statusName")].toString();
task.d_ptr->isClosed = d[QStringLiteral("isClosed")].toBool();
task.d_ptr->priority = d[QStringLiteral("priority")].toString();
task.d_ptr->priorityColor = d[QStringLiteral("priorityColor")].toString();
task.d_ptr->title = d[QStringLiteral("title")].toString();
task.d_ptr->description = d[QStringLiteral("description")].toString();
const QVariantList projectPHIDs = d[QStringLiteral("projectPHIDs")].toList();
task.d_ptr->projectPHIDs.reserve(projectPHIDs.size());
Q_FOREACH (const QVariant &projectPHID, projectPHIDs) {
task.d_ptr->projectPHIDs.push_back(projectPHID.toByteArray());
}
示例9: buildHTTPQuery
/*! \brief Returns parameters \a params as a string
*
* The string is formated like this: par1=var1&par2=var2
* \param params Parameters to convert
* \param skipOAuth Should parameters starting with oauth_ be omitted
* \return A string of sorted and encoded parameters
*/
QString Util::buildHTTPQuery(const QVariantMap ¶ms, bool skipOAuth)
{
if(params.size() == 0) {
return NULL;
}
QString out;
QMapIterator<QString, QVariant> it(params);
while(it.hasNext()) {
it.next();
QString key = Util::encode(it.key());
QString value = Util::encode(it.value().toString());
if(!(skipOAuth && key.contains("oauth_"))) {
out += QString("%1=%2&").arg(key).arg(value);
}
}
if(out.endsWith("&")) {
out.chop(1);
}
return out;
}
示例10: createHashMap
static jobject createHashMap(const QVariantMap &data) {
QAndroidJniEnvironment env;
jclass mapClass = env->FindClass("java/util/HashMap");
if (mapClass == NULL) {
qWarning() << "Failed to find class" << "java/util/HashMap";
return NULL;
}
jclass integerClass = env->FindClass("java/lang/Integer");
jmethodID integerConstructor = env->GetMethodID(integerClass, "<init>", "(I)V");
jclass booleanClass = env->FindClass("java/lang/Boolean");
jmethodID booleanConstructor = env->GetMethodID(booleanClass,"<init>","(Z)V");
jsize map_len = data.size();
jmethodID init = env->GetMethodID(mapClass, "<init>", "(I)V");
jobject hashMap = env->NewObject( mapClass, init, map_len);
jmethodID put = env->GetMethodID( mapClass, "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
QMapIterator<QString, QVariant> iter(data);
while (iter.hasNext()) {
iter.next();
// qDebug() << iter.key() << iter.value();
QString key = iter.key();
jstring jkey = env->NewStringUTF(key.toLocal8Bit().data());
QVariant v = iter.value();
if (v.type() == QVariant::String) {
QString str = v.toString();
jstring vString = env->NewStringUTF(str.toLocal8Bit().data());
env->CallObjectMethod(hashMap,put,jkey,vString);
} else if (v.type() == QVariant::Int) {
jobject integer = env->NewObject(integerClass,integerConstructor,v.toInt());
env->CallObjectMethod(hashMap,put,jkey,integer);
} else if (v.type() == QVariant::Bool) {
jobject boolean = env->NewObject(booleanClass,booleanConstructor,v.toBool());
env->CallObjectMethod(hashMap,put,jkey,boolean);
} else {
qWarning() << "QASystemDispatcher: Non-supported data type - " << v.type();
}
}
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
return hashMap;
}
示例11: testJSONToVariantMap
void UtilTest::testJSONToVariantMap() {
QString json = "{ \"jid\": \"[email protected]\", \"message\": \"test \\\"test\\\"\\nhoe is't ermee?\\n/me ducks\\\\\", \"name\": \"messageReceived\" }";
QVariantMap variantMap = Util::jsonToVariantMap(json);
QCOMPARE(variantMap.size(), 3);
QCOMPARE(variantMap["name"].toString(), QString("messageReceived"));
QCOMPARE(variantMap["jid"].toString(), QString("[email protected]"));
QCOMPARE(variantMap["message"].toString(), QString("test \"test\"\nhoe is't ermee?\n/me ducks\\"));
}
示例12: serializeData
void serializeData(QDataStream *stream, const QVariantMap &data)
{
*stream << static_cast<qint32>(-2);
const qint32 size = data.size();
*stream << size;
QByteArray bytes;
foreach (const QString &mime, data.keys()) {
bytes = data[mime].toByteArray();
bool compress = shouldCompress(bytes, mime);
*stream << compressMime(mime) << compress << ( compress ? qCompress(bytes) : bytes );
}
}
示例13: compare
static bool compare(const QVariantMap& one, const QVariantMap& other)
{
if (one.size() != other.size())
return false;
QVariantMap::const_iterator it1 = one.begin();
QVariantMap::const_iterator it2 = other.begin();
while (it1 != one.end()) {
if (it1.value().userType() != it2.value().userType())
return false;
if (!(it1.value() == it2.value())) {
if (it1.value().userType() == qMetaTypeId<QDBusObjectPath>()) {
if (!(it1.value().value<QDBusObjectPath>() == it2.value().value<QDBusObjectPath>()))
return false;
}
}
if (qMapLessThanKey(it1.key(), it2.key()) || qMapLessThanKey(it2.key(), it1.key()))
return false;
++it2;
++it1;
}
return true;
}
示例14: validate
bool QVariantMapValidator::validate(const QVariantMap &map) const
{
if (map.size() != m_infos.size())
return false;
for (auto I = map.constBegin(), E = map.constEnd(); I != E; ++I)
{
if (!m_infos.contains(I.key()))
return false;
if (m_infos.value(I.key()) != I.value().type())
return false;
}
return true;
}
示例15: markItemAtToList
void QSDiffRunnerAlgo::markItemAtToList(QSAlgoTypes::Type type, State& state)
{
if (insertStart >= 0 && type != QSAlgoTypes::Insert) {
/* Insert */
appendPatch(createInsertPatch(insertStart,
indexT - 1, to), false);
insertStart = -1;
}
if (type == QSAlgoTypes::Insert) {
if (insertStart < 0) {
insertStart = indexT;
}
}
if (type == QSAlgoTypes::Move) {
MoveOp change(state.posF,
indexT + state.posF - indexF,
indexT);
if (pendingMovePatch.isNull()) {
pendingMovePatch = change;
} else if (pendingMovePatch.canMerge(change)){
pendingMovePatch.merge(change);
} else {
appendMovePatch(pendingMovePatch);
pendingMovePatch = change;
}
state.isMoved = true;
hash[keyT] = state;
}
if (type != QSAlgoTypes::Move && !pendingMovePatch.isNull()) {
appendMovePatch(pendingMovePatch);
pendingMovePatch.clear();
}
if (indexT < to.size() && (type == QSAlgoTypes::Move || type == QSAlgoTypes::NoMove)) {
QVariantMap tmpItemF = from[state.posF].toMap();
QVariantMap diff = compareMap(tmpItemF, itemT);
if (diff.size()) {
updatePatches << QSPatch(QSPatch::Update, indexT, indexT, 1, diff);
}
}
}