Mantid
Loading...
Searching...
No Matches
qt
widgets
common
src
Batch
FindSubtreeRoots.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 +
7
#include "
MantidQtWidgets/Common/Batch/FindSubtreeRoots.h
"
8
#include "
MantidQtWidgets/Common/Batch/Subtree.h
"
9
#include <algorithm>
10
11
namespace
MantidQt::MantidWidgets::Batch
{
12
13
auto
FindSubtreeRoots::operator()
(std::vector<RowLocation> region) -> std::optional<std::vector<RowLocation>> {
14
std::sort(region.begin(), region.end());
15
if
(!region.empty()) {
16
auto
subtreeRootDepth = region[0].depth();
17
if
(
allSubtreeRootsShareAParentAndAllSubtreeNodesAreConnected
(subtreeRootDepth, region.cbegin(), region.cend())) {
18
removeIfDepthNotEqualTo(region, subtreeRootDepth);
19
return
region;
20
}
else
{
21
return
std::nullopt;
22
}
23
}
else
{
24
return
std::vector<RowLocation>();
25
}
26
}
27
28
void
FindSubtreeRoots::removeIfDepthNotEqualTo
(std::vector<RowLocation> ®ion,
int
expectedDepth)
const
{
29
region.erase(std::remove_if(
30
region.begin(), region.end(),
31
[expectedDepth](
RowLocation
const
&location) ->
bool
{ return location.depth() != expectedDepth; }),
32
region.end());
33
}
34
35
}
// namespace MantidQt::MantidWidgets::Batch
FindSubtreeRoots.h
Subtree.h
MantidQt::MantidWidgets::Batch::FindSubtreeRoots::removeIfDepthNotEqualTo
void removeIfDepthNotEqualTo(std::vector< RowLocation > ®ion, int expectedDepth) const
Definition
FindSubtreeRoots.cpp:28
MantidQt::MantidWidgets::Batch::FindSubtreeRoots::operator()
std::optional< std::vector< RowLocation > > operator()(std::vector< RowLocation > region)
Definition
FindSubtreeRoots.cpp:13
MantidQt::MantidWidgets::Batch::RowLocation
Definition
RowLocation.h:22
MantidQt::MantidWidgets::Batch
Definition
BuildSubtreeItems.h:21
MantidQt::MantidWidgets::Batch::allSubtreeRootsShareAParentAndAllSubtreeNodesAreConnected
bool allSubtreeRootsShareAParentAndAllSubtreeNodesAreConnected(int subtreeRootDepth, RowLocationConstIterator sortedRegionBegin, RowLocationConstIterator sortedRegionEnd)
Definition
Subtree.h:60
Generated by
1.9.8