コード例 #1
0
QDomNode QDomNodeProto:: removeChild(const QDomNode& oldChild)
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->removeChild(oldChild);
  return QDomNode();
}
コード例 #2
0
/*
  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;
}
コード例 #3
0
ファイル: bookmarkWidget.cpp プロジェクト: WeiqiJust/CHER-Ob
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();
}
コード例 #4
0
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();
    }
}
コード例 #5
0
ファイル: arnConfig.cpp プロジェクト: fanakin/arnlib
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;
*/
}
コード例 #6
0
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);

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

}
コード例 #7
0
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 );
  }
コード例 #8
0
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));
}
コード例 #9
0
ファイル: mainwindow.cpp プロジェクト: lomsansnom/IHM_OFELI
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();
    }
}
コード例 #10
0
void XMLWriter::clearNodeContents(QDomNode& p_node)
{
    while( p_node.hasChildNodes() )
    {
        QDomNode node = p_node.childNodes().at(0);
        p_node.removeChild(node);
        node.clear();
    }
}
コード例 #11
0
ファイル: xml.cpp プロジェクト: falbrechtskirchinger/yadu
void Xml::removeChildNodes(QDomNode &node) {
    QDomNode child = node.firstChild();

    while(!child.isNull()) {
        QDomNode temp = child;
        child = child.nextSibling();
        node.removeChild(temp);
    }
}
コード例 #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;
}
コード例 #13
0
// 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);
}
コード例 #14
0
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] );
}
コード例 #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 ) );
        }
    }
}
コード例 #16
0
ファイル: arnConfig.cpp プロジェクト: fanakin/arnlib
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;
}
コード例 #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 ;
}
コード例 #18
0
ファイル: xmlproc.cpp プロジェクト: sergey4475/SProject
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);
    }
}
コード例 #19
0
ファイル: configuration.cpp プロジェクト: jhludwig/mythtv
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;
        }
    }
}
コード例 #20
0
	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);
				}
			}
		}
	}
コード例 #21
0
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;
                }
            }
        }
    }
}
コード例 #22
0
ファイル: xmlhelper.cpp プロジェクト: liye0005/QT_POJ
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;
}
コード例 #23
0
ファイル: kxmlguifactory.cpp プロジェクト: vasi/kdelibs
/**
 * 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 );
        }
    }
}
コード例 #24
0
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();
  }
}
コード例 #25
0
ファイル: qgsmaplayer.cpp プロジェクト: FlavioFalcao/QGIS
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 );
}
コード例 #26
0
// 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();
  }
}
コード例 #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;
      }
    }
  }
}
コード例 #28
0
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();
  }
}
コード例 #29
0
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 );
}
コード例 #30
0
// 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();
        }
    }
}