Example #1
0
QDomNode DataBase::getNextNode(QDomNode &currentNode, QDomNode &lastNode) {
  DBGS(PRINT_START("currentNode: 0x%08x, lastNode: 0x%08x", &currentNode, &lastNode));

  QDomNode nextNode;

  if (currentNode.hasChildNodes()) {
    nextNode = currentNode.firstChild();
  }
  else {
    QDomNode previousNode = currentNode;
    nextNode = currentNode.nextSibling();

    while (nextNode.isNull()) {
      QDomNode parentNode = previousNode.parentNode();

      if (parentNode == lastNode) {
        break;
      }
      else {
        previousNode = parentNode;
        nextNode = parentNode.nextSibling();
      }
    }
  }

  DBGR(PRINT_RETURN("nextNode: 0x%08x", &nextNode));
  return nextNode;
}
void QQMlDom::removeDefaultNode(QDomElement nDocument, QString element)
{
    QDomNodeList removeList = nDocument.elementsByTagName(element);
    QDomNode rUrl = removeList.at(0);
    qDebug() << "is there a child node ?"  << rUrl.hasChildNodes() <<"  " << rUrl.childNodes().at(0).nodeName() ;
    rUrl.removeChild(rUrl.childNodes().at(0));
}
Example #3
0
QString ExampleContent::extractTextFromParagraph(const QDomNode &parentNode)
{
    QString description;
    QDomNode node = parentNode.firstChild();

    while (!node.isNull()) {
        QString beginTag;
        QString endTag;
        if (node.isText())
            description += Colors::contentColor + node.nodeValue();
        else if (node.hasChildNodes()) {
            if (node.nodeName() == "b") {
                beginTag = "<b>";
                endTag = "</b>";
            } else if (node.nodeName() == "a") {
                beginTag = Colors::contentColor;
                endTag = "</font>";
            } else if (node.nodeName() == "i") {
                beginTag = "<i>";
                endTag = "</i>";
            } else if (node.nodeName() == "tt") {
                beginTag = "<tt>";
                endTag = "</tt>";
            }
            description += beginTag + this->extractTextFromParagraph(node) + endTag;
        }
        node = node.nextSibling();
    }

    return description;
}
void ItemDefinitionGroup::processNode(const QDomNode &node)
{
    if (node.isElement())
        processNodeAttributes(node.toElement());
    if (node.hasChildNodes())
        processChildNodes(node.firstChild());
}
Example #5
0
bool QDomNodeProto:: hasChildNodes() const
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->hasChildNodes();
  return false;
}
Example #6
0
bool Configurator::loadSectionItem( QDomNode sectionItem, QListWidget& listWidget )
{
	if( false == sectionItem.hasChildNodes() )
		return false;

	if( sectionItem.nodeName() != c_sectionItemNodeName )
		return false;

	QDomNamedNodeMap sectionItemAttributes = sectionItem.attributes();
	if( false == sectionItemAttributes.contains(c_attributeName) )
		return false;

	if( false == sectionItemAttributes.contains(c_attributeText) )
		return false;

	// add the item to the section
	QString sectionItemName = sectionItemAttributes.namedItem(c_attributeName).nodeValue();
	QString sectionItemText = sectionItemAttributes.namedItem(c_attributeText).nodeValue();
	
	QListWidgetItem*	listWidgetItem = new QListWidgetItem();
					    listWidgetItem->setText( sectionItemText );
					    listWidgetItem->setData( Qt::UserRole, sectionItemName );

    listWidget.addItem( listWidgetItem );

	return true;
}
Example #7
0
bool ReturnInstruction::setAsXMLNode(QDomNode& node)
{
    if (node.hasChildNodes()) {
        QDomNodeList nodeList = node.childNodes();

        for (unsigned i = 0; i < nodeList.length(); i++) {
            QDomElement e = nodeList.item(i).toElement();

            if (!e.isNull()) {
                if (e.tagName() == "text") {
                    QDomNode t = e.firstChild();
                    setContents(t.nodeValue());
                } else if (e.tagName() == "comment") {
                    QDomNode t = e.firstChild();
                    setComment(t.nodeValue());
                }
            }
        }
    } else {
        // tekst, komentarz i pixmapa puste
    }

    validateContents();

    return true;
}
Example #8
0
/**
   Get the project title

   XML in file has this form:
\verbatim
   <qgis projectname="default project">
   <title>a project title</title>
\endverbatim

   @todo XXX we should go with the attribute xor title, not both.
*/
static void _getTitle( QDomDocument const &doc, QString & title )
{
  QDomNodeList nl = doc.elementsByTagName( "title" );

  title = "";                 // by default the title will be empty

  if ( !nl.count() )
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomNode titleNode = nl.item( 0 );  // there should only be one, so zeroth element ok

  if ( !titleNode.hasChildNodes() ) // if not, then there's no actual text
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomNode titleTextNode = titleNode.firstChild();  // should only have one child

  if ( !titleTextNode.isText() )
  {
    QgsDebugMsg( "unable to find title element" );
    return;
  }

  QDomText titleText = titleTextNode.toText();

  title = titleText.data();

} // _getTitle
Example #9
0
/* $Desc Add text inside the node s markups. If any already exists, it s
 *	over written.
 * $Parm p_node Node on which to write.
 * $Parm p_value Text to fill in.
 * $Rtrn /.
 */
