-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodeiterator.cpp
More file actions
44 lines (40 loc) · 1.18 KB
/
Copy pathnodeiterator.cpp
File metadata and controls
44 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "nodeiterator.h"
NodeIterator::NodeIterator()
{
}
NodeIterator::NodeIterator(QDomNode root)
{
this->root = root;
current = root;
}
bool NodeIterator::hasNext(){
if (!root.isNull()) {
//是否当前节点有子节点
if (!current.isNull() && current.hasChildNodes()) {
//将第一个子节点变成当前节点
current = current.firstChildElement();
isHasNext = true;
} else if (!current.isNull()&& !current.nextSiblingElement().isNull()) {
current = current.nextSiblingElement();
isHasNext = true;
} else if (!current.isNull()) {
while (!current.isNull() && current != root && current.nextSiblingElement().isNull()) {
current = current.parentNode();
}
if (!current.isNull() && current != root) {
current = current.nextSiblingElement();
isHasNext = true;
} else {
isHasNext = false;
}
} else {
isHasNext = false;
}
} else {
isHasNext = false;
}
return isHasNext;
}
QDomNode NodeIterator::next() {
return current;
}