本文整理汇总了C++中QDomElement::attributeNode方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomElement::attributeNode方法的具体用法?C++ QDomElement::attributeNode怎么用?C++ QDomElement::attributeNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomElement
的用法示例。
在下文中一共展示了QDomElement::attributeNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Constraint
ConstraintTypes::PlaylistFileSize::PlaylistFileSize( QDomElement& xmlelem, ConstraintNode* p )
: Constraint( p )
, m_size( 700 )
, m_unit( 1 )
, m_comparison( CompareNumEquals )
, m_strictness( 1.0 )
{
QDomAttr a;
a = xmlelem.attributeNode( "size" );
if ( !a.isNull() )
m_size = a.value().toInt();
a = xmlelem.attributeNode( "unit" );
if ( !a.isNull() )
m_unit = a.value().toInt();
a = xmlelem.attributeNode( "comparison" );
if ( !a.isNull() )
m_comparison = a.value().toInt();
a = xmlelem.attributeNode( "strictness" );
if ( !a.isNull() )
m_strictness = a.value().toDouble();
}
示例2: EMalformedPolicy
void
Pattern::xmlAddTransition(QDomElement _element)
{
// a transition must have a message tag
QDomAttr attrMessage = _element.attributeNode("message");
if (attrMessage.isNull() ||
attrMessage.value().isEmpty()) {
throw BehaviourEngine::
EMalformedPolicy(CORBA::string_dup("Transition without message."));
}
std::string message = attrMessage.value().latin1();
// a transition must have a target tag
QDomAttr attrPattern = _element.attributeNode("target");
if (attrPattern.isNull() ||
attrPattern.value().isEmpty()) {
throw BehaviourEngine::
EMalformedPolicy(CORBA::string_dup("Transition without target."));
}
std::string target = attrPattern.value().latin1();
// internal transitions are only possible within some policy
if (parent_ == NULL)
throw BehaviourEngine::
EMalformedPolicy(CORBA::string_dup("Internal transition at top level."));
parent_->transitions_.insert(std::make_pair(std::make_pair(getName(),
message),
target));
}
示例3: Constraint
ConstraintTypes::PlaylistLength::PlaylistLength( QDomElement& xmlelem, ConstraintNode* p )
: Constraint( p )
, m_length( 30 )
, m_comparison( CompareNumEquals )
, m_strictness( 1.0 )
{
QDomAttr a;
a = xmlelem.attributeNode( "length" );
if ( !a.isNull() ) {
m_length = a.value().toInt();
/* after 2.3.2, what was the PlaylistLength constraint became the
* PlaylistDuration constraint, so this works around the instance when
* a user loads an XML file generated with the old code -- sth*/
if ( m_length > 1000 )
m_length /= 240000;
}
a = xmlelem.attributeNode( "comparison" );
if ( !a.isNull() )
m_comparison = a.value().toInt();
a = xmlelem.attributeNode( "strictness" );
if ( !a.isNull() )
m_strictness = a.value().toDouble();
}
示例4: translateFromXML
BattleEvent* BattleEvent::translateFromXML(QDomElement element) {
QString ID = element.attributeNode("ID").value();
QDomElement typeElement = element.firstChildElement("type");
QString typeString = typeElement.attributeNode("value").value();
if (typeString != "BATTLE")
throw ProjectException("The translation of a battle event should have type BATTLE instead of " + typeString + ".");
Event::Trigger trigger = Event::NONE;
QString triggerString = element.firstChildElement("trigger").attributeNode("value").value();
if (triggerString == "TOUCH")
trigger = Event::TOUCH;
else if (triggerString == "INTERACT")
trigger = Event::INTERACT;
else if (triggerString == "NONE")
trigger = Event::NONE;
BattleEvent *event = create(ID, trigger);
Event::translateFromXML(element, event);
QDomElement activationElement = element.firstChildElement("activation");
event->setActivation(activationElement.attributeNode("value").value().toInt());
return event;
}
示例5: Constraint
ConstraintTypes::PlaylistDuration::PlaylistDuration( QDomElement& xmlelem, ConstraintNode* p )
: Constraint( p )
, m_duration( 0 )
, m_comparison( CompareNumEquals )
, m_strictness( 1.0 )
{
QDomAttr a;
a = xmlelem.attributeNode( "duration" );
if ( !a.isNull() ) {
m_duration = a.value().toInt();
} else {
// Accommodate schema change when PlaylistLength became PlaylistDuration
a = xmlelem.attributeNode( "length" );
if ( !a.isNull() )
m_duration = a.value().toInt();
}
a = xmlelem.attributeNode( "comparison" );
if ( !a.isNull() )
m_comparison = a.value().toInt();
a = xmlelem.attributeNode( "strictness" );
if ( !a.isNull() )
m_strictness = a.value().toDouble();
}
示例6: loadLine
void LevelLoader::loadLine(QDomElement lineNode)
{
// Reading the line number
QDomAttr attribute = lineNode.attributeNode(QStringLiteral("Number"));
QDomElement attributeNode = lineNode.firstChildElement(QStringLiteral("Number"));
if (!attribute.isNull()) {
m_lineNumber = attribute.value().toInt();
} else if (!attributeNode.isNull()) {
m_lineNumber = attributeNode.text().toInt();
} else {
// Standard line numbering: load next line
m_lineNumber++;
}
// Reading the brick information
attribute = lineNode.attributeNode(QStringLiteral("Bricks"));
attributeNode = lineNode.firstChildElement(QStringLiteral("Bricks"));
QString line;
if (!attribute.isNull()) {
line = attribute.value();
} else if (!attributeNode.isNull()) {
line = attributeNode.text();
} else {
line = lineNode.text();
}
if (line.size() > WIDTH) {
qCritical() << "Invalid levelset " << m_levelname << ": too many bricks in line "
<< m_lineNumber << endl;
}
emit newLine(line, m_lineNumber);
}
示例7: parseVar
Variable* XDVariableParser::parseVar(QDomNode& node, Variable* parent, bool fullname)
{
QDomElement e = node.toElement();
PHPVariable* var = new PHPVariable(parent);
int children = e.attributeNode("numchildren").value().toInt();
QString type = e.attributeNode("type").value();
QString fname = fullname?"fullname":"name";
var->setName(e.attributeNode(fname).value());
if(type == "object")
{
PHPObjectValue* objValue = new PHPObjectValue(var);
var->setValue(objValue);
objValue->setScalar(false);
objValue->setClassType(e.attributeNode("classname").value());
objValue->setList(parseList(e.childNodes(), var));
}
else if(children)
{
PHPArrayValue* arrayValue = new PHPArrayValue(var, children);
var->setValue(arrayValue);
arrayValue->setScalar(false);
if (e.childNodes().count() > 0)
{
arrayValue->setList(parseList(e.childNodes(), var, false));
}
}
else
{
PHPScalarValue* value = new PHPScalarValue(var);
var->setValue(value);
if(type == "null")
{
value->setType(PHPScalarValue::Undefined);
value->set("null");
}
else if(type == "int")
{
value->setType(PHPScalarValue::Integer);
value->set(e.text());
}
else if(type == "string")
{
value->setType(PHPScalarValue::String);
value->set(QString("\"") + QString(KCodecs::base64Decode (e.text().utf8())) + QString("\""));
}
else if(type == "float")
{
value->setType(PHPScalarValue::Double);
value->set(e.text());
}
}
return var;
}
示例8: Unmarshall
void Block::Unmarshall( QDomElement& blockElement, Level* level )
{
QDomAttr blockRowAttr = blockElement.attributeNode(BLOCK_ROW_ATTR);
QDomAttr blockColumnAttr = blockElement.attributeNode(BLOCK_COLUMN_ATTR);
UrAsset::setRow( blockRowAttr.value().toUInt() );
UrAsset::setColumn( blockColumnAttr.value().toUInt() );
UrAsset::calculateLevelEditorPosition(level->Row);
}
示例9: if
ConstraintTypes::TagMatch::TagMatch( QDomElement& xmlelem, ConstraintNode* p )
: MatchingConstraint( p )
, m_comparer( new Comparer() )
, m_fieldsModel( new TagMatchFieldsModel() )
{
DEBUG_BLOCK
QDomAttr a;
a = xmlelem.attributeNode( "field" );
if ( !a.isNull() ) {
if ( m_fieldsModel->contains( a.value() ) )
m_field = a.value();
else
debug() << a.value() << "is not a recognized field name" << endl;
}
a = xmlelem.attributeNode( "comparison" );
if ( !a.isNull() ) {
m_comparison = a.value().toInt();
}
a = xmlelem.attributeNode( "value" );
if ( !a.isNull() ) {
if ( m_fieldsModel->type_of( m_field ) == FieldTypeInt ) {
m_value = a.value().toInt();
} else if ( m_fieldsModel->type_of( m_field ) == FieldTypeDate ) {
if ( m_comparison == CompareDateWithin ) {
QStringList parts = a.value().split(" ");
if ( parts.size() == 2 ) {
int u = parts.at( 0 ).toInt();
int v = 0;
if ( parts.at( 1 ) == "months" )
v = 1;
else if ( parts.at( 1 ) == "years" )
v = 2;
m_value = QVariant::fromValue( DateRange( u, v ) );
} else
m_value = QVariant::fromValue( DateRange( 0, 0 ) );
} else
m_value = QDate::fromString( a.value(), Qt::ISODate );
} else { // String type
m_value = a.value();
}
}
a = xmlelem.attributeNode( "invert" );
if ( !a.isNull() && a.value() == "true" )
m_invert = true;
else
m_invert = false;
a = xmlelem.attributeNode( "strictness" );
if ( !a.isNull() )
m_strictness = a.value().toDouble();
debug() << getName();
}
示例10: checkUserProfile
int MainWindow::checkUserProfile(QString profile)
{
QFile file(profile);
qDebug()<<"本地profile文件检查";
if(!file.open(QFile::ReadOnly | QFile::Text))
{
qDebug()<<"XML文件打开失败";
this->statusBarLabel->setText("can't find xml file");
QMessageBox::critical(NULL,"错误", "找不到启动配置文件,进入登陆认证", QMessageBox::Yes, QMessageBox::Yes);
//goto ask for new config file,other exit
return -1;
}
qDebug()<<profile<< "file open";
// QDomDocument doc;
QString errStr;
int errLine, errCol;
// setContent 是将指定的内容指定给QDomDocument 解析,第一参数可以是QByteArray或者是文件名等。
if(!userProfile.setContent(&file, false, &errStr, &errLine, &errCol))
{
qDebug()<<tr("指定XML内容失败 原因: ") << errStr;
}
file.close();
QDomElement node = userProfile.documentElement();
qDebug()<<node.tagName();
node = node.firstChildElement();
int userInfo = 0;
while(!node.isNull())
{
if(node.tagName() == tr("userInfo")){
qDebug()<<node.attributeNode("userName").nodeValue();
qDebug()<<node.attributeNode("password").nodeValue();
qDebug()<<node.attributeNode("email").nodeValue();
userInfo++;
}
if(node.tagName() == tr("phoneInfo")){
qDebug()<<node.attributeNode("brand").nodeValue();
qDebug()<<node.attributeNode("model").nodeValue();
qDebug()<<node.attributeNode("rom").nodeValue();
userInfo++;
}
node = node.nextSiblingElement();
}
if(userInfo > 1){
QMessageBox info;
info.addButton(QMessageBox::Ok);
info.setText(tr("请重新输入密码、邮箱,选择对应的手机型号,如果找不到您的手机型号,请选择其他,并且你的其他中表示出的你的手机型号,功能加紧研发中,如果有特殊需求,请邮件联系[email protected]"));
info.exec();
return 1;
}
else{
qDebug()<<"user info error";
return -1;
}
}
示例11: loadLevel
void LevelLoader::loadLevel(QList< Brick* >& bricks)
{
// Selecting the correct level
m_level++;
if( m_levelset == 0 ){
qDebug() << "Error: No levelset specified" << endl;
return;
}
QDomElement levels = m_levelset->documentElement();
QDomNode node = levels.firstChild();
for( int i = 1; i < m_level; i++ ){
node = node.nextSibling();
}
// --
// Load level information
if( node.isNull() || node.toElement().tagName() != "Level" ){
// Level not found or no more levels
return;
}
QDomAttr attribute;
QDomElement level = node.toElement();
if( level.isNull() ){
qDebug() << "Invalid Levelset " << m_levelname << ": Can't read level information";
}
attribute = level.attributeNode("Name");
QString levelName;
if( !attribute.isNull() ){
levelName = level.attributeNode("Name").value();
}
node = node.firstChild();
// --
// Load bricks and gifts
m_lineNumber = 0;
while( !node.isNull() ){
QDomElement info = node.toElement();
if( info.isNull() ){ qDebug() << "Invalid levelset " << m_levelname << ": Can't read level information."; }
if( info.tagName() == "Line" ){
// Load one line of bricks
loadLine( info, bricks );
} else if( info.tagName() == "Gift" ){
// Load one gift type
loadGift( info, bricks );
} else {
qDebug() << "Invalid tag name " << info.tagName() << " has occured in level "
<< levelName << " in levelset " << m_levelname << endl;
}
node = node.nextSibling();
}
}
示例12: importKeySet
void Prefs_KeyboardShortcuts::importKeySet(QString filename)
{
searchTextLineEdit->clear();
QFileInfo fi = QFileInfo(filename);
if (fi.exists())
{
//import the file into qdomdoc
QDomDocument doc( "keymapentries" );
QFile file1( filename );
if ( !file1.open( QIODevice::ReadOnly ) )
return;
QTextStream ts(&file1);
ts.setCodec("UTF-8");
QString errorMsg;
int eline;
int ecol;
if ( !doc.setContent( ts.readAll(), &errorMsg, &eline, &ecol ))
{
qDebug("%s", QString("Could not open key set file: %1\nError:%2 at line: %3, row: %4").arg(filename).arg(errorMsg).arg(eline).arg(ecol).toLatin1().constData());
file1.close();
return;
}
file1.close();
//load the file now
QDomElement docElem = doc.documentElement();
if (docElem.tagName()=="shortcutset" && docElem.hasAttribute("name"))
{
QDomAttr keysetAttr = docElem.attributeNode( "name" );
//clear current menu entries
for (QMap<QString,Keys>::Iterator it=keyMap.begin(); it!=keyMap.end(); ++it)
it.value().keySequence = QKeySequence();
//load in new set
QDomNode n = docElem.firstChild();
while( !n.isNull() )
{
QDomElement e = n.toElement(); // try to convert the node to an element.
if( !e.isNull() )
{
if (e.hasAttribute("name") && e.hasAttribute( "shortcut" ))
{
QDomAttr nameAttr = e.attributeNode( "name" );
QDomAttr shortcutAttr = e.attributeNode( "shortcut" );
if (keyMap.contains(nameAttr.value()))
keyMap[nameAttr.value()].keySequence=QKeySequence(shortcutAttr.value());
}
}
n = n.nextSibling();
}
}
}
insertActions();
}
示例13: getNodeValue
QString cDefinable::getNodeValue( const QDomElement &Tag )
{
QString Value = QString();
if( !Tag.hasChildNodes() )
return "";
else
{
QDomNode childNode = Tag.firstChild();
while( !childNode.isNull() )
{
if( !childNode.isElement() )
{
if( childNode.isText() )
Value += childNode.toText().data();
childNode = childNode.nextSibling();
continue;
}
QDomElement childTag = childNode.toElement();
if( childTag.nodeName() == "random" )
{
if( childTag.attributes().contains("min") && childTag.attributes().contains("max") )
Value += QString("%1").arg( RandomNum( childTag.attributeNode("min").nodeValue().toInt(), childTag.attributeNode("max").nodeValue().toInt() ) );
else if( childTag.attributes().contains("valuelist") )
{
QStringList RandValues = QStringList::split(",", childTag.attributeNode("list").nodeValue());
Value += RandValues[ RandomNum(0,RandValues.size()-1) ];
}
else if( childTag.attributes().contains( "list" ) )
{
Value += DefManager->getRandomListEntry( childTag.attribute( "list" ) );
}
else if( childTag.attributes().contains("dice") )
Value += QString("%1").arg(rollDice(childTag.attributeNode("dice").nodeValue()));
else
Value += QString("0");
}
// Process the childnodes
QDomNodeList childNodes = childTag.childNodes();
for( int i = 0; i < childNodes.count(); i++ )
{
if( !childNodes.item( i ).isElement() )
continue;
Value += this->getNodeValue( childNodes.item( i ).toElement() );
}
childNode = childNode.nextSibling();
}
}
return hex2dec( Value );
}
示例14: loadGift
void LevelLoader::loadGift(QDomElement giftNode)
{
bool nodeTextRead = false;
// Reading the brick type
QDomAttr attribute = giftNode.attributeNode(QStringLiteral("Type"));
QDomElement attributeNode = giftNode.firstChildElement(QStringLiteral("Type"));
QString giftType;
if (!attribute.isNull()) {
giftType = attribute.value();
} else if (!attributeNode.isNull()) {
giftType = attributeNode.text();
nodeTextRead = true;
} else {
giftType = giftNode.text();
nodeTextRead = true;
}
// Reading number of gifts to be distributed. If not specified one gift is placed.
attribute = giftNode.attributeNode(QStringLiteral("Count"));
attributeNode = giftNode.firstChildElement(QStringLiteral("Count"));
int times = 1;
bool ok = true;
if (!attribute.isNull()) {
times = attribute.value().toInt(&ok);
} else if (!attributeNode.isNull()) {
times = attributeNode.text().toInt(&ok);
nodeTextRead = true;
} else if (!nodeTextRead) {
times = giftNode.text().toInt(&ok);
if (!ok) {
times = 1;
}
}
// If only one brick to be placed: see if position is given
QString position;
if (times == 1) {
attribute = giftNode.attributeNode(QStringLiteral("Position"));
attributeNode = giftNode.firstChildElement(QStringLiteral("Position"));
if (!attribute.isNull()) {
position = attribute.value();
} else if (!attributeNode.isNull()) {
position = attributeNode.text();
nodeTextRead = true;
} else if (!nodeTextRead && giftNode.text().contains(QLatin1Char(','))) {
position = giftNode.text();
nodeTextRead = true;
}
}
emit newGift(giftType, times, position);
}
示例15: mergeBenchmarkResults
static void mergeBenchmarkResults(const QString &xmlFile, BenchmarkResults *bmResults)
{
QFile f(xmlFile);
f.open(QIODevice::ReadOnly);
QByteArray xml = f.readAll();
QDomDocument doc;
int line;
int col;
QString errorMsg;
if (doc.setContent(xml, &errorMsg, &line, &col) == false) {
qDebug() << "dom setContent failed" << line << col << errorMsg;
}
int outputPos = 0;
QDomNodeList testFunctions = doc.elementsByTagName("TestFunction");
for (int i = 0; i < testFunctions.count(); ++i) {
QDomElement function = testFunctions.at(i).toElement();
QString functionName = function.attributeNode("name").value();
QDomNodeList results = function.elementsByTagName("BenchmarkResult");
for (int j = 0; j < results.count(); ++j) {
QDomElement result = results.at(j).toElement();
QString tag = result.attributeNode("tag").value();
QString metric = result.attributeNode("metric").value();
QString valueString = result.attributeNode("value").value();
QString iterationsString = result.attributeNode("iterations").value();
const int value = valueString.toInt();
const int iterations = iterationsString.toInt();
const QString funcTag = functionName + tag;
BenchmarkResult *bmResult = bmResults->value(funcTag);
if (!bmResult) {
bmResult = new BenchmarkResult(functionName, tag, outputPos++);
bmResults->insert(funcTag, bmResult);
}
MetricResult *metricResult = bmResult->metricResults.value(metric);
if (!metricResult) {
metricResult = new MetricResult(value, iterations);
bmResult->metricResults.insert(metric, metricResult);
}
}
}
}