Newer
Older
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
45
46
#include "MantidQtWidgets/Common/Batch/BuildSubtree.h"
#include <tuple>
namespace MantidQt {
namespace MantidWidgets {
namespace Batch {
BuildSubtree::BuildSubtree(QtStandardItemMutableTreeAdapter const &adaptedModel)
: m_adaptedModel(adaptedModel) {}
void BuildSubtree::operator()(QStandardItem *parentOfSubtreeRootItem,
RowLocation const &parentOfSubtreeRoot, int index,
Subtree const &subtree) {
if (!subtree.empty())
buildRecursively(parentOfSubtreeRootItem, index, parentOfSubtreeRoot, 0,
subtree.cbegin(), subtree.cend());
}
auto BuildSubtree::buildRecursively(QStandardItem *parentItem, int index,
RowLocation const &parent, int depth,
SubtreeConstIterator current,
SubtreeConstIterator end) -> SubtreeConstIterator {
parentItem->insertRow(index,
m_adaptedModel.rowFromRowText((*current).cells()));
++current;
while (current != end) {
auto currentRow = (*current).location();
auto currentDepth = currentRow.depth();
if (depth < currentDepth) {
current = buildRecursively(parentItem->child(index),
currentRow.rowRelativeToParent(),
parent.child(currentRow.rowRelativeToParent()),
depth + 1, current, end);
} else if (depth > currentDepth) {
return current;
} else {
parentItem->appendRow(m_adaptedModel.rowFromRowText((*current).cells()));
++current;
}
}
return end;
}
} // namespace Batch
} // namespace MantidWidgets
} // namespace MantidQt