Now it’s time to implement the delete function. The method of deletion is: given the number of nodes in the index (for example, index 2), we delete the third node (0, 1, 2).

Combined with the procedure in the previous chapter:

`TsfunGroup tg; tg.readXML("ss"); //tg.showXML(); NodeTS NTS (0.01923, 0.1023, QColor (123,32,67)); tg.addNodeToItem("maxMode",nts); tg.deleteNodeInItem("maxMode", 3); tg.deleteNodeInItem("maxMode", 5); tg.writeXML(); `Copy the code

A node is added, then a node is removed, and output to a file.

The NodeTS class is no longer required to delete a node, so we’ll create a new function inside the tsfunItem class:

`void TsfunItem::deleteNode(int i) { if(i>=0&&i<= TsNodes.count()) TsNodes.removeAt(i); } `Copy the code

Simply remove the element of the response coordinate from the list object.

Then to the tsfunGroup class:

`void TsfunGroup::deleteNodeInItem(QString itemName, int index) { for (int i = 0; i < tsfitmlist.count(); i++) { if (itemName == tsfitmlist[i].returnNameID()) { tsfitmlist[i].deleteNode(index); `}}}Copy the code

Similar to inserting the node before, first find the corresponding target, and then delete the node.

The effect after deletion is as follows:

'<Nodes> <Node> <NormalizedIntensity Value="0.01923"/> <Opacity Value="0.1023"/> <Emission ="123" B="67" G="32"/> </Node> <Node> <NormalizedIntensity Value="0"/> <Opacity Value="0"/> <Emission R="0" B="0" G="0"/> </Node> <Node> <NormalizedIntensity Value="0.13597"/> <Opacity Value="0"/> <Emission R="0" B="0" G="0"/> </Node> <Node> <NormalizedIntensity Value="0.288578"/> <Opacity Value="0.363502"/> <Emission R="0" B="0" G="0"/> </Node> <Node> <NormalizedIntensity Value="0.45417"/> <Opacity Value="1"/> <Emission R="0" B="0" G="0"/> </Node> </Nodes> 'Copy the code

One element is added, two are removed, and five are left.

Note that we add and delete nodes for our own data structures, rather than for the object created by QDomdocument. The advantage of this is that XML classes and data classes can be separated. We only need to operate on the data, and do not care about the structure of XML-related classes.

In the next section, we’re going to take advantage of all of this and implement an application.