本文整理汇总了C++中QDomElement::setAttributeNode方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomElement::setAttributeNode方法的具体用法?C++ QDomElement::setAttributeNode怎么用?C++ QDomElement::setAttributeNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomElement
的用法示例。
在下文中一共展示了QDomElement::setAttributeNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeXml
// 将销售记录写入文档
void Widget::writeXml()
{
// 先从文件读取
if (docRead()) {
QString currentDate = getDateTime(Date);
QDomElement root = doc.documentElement();
// 根据是否有日期节点进行处理
if (!root.hasChildNodes()) {
QDomElement date = doc.createElement(QString("日期"));
QDomAttr curDate = doc.createAttribute("date");
curDate.setValue(currentDate);
date.setAttributeNode(curDate);
root.appendChild(date);
createNodes(date);
} else {
QDomElement date = root.lastChild().toElement();
// 根据是否已经有今天的日期节点进行处理
if (date.attribute("date") == currentDate) {
createNodes(date);
} else {
QDomElement date = doc.createElement(QString("日期"));
QDomAttr curDate = doc.createAttribute("date");
curDate.setValue(currentDate);
date.setAttributeNode(curDate);
root.appendChild(date);
createNodes(date);
}
}
// 写入到文件
docWrite();
}
}
示例2: save
void Properties::save(QDomDocument &doc, QDomElement &parent)
{
QDomElement propertiesElem = doc.createElement(XML_TAGNAME.c_str());
parent.appendChild(propertiesElem);
QDomAttr propertieAttr;
for (std::map<std::string, Property*>::iterator it = _properties.begin(); it != _properties.end(); ++it)
{
// to save string lists, we save each value the format property_name[index]
const std::vector<std::string> &lst = it->second->valueStrList();
if(lst.size()>1)
{
for(unsigned int i=0;i<lst.size(); i++)
{
QString index;
index.sprintf("%i",i);
propertieAttr = doc.createAttribute(QString(it->second->name().c_str()).replace(' ', WHITESPACE_REPLACEMENT)+index);
propertieAttr.setValue(lst[i].c_str());
propertiesElem.setAttributeNode(propertieAttr);
}
}
else
{
propertieAttr = doc.createAttribute(QString(it->second->name().c_str()).replace(' ', WHITESPACE_REPLACEMENT));
propertieAttr.setValue(it->second->valueStr().c_str());
propertiesElem.setAttributeNode(propertieAttr);
}
}
}
示例3: internalSave
void Gear_ListBox::internalSave(QDomDocument &doc, QDomElement &gearElem)
{
std::ostringstream strValue;
strValue << getValue();
QDomAttr attrListBoxPos = doc.createAttribute("ListBoxPos");
attrListBoxPos.setValue(strValue.str().c_str());
gearElem.setAttributeNode(attrListBoxPos);
}
示例4:
void Schema::Connection::save(QDomDocument &doc, QDomElement &parent)
{
QDomElement connectionElem = doc.createElement("Connection");
parent.appendChild(connectionElem);
QDomAttr gearA = doc.createAttribute("GearA");
gearA.setValue(_gearA.c_str());
connectionElem.setAttributeNode(gearA);
QDomAttr input = doc.createAttribute("Input");
input.setValue(_input.c_str());
connectionElem.setAttributeNode(input);
QDomAttr gearB = doc.createAttribute("GearB");
gearB.setValue(_gearB.c_str());
connectionElem.setAttributeNode(gearB);
QDomAttr output = doc.createAttribute("Output");
output.setValue(_output.c_str());
connectionElem.setAttributeNode(output);
}
示例5: on_btn_select_clicked
void MainWindow::on_btn_select_clicked()
{
ui->listWidget->clear();
ui->listWidget->addItem(tr("无法添加"));
QFile file("my.xml");
if(!file.open(QIODevice::ReadOnly()))
{
return;
}
QDomDocument doc;
if(!doc.setContent(&file))
{
file.close();
return ;
}
file.close();
QDomElement root = doc.documentElement();
QDomElement book = doc.documentElement(tr("图书"));
QDomAttr id = doc.createAttribute(tr("编号"));
QDomElement title = doc.documentElement(tr("书名"));
QDomElement author = doc.documentElement(tr("作者"));
QDomText text;
QString num = root.lastChild().toElement().attribute(tr("编号"));
int count = num.toInt() +1;
id.setValue(QString::number(count));
book.setAttributeNode(id);
text = doc.createTextNode(ui->lineEdit_name->text());
title.appendChild(text);
text = doc.createTextNode(ui->lineEdit_author->text());
author.appendChild(text);
book.appendChild(title);
book.appendChild(author);
root.appendChild(book);
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
return;
}
QTextStream out(&file);
doc.save(out, 4);
file.close();
ui->listWidget->clear();
ui->listWidget->addItem(tr("添加成功"));
}
示例6: sipConvertFromNewType
static PyObject *meth_QDomElement_setAttributeNode(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const QDomAttr * a0;
QDomElement *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QDomElement, &sipCpp, sipType_QDomAttr, &a0))
{
QDomAttr *sipRes;
Py_BEGIN_ALLOW_THREADS
sipRes = new QDomAttr(sipCpp->setAttributeNode(*a0));
Py_END_ALLOW_THREADS
return sipConvertFromNewType(sipRes,sipType_QDomAttr,NULL);
}
}
示例7: getBlocks
QDomElement ExerciseWindow::getBlocks(const FCWidget *fc, QDomDocument &doc, QString Name)
{
int n = fc->layout()->count();
int i = 0;
QDomElement domElement = doc.createElement(Name);
while (i < n) {
QDomElement block;
QDomAttr attr = doc.createAttribute("text");
QString tag = fc->layout()->itemAt(i)->widget()->metaObject()->className();
if (tag != "FCLine" && tag != "FCLeftLine" && tag != "RightLine") {
block = doc.createElement(tag);
FCWidget *widget = (FCWidget*)fc->layout()->itemAt(i)->widget();
attr.setValue(widget->getText());
block.setAttributeNode(attr);
domElement.appendChild(block);
if (tag == "FCDivarWidget") {
FCDivarWidget *divar = (FCDivarWidget*)widget;
QDomElement left = getBlocks(divar->getRightLine(), doc, "Left");
QDomElement right = getBlocks(divar->getLeftLine(), doc, "Right");
block.appendChild(left);
block.appendChild(right);
}
else if (tag == "FCPrefixCycleWidget") {
FCPrefixCycleWidget *cycle = (FCPrefixCycleWidget*)widget;
QDomElement body = getBlocks(cycle->getCycleBody(), doc, "Body");
block.appendChild(body);
}
else if (tag == "FCPostfixCycleWidget") {
FCPostfixCycleWidget *cycle = (FCPostfixCycleWidget*)widget;
QDomElement body = getBlocks(cycle->getCycleBody(), doc, "Body");
block.appendChild(body);
}
else if (tag == "FCParameterCycleWidget") {
FCParameterCycleWidget *cycle = (FCParameterCycleWidget*)widget;
QDomElement body = getBlocks(cycle->getCycleBody(), doc, "Body");
block.appendChild(body);
}
}
i++;
}
return domElement;
}
示例8: makeElement
QDomElement makeElement( QDomDocument& domDoc,
const QString& strName,
const QString& strAttr = QString::null,
const QString& strText = QString::null
)
{
QDomElement domElement = domDoc.createElement(strName);
if (!strAttr.isEmpty()) {
QDomAttr domAttr = domDoc.createAttribute("number");
domAttr.setValue(strAttr);
domElement.setAttributeNode(domAttr);
}
if (!strText.isEmpty()) {
QDomText domText = domDoc.createTextNode(strText);
domElement.appendChild(domText);
}
return domElement;
}
示例9: saveDegree
void XmlDataPersistance::saveDegree(Degree *degree, QDomElement &element, QDomDocument &dom)
{
QDomElement degreeElement = dom.createElement("item");
degreeElement.setAttribute("type",degree->type());
element.appendChild(degreeElement);
QDomElement titleElement = dom.createElement("titre");
titleElement.appendChild(dom.createTextNode(degree->title()));
degreeElement.appendChild(titleElement);
QDomElement typeElement = dom.createElement("type");
typeElement.appendChild(dom.createTextNode(degree->type()));
degreeElement.appendChild(typeElement);
const QList<const Uv*> &uvs = degree->uvs();
for(int i = 0; i < uvs.size(); i++)
{
QDomElement uvElement = dom.createElement("uv");
uvElement.appendChild(dom.createTextNode(uvs.at(i)->code()));
degreeElement.appendChild(uvElement);
}
const QMap<QString,int> "as = degree->quotas();
QMapIterator<QString,int> it(quotas);
while(it.hasNext())
{
it.next();
QDomElement quotaElement = dom.createElement("quota");
QDomAttr cat = dom.createAttribute("categorie");
cat.setNodeValue(it.key());
quotaElement.setAttributeNode(cat);
quotaElement.appendChild(dom.createTextNode(QString::number(it.value())));
degreeElement.appendChild(quotaElement);
}
const QList<Degree*> &children = degree->children();
for(int i = 0; i < children.size(); i++)
saveDegree(children.at(i),degreeElement,dom);
}
示例10: sipConvertFromNewType
static PyObject *meth_QDomElement_setAttributeNode(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
const QDomAttr* a0;
QDomElement *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QDomElement, &sipCpp, sipType_QDomAttr, &a0))
{
QDomAttr*sipRes;
sipRes = new QDomAttr(sipCpp->setAttributeNode(*a0));
return sipConvertFromNewType(sipRes,sipType_QDomAttr,NULL);
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QDomElement, sipName_setAttributeNode, doc_QDomElement_setAttributeNode);
return NULL;
}
示例11: createNodes
// 创建节点
void Widget::createNodes(QDomElement &date)
{
QDomElement time = doc.createElement(QString("时间"));
QDomAttr curTime = doc.createAttribute("time");
curTime.setValue(getDateTime(Time));
time.setAttributeNode(curTime);
date.appendChild(time);
QDomElement type = doc.createElement(QString("类型"));
QDomElement brand = doc.createElement(QString("品牌"));
QDomElement price = doc.createElement(QString("单价"));
QDomElement num = doc.createElement(QString("数量"));
QDomElement sum = doc.createElement(QString("金额"));
QDomText text;
text = doc.createTextNode(QString("%1")
.arg(ui->sellTypeComboBox->currentText()));
type.appendChild(text);
text = doc.createTextNode(QString("%1")
.arg(ui->sellBrandComboBox->currentText()));
brand.appendChild(text);
text = doc.createTextNode(QString("%1")
.arg(ui->sellPriceLineEdit->text()));
price.appendChild(text);
text = doc.createTextNode(QString("%1")
.arg(ui->sellNumSpinBox->value()));
num.appendChild(text);
text = doc.createTextNode(QString("%1")
.arg(ui->sellSumLineEdit->text()));
sum.appendChild(text);
time.appendChild(type);
time.appendChild(brand);
time.appendChild(price);
time.appendChild(num);
time.appendChild(sum);
}
示例12: oldStyleNS
static QDomElement oldStyleNS(const QDomElement &e)
{
// find closest parent with a namespace
QDomNode par = e.parentNode();
while(!par.isNull() && par.namespaceURI().isNull())
par = par.parentNode();
bool noShowNS = false;
if(!par.isNull() && par.namespaceURI() == e.namespaceURI())
noShowNS = true;
QDomElement i;
uint x;
//if(noShowNS)
i = e.ownerDocument().createElement(e.tagName());
//else
// i = e.ownerDocument().createElementNS(e.namespaceURI(), e.tagName());
// copy attributes
QDomNamedNodeMap al = e.attributes();
for(x = 0; x < al.count(); ++x)
i.setAttributeNode(al.item(x).cloneNode().toAttr());
if(!noShowNS)
i.setAttribute("xmlns", e.namespaceURI());
// copy children
QDomNodeList nl = e.childNodes();
for(x = 0; x < nl.count(); ++x) {
QDomNode n = nl.item(x);
if(n.isElement())
i.appendChild(oldStyleNS(n.toElement()));
else
i.appendChild(n.cloneNode());
}
return i;
}
示例13: saveXmlAttribute
void RedisConnectionConfig::saveXmlAttribute(QDomDocument & document, QDomElement & root, const QString& name, const QString& value)
{
QDomAttr attr = document.createAttribute(name);
attr.setValue(value);
root.setAttributeNode(attr);
}
示例14: addNormalWidget
void writeJob::addNormalWidget(const QString property, const QString desc, const QString datatype,
const QString min, const QString max, const QString displaytype,
const QString displayvalue, const QStringList optiontextList,
const QStringList optionvalueList, const QString id, const QString boxID,
const QList<QString> radioIDList)
{
// qDebug()<<"writeJob::addNormalWidget::"<< property<< desc<< datatype<<min<< max<< displaytype<<
// displayvalue<< optiontextList<< optionvalueList<<id<<boxID<<radioIDList;
// 1.打开文件,分析文件,准备添加
if(alreadyReadJob==false)
{
if(!readJob())
{
qDebug()<<"readJob failed";
}
}
// 2. 添加各个属性
QDomElement propertyEle = doc.createElement("property");
QDomElement descEle = doc.createElement("desc");
QDomElement datatypeEle = doc.createElement("datatype");
QDomElement minEle = doc.createElement("min");
QDomElement maxEle = doc.createElement("max");
QDomElement displaytypeEle = doc.createElement("displaytype");
QDomElement idEle = doc.createElement("id");
// QDomElement optiontextEle = doc.createElement("option"); //多次创建,且在内层,不应当在此创建。
if(!property.isEmpty())
{
QDomAttr idAttr=doc.createAttribute("id"); // 写上id和名字用来判断
if(id!="")
{
idAttr.setValue(id);
}
if(id=="")
{
idAttr.setValue(boxID); //还要在下面的radio中加入id阿(radioIDList)
}
QDomAttr propertyAttr=doc.createAttribute("name");
propertyAttr.setValue(property);
propertyEle.setAttributeNode(idAttr);
propertyEle.setAttributeNode(propertyAttr);
moduleEle.appendChild(propertyEle); /// 应该将module添加进来
}
if(!desc.isEmpty())
{
QDomText descText=doc.createTextNode(desc);
descEle.appendChild(descText);
propertyEle.appendChild(descEle);
}
if(!datatype.isEmpty())
{
QDomText datatypeText=doc.createTextNode(datatype);
datatypeEle.appendChild(datatypeText);
propertyEle.appendChild(datatypeEle);
}
if(!min.isEmpty())
{
QDomText minText=doc.createTextNode(min);
minEle.appendChild(minText);
propertyEle.appendChild(minEle);
}
if(!max.isEmpty())
{
QDomText maxText=doc.createTextNode(max);
maxEle.appendChild(maxText);
propertyEle.appendChild(maxEle);
}
if(!displaytype.isEmpty())
{
QDomAttr displaytypeAttr=doc.createAttribute("name");
displaytypeAttr.setValue(displaytype);
displaytypeEle.setAttributeNode(displaytypeAttr);
/// ----------------------radio && combo---------------------------- ///
if(!optiontextList.isEmpty())
{
for(int i=0;i<optiontextList.size();i++)
{
QDomElement optiontextEle = doc.createElement("option"); // 这个是要动态创建的,因为要多个。。。
QDomAttr optiontextAttr=doc.createAttribute("value");
optiontextAttr.setValue(optiontextList.at(i));
optiontextEle.setAttributeNode(optiontextAttr);
/// <option value="CMP" id="Z2Q3bfYnd4KqMrx">checked</option>
if(!radioIDList.isEmpty()) //写上radioButton的id
{
QDomAttr optionRadioAttr=doc.createAttribute("id");
optionRadioAttr.setValue(radioIDList.at(i));
optiontextEle.setAttributeNode(optionRadioAttr);
}
if(!optionvalueList.isEmpty())
{
QDomText optionvalueText=doc.createTextNode(optionvalueList.at(i));
optiontextEle.appendChild(optionvalueText);
}
//.........这里部分代码省略.........
示例15: main
//.........这里部分代码省略.........
doc.appendChild( instruction );
QDomElement root = doc.createElement( "kdevelop" );
doc.appendChild( root );
QDomElement general = doc.createElement( "general" );
root.appendChild( general );
element = doc.createElement( "author" );
text = doc.createTextNode( "zeki" );
general.appendChild( element );
element.appendChild( text );
element = doc.createElement( "email" );
text = doc.createTextNode( "[email protected]" );
element.appendChild( text );
general.appendChild( element );
element = doc.createElement( "version" );
text = doc.createTextNode( "$VERSION" );
element.appendChild( text );
general.appendChild( element );
QDomElement keywords = doc.createElement( "keywords" );
element = doc.createElement( "keyword" );
text = doc.createTextNode( "C++" );
element.appendChild( text );
keywords.appendChild( element );
general.appendChild( keywords );
element = doc.createElement( "ignoreparts" );
general.appendChild( element );
QDomElement kdevfileview = doc.createElement( "kdevfileview" );
QDomElement groups = doc.createElement( "groups" );
element = doc.createElement( "group" );
QDomAttr pattern = doc.createAttribute( "pattern" );
pattern.setValue( "*.cpp;*.cxx;*.h" );
QDomAttr name = doc.createAttribute( "name" );
name.setValue( "Sources" );
element.setAttributeNode( pattern );
element.setAttributeNode( name );
groups.appendChild( element );
kdevfileview.appendChild( groups );
root.appendChild( kdevfileview );
QTextStream out( &file );
doc.save( out, 4 );
file.close();
a.exec();
}