本文整理汇总了C++中QXmlStreamAttributes::at方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlStreamAttributes::at方法的具体用法?C++ QXmlStreamAttributes::at怎么用?C++ QXmlStreamAttributes::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlStreamAttributes
的用法示例。
在下文中一共展示了QXmlStreamAttributes::at方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: htmlToString
void Xml::htmlToString(XmlReader& e, int level, QString* s)
{
*s += QString("<%1").arg(e.name().toString());
QXmlStreamAttributes map = e.attributes();
int n = map.size();
for (int i = 0; i < n; ++i) {
const QXmlStreamAttribute& a = map.at(i);
*s += QString(" %1=\"%2\"").arg(a.name().toString()).arg(a.value().toString());
}
*s += ">";
++level;
for (;;) {
QXmlStreamReader::TokenType t = e.readNext();
switch(t) {
case QXmlStreamReader::StartElement:
htmlToString(e, level, s);
break;
case QXmlStreamReader::EndElement:
*s += QString("</%1>").arg(e.name().toString());
--level;
return;
case QXmlStreamReader::Characters:
if (!e.isWhitespace())
*s += e.text().toString();
break;
case QXmlStreamReader::Comment:
break;
default:
qDebug("htmlToString: read token: %s", qPrintable(e.tokenString()));
return;
}
}
}
示例2: readPoint
QPointF XmlReader::readPoint()
{
Q_ASSERT(tokenType() == QXmlStreamReader::StartElement);
#ifndef NDEBUG
if (!attributes().hasAttribute("x")) {
QXmlStreamAttributes map = attributes();
qDebug("XmlReader::readPoint: x attribute missing: %s (%d)",
name().toUtf8().data(), map.size());
for (int i = 0; i < map.size(); ++i) {
const QXmlStreamAttribute& a = map.at(i);
qDebug(" attr <%s> <%s>", a.name().toUtf8().data(), a.value().toUtf8().data());
}
unknown();
}
if (!attributes().hasAttribute("y")) {
qDebug("XmlReader::readPoint: y attribute missing: %s", name().toUtf8().data());
unknown();
}
#endif
qreal x = doubleAttribute("x", 0.0);
qreal y = doubleAttribute("y", 0.0);
readNext();
return QPointF(x, y);
}
示例3: stackProcess
void XmlConsole::stackProcess(const QByteArray &data, bool incoming)
{
StackEnvironment *d = &(incoming ? m_stackIncoming : m_stackOutgoing);
d->reader.addData(data);
StackToken *token;
// debug() << incoming << data;
// debug() << "==================================================================";
while (d->reader.readNext() > QXmlStreamReader::Invalid) {
// qDebug() << incoming << d->reader.tokenString();
switch(d->reader.tokenType()) {
case QXmlStreamReader::StartElement:
// dbg << d->reader.name().toString() << d->depth
// << d->reader.attributes().value(QLatin1String("from")).toString();
d->depth++;
if (d->depth > 1) {
if (!d->tokens.isEmpty() && d->tokens.last()->type == QXmlStreamReader::Characters)
delete d->tokens.takeLast();
d->tokens << new StackToken(d->reader);
}
break;
case QXmlStreamReader::EndElement:
// dbg << d->reader.name().toString() << d->depth;
if (d->tokens.isEmpty())
break;
token = d->tokens.last();
if (token->type == QXmlStreamReader::StartElement && !token->startTag.empty)
token->startTag.empty = true;
else if (d->depth > 1)
d->tokens << new StackToken(d->reader);
if (d->depth == 2) {
QTextCursor cursor(m_ui->xmlBrowser->document());
cursor.movePosition(QTextCursor::End);
cursor.beginEditBlock();
QTextCharFormat zeroFormat = cursor.charFormat();
zeroFormat.setForeground(QColor(Qt::white));
QTextCharFormat bodyFormat = zeroFormat;
bodyFormat.setForeground(d->bodyColor);
QTextCharFormat tagFormat = zeroFormat;
tagFormat.setForeground(d->tagColor);
QTextCharFormat attributeFormat = zeroFormat;
attributeFormat.setForeground(d->attributeColor);
QTextCharFormat paramsFormat = zeroFormat;
paramsFormat.setForeground(d->paramColor);
QTextCharFormat bracketFormat = zeroFormat;
bracketFormat.setForeground(m_stackBracketsColor);
QString singleSpace = QLatin1String(" ");
cursor.insertBlock();
int depth = 0;
QString currentXmlns;
QXmlStreamReader::TokenType lastType = QXmlStreamReader::StartElement;
for (int i = 0; i < d->tokens.size(); i++) {
token = d->tokens.at(i);
if (token->type == QXmlStreamReader::StartElement) {
QString space = generate_stacked_space(depth);
cursor.insertText(QLatin1String("\n"));
cursor.insertText(space);
cursor.insertText(QLatin1String("<"), bracketFormat);
cursor.insertText(token->startTag.name->toString(), tagFormat);
const QStringRef &xmlns = *token->startTag.xmlns;
if (i == 0 || xmlns != currentXmlns) {
currentXmlns = xmlns.toString();
cursor.insertText(singleSpace);
cursor.insertText(QLatin1String("xmlns"), attributeFormat);
cursor.insertText(QLatin1String("="), zeroFormat);
cursor.insertText(QLatin1String("'"), paramsFormat);
cursor.insertText(currentXmlns, paramsFormat);
cursor.insertText(QLatin1String("'"), paramsFormat);
}
QXmlStreamAttributes *attributes = token->startTag.attributes;
for (int j = 0; j < attributes->count(); j++) {
const QXmlStreamAttribute &attr = attributes->at(j);
cursor.insertText(singleSpace);
cursor.insertText(attr.name().toString(), attributeFormat);
cursor.insertText(QLatin1String("="), zeroFormat);
cursor.insertText(QLatin1String("'"), paramsFormat);
cursor.insertText(attr.value().toString(), paramsFormat);
cursor.insertText(QLatin1String("'"), paramsFormat);
}
if (token->startTag.empty) {
cursor.insertText(QLatin1String("/>"), bracketFormat);
} else {
cursor.insertText(QLatin1String(">"), bracketFormat);
depth++;
}
} else if (token->type == QXmlStreamReader::EndElement) {
if (lastType == QXmlStreamReader::EndElement) {
QString space = generate_stacked_space(depth - 1);
cursor.insertText(QLatin1String("\n"));
cursor.insertText(space);
}
cursor.insertText(QLatin1String("</"), bracketFormat);
cursor.insertText(token->endTag.name->toString(), tagFormat);
cursor.insertText(QLatin1String(">"), bracketFormat);
depth--;
} else if (token->type == QXmlStreamReader::Characters) {
cursor.setCharFormat(bodyFormat);
QString text = token->charachters.text->toString();
if (text.contains(QLatin1Char('\n'))) {
QString space = generate_stacked_space(depth);
space.prepend(QLatin1Char('\n'));
//.........这里部分代码省略.........
示例4: file
bool fb2Creator::create(const QString& path, int width, int height, QImage& img)
{
QFile file(path);
KZip zip(path);
QIODevice *device;
const KArchiveDirectory *dir;
const KZipFileEntry *fb2File;
QXmlStreamReader qxml;
QString fileExt = QFileInfo(path).suffix().toLower();
if (fileExt == "fb2")
{
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "[fb2 thumbnailer]" << "Couldn't open" << path;
return false;
}
else
{
qDebug() << "[fb2 thumbnailer]" << "Reading" << path;
qxml.setDevice(&file);
}
}
else //if *.fb2.zip
{
if (!zip.open(QIODevice::ReadOnly))
{
qDebug() << "[fb2 thumbnailer]" << "Couldn't open" << path;
return false;
}
else
{
qDebug() << "[fb2 thumbnailer]" << "Reading" << path;
dir = zip.directory();
QStringList fileList = dir->entries();
for (int i=0; i < fileList.count(); i++)
{
if (fileList.at(i).endsWith(".fb2"))
{
fb2File = static_cast<const KZipFileEntry*>(dir->entry(fileList.at(i)));
device = fb2File->createDevice();
qxml.setDevice(device);
break;
}
}
}
}
//----
bool inCoverpage = false;
QString coverId = "";
QByteArray coverBase64;
while(!qxml.atEnd() && !qxml.hasError())
{
qxml.readNext();
if (qxml.name() == "coverpage")
{
if (qxml.isStartElement())
inCoverpage = true;
else
inCoverpage = false;
}
if (qxml.name() == "image" && qxml.isStartElement() && inCoverpage == true)
{
//various namespaces: xlink, l, NS2
QXmlStreamAttributes qxmlAttributes = qxml.attributes();
for (int pos = 0; pos < qxmlAttributes.size(); pos++)
{
if (qxmlAttributes.at(pos).name() == "href")
{
coverId = qxmlAttributes.at(pos).value().toString();
break;
}
}
if (coverId != "")
{
coverId.remove("#");
qDebug() << "[fb2 thumbnailer]" << "Found cover id:" << coverId;
}
}
if (qxml.name() == "binary" && qxml.isStartElement())
{
if (coverId != "")
{
if (qxml.attributes().value("id") == coverId)
{
qDebug() << "[fb2 thumbnailer]" << "Found cover data";
//.........这里部分代码省略.........