本文整理汇总了C++中QVariant::toList方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::toList方法的具体用法?C++ QVariant::toList怎么用?C++ QVariant::toList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::toList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DisplayProperties
void Properties::DisplayProperties(QVariant p) {
// get current property
QString propertyName;
QTreeWidgetItem* item = ui->propertyView->currentItem();
if (item) {
propertyName = item->data(0, Qt::DisplayRole).toString();
}
ui->propertyView->clear();
// only support QVariantMap or QVariantHash at this level
switch (p.type()) {
case QMetaType::QVariantMap:
ParseIterable(NULL, p.toMap());
break;
case QMetaType::QVariantHash:
ParseIterable(NULL, p.toHash());
break;
case QMetaType::QVariantList:
ParseList(NULL, p.toList());
break;
default:
qWarning("Trying to display scalar value as a property");
break;
}
// expand at least the first level
ui->propertyView->expandToDepth(0);
if (propertyName.size() != 0) {
// try to restore the path
QList<QTreeWidgetItem*> items =
ui->propertyView->findItems(propertyName, Qt::MatchRecursive);
if (items.size())
items.front()->setSelected(true);
}
}
示例2: foreach
QVector<JsonKitsPage::ConditionalFeature> JsonKitsPage::parseFeatures(const QVariant &data,
QString *errorMessage)
{
QVector<ConditionalFeature> result;
if (errorMessage)
errorMessage->clear();
if (data.isNull())
return result;
if (data.type() != QVariant::List) {
if (errorMessage)
*errorMessage = tr("Feature list is set and not of type list.");
return result;
}
foreach (const QVariant &element, data.toList()) {
if (element.type() == QVariant::String) {
result.append({ element.toString(), QVariant(true) });
} else if (element.type() == QVariant::Map) {
const QVariantMap obj = element.toMap();
const QString feature = obj.value(QLatin1String(KEY_FEATURE)).toString();
if (feature.isEmpty()) {
*errorMessage = tr("No \"%1\" key found in feature list object.")
.arg(QLatin1String(KEY_FEATURE));
return QVector<ConditionalFeature>();
}
result.append({ feature, obj.value(QLatin1String(KEY_CONDITION), true) });
} else {
if (errorMessage)
*errorMessage = tr("Feature list element is not a string or object.");
return QVector<ConditionalFeature>();
}
}
return result;
}
示例3: QVERIFY
void
TestPyOtherSide::testSetToList()
{
// Test if a Python set is converted to a list
PyObject *set = PySet_New(NULL);
QVERIFY(set != NULL);
PyObject *o = NULL;
o = PyLong_FromLong(123);
QVERIFY(o != NULL);
QVERIFY(PySet_Add(set, o) == 0);
o = PyLong_FromLong(321);
QVERIFY(o != NULL);
QVERIFY(PySet_Add(set, o) == 0);
o = PyLong_FromLong(444);
QVERIFY(o != NULL);
QVERIFY(PySet_Add(set, o) == 0);
// This will not be added (no duplicates in a set)
o = PyLong_FromLong(123);
QVERIFY(o != NULL);
QVERIFY(PySet_Add(set, o) == 0);
// At this point, we should have 3 items (123, 321 and 444)
QVERIFY(PySet_Size(set) == 3);
QVariant v = convertPyObjectToQVariant(set);
QVERIFY(v.canConvert(QMetaType::QVariantList));
QList<QVariant> l = v.toList();
QVERIFY(l.size() == 3);
QVERIFY(l.contains(123));
QVERIFY(l.contains(321));
QVERIFY(l.contains(444));
}
示例4: if
QByteArray Serializer::SerializerPrivate::serialize( const QVariant &v, int reserved )
{
QByteArray str;
bool error = false;
QByteArray indent;
if ( ! v.isValid() ) { // invalid or null?
str = "null";
} else if (( v.type() == QVariant::List ) || ( v.type() == QVariant::StringList )){ // an array or a stringlist?
const QVariantList list = v.toList();
QList<QByteArray> values;
Q_FOREACH( const QVariant& var, list )
{
reserved++;
QByteArray serializedValue = serialize( var,reserved );
reserved--;
if ( serializedValue.isNull() ) {
error = true;
break;
}
values << serializedValue;
}
if (indentMode == QJson::IndentMinimum) {
QByteArray indent = buildIndent(reserved - 1);
str = "[\n" + join( values, ",\n" ) + "\n" + indent + "]";
}
else if (indentMode == QJson::IndentMedium || indentMode == QJson::IndentFull){
QByteArray indent = buildIndent(reserved);
str = "[\n" + join( values, ",\n" ) + "\n" + indent + "]";
}
else {
str = "[ " + join( values, ", " ) + " ]";
}
} else if ( v.type() == QVariant::Map ) { // variant is a map?
示例5: addVariant
void Evaluate::addVariant(QVariant &object) {
if (object.isValid()) {
switch(object.type()) {
case QMetaType::QString:
{
QString string = object.toString();
addString(string);
}
break;
case QMetaType::QVariantList:
{
QVariantList list = object.toList();
addArray(list);
}
break;
case QMetaType::Double:
m_buffer.append(object.toString());
break;
case QMetaType::QVariantMap:
{
QVariantMap map = object.toMap();
addMap(map);
break;
}
case QMetaType::Bool:
{
m_buffer.append(object.toString());
break;
}
default:
m_buffer.append("null");
}
} else {
m_buffer.append("null");
}
}
示例6: writeName
// <name> or (rename <name> <altName>)
void writeName(QXmlStreamWriter &stream, const QVariant &v)
{
if (v.type() == QVariant::List)
{
QVariantList l = v.toList();
if (l[0].toString() != "rename")
{
qWarning("Wrong name description");
}
else
{
stream.writeAttribute("name", l[1].toString());
//stream.writeAttribute("altName", l[2].toString()); // TODO: strip quotes
}
}
else if (v.type() == QVariant::String)
{
stream.writeAttribute("name", v.toString());
}
else
{
qWarning("Wrong name description");
}
}
示例7: findValue
QStringList FindValueOperation::findValue(const QVariant &in, const QVariant &value,
const QString &prefix)
{
QStringList result;
if (in.type() == value.type() && in == value) {
result << prefix;
} else if (in.type() == QVariant::Map) {
const QVariantMap map = in.toMap();
for (QVariantMap::const_iterator i = map.begin(); i != map.end(); ++i) {
QString pfx = prefix;
if (!pfx.isEmpty())
pfx.append(QLatin1Char('/'));
pfx.append(i.key());
result.append(findValue(i.value(), value, 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(findValue(list.at(pos), value, pfx));
}
}
return result;
}
示例8: command
CommandDataModel::CommandDataModel()
{
// Load saveBeforeExecute option
QVariant s = mSettings.value(QLatin1String("saveBeforeExecute"), true);
mSaveBeforeExecute = s.toBool();
// Load command list
const QVariant variant = mSettings.value(QLatin1String("commandList"));
const QList<QVariant> commands = variant.toList();
foreach (const QVariant &commandVariant, commands)
mCommands.append(Command::fromQVariant(commandVariant));
// Add default commands the first time the app has booted up.
// This is useful on it's own and helps demonstrate how to use the commands.
const QString addPrefStr = QLatin1String("addedDefaultCommands");
const bool addedCommands = mSettings.value(addPrefStr, false).toBool();
if (!addedCommands) {
// Disable default commands by default so user gets an informative
// warning when clicking the command button for the first time
Command command(false);
#ifdef Q_WS_X11
command.command = QLatin1String("gedit %mapfile");
#elif defined(Q_WS_MAC)
command.command = QLatin1String("open -t %mapfile");
#endif
if (!command.command.isEmpty()) {
command.name = tr("Open in text editor");
mCommands.push_back(command);
}
commit();
mSettings.setValue(addPrefStr, true);
}
}
示例9: load
void AbstractInputTool::load(const QVariant& settings)
{
clear();
const QVariantList list = settings.toList();
for (int i = 0; i < list.size(); i++)
{
const QVariantMap map = list.at(i).toMap();
const QString id = map["instance"].toString();
const QVariantList vpath = map["path"].toList();
QList< int > path;
for (int j = 0; j < vpath.size(); j++)
{
path << vpath.at(j).toInt();
}
InterfaceDescriptor_ptr ref =
m_model->getReflective(id);
if (ref)
{
AbstractInputItem * item =
createAbstractInputItem(id, ref, path);
if (item)
{
item->load(map["config"]);
m_model->check(id, path);
}
}
}
}
示例10: if
bool Serializer::SerializerPrivate::serialize( const QVariant &v, QIODevice * io, int indentLevel, bool beginNoIndent )
{
if ( ! v.isValid() )
{
// invalid or null?
io->write("null");
}else if (( v.type() == QVariant::List ) || ( v.type() == QVariant::StringList ))
{
// an array or a stringlist?
bool isFirst = true;
io->write(getSeparator(indentMode, beginNoIndent ? 0 : indentLevel, BeginSeparator, SquareBracket));
const QVariantList list = v.toList();
Q_FOREACH( const QVariant& var, list )
{
if(!isFirst)
io->write(getSeparator(indentMode, indentLevel, JoinSeparator, SquareBracket));
isFirst = false;
if(!serialize( var, io, indentLevel+1))
return false;
}
io->write(getSeparator(indentMode, indentLevel, EndSeparator, SquareBracket));
} else if ( v.type() == QVariant::Map )
示例11: variantAsObject
static LfpObject variantAsObject(const QVariant &v, const QString &name = QString())
{
if(v.type() == QVariant::List)
{
QVariantList list = v.toList();
LfpObject obj("sequence", name);
for(int n = 0; n < list.count(); ++n)
obj += variantAsObject(list[n]);
return obj;
}
else if(v.type() == QVariant::Map)
{
QVariantMap map = v.toMap();
LfpObject obj("map", name);
QMapIterator<QString, QVariant> it(map);
while(it.hasNext())
{
it.next();
obj += variantAsObject(it.value(), it.key());
}
return obj;
}
else
{
if(v.type() == QVariant::Bool)
return LfpObject("bool", name, v);
else if(v.type() == QVariant::Int || v.type() == QVariant::LongLong)
return LfpObject("int", name, v);
else if(v.type() == QVariant::String)
return LfpObject("string", name, v);
else if(v.type() == QVariant::ByteArray)
return LfpObject("bytearray", name, v);
else
return LfpObject(); // TODO: error?
}
}
示例12: wrapResult
QJsonValue QMetaObjectPublisher::wrapResult(const QVariant &result)
{
if (QObject *object = result.value<QObject *>()) {
QJsonObject objectInfo;
objectInfo[KEY_QOBJECT] = true;
QString id = registeredObjectIds.value(object);
if (id.isEmpty()) {
// neither registered, nor wrapped, do so now
id = QUuid::createUuid().toString();
registeredObjectIds[object] = id;
registeredObjects[id] = object;
QJsonObject info = classInfoForObject(object);
wrappedObjects[object] = info;
objectInfo[KEY_DATA] = info;
if (propertyUpdatesInitialized) {
// if other objects are initialized already, do the same here
initializePropertyUpdates(object, info);
}
} else if (wrappedObjects.contains(object)) {
// if this object was wrapped, send the full class info
// this is required for proper multi-client support
objectInfo[KEY_DATA] = wrappedObjects.value(object);
}
objectInfo[KEY_ID] = id;
return objectInfo;
} else if (result.canConvert<QVariantList>()) {
// recurse and potentially wrap contents of the array
return wrapList(result.toList());
}
// no need to wrap this
return QJsonValue::fromVariant(result);
}
示例13: serialize
QByteArray Json::serialize(const QVariant &data, bool &success)
{
QByteArray str;
success = true;
if(!data.isValid()) // invalid or null?
{
str = "null";
}
else if((data.type() == QVariant::List) ||
(data.type() == QVariant::StringList)) // variant is a list?
{
QList<QByteArray> values;
const QVariantList list = data.toList();
Q_FOREACH(const QVariant& v, list)
{
QByteArray serializedValue = serialize(v);
if(serializedValue.isNull())
{
success = false;
break;
}
values << serializedValue;
}
示例14: remove
int JsonDbPartition::remove(const QJSValue &object, const QJSValue &options, const QJSValue &callback)
{
QJSValue actualOptions = options;
QJSValue actualCallback = callback;
if (options.isCallable()) {
if (!callback.isUndefined()) {
qWarning() << "Callback should be the last parameter.";
return -1;
}
actualCallback = actualOptions;
actualOptions = QJSValue(QJSValue::UndefinedValue);
}
QVariantMap opts = qjsvalue_to_qvariant(actualOptions).toMap();
QJsonDbWriteRequest::ConflictResolutionMode conflictMode =
static_cast<QJsonDbWriteRequest::ConflictResolutionMode>(opts.value(QStringLiteral("mode")).toInt());
QVariant obj = qjsvalue_to_qvariant(object);
QJsonDbWriteRequest *request(0);
if (obj.type() == QVariant::List) {
request = new QJsonDbRemoveRequest(qvariantlist_to_qjsonobject_list(obj.toList()));
} else {
request = new QJsonDbRemoveRequest(QJsonObject::fromVariantMap(obj.toMap()));
}
request->setPartition(_name);
request->setConflictResolutionMode(conflictMode);
connect(request, SIGNAL(finished()), this, SLOT(requestFinished()));
connect(request, SIGNAL(finished()), request, SLOT(deleteLater()));
connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
this, SLOT(requestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
request, SLOT(deleteLater()));
JsonDatabase::sharedConnection().send(request);
writeCallbacks.insert(request, actualCallback);
return request->property("requestId").toInt();
}
示例15: isFalse
bool QtVariantContext::isFalse(const QString& key) const
{
QVariant value = this->value(key);
switch (value.userType()) {
case QMetaType::QChar:
case QMetaType::Double:
case QMetaType::Float:
case QMetaType::Int:
case QMetaType::UInt:
case QMetaType::LongLong:
case QMetaType::ULongLong:
case QVariant::Bool:
return !value.toBool();
case QVariant::List:
case QVariant::StringList:
return value.toList().isEmpty();
case QVariant::Hash:
return value.toHash().isEmpty();
case QVariant::Map:
return value.toMap().isEmpty();
default:
return value.toString().isEmpty();
}
}