Mantid
Loading...
Searching...
No Matches
BuildSubtreeItems.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
10
12 RowLocationAdapter const &rowLocationAdapter)
13 : m_adaptedMainModel(adaptedModel), m_rowLocations(rowLocationAdapter) {}
14
15auto BuildSubtreeItems::buildRecursively(int insertionIndex, RowLocation const &parent, SubtreeConstIterator current,
17 auto lastRowInsertedAtThisDepth = QModelIndexForMainModel();
18 auto const insertionDepth = (*current).location().depth();
19 while (current != end) {
20 auto currentRow = (*current).location();
21 auto currentDepth = currentRow.depth();
22 // `currentDepth` tracks the depth of the currentRow whearas
23 // `insertionDepth` tracks
24 // the depth of the locations this recursive call will insert at.
25
26 if (insertionDepth < currentDepth) {
27 current = buildRecursively(currentRow.rowRelativeToParent(), parent.child(lastRowInsertedAtThisDepth.row()),
28 current, end);
29 } else if (insertionDepth > currentDepth) {
30 return current;
31 } else {
32 lastRowInsertedAtThisDepth =
33 m_adaptedMainModel.insertChildRow(modelIndexAt(parent), insertionIndex, (*current).cells());
34 ++insertionIndex;
35 ++current;
36 }
37 }
38 return end;
39}
40
41void BuildSubtreeItems::operator()(RowLocation const &parentOfSubtreeRoot, int firstInsertionIndex,
42 Subtree const &subtree) {
43 if (!subtree.empty()) {
44 buildRecursively(firstInsertionIndex, parentOfSubtreeRoot, subtree.cbegin(), subtree.cend());
45 }
46}
47
49 return m_rowLocations.indexAt(parent);
50}
51} // namespace MantidQt::MantidWidgets::Batch
QModelIndexForMainModel modelIndexAt(RowLocation const &parent) const
SubtreeConstIterator buildRecursively(int index, RowLocation const &parent, SubtreeConstIterator current, SubtreeConstIterator end)
void operator()(RowLocation const &parentOfSubtreeRoot, int index, Subtree const &subtree)
typename Subtree::const_iterator SubtreeConstIterator
BuildSubtreeItems(QtStandardItemTreeModelAdapter &adaptedModel, RowLocationAdapter const &rowLocationAdapter)
QModelIndexForMainModel indexAt(RowLocation const &location, int column=0) const
std::vector< Row > Subtree
Definition: Subtree.h:18