void
XmlBehavior::addText(QDomNode& p_node, const QString& p_value) const
{
	if(p_node.hasChildNodes())
		logE("Try to add text to a node with children");

	p_node.appendChild(p_node.ownerDocument().createTextNode(p_value));
}
Example #10
0
void Project::processNode(const QDomNode &node)
{
    if (node.isElement())
        processNodeAttributes(node.toElement());

    if (node.hasChildNodes())
        processChildNodes(node.firstChild());
}
Example #11
0
quint16 BaseDataHandler::getUint16(const QDomNode& node) const
{
    quint16 result(0);
    if (node.hasChildNodes()){
        QString text = node.firstChild().nodeValue();
        QTextStream stream(&text);
        stream >> result;
    }
void XMLWriter::clearNodeContents(QDomNode& p_node)
{
    while( p_node.hasChildNodes() )
    {
        QDomNode node = p_node.childNodes().at(0);
        p_node.removeChild(node);
        node.clear();
    }
}
Example #13
0
QString QDomNodeProto::toString() const
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return QString("[QDomNode(%1=%2, %3, %4)]")
                    .arg(item->nodeName())
                    .arg(item->nodeValue())
                    .arg(item->nodeType())
                    .arg(item->hasChildNodes() ? "has children" : "leaf node");
  return QString("[QDomNode(unknown)]");
}
Example #14
0
void	pokedex::parse_moves(const QDomNode &noeud, pokemon &poke)
{
	if (noeud.hasChildNodes())
	{
		QDomNode noeud2 = noeud.firstChild();
		while (!noeud2.isNull())
		{
			this->parse_move(noeud2, poke);
			noeud2 = noeud2.nextSibling();
		}
	}
}
Example #15
0
void	pokedex::parse_ratio(const QDomNode &noeud, pokemon &poke)
{
	if (noeud.hasChildNodes())
	{
		QDomNode noeud2 = noeud.firstChild();
		while (!noeud2.isNull())
		{	
			if (noeud2.nodeName() == "male")
				poke.setRatioMale(noeud2.toElement().text().toFloat());
			else if (noeud2.nodeName() == "female")
				poke.setRatioFemale(noeud2.toElement().text().toFloat());
			noeud2 = noeud2.nextSibling();
		}
	}
}
Example #16
0
bool CAnm2DXml::loadImage(QDomNode node, AnmImage &data)
{
	while ( !node.isNull() ) {
		if ( node.nodeName() == "FilePath" ) {
			if ( !node.hasChildNodes() ) {
				return false ;
			}
			data.path = node.firstChild().toText().nodeValue() ;
			data.path = getAbsolutePath(m_fileName, data.path) ;
		}
		else if ( node.nodeName() == "Size" ) {
			if ( !node.hasChildNodes() ) {
				return false ;
			}
			QStringList size = node.firstChild().toText().nodeValue().split(" ") ;
			if ( size.size() != 2 ) {
				return false ;
			}
			data.origSize = QSize(size[0].toInt(), size[1].toInt()) ;
		}
		node = node.nextSibling() ;
	}
	return true ;
}
// debugging function that visualises the xml structure
void
printNode(QDomNode n, uint level) {
    while (!n.isNull()) {
        for (uint i=0; i<level; ++i) out << ' ';
        out << n.nodeName() << endl;
        if (n.isElement()) {
            QDomElement e = n.toElement();
            printAttributes(e, level+2);
        }
        if (n.hasChildNodes()) {
            printNode(n.firstChild(), level+1);
        }
        n = n.nextSibling();
    }
}
Example #18
0
QDomNode getChildByName( QDomNode parentNode, QString childNodeName )
{
	if( false == parentNode.hasChildNodes() )
		return QDomNode();

	QDomNode childNode = parentNode.firstChild();
	while( false == childNode.isNull() )
	{
		if( childNodeName == childNode.toElement().nodeName() )
			break;

		childNode = childNode.nextSibling();
	}
	
	return childNode;
}
// function that looks for an XML element with the attribute 'name' that has
// the wanted value. When the element is found it is copied into argument 't'
// and the rest of the tree is parsed. When more elements with the name
// are found an error is reported
void
findTypeElement(QString type, QDomNode n, QDomElement &t) {
    while (!n.isNull()) {
        if (n.toElement().attribute("name") == type) {
            if (t.isNull()) {
                t = n.toElement();
            } else {
                err << "Hmm, there are more elements with"
                    << "name=\"" << type << "\"." << endl;
            }
        }
        if (n.hasChildNodes()) {
            findTypeElement(type, n.firstChild(), t);
        }
        n = n.nextSibling();
    }
}
Example #20
0
void output(QDomNode node)
{
  QDomNode next;
  if (node.nodeName()=="li") std::cout << "\n* ";
  if (node.nodeName()=="h1") std::cout << "\n= ";
  if (node.nodeName()=="h2") std::cout << "\n== ";
  if (node.nodeName()=="p") std::cout << "\n\n";
  if (node.nodeName()=="br") std::cout << "\n";
  if (node.isText()) std::cout << QString(node.nodeValue().toUtf8()).toStdString();
  if (node.hasChildNodes()) 
  {
    for (int i=0; i<=node.childNodes().count(); ++i) output(node.childNodes().at(i));
  }
  if (node.nodeName()=="p") std::cout << "\n\n";
  if (node.nodeName()=="h1") std::cout << " =";
  if (node.nodeName()=="h2") std::cout << " ==";
}
void AssemblyReference_Private::processNode(const QDomNode &node)
{
    if (node.isNull())
        return;
    
//    vc_dbg << "Node Name: " << node.nodeName();
//    vc_dbg << "Node type: " << node.nodeType();
    
    if (node.nodeType() == QDomNode::ElementNode)
        processNodeAttributes(node.toElement());
    
    if (node.hasChildNodes()) {
        QDomNode firstChild = node.firstChild();
        if (!firstChild.isNull())
            processReferenceConfig(firstChild);
    }
}
Example #22
0
bool Configurator::loadSection( QDomNode section )
{
	// make some checks
	if( false == section.hasChildNodes() )
		return false;

	if( section.nodeName() != c_sectionNodeName )
		return false;

	QDomNamedNodeMap sectionAttributes = section.attributes();
	if( false == sectionAttributes.contains(c_attributeName) )
		return false;

	if( false == sectionAttributes.contains(c_attributeText) )
		return false;

	// we have all the attribbutes for this section, now build it usign GUI controls
	QString sectionName = sectionAttributes.namedItem(c_attributeName).nodeValue();
	QString sectionText = sectionAttributes.namedItem(c_attributeText).nodeValue();
	
	// build the UI
	QListWidget*	listWidget = new QListWidget();
				    listWidget->setObjectName( sectionName );
				    listWidget->setSelectionBehavior( QAbstractItemView::SelectRows );

	connect( listWidget,    SIGNAL	(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
			 this,		    SLOT	(currentItemChanged(QListWidgetItem*,QListWidgetItem*))	);

	_sections->addItem( listWidget, sectionText );
			
	// adding items for this section
	QDomNode sectionItem = section.firstChild();
	while( false == sectionItem.isNull() )
	{
	    if( QDomNode::CommentNode != section.nodeType() )
		if( false == loadSectionItem(sectionItem,*listWidget) )
			return false;
	
		sectionItem = sectionItem.nextSibling();				
	}

	return true;
}
Example #23
0
File: ssu.cpp Project: lbt/ssu
bool Ssu::setCredentials(QDomDocument *response){
  SsuCoreConfig *settings = SsuCoreConfig::instance();
  // generate list with all scopes for generic section, add sections
  QDomNodeList credentialsList = response->elementsByTagName("credentials");
  QStringList credentialScopes;
  for (int i=0;i<credentialsList.size();i++){
    QDomNode node = credentialsList.at(i);
    QString scope;

    QDomNamedNodeMap attributes = node.attributes();
    if (attributes.contains("scope")){
      scope = attributes.namedItem("scope").toAttr().value();
    } else {
      setError(tr("Credentials element does not have scope"));
      return false;
    }

    if (node.hasChildNodes()){
      QDomElement username = node.firstChildElement("username");
      QDomElement password = node.firstChildElement("password");
      if (username.isNull() || password.isNull()){
        setError(tr("Username and/or password not set"));
        return false;
      } else {
        settings->beginGroup("credentials-" + scope);
        settings->setValue("username", username.text());
        settings->setValue("password", password.text());
        settings->endGroup();
        settings->sync();
        credentialScopes.append(scope);
      }
    } else {
      setError("");
      return false;
    }
  }
  settings->setValue("credentialScopes", credentialScopes);
  settings->setValue("lastCredentialsUpdate", QDateTime::currentDateTime());
  settings->sync();
  emit credentialsChanged();

  return true;
}
Example #24
0
bool Configurator::loadSettingsFile()
{
	// check if we can read the file
	QFile configurationFile( _configurationFileName );
	if( false == configurationFile.open(QIODevice::ReadOnly) )
		return false;
	
	// loading settings file into memory
	if( false == _domDocument.setContent(&configurationFile) )
	{
		configurationFile.close();
		return false;
	}
	configurationFile.close();

	// validating the root node
	QDomNode configurator = _domDocument.documentElement();
	if( configurator.isNull() )
		return false;

	if( configurator.nodeName() != c_configuratorNodeName )
		return false;

	if( false == configurator.hasChildNodes() )
		return false;

	// set title text
	QDomNamedNodeMap configuratorAttributes = configurator.attributes();
	setWindowTitle( configuratorAttributes.namedItem(c_attributeTitleText).nodeValue() );	
	
	// validating and adding the sections nodes
	QDomNode section = configurator.firstChild();
	while( false == section.isNull() )
	{
	    if( QDomNode::CommentNode != section.nodeType() )
		if( false == loadSection(section) )
			return false;

		section = section.nextSibling();		
	}

	return true;
}
Example #25
0
void QtSimpleXml::parse(QDomNode node)
{
 //   puts("parse");
    if (node.isNull())
        return;

    valid = true;
    n = node.nodeName();
    QDomElement element = node.toElement();

    QDomNamedNodeMap attrs = element.attributes();
    for (int i = 0; i < (int) attrs.count(); ++i) {
        QDomAttr attribute = attrs.item(i).toAttr();
        attr.insert(attribute.name(), attribute.value());
    }

    if (element.firstChild().isText()) {
  //      printf("Got text %s\n", element.text().stripWhiteSpace().latin1());
        s = element.text().trimmed();
        return;
    }

    if (node.hasChildNodes()) {

        // Skip to first element child
        QDomNode child = node.firstChild();
        while (!child.isNull() && !child.isElement())
            child = child.nextSibling();

        while (!child.isNull()) {
            QtSimpleXml *xmlNode = new QtSimpleXml;
            xmlNode->parse(child);
            children.insert(xmlNode->name(), xmlNode);

            node = node.nextSibling();

            do {
                child = child.nextSibling();
            } while (!child.isNull() && !child.isElement());
        }
    }
}
Example #26
0
void Filter::processNode(const QDomNode &node)
{
    if (node.isNull())
        return;

//    vc_dbg << "Node Name: " << node.nodeName();
//    vc_dbg << "Node type: " << node.nodeType();

    if (node.nodeType() == QDomNode::ElementNode)
        processNodeAttributes(node.toElement());

    if (node.hasChildNodes()) {
        QDomNode firstChild = node.firstChild();
        if (!firstChild.isNull()) {
            if (firstChild.nodeName() == QString("Filter"))
                processFilter(firstChild);
            else if (firstChild.nodeName() == QString("File"))
                processFile(firstChild);
        }
    }
}
Example #27
0
std::string QtXmlWrapper::getparstr(const std::string &name,
                                    const std::string &defaultpar) const
{
    QDomNode tmp = findElement( d->m_node, "string", "name", name.c_str() );
    if( tmp.isNull() || !tmp.hasChildNodes() )
    {
        return defaultpar;
    }

    tmp = tmp.firstChild();
    if( tmp.nodeType() == QDomNode::ElementNode && !tmp.toElement().tagName().isEmpty() )
    {
        return tmp.toElement().tagName().toUtf8().constData();
    }
    if( tmp.nodeType() == QDomNode::TextNode && !tmp.toText().data().isEmpty() )
    {
        return tmp.toText().data().toUtf8().constData();
    }

    return defaultpar;
}
Example #28
0
void XmlConfiguration::SetValue( const QString &sSetting, QString sValue ) 
{
    QDomNode node   = FindNode( sSetting, true );

    if (!node.isNull())
    {
        QDomText textNode;

        if (node.hasChildNodes())
        {
            // -=>TODO: This Always assumes only child is a Text Node... should change
            textNode = node.firstChild().toText();
            textNode.setNodeValue( sValue );
        }
        else
        {
            textNode = m_config.createTextNode( sValue );
            node.appendChild( textNode );
        }
    }
}
Example #29
0
void QtXmlWrapper::getparstr(const std::string &name, char *par, int maxstrlen) const
{
    ZERO(par, maxstrlen);
    QDomNode tmp = findElement( d->m_node, "string", "name", name.c_str() );
    if( tmp.isNull() || !tmp.hasChildNodes() )
    {
        return;
    }

    tmp = tmp.firstChild();
    if( tmp.nodeType() == QDomNode::ElementNode )
    {
        snprintf(par, maxstrlen, "%s", tmp.toElement().tagName().toUtf8().constData() );
        return;
    }
    if( tmp.nodeType() == QDomNode::TextNode )
    {
        snprintf(par, maxstrlen, "%s", tmp.toText().data().toUtf8().constData() );
        return;
    }
}
Example #30
0
void DataFile::cleanMetaNodes( QDomElement _de )
{
	QDomNode node = _de.firstChild();
	while( !node.isNull() )
	{
		if( node.isElement() )
		{
			if( node.toElement().attribute( "metadata" ).toInt() )
			{
				QDomNode ns = node.nextSibling();
				_de.removeChild( node );
				node = ns;
				continue;
			}
			if( node.hasChildNodes() )
			{
				cleanMetaNodes( node.toElement() );
			}
		}
		node = node.nextSibling();
	}
}