本文整理汇总了C++中QXmlStreamAttributes::count方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlStreamAttributes::count方法的具体用法?C++ QXmlStreamAttributes::count怎么用?C++ QXmlStreamAttributes::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlStreamAttributes
的用法示例。
在下文中一共展示了QXmlStreamAttributes::count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: attributesStartElementNsHandler
static void attributesStartElementNsHandler(AttributeParseState* state, const QXmlStreamAttributes& attrs)
{
if (attrs.count() <= 0)
return;
state->gotAttributes = true;
for (int i = 0; i < attrs.count(); i++) {
const QXmlStreamAttribute& attr = attrs[i];
String attrLocalName = attr.name();
String attrValue = attr.value();
String attrURI = attr.namespaceUri();
String attrQName = attr.qualifiedName();
state->attributes.set(attrQName, attrValue);
}
}
示例2: handleElementAttributes
static inline void handleElementAttributes(Element* newElement, const QXmlStreamAttributes &attrs, ExceptionCode& ec)
{
for (int i = 0; i < attrs.count(); ++i) {
const QXmlStreamAttribute &attr = attrs[i];
String attrLocalName = attr.name();
String attrValue = attr.value();
String attrURI = attr.namespaceUri().isEmpty() ? String() : String(attr.namespaceUri());
String attrQName = attr.qualifiedName();
newElement->setAttributeNS(attrURI, attrQName, attrValue, ec);
if (ec) // exception setting attributes
return;
}
}
示例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'));
//.........这里部分代码省略.........