After reading Nodes and other attributes in the previous section, we read the two items into the group.
`#pragma once #include <QObject> #include "tsfunitem.hpp" class TsfunGroup : public QObject { Q_OBJECT public: TsfunGroup(QObject * parent = Q_NULLPTR); ~TsfunGroup(); TsfunItemList tsfitmlist; QDomDocument xmlFile; void readXML(const QString& filename); private: QString filename; }; `Copy the code
Note that TsfunItemList is the list of tsFunItems defined earlier. The key is the readMXL file:
`#include "tsfungroup.hpp"
#include "debugwidget.hpp"
TsfunGroup::TsfunGroup(QObject * parent) : QObject(parent) {
}
TsfunGroup::~TsfunGroup() {
}`
Copy the code
Let’s put the two irrelevant functions in first, and then the functions:
`void TsfunGroup::readXML(const QString& filename)
{
}`
Copy the code
For the sake of simplicity, let’s explain the procedure paragraph by paragraph:
` DebugWidget *dw = new DebugWidget; QFile file("C:\\Developer\\Rendering\\Rendering\\XML\\transferfunction.xml"); if (! file.open(QIODevice::ReadOnly)) dw->addContents("error 1"); if (! xmlFile.setContent(&file)) { file.close(); dw->addContents("error 2"); } file.close(); // There is information about the first child node like version. QDomNode firstChild = xmlFile.firstChild(); if (firstChild.nodeName() == "xml") { dw->addContents(firstChild.nodeName()); dw->addContents(firstChild.nodeValue()); } else { dw->addContents("No version , No Format"); }dw->addContents(""); `Copy the code
There’s nothing special about this paragraph, it’s been said many times before. The printout looks like this:
The XML version = '1.0' encoding = "utf-8"
Then we read the root element and print:
'// Read the root element <TsfunGroup> QDomElement root = xmlfile.documentElement (); dw->addContents("[" + root.tagName() + "]"); dw->addContents(""); `Copy the code
This has been said many times before, the comprehensive printing effect is as follows:
'XML version='1.0' encoding='UTF-8' [TsfunGroup] QDomNode TsfunItem1 = root.firstChild(); //dw->addContents(TsfunItem1.toElement().tagName()); while (! TsfunItem1.isNull()) { dw->addContents(TsfunItem1.toElement().tagName()+" "+ TsfunItem1.toElement().attribute("Name")); TsfunItem tsfunitemdata; tsfunitemdata.readTsfunItem(TsfunItem1.childNodes()); tsfitmlist.append(tsfunitemdata); dw->addContents(QString::number(tsfunitemdata.returnNumOfNodes())); TsfunItem1 = TsfunItem1.nextSiblingElement(); } `Copy the code
The loop is the same as before, except that readTsfunItem(tsFunItem1.childNodes ()) is used directly inside the loop. , it reads the data in TsfunItem1, then TsfunItem1 iterates over to the next TsfunItem, and then reads it out. The printing effect is as follows:
'XML version='1.0' Encoding ='UTF-8' [TsfunGroup] TsfunItem normalMode 6 TsfunItem maxMode 6Copy the code
The statement does read the six elements, but we’ll have to find a way to test them in the output. Since these variables are private, we’ll add some more interfaces, which we’ll leave to the next section.