From 9e7e9176cbf4738cb182dfc8599d6b796d9c8cfe Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Sun, 26 Nov 2017 01:25:58 +0100 Subject: [PATCH] ui: Added option to show/hide referenced builtin types in graph, default is hide (issue #409) --- bin/app/user/ApplicationSettings_template.xml | 1 + .../component/controller/GraphController.cpp | 44 +++++++++++---- .../component/controller/GraphController.h | 6 ++- src/lib/data/NodeType.cpp | 54 ++++++++++--------- src/lib/data/NodeType.h | 1 + src/lib/data/storage/PersistentStorage.cpp | 2 +- src/lib/settings/ApplicationSettings.cpp | 10 ++++ src/lib/settings/ApplicationSettings.h | 3 ++ .../QtProjectWizzardContentPreferences.cpp | 12 +++-- .../QtProjectWizzardContentPreferences.h | 2 + 10 files changed, 94 insertions(+), 41 deletions(-) diff --git a/bin/app/user/ApplicationSettings_template.xml b/bin/app/user/ApplicationSettings_template.xml index 16e72eb3..a90dd894 100644 --- a/bin/app/user/ApplicationSettings_template.xml +++ b/bin/app/user/ApplicationSettings_template.xml @@ -21,6 +21,7 @@ + diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 52e09a5c..0cc7fe5d 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -18,6 +18,7 @@ #include "data/graph/token_component/TokenComponentAccess.h" #include "data/graph/Graph.h" #include "data/parser/AccessKind.h" +#include "settings/ApplicationSettings.h" GraphController::GraphController(StorageAccess* storageAccess) : m_storageAccess(storageAccess) @@ -40,7 +41,7 @@ void GraphController::handleMessage(MessageActivateAll* message) if (message->filter) { - createDummyGraphForTokenIdsAndSetActiveAndVisibility( + createDummyGraphAndSetActiveAndVisibility( std::vector(), m_storageAccess->getGraphForFilter(message->filter)); addCharacterIndex(); @@ -49,7 +50,7 @@ void GraphController::handleMessage(MessageActivateAll* message) } else { - createDummyGraphForTokenIdsAndSetActiveAndVisibility(std::vector(), m_storageAccess->getGraphForAll()); + createDummyGraphAndSetActiveAndVisibility(std::vector(), m_storageAccess->getGraphForAll()); bundleNodesByType(); @@ -101,7 +102,7 @@ void GraphController::handleMessage(MessageActivateTokens* message) bool isNamespace = false; std::shared_ptr graph = m_storageAccess->getGraphForActiveTokenIds(tokenIds, getExpandedNodeIds(), &isNamespace); - createDummyGraphForTokenIdsAndSetActiveAndVisibility(tokenIds, graph); + createDummyGraphAndSetActiveAndVisibility(tokenIds, graph); if (isNamespace) { @@ -157,7 +158,7 @@ void GraphController::handleMessage(MessageActivateTrail* message) std::shared_ptr graph = m_storageAccess->getGraphForTrail( message->originId, message->targetId, message->trailType, message->depth); - createDummyGraphForTokenIds(m_activeNodeIds, graph); + createDummyGraph(graph); m_graph->setTrailMode(message->horizontalLayout ? Graph::TRAIL_HORIZONTAL : Graph::TRAIL_VERTICAL); setVisibility(setActive(m_activeNodeIds, true)); @@ -356,7 +357,8 @@ void GraphController::handleMessage(MessageGraphNodeExpand* message) break; } - std::shared_ptr aggregationGraph = m_storageAccess->getGraphForActiveTokenIds(aggregationIds, std::vector()); + std::shared_ptr aggregationGraph = + m_storageAccess->getGraphForActiveTokenIds(aggregationIds, std::vector()); aggregationGraph->forEachEdge( [this](Edge* e) @@ -439,7 +441,7 @@ void GraphController::clear() getView()->clear(); } -void GraphController::createDummyGraphForTokenIds(const std::vector& tokenIds, const std::shared_ptr graph) +void GraphController::createDummyGraph(const std::shared_ptr graph) { TRACE(); @@ -517,12 +519,12 @@ void GraphController::createDummyGraphForTokenIds(const std::vector& tokenId m_useBezierEdges = false; } -void GraphController::createDummyGraphForTokenIdsAndSetActiveAndVisibility( +void GraphController::createDummyGraphAndSetActiveAndVisibility( const std::vector& tokenIds, const std::shared_ptr graph ){ std::vector expandedNodeIds = getExpandedNodeIds(); - createDummyGraphForTokenIds(tokenIds, graph); + createDummyGraph(graph); bool noActive = setActive(tokenIds, false); @@ -530,6 +532,8 @@ void GraphController::createDummyGraphForTokenIdsAndSetActiveAndVisibility( setExpandedNodeIds(expandedNodeIds); setVisibility(noActive); + + hideBuiltinTypes(); } std::vector> GraphController::createDummyNodeTopDown(Node* node, Id ancestorId) @@ -782,6 +786,22 @@ void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode* node, bool pa } } +void GraphController::hideBuiltinTypes() +{ + if (ApplicationSettings::getInstance()->getShowBuiltinTypesInGraph() || m_activeNodeIds.size() != 1) + { + return; + } + + for (const std::shared_ptr& node : m_dummyNodes) + { + if (node->isGraphNode() && !node->active && node->data->getType().isBuiltin()) + { + node->visible = false; + } + } +} + void GraphController::bundleNodes() { TRACE(); @@ -1301,7 +1321,8 @@ void GraphController::layoutNestingRecursive(DummyNode* node) const if (node->isGraphNode()) { - margins = GraphViewStyle::getMarginsForDataNode(node->data->getType().getNodeStyle(), node->data->getType().hasIcon(), node->childVisible); + margins = GraphViewStyle::getMarginsForDataNode( + node->data->getType().getNodeStyle(), node->data->getType().hasIcon(), node->childVisible); } else if (node->isAccessNode()) { @@ -1315,7 +1336,8 @@ void GraphController::layoutNestingRecursive(DummyNode* node) const { if (node->bundledNodeType.getType() != NodeType::NODE_SYMBOL) { - margins = GraphViewStyle::getMarginsForDataNode(node->bundledNodeType.getNodeStyle(), node->bundledNodeType.hasIcon(), false); + margins = GraphViewStyle::getMarginsForDataNode( + node->bundledNodeType.getNodeStyle(), node->bundledNodeType.hasIcon(), false); } else { @@ -1822,7 +1844,7 @@ void GraphController::handleMessage(MessageColorSchemeTest* message) } ); - createDummyGraphForTokenIds(std::vector(), graph); + createDummyGraph(graph); for (size_t i = 0; i < 2; i++) { diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 9362c3f4..56e47efb 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -72,8 +72,8 @@ private: virtual void clear(); - void createDummyGraphForTokenIds(const std::vector& tokenIds, const std::shared_ptr graph); - void createDummyGraphForTokenIdsAndSetActiveAndVisibility( + void createDummyGraph(const std::shared_ptr graph); + void createDummyGraphAndSetActiveAndVisibility( const std::vector& tokenIds, const std::shared_ptr graph); std::vector> createDummyNodeTopDown(Node* node, Id ancestorId); @@ -88,6 +88,8 @@ private: bool setNodeVisibilityRecursiveBottomUp(DummyNode* node, bool noActive) const; void setNodeVisibilityRecursiveTopDown(DummyNode* node, bool parentExpanded) const; + void hideBuiltinTypes(); + void bundleNodes(); void bundleNodesAndEdgesMatching( std::function matcher, size_t count, bool countConnectedNodes, diff --git a/src/lib/data/NodeType.cpp b/src/lib/data/NodeType.cpp index 89aba257..f29dc298 100644 --- a/src/lib/data/NodeType.cpp +++ b/src/lib/data/NodeType.cpp @@ -25,6 +25,12 @@ bool NodeType::isFile() const return ((m_type & mask) > 0); } +bool NodeType::isBuiltin() const +{ + const NodeType::TypeMask mask = NodeType::NODE_BUILTIN_TYPE; + return ((m_type & mask) > 0); +} + bool NodeType::isUnknownSymbol() const { const NodeType::TypeMask mask = @@ -36,11 +42,11 @@ bool NodeType::isInheritable() const { // what about java enums? const NodeType::TypeMask mask = - NodeType::NODE_SYMBOL | - NodeType::NODE_BUILTIN_TYPE | - NodeType::NODE_TYPE | - NodeType::NODE_STRUCT | - NodeType::NODE_CLASS | + NodeType::NODE_SYMBOL | + NodeType::NODE_BUILTIN_TYPE | + NodeType::NODE_TYPE | + NodeType::NODE_STRUCT | + NodeType::NODE_CLASS | NodeType::NODE_INTERFACE; return ((m_type & mask) > 0); @@ -73,12 +79,12 @@ bool NodeType::isVariable() const bool NodeType::isUsable() const { const NodeType::TypeMask mask = - NodeType::NODE_SYMBOL | - NodeType::NODE_BUILTIN_TYPE | - NodeType::NODE_STRUCT | - NodeType::NODE_CLASS | - NodeType::NODE_ENUM | - NodeType::NODE_UNION | + NodeType::NODE_SYMBOL | + NodeType::NODE_BUILTIN_TYPE | + NodeType::NODE_STRUCT | + NodeType::NODE_CLASS | + NodeType::NODE_ENUM | + NodeType::NODE_UNION | NodeType::NODE_INTERFACE | NodeType::NODE_TYPEDEF; return ((m_type & mask) > 0); @@ -87,13 +93,13 @@ bool NodeType::isUsable() const bool NodeType::isPotentialMember() const { const NodeType::TypeMask mask = - NodeType::NODE_METHOD | - NodeType::NODE_FIELD | - NodeType::NODE_CLASS | - NodeType::NODE_INTERFACE | - NodeType::NODE_STRUCT | - NodeType::NODE_UNION | - NodeType::NODE_TYPEDEF | + NodeType::NODE_METHOD | + NodeType::NODE_FIELD | + NodeType::NODE_CLASS | + NodeType::NODE_INTERFACE | + NodeType::NODE_STRUCT | + NodeType::NODE_UNION | + NodeType::NODE_TYPEDEF | NodeType::NODE_ENUM; return ((m_type & mask) > 0); @@ -102,12 +108,12 @@ bool NodeType::isPotentialMember() const bool NodeType::isCollapsible() const { const NodeType::TypeMask mask = - NodeType::NODE_SYMBOL | - NodeType::NODE_TYPE | - NodeType::NODE_BUILTIN_TYPE | - NodeType::NODE_CLASS | - NodeType::NODE_STRUCT | - NodeType::NODE_ENUM | + NodeType::NODE_SYMBOL | + NodeType::NODE_TYPE | + NodeType::NODE_BUILTIN_TYPE | + NodeType::NODE_CLASS | + NodeType::NODE_STRUCT | + NodeType::NODE_ENUM | NodeType::NODE_UNION | NodeType::NODE_INTERFACE; return ((m_type & mask) > 0); diff --git a/src/lib/data/NodeType.h b/src/lib/data/NodeType.h index 3a4f78cd..053f5e8c 100644 --- a/src/lib/data/NodeType.h +++ b/src/lib/data/NodeType.h @@ -56,6 +56,7 @@ public: Type getType() const; bool isFile() const; + bool isBuiltin() const; bool isUnknownSymbol() const; bool isInheritable() const; bool isPackage() const; diff --git a/src/lib/data/storage/PersistentStorage.cpp b/src/lib/data/storage/PersistentStorage.cpp index bc629925..9d57dab7 100644 --- a/src/lib/data/storage/PersistentStorage.cpp +++ b/src/lib/data/storage/PersistentStorage.cpp @@ -96,7 +96,7 @@ void PersistentStorage::addFile(const StorageFile& data) { m_sqliteIndexStorage.addFile(data); } - + if (!storedFile.complete && data.complete) { m_sqliteIndexStorage.setFileComplete(data.complete, storedFile.id); diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index 3dcba234..6d0162ef 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -137,6 +137,16 @@ void ApplicationSettings::setUseAnimations(bool useAnimations) setValue("application/use_animations", useAnimations); } +bool ApplicationSettings::getShowBuiltinTypesInGraph() const +{ + return getValue("application/builtin_types_in_graph", false); +} + +void ApplicationSettings::setShowBuiltinTypesInGraph(bool showBuiltinTypes) +{ + setValue("application/builtin_types_in_graph", showBuiltinTypes); +} + FilePath ApplicationSettings::getColorSchemePath() const { FilePath defaultPath(ResourcePaths::getColorSchemesPath().concat(FilePath("bright.xml"))); diff --git a/src/lib/settings/ApplicationSettings.h b/src/lib/settings/ApplicationSettings.h index b6a4a6a9..49906a42 100644 --- a/src/lib/settings/ApplicationSettings.h +++ b/src/lib/settings/ApplicationSettings.h @@ -50,6 +50,9 @@ public: bool getUseAnimations() const; void setUseAnimations(bool useAnimations); + bool getShowBuiltinTypesInGraph() const; + void setShowBuiltinTypesInGraph(bool showBuiltinTypes); + int getWindowBaseWidth() const; int getWindowBaseHeight() const; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp index e9b771eb..2a2f89d8 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp @@ -70,6 +70,10 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) m_useAnimations = addCheckBox("Animations", "Enable animations", "

Enable animations throughout the user interface.

", layout, row); + // built-in types + m_showBuiltinTypes = addCheckBox("Built-in Types", "Show built-in types in graph when referenced", + "

Enable display of referenced built-in types in the graph view.

", layout, row); + // logging m_loggingEnabled = addCheckBox("Logging", "Enable console and file logging", "

Show logs in the console and save this information in files.

", layout, row); @@ -155,7 +159,7 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) addLabelAndWidget("Indexer Threads", threadsWidget, layout, row, Qt::AlignLeft); addHelpButton( - "Indexer Threads", + "Indexer Threads", "

Set the number of threads used to work on indexing your project in parallel.

" "

When setting this value to 0 Sourcetrail tries to use the ideal thread count for your computer.

", layout, row @@ -246,7 +250,7 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) layout->addWidget(label, row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignTop); addHelpButton( - "JRE System Library", + "JRE System Library", "

Only required for indexing Java projects.

" "

Add the jar files of your JRE System Library. These jars can be found inside your JRE install directory.

", layout, row); @@ -276,7 +280,7 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) addLabelAndWidget("Maven Path", m_mavenPath, layout, row); addHelpButton( - "Maven Path", + "Maven Path", "

Only required for indexing projects using Maven.

" "

Provide the location of your installed Maven executable. You can also use the auto detection below.

" , layout, row @@ -317,6 +321,7 @@ void QtProjectWizzardContentPreferences::load() } m_useAnimations->setChecked(appSettings->getUseAnimations()); + m_showBuiltinTypes->setChecked(appSettings->getShowBuiltinTypesInGraph()); m_loggingEnabled->setChecked(appSettings->getLoggingEnabled()); m_verboseIndexerLoggingEnabled->setChecked(appSettings->getVerboseIndexerLoggingEnabled()); @@ -364,6 +369,7 @@ void QtProjectWizzardContentPreferences::save() m_oldColorSchemeIndex = -1; appSettings->setUseAnimations(m_useAnimations->isChecked()); + appSettings->setShowBuiltinTypesInGraph(m_showBuiltinTypes->isChecked()); appSettings->setLoggingEnabled(m_loggingEnabled->isChecked()); appSettings->setVerboseIndexerLoggingEnabled(m_verboseIndexerLoggingEnabled->isChecked()); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h index 8d3fad68..75acd063 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h @@ -64,6 +64,8 @@ private: int m_newColorSchemeIndex; QCheckBox* m_useAnimations; + QCheckBox* m_showBuiltinTypes; + QCheckBox* m_loggingEnabled; QCheckBox* m_verboseIndexerLoggingEnabled;