From ca9dfe7f75147fc1b14533a008e34390d493398b Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Mon, 9 Mar 2015 14:07:58 +0100 Subject: [PATCH] ui: improved file nodes * added colors for file nodes and dependency edges * use TokenComponentFilePath on file nodes to store FilePath --- bin/app/data/ApplicationSettings_template.xml | 5 ++- src/app/qt/utility/QtGraphPostprocessor.cpp | 2 +- src/app/qt/view/graphElements/QtGraphEdge.cpp | 3 ++ src/app/qt/view/graphElements/QtGraphNode.cpp | 24 ++----------- src/lib/CMakeLists.txt | 2 ++ src/lib/Project.cpp | 7 ++++ src/lib/data/Storage.cpp | 34 +++++++++++++++---- src/lib/data/Storage.h | 2 ++ src/lib/data/graph/FilterableGraph.cpp | 9 +---- src/lib/data/graph/Node.cpp | 26 +++++++++----- src/lib/data/graph/Node.h | 2 ++ .../TokenComponentFilePath.cpp | 20 +++++++++++ .../token_component/TokenComponentFilePath.h | 23 +++++++++++++ src/lib/utility/file/FileManager.h | 1 + src/lib/utility/file/FilePath.cpp | 2 +- 15 files changed, 114 insertions(+), 48 deletions(-) create mode 100644 src/lib/data/graph/token_component/TokenComponentFilePath.cpp create mode 100644 src/lib/data/graph/token_component/TokenComponentFilePath.h diff --git a/bin/app/data/ApplicationSettings_template.xml b/bin/app/data/ApplicationSettings_template.xml index 4d2d9329..ee1b72fc 100644 --- a/bin/app/data/ApplicationSettings_template.xml +++ b/bin/app/data/ApplicationSettings_template.xml @@ -99,6 +99,9 @@ #ededed #dddddd - } + + #A3BA8A + #87BA50 + diff --git a/src/app/qt/utility/QtGraphPostprocessor.cpp b/src/app/qt/utility/QtGraphPostprocessor.cpp index af0a01ac..361c9720 100644 --- a/src/app/qt/utility/QtGraphPostprocessor.cpp +++ b/src/app/qt/utility/QtGraphPostprocessor.cpp @@ -1,7 +1,7 @@ #include "QtGraphPostprocessor.h" // remark: maybe those two values could at some point be moved to an external config file (?) -unsigned int QtGraphPostprocessor::s_cellSize = 20; +unsigned int QtGraphPostprocessor::s_cellSize = 5; unsigned int QtGraphPostprocessor::s_cellPadding = 10; void QtGraphPostprocessor::doPostprocessing(std::list>& nodes) diff --git a/src/app/qt/view/graphElements/QtGraphEdge.cpp b/src/app/qt/view/graphElements/QtGraphEdge.cpp index 495fc5b0..0dc22b3c 100644 --- a/src/app/qt/view/graphElements/QtGraphEdge.cpp +++ b/src/app/qt/view/graphElements/QtGraphEdge.cpp @@ -464,6 +464,9 @@ void QtGraphEdge::updateLine() case Edge::EDGE_AGGREGATION: color = QColor("#F8F8F8"); break; + case Edge::EDGE_INCLUDE: + color = QColor("#87BA50"); + break; default: color = QColor("#878787"); break; diff --git a/src/app/qt/view/graphElements/QtGraphNode.cpp b/src/app/qt/view/graphElements/QtGraphNode.cpp index 1948d3b3..936de980 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.cpp +++ b/src/app/qt/view/graphElements/QtGraphNode.cpp @@ -56,12 +56,9 @@ QFont QtGraphNode::getFontForNodeType(Node::NodeType type) break; case Node::NODE_UNDEFINED_FUNCTION: + case Node::NODE_UNDEFINED_VARIABLE: case Node::NODE_FUNCTION: case Node::NODE_METHOD: - font.setPixelSize(11); - break; - - case Node::NODE_UNDEFINED_VARIABLE: case Node::NODE_GLOBAL_VARIABLE: case Node::NODE_FIELD: case Node::NODE_ENUM_CONSTANT: @@ -355,28 +352,11 @@ void QtGraphNode::setStyle() break; case Node::NODE_UNDEFINED_FUNCTION: + case Node::NODE_UNDEFINED_VARIABLE: useUndefinedPattern = true; useUndefinedColor = true; case Node::NODE_FUNCTION: case Node::NODE_METHOD: - if (m_isActive || m_isHovering) - { - color = ApplicationSettings::getInstance()->getNodeTypeColor(m_data->getType(), "hover").c_str(); - font.setWeight(QFont::Bold); - } - else - { - color = ApplicationSettings::getInstance()->getNodeTypeColor(m_data->getType()).c_str(); - } - - radius = 8.0f; - padding.x = 5; - padding.y = 3; - break; - - case Node::NODE_UNDEFINED_VARIABLE: - useUndefinedPattern = true; - useUndefinedColor = true; case Node::NODE_GLOBAL_VARIABLE: case Node::NODE_FIELD: case Node::NODE_ENUM_CONSTANT: diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index b8bf44eb..d17b62d9 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -105,6 +105,8 @@ add_files( data/graph/token_component/TokenComponentAggregation.h data/graph/token_component/TokenComponentConst.cpp data/graph/token_component/TokenComponentConst.h + data/graph/token_component/TokenComponentFilePath.cpp + data/graph/token_component/TokenComponentFilePath.h data/graph/token_component/TokenComponentName.cpp data/graph/token_component/TokenComponentName.h data/graph/token_component/TokenComponentSignature.cpp diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index d99abc51..95bf0642 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -134,6 +134,13 @@ void Project::parseCode() headerSearchPaths.push_back(includePaths[i]); } + // std::cout << "parse files" << std::endl; + // for (const FilePath& path : filesToParse) + // { + // std::cout << path.absoluteStr() << std::endl; + // } + // std::cout << std::endl; + CxxParser parser(m_storage.get(), m_fileManager.get()); clock_t time = clock(); parser.parseFiles( diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 3074b268..99afcaea 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -8,6 +8,7 @@ #include "data/graph/token_component/TokenComponentConst.h" #include "data/graph/token_component/TokenComponentName.h" #include "data/graph/token_component/TokenComponentStatic.h" +#include "data/graph/token_component/TokenComponentFilePath.h" #include "data/graph/SubGraph.h" #include "data/location/TokenLocation.h" #include "data/location/TokenLocationFile.h" @@ -46,13 +47,13 @@ void Storage::clearFileData(const std::set& filePaths) { for (const FilePath& filePath : filePaths) { - TokenLocationFile* errorFile = m_errorLocationCollection.findTokenLocationFileByPath(filePath.str()); + TokenLocationFile* errorFile = m_errorLocationCollection.findTokenLocationFileByPath(filePath); if (errorFile) { m_errorLocationCollection.removeTokenLocationFile(errorFile); } - TokenLocationFile* file = m_locationCollection.findTokenLocationFileByPath(filePath.str()); + TokenLocationFile* file = m_locationCollection.findTokenLocationFileByPath(filePath); if (!file) { continue; @@ -105,7 +106,7 @@ std::set Storage::getDependingFilePathsAndRemoveFileNodes(const std::s for (const FilePath& filePath : filePaths) { - SearchNode* searchNode = m_tokenIndex.getNode(filePath.absoluteStr()); + SearchNode* searchNode = m_tokenIndex.getNode(filePath.fileName()); if (!searchNode || searchNode->getTokenIds().size() != 1) { continue; @@ -118,6 +119,13 @@ std::set Storage::getDependingFilePathsAndRemoveFileNodes(const std::s continue; } + if (!fileNode->getComponent() || + fileNode->getComponent()->getFilePath() != filePath) + { + LOG_ERROR("Node is not resolving to the same file."); + continue; + } + addDependingFilePathsAndRemoveFileNodesRecursive(fileNode, &dependingFilePaths); } @@ -640,7 +648,7 @@ Id Storage::onFileParsed(const std::string& filePath) { log("file", filePath, ParseLocation()); - Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector(1, FilePath(filePath).absoluteStr())); + Node* fileNode = addFileNode(filePath); return fileNode->getId(); } @@ -648,8 +656,8 @@ Id Storage::onFileIncludeParsed(const ParseLocation& location, const std::string { log("include", includedPath, location); - Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector(1, FilePath(filePath).absoluteStr())); - Node* includedFileNode = addNodeHierarchy(Node::NODE_FILE, std::vector(1, FilePath(includedPath).absoluteStr())); + Node* fileNode = addFileNode(filePath); + Node* includedFileNode = addFileNode(includedPath); Edge* edge = m_graph.createEdge(Edge::EDGE_INCLUDE, fileNode, includedFileNode); addTokenLocation(edge, location); @@ -1071,6 +1079,18 @@ Node* Storage::addNodeHierarchyWithDistinctSignature(Node::NodeType type, const return m_graph.createNodeHierarchyWithDistinctSignature(type, searchNode, signature); } +Node* Storage::addFileNode(const FilePath& filePath) +{ + Node* fileNode = addNodeHierarchy(Node::NODE_FILE, std::vector(1, filePath.fileName())); + + if (!fileNode->getComponent()) + { + fileNode->addComponentFilePath(std::make_shared(filePath)); + } + + return fileNode; +} + TokenComponentAccess::AccessType Storage::convertAccessType(ParserClient::AccessType access) const { switch (access) @@ -1259,7 +1279,7 @@ bool Storage::getQuerySearchResults(const std::string& query, const std::string& void Storage::addDependingFilePathsAndRemoveFileNodesRecursive(Node* fileNode, std::set* filePaths) { - bool inserted = filePaths->insert(FilePath(fileNode->getFullName())).second; + bool inserted = filePaths->insert(fileNode->getComponent()->getFilePath()).second; if (!inserted) { return; diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index 0736eabe..16565abd 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -139,6 +139,8 @@ private: Node* addNodeHierarchy(Node::NodeType type, std::vector nameHierarchy); Node* addNodeHierarchyWithDistinctSignature(Node::NodeType type, const ParseFunction& function); + Node* addFileNode(const FilePath& filePath); + TokenComponentAccess::AccessType convertAccessType(ParserClient::AccessType access) const; TokenComponentAccess* addAccess(Node* node, ParserClient::AccessType access); diff --git a/src/lib/data/graph/FilterableGraph.cpp b/src/lib/data/graph/FilterableGraph.cpp index 9792bb3f..282d6e4b 100644 --- a/src/lib/data/graph/FilterableGraph.cpp +++ b/src/lib/data/graph/FilterableGraph.cpp @@ -52,14 +52,7 @@ void FilterableGraph::printBasic(std::ostream& ostream) const forEachNode( [&ostream](Node* n) { - if (n->isType(Node::NODE_FILE)) - { - ostream << ' ' << n->getTypeString() << ':' << n->getName(); - } - else - { - ostream << ' ' << n->getTypeString() << ':' << n->getFullName(); - } + ostream << ' ' << n->getTypeString() << ':' << n->getFullName(); } ); ostream << '\n'; diff --git a/src/lib/data/graph/Node.cpp b/src/lib/data/graph/Node.cpp index 597f9116..82e9416a 100644 --- a/src/lib/data/graph/Node.cpp +++ b/src/lib/data/graph/Node.cpp @@ -10,6 +10,7 @@ #include "data/graph/token_component/TokenComponentName.h" #include "data/graph/token_component/TokenComponentStatic.h" #include "data/graph/token_component/TokenComponentSignature.h" +#include "data/graph/token_component/TokenComponentFilePath.h" Node::Node(NodeType type, std::shared_ptr nameComponent) : m_type(type) @@ -52,14 +53,7 @@ bool Node::isType(NodeTypeMask mask) const std::string Node::getName() const { - if (isType(NODE_FILE)) - { - return FileSystem::fileName(m_nameComponent->getName()); - } - else - { - return m_nameComponent->getName(); - } + return m_nameComponent->getName(); } std::string Node::getFullName() const @@ -317,6 +311,22 @@ void Node::addComponentSignature(std::shared_ptr compon } } +void Node::addComponentFilePath(std::shared_ptr component) +{ + if (getComponent()) + { + LOG_ERROR("TokenComponentFilePath has been set before!"); + } + else if (!isType(NODE_FILE)) + { + LOG_ERROR("TokenComponentSignature can't be set on node of type: " + getTypeString()); + } + else + { + addComponent(component); + } +} + std::string Node::getTypeString(NodeType type) { switch (type) diff --git a/src/lib/data/graph/Node.h b/src/lib/data/graph/Node.h index 975135f2..1bb7b640 100644 --- a/src/lib/data/graph/Node.h +++ b/src/lib/data/graph/Node.h @@ -14,6 +14,7 @@ class TokenComponentConst; class TokenComponentName; class TokenComponentStatic; class TokenComponentSignature; +class TokenComponentFilePath; class Node: public Token { @@ -85,6 +86,7 @@ public: void addComponentConst(std::shared_ptr component); void addComponentStatic(std::shared_ptr component); void addComponentSignature(std::shared_ptr component); + void addComponentFilePath(std::shared_ptr component); // Logging. virtual std::string getTypeString() const; diff --git a/src/lib/data/graph/token_component/TokenComponentFilePath.cpp b/src/lib/data/graph/token_component/TokenComponentFilePath.cpp new file mode 100644 index 00000000..fa8d37e2 --- /dev/null +++ b/src/lib/data/graph/token_component/TokenComponentFilePath.cpp @@ -0,0 +1,20 @@ +#include "data/graph/token_component/TokenComponentFilePath.h" + +TokenComponentFilePath::TokenComponentFilePath(const FilePath& path) + : m_path(path) +{ +} + +TokenComponentFilePath::~TokenComponentFilePath() +{ +} + +std::shared_ptr TokenComponentFilePath::copy() const +{ + return std::make_shared(*this); +} + +const FilePath& TokenComponentFilePath::getFilePath() const +{ + return m_path; +} diff --git a/src/lib/data/graph/token_component/TokenComponentFilePath.h b/src/lib/data/graph/token_component/TokenComponentFilePath.h new file mode 100644 index 00000000..66e9e69b --- /dev/null +++ b/src/lib/data/graph/token_component/TokenComponentFilePath.h @@ -0,0 +1,23 @@ +#ifndef TOKEN_COMPONENT_FILE_PATH_H +#define TOKEN_COMPONENT_FILE_PATH_H + +#include "utility/file/FilePath.h" + +#include "data/graph/token_component/TokenComponent.h" + +class TokenComponentFilePath + : public TokenComponent +{ +public: + TokenComponentFilePath(const FilePath& path); + virtual ~TokenComponentFilePath(); + + virtual std::shared_ptr copy() const; + + const FilePath& getFilePath() const; + +private: + const FilePath m_path; +}; + +#endif // TOKEN_COMPONENT_FILE_PATH_H diff --git a/src/lib/utility/file/FileManager.h b/src/lib/utility/file/FileManager.h index 9196b07a..e9615b60 100644 --- a/src/lib/utility/file/FileManager.h +++ b/src/lib/utility/file/FileManager.h @@ -1,6 +1,7 @@ #ifndef FILE_MANAGER_H #define FILE_MANAGER_H +#include #include #include diff --git a/src/lib/utility/file/FilePath.cpp b/src/lib/utility/file/FilePath.cpp index 240b1bf2..fccb5c01 100644 --- a/src/lib/utility/file/FilePath.cpp +++ b/src/lib/utility/file/FilePath.cpp @@ -75,5 +75,5 @@ bool FilePath::operator!=(const FilePath& other) const bool FilePath::operator<(const FilePath& other) const { - return m_path.compare(other.m_path) < 0; + return boost::filesystem::absolute(m_path).compare(boost::filesystem::absolute(other.m_path)) < 0; }