本文整理汇总了C++中QDomDocument::firstChildElement方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomDocument::firstChildElement方法的具体用法?C++ QDomDocument::firstChildElement怎么用?C++ QDomDocument::firstChildElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomDocument
的用法示例。
在下文中一共展示了QDomDocument::firstChildElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: interpretResourceFile
bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
const QString &fname, QString currentPath, bool ignoreErrors)
{
Q_ASSERT(m_errorDevice);
const QChar slash = QLatin1Char('/');
if (!currentPath.isEmpty() && !currentPath.endsWith(slash))
currentPath += slash;
QDomDocument document;
{
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
if (!document.setContent(inputDevice, &errorMsg, &errorLine, &errorColumn)) {
if (ignoreErrors)
return true;
const QString msg = QString::fromUtf8("RCC Parse Error: '%1' Line: %2 Column: %3 [%4]\n").arg(fname).arg(errorLine).arg(errorColumn).arg(errorMsg);
m_errorDevice->write(msg.toUtf8());
return false;
}
}
QDomElement domRoot = document.firstChildElement(m_strings.TAG_RCC).toElement();
if (!domRoot.isNull() && domRoot.tagName() == m_strings.TAG_RCC) {
for (QDomNode node = domRoot.firstChild(); !node.isNull(); node = node.nextSibling()) {
if (!node.isElement())
continue;
QDomElement child = node.toElement();
if (!child.isNull() && child.tagName() == m_strings.TAG_RESOURCE) {
QLocale::Language language = QLocale::c().language();
QLocale::Country country = QLocale::c().country();
if (child.hasAttribute(m_strings.ATTRIBUTE_LANG)) {
QString attribute = child.attribute(m_strings.ATTRIBUTE_LANG);
QLocale lang = QLocale(attribute);
language = lang.language();
if (2 == attribute.length()) {
// Language only
country = QLocale::AnyCountry;
} else {
country = lang.country();
}
}
QString prefix;
if (child.hasAttribute(m_strings.ATTRIBUTE_PREFIX))
prefix = child.attribute(m_strings.ATTRIBUTE_PREFIX);
if (!prefix.startsWith(slash))
prefix.prepend(slash);
if (!prefix.endsWith(slash))
prefix += slash;
for (QDomNode res = child.firstChild(); !res.isNull(); res = res.nextSibling()) {
if (res.isElement() && res.toElement().tagName() == m_strings.TAG_FILE) {
QString fileName(res.firstChild().toText().data());
if (fileName.isEmpty()) {
const QString msg = QString::fromUtf8("RCC: Warning: Null node in XML of '%1'\n").arg(fname);
m_errorDevice->write(msg.toUtf8());
}
QString alias;
if (res.toElement().hasAttribute(m_strings.ATTRIBUTE_ALIAS))
alias = res.toElement().attribute(m_strings.ATTRIBUTE_ALIAS);
else
alias = fileName;
int compressLevel = m_compressLevel;
if (res.toElement().hasAttribute(m_strings.ATTRIBUTE_COMPRESS))
compressLevel = res.toElement().attribute(m_strings.ATTRIBUTE_COMPRESS).toInt();
int compressThreshold = m_compressThreshold;
if (res.toElement().hasAttribute(m_strings.ATTRIBUTE_THRESHOLD))
compressThreshold = res.toElement().attribute(m_strings.ATTRIBUTE_THRESHOLD).toInt();
// Special case for -no-compress. Overrides all other settings.
if (m_compressLevel == -2)
compressLevel = 0;
alias = QDir::cleanPath(alias);
while (alias.startsWith(QLatin1String("../")))
alias.remove(0, 3);
alias = QDir::cleanPath(m_resourceRoot) + prefix + alias;
QString absFileName = fileName;
if (QDir::isRelativePath(absFileName))
absFileName.prepend(currentPath);
QFileInfo file(absFileName);
if (!file.exists()) {
m_failedResources.push_back(absFileName);
const QString msg = QString::fromUtf8("RCC: Error in '%1': Cannot find file '%2'\n").arg(fname).arg(fileName);
m_errorDevice->write(msg.toUtf8());
if (ignoreErrors)
continue;
else
return false;
} else if (file.isFile()) {
const bool arc =
addFile(alias,
RCCFileInfo(alias.section(slash, -1),
file,
//.........这里部分代码省略.........
示例2: ReadAvatarAppearance
bool LegacyAvatarSerializer::ReadAvatarAppearance(RexLogic::EC_AvatarAppearance& dest, const QDomDocument& source, bool read_mesh)
{
PROFILE(Avatar_ReadAvatarAppearance);
QDomElement avatar = source.firstChildElement("avatar");
if (avatar.isNull())
{
RexLogicModule::LogError("No avatar element");
return false;
}
// Get mesh & skeleton
if (read_mesh)
{
dest.Clear();
QDomElement base_elem = avatar.firstChildElement("base");
if (!base_elem.isNull())
{
AvatarAsset mesh;
mesh.name_ = base_elem.attribute("mesh").toStdString();
dest.SetMesh(mesh);
}
// Get skeleton
QDomElement skeleton_elem = avatar.firstChildElement("skeleton");
if (!skeleton_elem.isNull())
{
AvatarAsset skeleton;
skeleton.name_ = skeleton_elem.attribute("name").toStdString();
dest.SetSkeleton(skeleton);
}
}
// Get materials, should be 2 of them
uint mat_index = 0;
QDomElement material_elem = avatar.firstChildElement("material");
AvatarMaterialVector materials;
while (!material_elem.isNull())
{
AvatarMaterial material;
material.asset_.name_ = material_elem.attribute("name").toStdString();
// Check for texture override
QDomElement texture_elem;
switch (mat_index)
{
case 0:
texture_elem = avatar.firstChildElement("texture_body");
break;
case 1:
texture_elem = avatar.firstChildElement("texture_face");
break;
}
if (!texture_elem.isNull())
{
std::string tex_name = texture_elem.attribute("name").toStdString();
if (!tex_name.empty())
{
AvatarAsset texture;
texture.name_ = tex_name;
material.textures_.push_back(texture);
}
}
materials.push_back(material);
material_elem = material_elem.nextSiblingElement("material");
++mat_index;
}
dest.SetMaterials(materials);
// Get main transform
QDomElement transform_elem = avatar.firstChildElement("transformation");
if (!transform_elem.isNull())
{
Transform trans;
trans.position_ = ParseVector3(transform_elem.attribute("position").toStdString());
trans.orientation_ = ParseQuaternion(transform_elem.attribute("rotation").toStdString());
trans.scale_ = ParseVector3(transform_elem.attribute("scale").toStdString());
dest.SetTransform(trans);
}
// Get attachments
QDomElement attachment_elem = avatar.firstChildElement("attachment");
AvatarAttachmentVector attachments;
while (!attachment_elem.isNull())
{
ReadAttachment(attachments, attachment_elem);
attachment_elem = attachment_elem.nextSiblingElement("attachment");
}
dest.SetAttachments(attachments);
// Get bone modifiers
QDomElement bonemodifier_elem = avatar.firstChildElement("dynamic_animation");
BoneModifierSetVector bonemodifiers;
while (!bonemodifier_elem.isNull())
{
ReadBoneModifierSet(bonemodifiers, bonemodifier_elem);
bonemodifier_elem = bonemodifier_elem.nextSiblingElement("dynamic_animation");
}
//.........这里部分代码省略.........
示例3: file
Core::IDocument::OpenResult ResourceFile::load()
{
m_error_message.clear();
if (m_file_name.isEmpty()) {
m_error_message = tr("The file name is empty.");
return Core::IDocument::OpenResult::ReadError;
}
QFile file(m_file_name);
if (!file.open(QIODevice::ReadOnly)) {
m_error_message = file.errorString();
return Core::IDocument::OpenResult::ReadError;
}
QByteArray data = file.readAll();
// Detect line ending style
m_textFileFormat = Utils::TextFileFormat::detect(data);
// we always write UTF-8 when saving
m_textFileFormat.codec = QTextCodec::codecForName("UTF-8");
file.close();
clearPrefixList();
QDomDocument doc;
QString error_msg;
int error_line, error_col;
if (!doc.setContent(data, &error_msg, &error_line, &error_col)) {
m_error_message = tr("XML error on line %1, col %2: %3")
.arg(error_line).arg(error_col).arg(error_msg);
return Core::IDocument::OpenResult::CannotHandle;
}
QDomElement root = doc.firstChildElement(QLatin1String("RCC"));
if (root.isNull()) {
m_error_message = tr("The <RCC> root element is missing.");
return Core::IDocument::OpenResult::CannotHandle;
}
QDomElement relt = root.firstChildElement(QLatin1String("qresource"));
for (; !relt.isNull(); relt = relt.nextSiblingElement(QLatin1String("qresource"))) {
QString prefix = fixPrefix(relt.attribute(QLatin1String("prefix")));
if (prefix.isEmpty())
prefix = QString(QLatin1Char('/'));
const QString language = relt.attribute(QLatin1String("lang"));
const int idx = indexOfPrefix(prefix, language);
Prefix * p = 0;
if (idx == -1) {
p = new Prefix(prefix, language);
m_prefix_list.append(p);
} else {
p = m_prefix_list[idx];
}
Q_ASSERT(p);
QDomElement felt = relt.firstChildElement(QLatin1String("file"));
for (; !felt.isNull(); felt = felt.nextSiblingElement(QLatin1String("file"))) {
const QString fileName = absolutePath(felt.text());
const QString alias = felt.attribute(QLatin1String("alias"));
File * const file = new File(p, fileName, alias);
file->compress = felt.attribute(QLatin1String("compress"));
file->threshold = felt.attribute(QLatin1String("threshold"));
p->file_list.append(file);
}
}
return Core::IDocument::OpenResult::Success;
}