From 91b0c5d05fca06726b5f39b2f2d77de2fbbdef40 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Thu, 7 Dec 2017 14:52:12 +0100 Subject: [PATCH] src: replaced references to NODE_FILE with call to isFile --- .../controller/BookmarkController.cpp | 2 +- .../component/controller/GraphController.cpp | 4 ++-- src/lib/data/NodeTypeSet.cpp | 18 ++++++++++++++++++ src/lib/data/NodeTypeSet.h | 3 +++ src/lib/data/search/SearchMatch.cpp | 2 +- src/lib/data/storage/PersistentStorage.cpp | 12 ++++++------ src/lib/utility/messaging/type/MessageSearch.h | 2 +- src/lib_gui/qt/element/QtHistoryList.cpp | 2 +- src/lib_gui/qt/window/QtMainWindow.cpp | 2 +- 9 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/lib/component/controller/BookmarkController.cpp b/src/lib/component/controller/BookmarkController.cpp index 89592e40..227f55b8 100644 --- a/src/lib/component/controller/BookmarkController.cpp +++ b/src/lib/component/controller/BookmarkController.cpp @@ -503,7 +503,7 @@ std::string BookmarkController::getNodeDisplayName(const Id nodeId) const NodeType type = m_storageAccess->getNodeTypeForNodeWithId(nodeId); NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeId(nodeId); - if (type.getType() == NodeType::NODE_FILE) + if (type.isFile()) { return FilePath(nameHierarchy.getQualifiedName()).fileName(); } diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 79430f19..41597bd3 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -979,7 +979,7 @@ void GraphController::bundleNodes() bundleNodesAndEdgesMatching( [](const DummyNode::BundleInfo& info, const Node* data) { - return data->isType(NodeType::NODE_FILE); + return data->getType().isFile(); }, 1, false, @@ -1009,7 +1009,7 @@ void GraphController::bundleNodes() bundleNodesAndEdgesMatching( [](const DummyNode::BundleInfo& info, const Node* data) { - return info.isDefined && info.isReferenced && data->isType(NodeType::NODE_BUILTIN_TYPE); + return info.isDefined && info.isReferenced && data->getType().isBuiltin(); }, 3, false, diff --git a/src/lib/data/NodeTypeSet.cpp b/src/lib/data/NodeTypeSet.cpp index e1ee2a07..e8ed8e32 100644 --- a/src/lib/data/NodeTypeSet.cpp +++ b/src/lib/data/NodeTypeSet.cpp @@ -79,6 +79,24 @@ NodeTypeSet NodeTypeSet::getWithRemoved(const NodeTypeSet& typeSet) const return ret; } +void NodeTypeSet::removeIf(const std::function condition) +{ + for (const NodeType& type : s_allNodeTypes) + { + if (m_nodeTypeMask & nodeTypeToMask(type) && condition(type)) + { + remove(type); + } + } +} + +NodeTypeSet NodeTypeSet::getWithRemovedIf(const std::function condition) const +{ + NodeTypeSet ret(*this); + ret.removeIf(condition); + return ret; +} + bool NodeTypeSet::isEmpty() const { return m_nodeTypeMask == 0; diff --git a/src/lib/data/NodeTypeSet.h b/src/lib/data/NodeTypeSet.h index 23fda732..41b1b7c3 100644 --- a/src/lib/data/NodeTypeSet.h +++ b/src/lib/data/NodeTypeSet.h @@ -28,6 +28,9 @@ public: void remove(const NodeTypeSet& typeSet); NodeTypeSet getWithRemoved(const NodeTypeSet& typeSet) const; + void removeIf(const std::function condition); + NodeTypeSet getWithRemovedIf(const std::function condition) const; + bool isEmpty() const; bool contains(const NodeType& type) const; bool intersectsWith(const NodeTypeSet& typeSet) const; diff --git a/src/lib/data/search/SearchMatch.cpp b/src/lib/data/search/SearchMatch.cpp index d1d8eb87..9e855566 100644 --- a/src/lib/data/search/SearchMatch.cpp +++ b/src/lib/data/search/SearchMatch.cpp @@ -219,7 +219,7 @@ void SearchMatch::print(std::ostream& ostream) const std::string SearchMatch::getFullName() const { - if (searchType == SEARCH_TOKEN && nodeType.getType() == NodeType::NODE_FILE) + if (searchType == SEARCH_TOKEN && nodeType.isFile()) { return text; } diff --git a/src/lib/data/storage/PersistentStorage.cpp b/src/lib/data/storage/PersistentStorage.cpp index 6faa3836..5472692c 100644 --- a/src/lib/data/storage/PersistentStorage.cpp +++ b/src/lib/data/storage/PersistentStorage.cpp @@ -576,12 +576,12 @@ std::vector PersistentStorage::getAutocompletionMatches(const std:: // create SearchMatches std::vector matches; - if (!acceptedNodeTypes.getWithRemoved(NodeType(NodeType::NODE_FILE)).isEmpty()) + if (!acceptedNodeTypes.getWithRemovedIf([](const NodeType& type) { return type.isFile(); }).isEmpty()) { utility::append(matches, getAutocompletionSymbolMatches(query, acceptedNodeTypes, maxResultsCount, maxBestScoredResultsLength)); } - if (acceptedNodeTypes.contains(NodeType(NodeType::NODE_FILE))) + if (!acceptedNodeTypes.getWithRemovedIf([](const NodeType& type) { return !type.isFile(); }).isEmpty()) { utility::append(matches, getAutocompletionFileMatches(query, maxResultsCount)); } @@ -802,7 +802,7 @@ std::vector PersistentStorage::getSearchMatchesForTokenIds(const st match.delimiter = nameHierarchy.getDelimiter(); - if (match.nodeType.getType() == NodeType::NODE_FILE) + if (match.nodeType.isFile()) { match.text = FilePath(match.text).fileName(); } @@ -1727,7 +1727,7 @@ TooltipInfo PersistentStorage::getTooltipInfoForTokenIds(const std::vector& } } - if (type.getType() == NodeType::NODE_FILE && m_fileNodePaths.find(node.id) != m_fileNodePaths.end()) + if (type.isFile() && m_fileNodePaths.find(node.id) != m_fileNodePaths.end()) { if (!getFileNodeComplete(node.id)) { @@ -2174,7 +2174,7 @@ void PersistentStorage::addNodesToGraph(const std::vector& newNodeIds, Graph for (const StorageNode& storageNode : m_sqliteIndexStorage.getAllByIds(nodeIds)) { const NodeType type(utility::intToType(storageNode.type)); - if (type.getType() == NodeType::NODE_FILE) + if (type.isFile()) { const FilePath filePath(NameHierarchy::deserialize(storageNode.serializedName).getRawName()); @@ -2540,7 +2540,7 @@ void PersistentStorage::buildSearchIndex() for (StorageNode& node : m_sqliteIndexStorage.getAll()) { NodeType type = utility::intToType(node.type); - if (type == NodeType::NODE_FILE) + if (type.isFile()) { auto it = m_fileNodePaths.find(node.id); if (it != m_fileNodePaths.end()) diff --git a/src/lib/utility/messaging/type/MessageSearch.h b/src/lib/utility/messaging/type/MessageSearch.h index a69b149c..ae3db1fe 100644 --- a/src/lib/utility/messaging/type/MessageSearch.h +++ b/src/lib/utility/messaging/type/MessageSearch.h @@ -28,7 +28,7 @@ public: for (size_t i = 0; i < m_matches.size(); i++) { ss << '@'; - if (m_matches[i].nodeType.getType() == NodeType::NODE_FILE) + if (m_matches[i].nodeType.isFile()) { ss << m_matches[i].subtext; } diff --git a/src/lib_gui/qt/element/QtHistoryList.cpp b/src/lib_gui/qt/element/QtHistoryList.cpp index 023b10df..c9d85b70 100644 --- a/src/lib_gui/qt/element/QtHistoryList.cpp +++ b/src/lib_gui/qt/element/QtHistoryList.cpp @@ -22,7 +22,7 @@ QtHistoryItem::QtHistoryItem(const SearchMatch& match, size_t index, bool isCurr layout->setContentsMargins(0, 0, 0, 0); layout->setAlignment(Qt::AlignTop); - std::string name = utility::elide(match.nodeType.getType() == NodeType::NODE_FILE ? match.text : match.name, utility::ELIDE_RIGHT, 100); + std::string name = utility::elide(match.nodeType.isFile() ? match.text : match.name, utility::ELIDE_RIGHT, 100); m_name = new QLabel(name.c_str(), this); m_name->setAttribute(Qt::WA_MacShowFocusRect, 0); diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index 10ad6ef1..66fca4c5 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -879,7 +879,7 @@ void QtMainWindow::setupHistoryMenu() for (size_t i = 0; i < m_history.size(); i++) { SearchMatch& match = m_history[i]; - std::string name = utility::elide(match.nodeType.getType() == NodeType::NODE_FILE ? match.text : match.name, utility::ELIDE_RIGHT, 50); + std::string name = utility::elide(match.nodeType.isFile() ? match.text : match.name, utility::ELIDE_RIGHT, 50); QAction* action = new QAction(); action->setText(name.c_str());