本文整理汇总了C++中QVariantHash::constBegin方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariantHash::constBegin方法的具体用法?C++ QVariantHash::constBegin怎么用?C++ QVariantHash::constBegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariantHash
的用法示例。
在下文中一共展示了QVariantHash::constBegin方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: render
QByteArray ViewJson::render(Context *c) const
{
Q_D(const ViewJson);
QByteArray ret;
QJsonObject obj;
const QVariantHash stash = c->stash();
switch (d->exposeMode) {
case All:
obj = QJsonObject::fromVariantHash(stash);
break;
case String:
{
auto it = stash.constFind(d->exposeKey);
if (it != stash.constEnd()) {
obj.insert(d->exposeKey, QJsonValue::fromVariant(it.value()));
}
break;
}
case StringList:
{
QVariantHash exposedStash;
auto it = stash.constBegin();
while (it != stash.constEnd()) {
const QString key = it.key();
if (d->exposeKeys.contains(key)) {
exposedStash.insertMulti(it.key(), it.value());
}
++it;
}
obj = QJsonObject::fromVariantHash(exposedStash);
break;
}
case RegularExpression:
{
QVariantHash exposedStash;
QRegularExpression re = d->exposeRE; // thread safety
auto it = stash.constBegin();
while (it != stash.constEnd()) {
const QString key = it.key();
if (re.match(key).hasMatch()) {
exposedStash.insertMulti(key, it.value());
}
++it;
}
obj = QJsonObject::fromVariantHash(exposedStash);
break;
}
}
c->response()->setContentType(QStringLiteral("application/json"));
ret = QJsonDocument(obj).toJson(d->format);
return ret;
}
示例2: writeMapping
QByteArray FSTReader::writeMapping(const QVariantHash& mapping) {
static const QStringList PREFERED_ORDER = QStringList() << NAME_FIELD << TYPE_FIELD << SCALE_FIELD << FILENAME_FIELD
<< TEXDIR_FIELD << JOINT_FIELD << FREE_JOINT_FIELD
<< BLENDSHAPE_FIELD << JOINT_INDEX_FIELD;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
for (auto key : PREFERED_ORDER) {
auto it = mapping.find(key);
if (it != mapping.constEnd()) {
if (key == FREE_JOINT_FIELD) { // writeVariant does not handle strings added using insertMulti.
for (auto multi : mapping.values(key)) {
buffer.write(key.toUtf8());
buffer.write(" = ");
buffer.write(multi.toByteArray());
buffer.write("\n");
}
} else {
writeVariant(buffer, it);
}
}
}
for (auto it = mapping.constBegin(); it != mapping.constEnd(); it++) {
if (!PREFERED_ORDER.contains(it.key())) {
writeVariant(buffer, it);
}
}
return buffer.data();
}
示例3: variantToString
static QString
variantHashToString( const QVariantHash& variantHash )
{
QStringList result;
for ( auto it = variantHash.constBegin(); it != variantHash.constEnd(); ++it )
result.append( it.key() + '=' + variantToString( it.value() ) );
return '<' + result.join(',') + '>';
}
示例4: fromVariantHash
/*!
Converts the variant hash \a hash to a QJsonObject.
\since 5.5
The keys in \a hash will be used as the keys in the JSON object,
and the QVariant values will be converted to JSON values.
\sa fromVariantMap(), toVariantHash(), QJsonValue::fromVariant()
*/
QJsonObject QJsonObject::fromVariantHash(const QVariantHash &hash)
{
// ### this is implemented the trivial way, not the most efficient way
QJsonObject object;
for (QVariantHash::const_iterator it = hash.constBegin(); it != hash.constEnd(); ++it)
object.insert(it.key(), QJsonValue::fromVariant(it.value()));
return object;
}
示例5: serializeHash
void ClearSilverPrivate::serializeHash(HDF *hdf, const QVariantHash &hash, const QString &prefix) const
{
QString _prefix;
if (!prefix.isEmpty()) {
_prefix = prefix + QLatin1Char('.');
}
auto it = hash.constBegin();
while (it != hash.constEnd()) {
serializeVariant(hdf, it.value(), _prefix + it.key());
++it;
}
}
示例6: writeMapping
QByteArray FSTReader::writeMapping(const QVariantHash& mapping) {
static const QStringList PREFERED_ORDER = QStringList() << NAME_FIELD << TYPE_FIELD << SCALE_FIELD << FILENAME_FIELD
<< TEXDIR_FIELD << JOINT_FIELD << FREE_JOINT_FIELD
<< BLENDSHAPE_FIELD << JOINT_INDEX_FIELD;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
for (auto key : PREFERED_ORDER) {
auto it = mapping.find(key);
if (it != mapping.constEnd()) {
writeVariant(buffer, it);
}
}
for (auto it = mapping.constBegin(); it != mapping.constEnd(); it++) {
if (!PREFERED_ORDER.contains(it.key())) {
writeVariant(buffer, it);
}
}
return buffer.data();
}
示例7: writeVariant
void FSTReader::writeVariant(QBuffer& buffer, QVariantHash::const_iterator& it) {
QByteArray key = it.key().toUtf8() + " = ";
QVariantHash hashValue = it.value().toHash();
if (hashValue.isEmpty()) {
buffer.write(key + it.value().toByteArray() + "\n");
return;
}
for (QVariantHash::const_iterator second = hashValue.constBegin(); second != hashValue.constEnd(); second++) {
QByteArray extendedKey = key + second.key().toUtf8();
QVariantList listValue = second.value().toList();
if (listValue.isEmpty()) {
buffer.write(extendedKey + " = " + second.value().toByteArray() + "\n");
continue;
}
buffer.write(extendedKey);
for (QVariantList::const_iterator third = listValue.constBegin(); third != listValue.constEnd(); third++) {
buffer.write(" = " + third->toByteArray());
}
buffer.write("\n");
}
}
示例8: zipModel
bool ModelPackager::zipModel() {
QTemporaryDir dir;
dir.setAutoRemove(true);
QDir tempDir(dir.path());
QByteArray nameField = _mapping.value(NAME_FIELD).toByteArray();
tempDir.mkpath(nameField + "/textures");
tempDir.mkpath(nameField + "/scripts");
QDir fbxDir(tempDir.path() + "/" + nameField);
QDir texDir(fbxDir.path() + "/textures");
QDir scriptDir(fbxDir.path() + "/scripts");
// Copy textures
listTextures();
if (!_textures.empty()) {
QByteArray texdirField = _mapping.value(TEXDIR_FIELD).toByteArray();
_texDir = _modelFile.path() + "/" + texdirField;
copyTextures(_texDir, texDir);
}
// Copy scripts
QByteArray scriptField = _mapping.value(SCRIPT_FIELD).toByteArray();
_mapping.remove(SCRIPT_FIELD);
if (scriptField.size() > 1) {
tempDir.mkpath(nameField + "/scripts");
_scriptDir = _modelFile.path() + "/" + scriptField;
QDir wdir = QDir(_scriptDir);
_mapping.remove(SCRIPT_FIELD);
wdir.setSorting(QDir::Name | QDir::Reversed);
auto list = wdir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries);
for (auto script : list) {
auto sc = tempDir.relativeFilePath(scriptDir.path()) + "/" + QUrl(script).fileName();
_mapping.insertMulti(SCRIPT_FIELD, sc);
}
copyDirectoryContent(wdir, scriptDir);
}
// Copy LODs
QVariantHash lodField = _mapping.value(LOD_FIELD).toHash();
if (!lodField.empty()) {
for (auto it = lodField.constBegin(); it != lodField.constEnd(); ++it) {
QString oldPath = _modelFile.path() + "/" + it.key();
QFile lod(oldPath);
QString newPath = fbxDir.path() + "/" + QFileInfo(lod).fileName();
if (lod.exists()) {
lod.copy(newPath);
}
}
}
// Copy FBX
QFile fbx(_fbxInfo.filePath());
QByteArray filenameField = _mapping.value(FILENAME_FIELD).toByteArray();
QString newPath = fbxDir.path() + "/" + QFileInfo(filenameField).fileName();
fbx.copy(newPath);
// Correct FST
_mapping[FILENAME_FIELD] = tempDir.relativeFilePath(newPath);
_mapping[TEXDIR_FIELD] = tempDir.relativeFilePath(texDir.path());
for (auto multi : _mapping.values(SCRIPT_FIELD)) {
multi.fromValue(tempDir.relativeFilePath(scriptDir.path()) + multi.toString());
}
// Copy FST
QFile fst(tempDir.path() + "/" + nameField + ".fst");
if (fst.open(QIODevice::WriteOnly)) {
fst.write(FSTReader::writeMapping(_mapping));
fst.close();
} else {
qCDebug(interfaceapp) << "Couldn't write FST file" << fst.fileName();
return false;
}
QString saveDirPath = QFileDialog::getExistingDirectory(nullptr, "Save Model",
"", QFileDialog::ShowDirsOnly);
if (saveDirPath.isEmpty()) {
qCDebug(interfaceapp) << "Invalid directory" << saveDirPath;
return false;
}
QDir saveDir(saveDirPath);
copyDirectoryContent(tempDir, saveDir);
return true;
}
示例9: onThemeChanged
void WelcomeMode::onThemeChanged()
{
const QVariantHash creatorTheme = Utils::creatorTheme()->values();
for (auto it = creatorTheme.constBegin(); it != creatorTheme.constEnd(); ++it)
m_themeProperties.insert(it.key(), it.value());
}
示例10: zipModel
bool ModelPackager::zipModel() {
QTemporaryDir dir;
dir.setAutoRemove(true);
QDir tempDir(dir.path());
QByteArray nameField = _mapping.value(NAME_FIELD).toByteArray();
tempDir.mkpath(nameField + "/textures");
QDir fbxDir(tempDir.path() + "/" + nameField);
QDir texDir(fbxDir.path() + "/textures");
// Copy textures
listTextures();
if (!_textures.empty()) {
QByteArray texdirField = _mapping.value(TEXDIR_FIELD).toByteArray();
_texDir = _modelFile.path() + "/" + texdirField;
copyTextures(_texDir, texDir);
}
// Copy LODs
QVariantHash lodField = _mapping.value(LOD_FIELD).toHash();
if (!lodField.empty()) {
for (auto it = lodField.constBegin(); it != lodField.constEnd(); ++it) {
QString oldPath = _modelFile.path() + "/" + it.key();
QFile lod(oldPath);
QString newPath = fbxDir.path() + "/" + QFileInfo(lod).fileName();
if (lod.exists()) {
lod.copy(newPath);
}
}
}
// Copy FBX
QFile fbx(_fbxInfo.filePath());
QByteArray filenameField = _mapping.value(FILENAME_FIELD).toByteArray();
QString newPath = fbxDir.path() + "/" + QFileInfo(filenameField).fileName();
fbx.copy(newPath);
// Correct FST
_mapping[FILENAME_FIELD] = tempDir.relativeFilePath(newPath);
_mapping[TEXDIR_FIELD] = tempDir.relativeFilePath(texDir.path());
// Copy FST
QFile fst(tempDir.path() + "/" + nameField + ".fst");
if (fst.open(QIODevice::WriteOnly)) {
fst.write(FSTReader::writeMapping(_mapping));
fst.close();
} else {
qCDebug(interfaceapp) << "Couldn't write FST file" << fst.fileName();
return false;
}
QString saveDirPath = QFileDialog::getExistingDirectory(nullptr, "Save Model",
"", QFileDialog::ShowDirsOnly);
if (saveDirPath.isEmpty()) {
qCDebug(interfaceapp) << "Invalid directory" << saveDirPath;
return false;
}
QDir saveDir(saveDirPath);
copyDirectoryContent(tempDir, saveDir);
return true;
}
示例11: sipConvertFromType
//.........这里部分代码省略.........
QVariantList *ql = reinterpret_cast<QVariantList *>(cpp);
py = PyList_New(ql->size());
if (py)
{
for (int i = 0; i < ql->size(); ++i)
{
PyObject *val_obj = toAnyPyObject(ql->at(i));
if (!val_obj)
{
Py_DECREF(py);
py = 0;
break;
}
PyList_SET_ITEM(py, i, val_obj);
}
}
break;
}
case QMetaType::QVariantMap:
{
py = PyDict_New();
if (py)
{
QVariantMap *qm = reinterpret_cast<QVariantMap *>(cpp);
for (QVariantMap::const_iterator it = qm->constBegin(); it != qm->constEnd(); ++it)
if (!add_variant_to_dict(py, it.key(), it.value()))
{
Py_DECREF(py);
py = 0;
break;
}
}
break;
}
#if QT_VERSION >= 0x040500
case QMetaType::QVariantHash:
{
py = PyDict_New();
if (py)
{
QVariantHash *qh = reinterpret_cast<QVariantHash *>(cpp);
for (QVariantHash::const_iterator it = qh->constBegin(); it != qh->constEnd(); ++it)
if (!add_variant_to_dict(py, it.key(), it.value()))
{
Py_DECREF(py);
py = 0;
break;
}
}
break;