本文整理汇总了C++中QVariantMap::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariantMap::begin方法的具体用法?C++ QVariantMap::begin怎么用?C++ QVariantMap::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariantMap
的用法示例。
在下文中一共展示了QVariantMap::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillFromJson
void dataBase::fillFromJson(const QString &path)
{
QProgressBar bar;
bar.show();
QFile file(path);
if(!file.open(QFile::ReadOnly))
{
throw std::runtime_error(("No file "+ path).toStdString());
}
bool ok = false;
QVariantMap map = QtJson::parse(QString::fromUtf8(file.readAll().data()), ok).toMap();
if(!ok)
{
throw std::runtime_error(("Cant parse "+ path).toStdString());
}
for(QVariantMap::const_iterator it = map.begin(); it != map.end(); ++it)
{
QList<QVariant> list = it.value().toList();
for(QList<QVariant>::const_iterator list_it = list.begin(); list_it != list.end(); ++list_it)
{
bar.setValue(bar.value() >= bar.maximum() ? 0 : bar.value()+1);
qApp->processEvents();
QList<QVariant> values = list_it->toList();
QString q_text = QString("INSERT INTO %1 ( coeff, hrn ) VALUES ( '%2', '%3' )")
.arg(it.key())
.arg(values.at(0).toString())
.arg(values.at(1).toString());
query(q_text);
}
}
QList<QVariant> regions = map["regions"].toList();
for(QList<QVariant>::const_iterator it = regions.begin(); it!= regions.end(); ++it )
{
QList<QVariant> towns = it->toList().at(2).toList();
for(QList<QVariant>::const_iterator town_it = towns.begin(); town_it != towns.end(); ++town_it )
{
bar.setValue(bar.value() >= bar.maximum() ? 0 : bar.value()+1);
qApp->processEvents();
QList<QVariant> town_desc = town_it->toList();
QString q_text = QString("INSERT INTO towns VALUES ( %1, '%2', %3, %4, %5)")
.arg(town_desc.at(0).toInt())
.arg(town_desc.at(1).toString())
.arg(town_desc.at(2).toString())
.arg(town_desc.at(3).toString())
.arg(it->toList().at(0).toInt());
query(q_text);
}
}
bar.close();
}
示例2: addQt
QVariantMap AddQtOperation::addQt(const QVariantMap &map,
const QString &id, const QString &displayName, const QString &type,
const QString &qmake, const KeyValuePairList &extra)
{
QString sdkId = extendId(id);
// Sanity check: Make sure autodetection source is not in use already:
if (exists(map, sdkId)) {
std::cerr << "Error: Id " << qPrintable(id) << " already defined as Qt versions." << std::endl;
return QVariantMap();
}
// Find position to insert:
int versionCount = 0;
for (QVariantMap::const_iterator i = map.begin(); i != map.end(); ++i) {
if (!i.key().startsWith(QLatin1String(PREFIX)))
continue;
QString number = i.key().mid(QString::fromLatin1(PREFIX).count());
bool ok;
int count = number.toInt(&ok);
if (ok && count >= versionCount)
versionCount = count + 1;
}
const QString qt = QString::fromLatin1(PREFIX) + QString::number(versionCount);
// Sanity check: Make sure displayName is unique.
QStringList nameKeys = FindKeyOperation::findKey(map, QLatin1String(DISPLAYNAME));
QStringList nameList;
foreach (const QString &nameKey, nameKeys)
nameList << GetOperation::get(map, nameKey).toString();
const QString uniqueName = makeUnique(displayName, nameList);
// Sanitize qmake path:
QString saneQmake = QDir::cleanPath(QDir::fromNativeSeparators(qmake));
// insert data:
KeyValuePairList data;
data << KeyValuePair(QStringList() << qt << QLatin1String(ID), QVariant(-1));
data << KeyValuePair(QStringList() << qt << QLatin1String(DISPLAYNAME), QVariant(uniqueName));
data << KeyValuePair(QStringList() << qt << QLatin1String(AUTODETECTED), QVariant(true));
data << KeyValuePair(QStringList() << qt << QLatin1String(AUTODETECTION_SOURCE), QVariant(sdkId));
data << KeyValuePair(QStringList() << qt << QLatin1String(QMAKE), QVariant(saneQmake));
data << KeyValuePair(QStringList() << qt << QLatin1String(TYPE), QVariant(type));
KeyValuePairList qtExtraList;
foreach (const KeyValuePair &pair, extra)
qtExtraList << KeyValuePair(QStringList() << qt << pair.key, pair.value);
data.append(qtExtraList);
return AddKeysOperation::addKeys(map, data);
}
示例3: BufferViewManager
CoreBufferViewManager::CoreBufferViewManager(SignalProxy *proxy, CoreSession *parent)
: BufferViewManager(proxy, parent),
_coreSession(parent)
{
QVariantMap views = Core::getUserSetting(_coreSession->user(), "BufferViews").toMap();
QVariantMap::iterator iter = views.begin();
QVariantMap::iterator iterEnd = views.end();
CoreBufferViewConfig *config = 0;
while (iter != iterEnd) {
config = new CoreBufferViewConfig(iter.key().toInt(), iter.value().toMap(), this);
addBufferViewConfig(config);
++iter;
}
}
示例4: setWidgetData
void table_widget_delegate::setWidgetData(const QModelIndex &index, QWidget *editor, const QVariant& data) const
{
if (!editor){
return;
}
column_data_ptr cd = _column_datas[index.column()];
if (!cd){
return;
}
switch (cd->type)
{
case WIDGET_CHECKBOX:
{
QCheckBox *widget = qobject_cast<QCheckBox*>(editor);
if(widget){
widget->setChecked(data.toBool());
}
}
break;
case WIDGET_COMBOBOX:
{
QComboBox *widget = qobject_cast<QComboBox*>(editor);
switch (cd->data.type())
{
case QVariant::StringList:
widget->setCurrentText(data.toString());
break;
case QVariant::Map:
{
QVariantMap map = cd->data.toMap();
QString text;
for (auto it = map.begin(); it != map.end(); ++it){
if (data == it.value()){
text = it.key();
}
}
widget->setCurrentText(text);
}
break;
default:
break;
}
}
default:
break;
}
}
示例5: findKey
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;
}
}
示例6: 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;
}
示例7: setParameters
void RecognitionDatabase::setParameters(const QVariantMap& parameters)
{
if (!d || !d->dbAvailable)
{
return;
}
QMutexLocker lock(&d->mutex);
for (QVariantMap::const_iterator it = parameters.begin(); it != parameters.end(); ++it)
{
d->parameters.insert(it.key(), it.value());
}
d->applyParameters();
}
示例8: prettyPrint
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;
}
示例9: serialize
void JSONSerializer::serialize(const QVariant &variant) {
if (!variant.isValid()) { // Case of JSON null/undefined
// TODO:find a way to differenciate null/undefined
m_stream << JSON_NULL;
} else if (variant.type() == QVariant::Bool) { // Case of JSON boolean
m_stream << (variant.toBool() ? JSON_TRUE: JSON_FALSE);
} else if (variant.type() == QVariant::Map) { // Case of JSON object
m_stream << JSON_OBJECT_BEGIN;
const QVariantMap elements = variant.toMap();
auto it = elements.begin();
if (it != elements.end()) {
m_stream << sanitizeString(it.key()) << JSON_MEMBER_SEP;
serialize(it.value());
it++;
}
while (it != elements.end()) {
m_stream << JSON_ELEMENT_SEP << sanitizeString(it.key()) << JSON_MEMBER_SEP;
serialize(it.value());
it++;
}
m_stream << JSON_OBJECT_END;
} else if (variant.type() == QVariant::List) { // Case of JSON array
m_stream << JSON_ARRAY_BEGIN;
const QVariantList elements = variant.toList();
auto it = elements.begin();
if (it != elements.end()) {
serialize(*it);
it++;
}
while (it != elements.end()) {
m_stream << JSON_MEMBER_SEP;
serialize(*it);
it++;
}
m_stream << JSON_ARRAY_END;
} else if ((variant.type() == QVariant::String)
|| (variant.type() == QVariant::ByteArray)) { // Case of JSON string
m_stream << sanitizeString(variant.toString());
} else if ((variant.type() == QVariant::Double) || variant.canConvert<double>()) {
m_stream << QString::number(variant.toDouble()).replace("inf", "infinity");
} else if ((variant.type() == QVariant::String) || variant.canConvert<QString>()) {
m_stream << variant.toString();
} else {
throw JSONSerializerException("Fatal: QVariant type not managed.");
}
}
示例10: handleRequest
QVariantMap SetConfigHandler::handleRequest(QVariantMap request) {
if (request["target"] != "set_config") {
return next->handleRequest(request);
}
QSettings settings("config/config.ini", QSettings::IniFormat);
settings.setIniCodec("UTF-8");
QVariantMap items = request["items"].toMap();
QVariantMap response;
// 依次设置每一项,未作检测,危险
for (auto it = items.begin(); it != items.end(); it++) {
settings.setValue(it.key(), it.value());
}
response["status"] = "ok";
return response;
}
示例11: qvariant2qobject
void qvariant2qobject(const QVariantMap& variant, T* object)
{
for ( QVariantMap::const_iterator iter = variant.begin(); iter != variant.end(); ++iter )
{
const int propertyIndex = T::staticMetaObject.indexOfProperty(iter.key().toLatin1());
if (propertyIndex < 0) {
qCWarning(KDECONNECT_CORE) << "missing property" << object << iter.key();
continue;
}
QMetaProperty property = T::staticMetaObject.property(propertyIndex);
bool ret = property.writeOnGadget(object, *iter);
if (!ret) {
qCWarning(KDECONNECT_CORE) << "couldn't set" << object << "->" << property.name() << '=' << *iter;
}
}
}
示例12: setConfig
void QgsValueMapConfigDlg::setConfig( const QVariantMap& config )
{
tableWidget->clearContents();
for ( int i = tableWidget->rowCount() - 1; i > 0; i-- )
{
tableWidget->removeRow( i );
}
int row = 0;
QVariantMap values = config.value( QStringLiteral( "map" ) ).toMap();
for ( QVariantMap::ConstIterator mit = values.begin(); mit != values.end(); mit++, row++ )
{
if ( mit.value().isNull() )
setRow( row, mit.key(), QString() );
else
setRow( row, mit.value().toString(), mit.key() );
}
}
示例13: fromVariant
void ReplicaSetSettings::fromVariant(const QVariantMap &map)
{
setSetName(map.value("setName").toString().toStdString());
// Extract and set replica members
std::vector<std::string> vec;
auto itr = map.begin();
int idx = 0;
do
{
itr = map.find(QString::number(idx));
if (map.end() == itr) break;
vec.push_back(itr->toString().toStdString());
++idx;
} while (map.end() != itr);
setMembers(vec);
// Extract and set read reference
setReadPreference(static_cast<ReadPreference>(map.value("readPreference").toInt()));
}
示例14: toJSLiteral_impl
static QString toJSLiteral_impl(const QVariantMap &vm, int level = 0)
{
QString indent;
for (int i = 0; i < level; ++i)
indent += QLatin1String(" ");
QString str;
for (QVariantMap::const_iterator it = vm.begin(); it != vm.end(); ++it) {
if (it.value().type() == QVariant::Map) {
str += indent + it.key() + QLatin1String(": {\n");
str += toJSLiteral_impl(it.value().toMap(), level + 1);
str += indent + QLatin1String("}\n");
} else {
str += indent + it.key() + QLatin1String(": ") + toJSLiteral(it.value())
+ QLatin1Char('\n');
}
}
return str;
}
示例15: undoOperation
bool LicenseOperation::undoOperation()
{
const QVariantMap licenses = value(QLatin1String("licenses")).toMap();
if (licenses.isEmpty()) {
setError(UserDefinedError);
setErrorString(tr("No license files found to delete."));
return false;
}
QString targetDir = arguments().value(0);
for (QVariantMap::const_iterator it = licenses.begin(); it != licenses.end(); ++it)
QFile::remove(targetDir + QDir::separator() + it.key());
QDir dir;
dir.rmdir(targetDir);
return true;
}