Skip to content

Commit

Permalink
3523: Replace CountHiddenNodesVisitor with lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
kduske committed Nov 4, 2020
1 parent 4c6fba4 commit 88129f6
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions common/src/View/MapFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "View/QtUtils.h"
#include "View/MapViewToolBox.h"

#include <kdl/overload.h>
#include <kdl/string_format.h>
#include <kdl/string_utils.h>

Expand Down Expand Up @@ -546,49 +547,45 @@ namespace TrenchBroom {
}

// count hidden objects
class CountHiddenNodesVisitor : public Model::ConstNodeVisitor {
private:
const Model::EditorContext& m_editorContext;
public:
size_t hiddenGroups = 0u;
size_t hiddenBrushes = 0u;
size_t hiddenEntities = 0u;
public:
explicit CountHiddenNodesVisitor(const Model::EditorContext& editorContext) : m_editorContext(editorContext) {}
private:
void doVisit(const Model::WorldNode*) override {}
void doVisit(const Model::LayerNode*) override {}
void doVisit(const Model::GroupNode* group) override {
if (!m_editorContext.visible(group)) {
size_t hiddenGroups = 0u;
size_t hiddenEntities = 0u;
size_t hiddenBrushes = 0u;

const auto& editorContext = document->editorContext();
document->world()->acceptLambda(kdl::overload(
[](auto&& thisLambda, const Model::WorldNode* world) { world->visitChildren(thisLambda); },
[](auto&& thisLambda, const Model::LayerNode* layer) { layer->visitChildren(thisLambda); },
[&](auto&& thisLambda, const Model::GroupNode* group) {
if (!editorContext.visible(group)) {
++hiddenGroups;
}
}
void doVisit(const Model::EntityNode* entity) override {
if (!m_editorContext.visible(entity)) {
group->visitChildren(thisLambda);
},
[&](auto&& thisLambda, const Model::EntityNode* entity) {
if (!editorContext.visible(entity)) {
++hiddenEntities;
}
}
void doVisit(const Model::BrushNode* brush) override {
if (!m_editorContext.visible(brush)) {
entity->visitChildren(thisLambda);
},
[&](const Model::BrushNode* brush) {
if (!editorContext.visible(brush)) {
++hiddenBrushes;
}
}
};
auto visitor = CountHiddenNodesVisitor(document->editorContext());
document->world()->acceptAndRecurse(visitor);
}
));

// print hidden objects
if (visitor.hiddenGroups > 0 || visitor.hiddenEntities > 0 || visitor.hiddenBrushes > 0) {
if (hiddenGroups > 0 || hiddenEntities > 0 || hiddenBrushes > 0) {
std::vector<std::string> hiddenDescriptors;

if (visitor.hiddenGroups > 0) {
hiddenDescriptors.push_back(numberWithSuffix(visitor.hiddenGroups, "group", "groups"));
if (hiddenGroups > 0) {
hiddenDescriptors.push_back(numberWithSuffix(hiddenGroups, "group", "groups"));
}
if (visitor.hiddenEntities > 0) {
hiddenDescriptors.push_back(numberWithSuffix(visitor.hiddenEntities, "entity", "entities"));
if (hiddenEntities > 0) {
hiddenDescriptors.push_back(numberWithSuffix(hiddenEntities, "entity", "entities"));
}
if (visitor.hiddenBrushes > 0) {
hiddenDescriptors.push_back(numberWithSuffix(visitor.hiddenBrushes, "brush", "brushes"));
if (hiddenBrushes > 0) {
hiddenDescriptors.push_back(numberWithSuffix(hiddenBrushes, "brush", "brushes"));
}

pipeSeparatedSections << QObject::tr("%1 hidden")
Expand Down

0 comments on commit 88129f6

Please sign in to comment.