Beispiel #1
0
QDomNode QDomNodeProto:: removeChild(const QDomNode& oldChild)
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->removeChild(oldChild);
  return QDomNode();
}
/*
  Remove a file from the project file.
  Don't delete the file.
*/
bool ProjectManager::removeFromProjectFile(QString projectPath, QString filePath)
{
  bool retval = false;
  QDomDocument doc;
  QDir dir(projectPath);
  QFile projectFile(dir.filePath(dir.dirName() + ".xml"));
  if(doc.setContent(&projectFile))
  {
    projectFile.close();
    QDomNodeList files = doc.elementsByTagName("files").at(0).childNodes();
    for(int i = 0; i < files.count(); i++)
    {
      if(files.at(i).toElement().text() == dir.relativeFilePath(filePath))
      {
        QDomNode parent = files.at(i).parentNode();
        parent.removeChild(files.at(i));
        if(projectFile.open(QIODevice::WriteOnly|QFile::Text))
        {
          projectFile.write(doc.toByteArray(2));
          retval = true;
        }
      }
    }
  }
  return retval;
}
Beispiel #3
0
void BookmarkWidget::deleteItemPermanently(const QString xmlPath, QTreeWidgetItem* item)
{
    if(!item) {
        QList<QTreeWidgetItem*> list = bTreeWidget->selectedItems();
        if(list.isEmpty()) return;
        item = list.at(0);
        if(!item) return;
    }
    // DT: don't move this!
    QString uuid = item->text(UUID_COLUMN);

    QDomDocument doc;
    QDomElement elt = findElementbyUUID(doc, uuid, BOOKMARK, xmlPath);

    QList<QTreeWidgetItem *> items = bTreeWidget->findItems(uuid, Qt::MatchExactly, UUID_COLUMN);
    item = items.at(0);
    delete item;

    if(elt.isNull()) return;

    QDomNode parent = elt.parentNode();
    parent.removeChild(elt);
    saveDOMToFile(doc, xmlPath);
    //refreshBookmarkList();
}
void
PolicyDocumentClass::delTransitionsTo(const QString& name)
{
    QDomElement docElem = document_->documentElement();

    // for all actionPatterns ... //
    QDomNode patternNode = docElem.firstChild();
    while(!patternNode.isNull()) {

        // for all children (behaviours, transitions, arbiters) ... //
        QDomNode node = patternNode.firstChild();
        while(!node.isNull()) {

            // if tagName == "transition" -> check target //
            if (node.toElement().tagName() == XML_TAG_TRANSITION) {

                QDomElement element = node.toElement();
                // if target == pattern name -> delete transition //
                if (element.attribute("target") == name) {
                    patternNode.removeChild(node);
                    node = patternNode.firstChild();	// TODO: improve!
                    modified_ = true;
                }
            }

            // TODO: check if this does the right thing when a node is deleted!
            node = node.nextSibling();
        }

        patternNode = patternNode.nextSibling();
    }
}
Beispiel #5
0
bool arnConfig::modifykey(const char *key, const char *newvalue)
{
    QString nodeKey (key);
    QDomNode out;
    
    if (doc->nodeName() == key) {
	doc->setNodeValue (QString(newvalue));
	return true;
    } 

    if (!(out = _findkeyonchildren (*doc, key)).isNull()) {
	out.removeChild (out.firstChild());
	out.appendChild (doc->createTextNode (newvalue));

	return true;
    }

    return false;

/*
    xmlNodePtr rn = xmlDocGetRootElement(doc);
    xmlNodePtr out;
    if ((!xmlStrcmp(rn->name,(const xmlChar*)key))) {
        xmlNodeSetContent(rn,(const xmlChar*)newvalue);
        return true;
        }
    if ((out = _findkeyonchildren(rn,key))) {
        xmlNodeSetContent(out,(const xmlChar*)newvalue);
        return true;
        }
    return false;
*/
}
void projectviewer::setprojContent(QFile* input)
{
	QString err_msg; int err_line; int err_column;
	doc.clear();
	clear();
	bool set_cont = doc.setContent(input, &err_msg, &err_line, &err_column);
	if (!set_cont)
	{
		emit(errorOpeningFile(qPrintable(err_msg), err_line, err_column));
		return;
	}

	QStandardItem *parentItem = invisibleRootItem();
	addNode(&doc.firstChild().firstChild().firstChild(), parentItem);
	
// -------- add cwd entry if necessary
	char dummy[300];
	if (setXMLEntry(&doc, "workingDirectory", dummy))
	{
		QDomNode currentItem = doc.elementsByTagName("workingDirectory").item(0);
		QDomNode parrent = currentItem.parentNode();
		parrent.removeChild(currentItem);
	}
		QDomElement newelement = doc.createElement("workingDirectory");
		QDomText newnodetext = doc.createTextNode(QDir::current().absolutePath());
		newelement.appendChild(newnodetext);
		doc.firstChild().firstChild().appendChild(newelement);

// ----------

}
void QgsObjectCustomProperties::writeXml( QDomNode& parentNode, QDomDocument& doc ) const
{
  //remove already existing <customproperties> tags
  QDomNodeList propertyList = parentNode.toElement().elementsByTagName( "customproperties" );
  for ( int i = 0; i < propertyList.size(); ++i )
  {
    parentNode.removeChild( propertyList.at( i ) );
  }

  QDomElement propsElement = doc.createElement( "customproperties" );

  for ( QMap<QString, QVariant>::const_iterator it = mMap.constBegin(); it != mMap.constEnd(); ++it )
  {
    QDomElement propElement = doc.createElement( "property" );
    propElement.setAttribute( "key", it.key() );
    if ( it.value().canConvert<QString>() )
    {
      propElement.setAttribute( "value", it.value().toString() );
    }
    else if ( it.value().canConvert<QStringList>() )
    {
      Q_FOREACH ( const QString& value, it.value().toStringList() )
      {
        QDomElement itemElement = doc.createElement( "value" );
        itemElement.appendChild( doc.createTextNode( value ) );
        propElement.appendChild( itemElement );
      }
    }
    propsElement.appendChild( propElement );
  }
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));
}
Beispiel #9
0
void MainWindow::deleteSelectedNode()
{
    if(modelIsSet && currentIndex.isValid())
    {
        QDomNode parent = currentDocument->elementsByTagName(model->itemFromIndex(treeView->currentIndex().sibling(treeView->currentIndex().row(), 0))->parent()->text()).at(0);
        parent.removeChild(parent.childNodes().item(treeView->currentIndex().row()));        
        updateTree();
    }
}
void XMLWriter::clearNodeContents(QDomNode& p_node)
{
    while( p_node.hasChildNodes() )
    {
        QDomNode node = p_node.childNodes().at(0);
        p_node.removeChild(node);
        node.clear();
    }
}
Beispiel #11
0
void Xml::removeChildNodes(QDomNode &node) {
    QDomNode child = node.firstChild();

    while(!child.isNull()) {
        QDomNode temp = child;
        child = child.nextSibling();
        node.removeChild(temp);
    }
}
Beispiel #12
0
bool KOfficePlugin::writeInfo( const KFileMetaInfo& info) const
{
  bool no_errors = true;
  QDomDocument doc = getMetaDocument(info.path());
  QDomElement base = getBaseNode(doc).toElement();
  if (base.isNull())
    return false;
  for (int i = 0; Information[i]; i+=2)
    no_errors = no_errors &&
      writeTextNode(doc, base, Information[i],
		    info[DocumentInfo][Information[i]].value().toString());
  // If we need a meta:keywords container, we create it.
  if (base.namedItem(metakeywords).isNull())
    base.appendChild(doc.createElement(metakeywords));
  QDomNode metaKeyNode = base.namedItem(metakeywords);

  QDomNodeList childs = doc.elementsByTagName(metakeyword);
  for (int i = childs.length(); i >= 0; --i){
	  metaKeyNode.removeChild( childs.item(i) );
  }
  QStringList keywordList = QStringList::split(",", info[DocumentInfo][metakeyword].value().toString().stripWhiteSpace(), false);
  for ( QStringList::Iterator it = keywordList.begin(); it != keywordList.end(); ++it ) {
	QDomElement elem = doc.createElement(metakeyword);
	metaKeyNode.appendChild(elem);
	elem.appendChild(doc.createTextNode((*it).stripWhiteSpace()));
    }

  // Now, we store the user-defined data
  QDomNodeList theElements = base.elementsByTagName(metauserdef);
  for (uint i = 0; i < theElements.length(); i++)
    {
      QDomElement el = theElements.item(i).toElement();
      if (el.isNull()){
	kdDebug(7034) << metauserdef << " is not an Element" << endl;
	no_errors = false;
      }

      QString s = info[UserDefined][el.attribute(metaname)].value().toString();
      if (s != el.text()){
	QDomText txt = doc.createTextNode(s);
	if (!el.firstChild().isNull())
	  el.replaceChild(txt, el.firstChild());
	else
	  el.appendChild(txt);
      }
    }

  if (!no_errors){
    kdDebug(7034) << "Errors were found while building " << metafile
	     	  << " for file " << info.path() << endl;
    // It is safer to avoid to manipulate meta.xml if errors, we abort.
    return false;
  }
  writeMetaData(info.path(), doc);
  return true;
}
// deletes a given behaviour //
void PolicyDocumentClass::delBehaviour(const QString& patternName, 
				       const QString& behaviourName)
{
  // get DOM node of the given pattern and behaviour //
  QDomNode patternNode   = getPatternNode(patternName);
  QDomNode behaviourNode = getBehaviourNode(patternName, behaviourName);
  
  // remove DOM node //
  patternNode.removeChild(behaviourNode);
}
void CustomMakeConfigWidget::envRemoved()
{
    QString env = envs_combo->currentText();
    QDomNode node = DomUtil::elementByPath(m_dom, m_configGroup + "/make/environments");
    node.removeChild(node.namedItem(env));
    m_allEnvironments.remove(env);
    envs_combo->clear();
    envs_combo->insertStringList(m_allEnvironments);
    m_currentEnvironment = QString::null;
    envChanged( m_allEnvironments[0] );
}
Beispiel #15
0
void NewstuffModelPrivate::changeNode( QDomNode &node, QDomDocument &domDocument, const QString &key, const QString &value, NodeAction action )
{
    if ( action == Append ) {
        QDomNode newNode = node.appendChild( domDocument.createElement( key ) );
        newNode.appendChild( domDocument.createTextNode( value ) );
    } else {
        QDomNode oldNode = node.namedItem( key );
        if ( !oldNode.isNull() ) {
            oldNode.removeChild( oldNode.firstChild() );
            oldNode.appendChild( domDocument.createTextNode( value ) );
        }
    }
}
Beispiel #16
0
QDomNode arnConfig::addTextNode (QDomNode &node, const QString &tag, const QString &value)
{
    QDomElement element = doc->createElement (tag);
    QDomText text = doc->createTextNode (value);

//    element.setTagName (tag);
//    text.setData (value);

    element.appendChild (text);
    node.removeChild (node.firstChild());
    node.appendChild (element);

    return element;
}
Beispiel #17
0
void
vleSmDT::rmInitialValue(const QString& varName)
{
    QDomNode var = nodeVariable(varName);
    if (var.isNull()) {
        return;
    }
    QDomNodeList initList = var.toElement().elementsByTagName("initial_value");
    if (initList.length() == 0) {
        return;
    }
    undoStackSm->snapshot(var);
    var.removeChild(initList.at(0));
    return ;
}
Beispiel #18
0
void XMLProc::remove(xmlItem context)
{
    long id;
    xmlItem child;

    QDomNode own = context.parentNode();
    if (!own.isNull()) {
        id = attr( context, mda_id ).toLong();
        child = firstChild(context);
        remove(child);
        idcache.remove( id );
        own.removeChild(context);
        SetModify(true);
    }
}
Beispiel #19
0
void XmlConfiguration::ClearValue( const QString &sSetting )
{
    QDomNode node = FindNode(sSetting);
    if (!node.isNull())
    {
        QDomNode parent = node.parentNode();
        parent.removeChild(node);
        while (parent.childNodes().count() == 0)
        {
            QDomNode next_parent = parent.parentNode();
            next_parent.removeChild(parent);
            parent = next_parent;
        }
    }
}
	void removeNamedElementsRecursive (const QStringList &names, QDomNode &parent) {
		QDomNode nchild;

		for (QDomNode child = parent.firstChild (); !child.isNull (); child = nchild) {
			removeNamedElementsRecursive (names, child);

			nchild = child.nextSibling ();		// need to fetch next sibling here, as we might remove the child below
			if (child.isElement ()) {
				QDomElement e = child.toElement ();
				if (names.contains (e.attribute ("name"))) {
					parent.removeChild (child);
				}
			}
		}
	}
