本文整理汇总了C++中BaseNode::from_xml方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseNode::from_xml方法的具体用法?C++ BaseNode::from_xml怎么用?C++ BaseNode::from_xml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseNode
的用法示例。
在下文中一共展示了BaseNode::from_xml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openDocument
/*! Opens specified file. This function does not ask the user to save an
unsaved modified diagram. That is the MainWindow's job. This function
will simply clear out the node vector and load the file in.
*/
void Document::openDocument(QString openName)
{
QDomDocument* xmlDoc = openSaveFile(openName);
QDomElement docElem = getNextDocumentElement(xmlDoc);
QDomElement nodesVectorElement;
QDomElement n;
BaseNode* newNode;
// Clear the nodes vector
nodes.clear();
ordering.clear();
// Get the diagram type
diagramType = static_cast<BaseNode::DiagramType>(docElem.attribute("diagramType").toInt());
// First get out the first (and hopefully only) nodes_vector_element.
nodesVectorElement = docElem.firstChildElement("nodes_vector_element");
// Now we have to iterate over all the Node elements and restor them.
// This style of iteration loop was taken from the Qt documentation for
// QDomElement.
n = nodesVectorElement.firstChildElement("Node");
for (; !n.isNull(); n = n.nextSiblingElement("Node")) {
// Now that we have the QDomElement, try to produce the node
newNode = NodeFactory::getInstance()->produceFromClassName(n.attribute("class_name"));
// Check we failed
if (newNode == 0) {
qDebug() << "Document::openDocument Error: Couldn't produce a " << n.attribute("class_name") << " with the node factory.";
} else {
// Restore the unique id and all the properties
newNode->from_xml(n);
// Push the node onto the node vector
nodes.push_back(newNode);
ordering.push_back(nodes.size()-1);
}
}
// Now that we have all the id's restored, we can restore the connections
// between the nodes. We loop over all the Node elements in
// node_vector_element and loop over all the ConnectedObject elements in
// each Node.
n = nodesVectorElement.firstChildElement("Node");
for (; !n.isNull(); n = n.nextSiblingElement("Node")) {
BaseNode* sourcenode;
QUuid sourceid;
// Find the node that we created earlier from this element
sourceid = QUuid(n.attribute("Id"));
sourcenode = this->findNodeById(sourceid);
if (sourcenode == 0) {
qDebug() << "Document::openDocument Error: Couldn't find source node by id";
} else {
QUuid targetid;
BaseNode* targetnode;
// Now that we have the element and it's associated node, iterate
// over all of the element's children ("ConnectedObjects")
QDomElement child = n.firstChildElement("ConnectedObject");
for (; !child.isNull(); child = child.nextSiblingElement("ConnectedObject")) {
// Find the targeted node by id
targetid = QUuid(child.attribute("id"));
targetnode = this->findNodeById(targetid);
// Check if it failed
if (targetnode == 0) {
qDebug() << "Document::openDocument Error: Couldn't find a target node by id";
} else {
// If it didn't fail, add the connection!
sourcenode->addConnectedNode(targetnode);
}
}
}
}
setFilename(openName);
setModified(false);
update();
}