本文整理汇总了C++中QXmlStreamAttributes::size方法的典型用法代码示例。如果您正苦于以下问题:C++ QXmlStreamAttributes::size方法的具体用法?C++ QXmlStreamAttributes::size怎么用?C++ QXmlStreamAttributes::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QXmlStreamAttributes
的用法示例。
在下文中一共展示了QXmlStreamAttributes::size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: readVector
bool CommandCrossSection::readVector(const QXmlStreamAttributes &attributes, CCVector3 &P, QString element, const ccCommandLineInterface &cmd)
{
if (attributes.size() < 3)
{
return cmd.error(QString("Invalid XML file (3 attributes expected for element '<%1>')").arg(element));
}
int count = 0;
for (int i = 0; i < attributes.size(); ++i)
{
QString name = attributes[i].name().toString().toUpper();
QString value = attributes[i].value().toString();
bool ok = false;
if (name == "X")
{
P.x = value.toDouble(&ok);
++count;
}
else if (name == "Y")
{
P.y = value.toDouble(&ok);
++count;
}
else if (name == "Z")
{
P.z = value.toDouble(&ok);
++count;
}
else
{
ok = true;
}
if (!ok)
{
return cmd.error(QString("Invalid XML file (numerical attribute expected for attribute '%1' of element '<%2>')").arg(name, element));
}
}
if (count < 3)
{
return cmd.error(QString("Invalid XML file (attributes 'X','Y' and 'Z' are mandatory for element '<%1>')").arg(element));
}
return true;
}
示例3: 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);
}
示例4: valid
void
DirectParser::ParseSendfile (QXmlStreamReader & xread,
DirectMessage & msg,
qint64 & offset,
bool & complete,
bool & good,
QXmlStreamAttributes & atts)
{
QString subop = atts.value("subop").toString().toLower();
msg.SetSubop (subop);
bool valid (false);
if (subop == "chunk-data") {
ReadNext (xread);
if (xread.isCharacters ()) {
msg.SetData (xread.text().toString().toUtf8());
valid = true;
ReadNext (xread);
}
offset = xread.characterOffset ();
} else {
valid= ( subop == "sendreq"
|| subop == "samreq"
|| subop == "goahead"
|| subop == "deny"
|| subop == "chunk-ack"
|| subop == "snd-done"
|| subop == "abort"
);
ReadNext (xread);
}
if (valid) {
for (int i=0; i< atts.size(); i++) {
msg.SetAttribute (atts[i].name().toString().toLower(),
atts[i].value().toString());
}
good = true;
complete = true;
offset = xread.characterOffset ();
}
}
示例5: initCdr
int Dialog::initCdr(VCCdrDefines *pvcCdrDefines, QString fileName)
{
LOG_FUNC(Dialog::initCdr);
//初始化返回参数
pvcCdrDefines->clear();
CCdrBaseInfo BaseInfo;
//打开xml配置文件
QFile file;
//QMessageBox mb;
//mb.setText(QDir::currentPath() + "/cdrcomfig.xml");
//mb.exec();
file.setFileName(fileName);
if(!file.open(QIODevice::ReadOnly))
{
file.setFileName(XML_LOCATION);
if(!file.open(QIODevice::ReadOnly))
{
return FAIL;
}
}
//创建一个新的节点用来处理
QXmlStreamReader xmlReader(&file);
CCdrDefine* cCdeDefine = 0;
VCAttributes vcAttributes;
for(QXmlStreamReader::TokenType type = xmlReader.readNext();!xmlReader.atEnd(); type = xmlReader.readNext())
{
switch(type)
{
//开始节点
case QXmlStreamReader::StartElement:
#ifdef DEBUG
qDebug()<<"\t\t\ttype = QXmlStreamReader::StartElement; name = "<<xmlReader.name();
#endif
//cdr表示一张话单的开始
if(!xmlReader.name().compare("cdr"))
//todo 这里处理一个话单开始的工作,比如创建一个新的对象
{
#ifdef DEBUG
qDebug()<<"new cdr"<<xmlReader.name();
#endif
cCdeDefine = new CCdrDefine;
QXmlStreamAttributes qStreamAttr = xmlReader.attributes();
//遍历所有的属性,插入可以使用的属性
for(QXmlStreamAttributes::iterator iter = qStreamAttr.begin();iter != qStreamAttr.end();iter++)
{
if(BaseInfo.checkTypeAttr(BaseInfo.cdr(),iter->name().toString()))
{
cCdeDefine->vcCdrAttr.addOne(iter->name().toString(),iter->value().toString());
}
}
}
else if(!xmlReader.name().compare("filename"))
//如果这里是filename,就应该创建一个节点,用来存储相关的信息;
;
else if(!xmlReader.name().compare("element"))
//如果是element,表示是字段了.
;
else if(!xmlReader.name().compare("name") && cCdeDefine != 0)
{
//清空上次使用的attributes
vcAttributes.clear();
QXmlStreamAttributes qStreamAttr = xmlReader.attributes();
//在第一个位置添加这个节点的值
vcAttributes.addOne(xmlReader.name().toString(),xmlReader.readElementText());
//遍历所有的属性,插入可以使用的属性
for(QXmlStreamAttributes::iterator iter = qStreamAttr.begin();iter != qStreamAttr.end();iter++)
{
if(BaseInfo.checkTypeAttr(BaseInfo.fileName(),iter->name().toString()))
{
vcAttributes.addOne(iter->name().toString(),iter->value().toString());
}
}
#ifdef DEBUG
qDebug()<<"\tinsert into NameDef, name = "<<xmlReader.name();
#endif
//插入到链表中去
cCdeDefine->addNameDef(vcAttributes);
}
else if(!xmlReader.name().compare("field"))
{
//清空上次使用的attributes
vcAttributes.clear();
QXmlStreamAttributes qStreamAttr = xmlReader.attributes();
#ifdef DEBUG
qDebug()<<"\txmlReader.attributes()="<<qStreamAttr.size();
#endif
//.........这里部分代码省略.........
示例6: 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";
//.........这里部分代码省略.........