void XbelTree::keyPressEvent ( QKeyEvent * event )
{
    QTreeWidget::keyPressEvent(event);
    if( !this->selectedItems().isEmpty() ) {
        if(event->key() == Qt::Key_Delete) {
            QList<QTreeWidgetItem*> list = this->selectedItems();
            for (int i = 0; i < list.size(); ++i) {
                if( !domElementForItem[list.at(i)].attribute("device").isNull() ) {
                    QDomNode parent = domElementForItem[list.at(i)].parentNode();
                    parent.removeChild(domElementForItem[list.at(i)]);
                    RenumDevices();
                    Reset();
                    return;
                }
            }
        }
    }
}
Beispiel #22
0
bool XmlHelper::RemoveNodeChild(const QString &node_tag)
{
    QDomNodeList node_list = doc_.elementsByTagName(node_tag);
    if (node_list.count() > 0)
    {
        QDomNode parent = node_list.at(0);

        QDomNodeList childs = parent.childNodes();
        for (int i = childs.count() - 1; i >= 0; i--)
        {
            parent.removeChild(childs.at(i));
        }

        return true;
    }

    return false;
}
Beispiel #23
0
/**
 * Removes all QDomComment objects from the specified node and all its children.
 */
static void removeDOMComments( QDomNode &node )
{
    QDomNode n = node.firstChild();
    while ( !n.isNull() )
    {
        if ( n.nodeType() == QDomNode::CommentNode )
        {
            QDomNode tmp = n;
            n = n.nextSibling();
            node.removeChild( tmp );
        }
        else
        {
            QDomNode tmp = n;
            n = n.nextSibling();
            removeDOMComments( tmp );
        }
    }
}
void PolicyDocumentClass::delArbiter(const QString& patternName)
{
  // COMMENT: this removes ALL arbiters (although only one should be set!)

  // get DOM node of the given pattern //
  QDomNode patternNode = getPatternNode(patternName);

  // check for each child: if it is an arbiter //
  QDomNode node = patternNode.firstChild();
  while(!node.isNull()) {

    // if tagName == "arbiter" -> remove node //
    if (node.toElement().tagName() == XML_TAG_ARBITER) {
      patternNode.removeChild(node);
      node = patternNode.firstChild();  // TODO: improve
    }

    node = node.nextSibling();
  }
}
Beispiel #25
0
void QgsMapLayer::writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const
{
  //remove already existing <customproperties> tags
  QDomNodeList propertyList = layerNode.toElement().elementsByTagName( "customproperties" );
  for ( int i = 0; i < propertyList.size(); ++i )
  {
    layerNode.removeChild( propertyList.at( i ) );
  }

  QDomElement propsElement = doc.createElement( "customproperties" );

  for ( QMap<QString, QVariant>::const_iterator it = mCustomProperties.constBegin(); it != mCustomProperties.constEnd(); ++it )
  {
    QDomElement propElement = doc.createElement( "property" );
    propElement.setAttribute( "key", it.key() );
    propElement.setAttribute( "value", it.value().toString() );
    propsElement.appendChild( propElement );
  }

  layerNode.appendChild( propsElement );
}
// deletes all parameters of the given behaviour in the given pattern //
void PolicyDocumentClass::delParameters(const QString& patternName, 
					const QString& behaviourName)
{
  // get DOM node of the given behaviour //
  QDomNode behaviourNode = getBehaviourNode(patternName, behaviourName);

  // check for each child: if it is a parameter //
  QDomNode node = behaviourNode.firstChild();
  while(!node.isNull()) {

    // if tagName == "parameter" -> remove node //
    if (node.toElement().tagName() == XML_TAG_PARAMETER) {

      behaviourNode.removeChild(node);
      node = behaviourNode.firstChild();  // TODO: improve
      continue;
    }

    node = node.nextSibling();
  }
}
Beispiel #27
0
/*
  Remove the file in the current project's project file.
  The file has already been removed from the filebrowser UI.
*/
void ProjectInfo::onRemoveFileRequest(QString filename)
{
  QFile projectFile(projectFilePath( ));
  QDomDocument doc;
  if(doc.setContent(&projectFile))
  {
    projectFile.close();
    QDomNodeList files = doc.elementsByTagName("files").at(0).childNodes();
    for(int i = 0; i < files.count(); i++)
    {
      if(files.at(i).toElement().text() == filename)
      {
        QDomNode parent = files.at(i).parentNode();
        parent.removeChild(files.at(i));
        if(projectFile.open(QIODevice::WriteOnly|QFile::Text))
          projectFile.write(doc.toByteArray());
        mainWindow->removeFileFromProject(filename);
        return;
      }
    }
  }
}
void 
ItemXML::deleteItem()
{
  // schedule for deletion
  // this will also remove the listviewitem
  deleteLater();

  // remove this node at the parent node
  // as this is not taken care of in
  // the dtor of this class
  QDomNode n = node_.parentNode();
  MIRO_ASSERT(!n.isNull());
  n.removeChild(node_);

  // tell the parent, that he is modified
  // as he will not be able to ask us about it anymore
  ItemXML * p = 
    dynamic_cast<ItemXML *>(parent());
  if (p != NULL) {
    p->setModified();
  }
}
void QgsObjectCustomProperties::writeXml( QDomNode &parentNode, QDomDocument &doc ) const
{
  //remove already existing <customproperties> tags
  QDomNodeList propertyList = parentNode.toElement().elementsByTagName( QStringLiteral( "customproperties" ) );
  for ( int i = 0; i < propertyList.size(); ++i )
  {
    parentNode.removeChild( propertyList.at( i ) );
  }

  QDomElement propsElement = doc.createElement( QStringLiteral( "customproperties" ) );

  auto keys = mMap.keys();

  std::sort( keys.begin(), keys.end() );

  for ( const auto &key : qgis::as_const( keys ) )
  {
    QDomElement propElement = doc.createElement( QStringLiteral( "property" ) );
    propElement.setAttribute( QStringLiteral( "key" ), key );
    const QVariant value = mMap.value( key );
    if ( value.canConvert<QString>() )
    {
      propElement.setAttribute( QStringLiteral( "value" ), value.toString() );
    }
    else if ( value.canConvert<QStringList>() )
    {
      const auto constToStringList = value.toStringList();
      for ( const QString &value : constToStringList )
      {
        QDomElement itemElement = doc.createElement( QStringLiteral( "value" ) );
        itemElement.appendChild( doc.createTextNode( value ) );
        propElement.appendChild( itemElement );
      }
    }
    propsElement.appendChild( propElement );
  }

  parentNode.appendChild( propsElement );
}
// function that parses an XML DOM for 'xs:include' directives and loads
// and inserts the mentioned documents into it
void
load(QDomNode n) {
    while (!n.isNull()) {
        if (n.hasChildNodes()) {
            load(n.firstChild());
        }
        if (n.nodeName() == "xs:include") {
            QString f = n.toElement().attribute("schemaLocation");
            QDomDocument d = loadDocument(dir+"/"+f);
            QDomDocument o = n.ownerDocument();
            QDomNode newn = o.importNode(d.documentElement(), true);
            QDomNode p = n.parentNode();
            QDomNode old = n;
            n = n.nextSibling();
            p.removeChild(old);
            while (!newn.firstChild().isNull()) {
                p.insertBefore(newn.firstChild(), n);
            }
        } else {
            n = n.nextSibling();
        }
    }
}