diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index d4a12059..075eddaf 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -55,6 +55,8 @@ add_files( qt/view/graphElements/QtGraphNode.h qt/view/graphElements/QtGraphNodeAccess.cpp qt/view/graphElements/QtGraphNodeAccess.h + qt/view/graphElements/QtGraphNodeExpandToggle.cpp + qt/view/graphElements/QtGraphNodeExpandToggle.h qt/view/QtCodeView.cpp qt/view/QtCodeView.h diff --git a/src/app/qt/graphics/QtStraightLineItem.cpp b/src/app/qt/graphics/QtStraightLineItem.cpp index d6acf9a4..2e22fcbc 100644 --- a/src/app/qt/graphics/QtStraightLineItem.cpp +++ b/src/app/qt/graphics/QtStraightLineItem.cpp @@ -20,8 +20,8 @@ QtStraightLineItem::QtStraightLineItem(QGraphicsItem* parent) m_circle->setAcceptHoverEvents(true); QFont font; - font.setFamily(GraphViewStyle::getFontNameOfNumber().c_str()); - font.setPixelSize(GraphViewStyle::getFontSizeOfNumber()); + font.setFamily(GraphViewStyle::getFontNameOfExpandToggleNode().c_str()); + font.setPixelSize(GraphViewStyle::getFontSizeOfExpandToggleNode()); font.setWeight(QFont::Normal); m_number = new QGraphicsSimpleTextItem(this); diff --git a/src/app/qt/utility/QtGraphPostprocessor.cpp b/src/app/qt/utility/QtGraphPostprocessor.cpp index 361c9720..57cabd3c 100644 --- a/src/app/qt/utility/QtGraphPostprocessor.cpp +++ b/src/app/qt/utility/QtGraphPostprocessor.cpp @@ -423,14 +423,14 @@ void QtGraphPostprocessor::resizeNodes(std::list>& Vec2i size = (*it)->getSize(); int newWidth = s_cellSize; - while(size.x - newWidth > 0) + while(size.x - newWidth > 3) { newWidth += s_cellPadding + s_cellSize; } size.x = newWidth; int newHeight = s_cellSize; - while(size.y - newHeight > 0) + while(size.y - newHeight > 3) { newHeight += s_cellPadding + s_cellSize; } diff --git a/src/app/qt/view/QtGraphView.cpp b/src/app/qt/view/QtGraphView.cpp index dc21f1fe..04322aa2 100644 --- a/src/app/qt/view/QtGraphView.cpp +++ b/src/app/qt/view/QtGraphView.cpp @@ -17,6 +17,7 @@ #include "qt/view/graphElements/QtGraphEdge.h" #include "qt/view/graphElements/QtGraphNode.h" #include "qt/view/graphElements/QtGraphNodeAccess.h" +#include "qt/view/graphElements/QtGraphNodeExpandToggle.h" QtGraphView::QtGraphView(ViewLayout* viewLayout) : GraphView(viewLayout) @@ -229,13 +230,17 @@ std::shared_ptr QtGraphView::createNodeRecursive( } std::shared_ptr newNode; - if (node.data) + if (node.isGraphNode()) { - newNode = std::make_shared(node.data); + newNode = std::make_shared(node.data, node.childVisible); } - else + else if (node.isAccessNode()) { - newNode = std::make_shared(node.accessType, node.isExpanded(), node.invisibleSubNodeCount); + newNode = std::make_shared(node.accessType); + } + else if (node.isExpandToggleNode()) + { + newNode = std::make_shared(node.isExpanded(), node.invisibleSubNodeCount); } newNode->setPosition(node.position); @@ -325,7 +330,8 @@ void QtGraphView::compareNodesRecursive( if (((*it)->getTokenId() && (*it)->getTokenId() == (*it2)->getTokenId()) || ((*it)->isAccessNode() && (*it2)->isAccessNode() && dynamic_cast((*it).get())->getAccessType() == - dynamic_cast((*it2).get())->getAccessType())) + dynamic_cast((*it2).get())->getAccessType()) || + ((*it)->isExpandToggleNode() && (*it2)->isExpandToggleNode())) { remainingNodes->push_back(std::pair((*it).get(), (*it2).get())); compareNodesRecursive((*it)->getSubNodes(), (*it2)->getSubNodes(), appearingNodes, vanishingNodes, remainingNodes); diff --git a/src/app/qt/view/graphElements/QtGraphNode.cpp b/src/app/qt/view/graphElements/QtGraphNode.cpp index f9d20de1..0349adef 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.cpp +++ b/src/app/qt/view/graphElements/QtGraphNode.cpp @@ -45,6 +45,7 @@ QtGraphNode::QtGraphNode() , m_undefinedRect(nullptr) , m_isActive(false) , m_isHovering(false) + , m_childVisible(false) { this->setPen(QPen(Qt::transparent)); @@ -52,11 +53,12 @@ QtGraphNode::QtGraphNode() m_text = new QGraphicsSimpleTextItem(this); } -QtGraphNode::QtGraphNode(const Node* data) +QtGraphNode::QtGraphNode(const Node* data, bool childVisible) : GraphNode(data) , m_undefinedRect(nullptr) , m_isActive(false) , m_isHovering(false) + , m_childVisible(childVisible) { this->setPen(QPen(Qt::transparent)); @@ -87,6 +89,11 @@ bool QtGraphNode::isAccessNode() const return false; } +bool QtGraphNode::isExpandToggleNode() const +{ + return false; +} + Vec2i QtGraphNode::getPosition() const { return Vec2i(this->scenePos().x(), this->scenePos().y()); @@ -263,7 +270,7 @@ void QtGraphNode::hoverEnter() void QtGraphNode::updateStyle() { GraphViewStyle::NodeStyle style = - GraphViewStyle::getStyleForNodeType(m_data->getType(), m_isActive, m_isHovering, m_subNodes.size() > 0); + GraphViewStyle::getStyleForNodeType(m_data->getType(), m_isActive, m_isHovering, m_childVisible); setStyle(style); } diff --git a/src/app/qt/view/graphElements/QtGraphNode.h b/src/app/qt/view/graphElements/QtGraphNode.h index c16b02b9..b69c7bd1 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.h +++ b/src/app/qt/view/graphElements/QtGraphNode.h @@ -32,13 +32,14 @@ public: static QFont getFontForNodeType(Node::NodeType type); QtGraphNode(); - QtGraphNode(const Node* data); + QtGraphNode(const Node* data, bool childVisible); virtual ~QtGraphNode(); virtual std::string getName() const; void setName(const std::string& name); virtual bool isAccessNode() const; + virtual bool isExpandToggleNode() const; virtual Vec2i getPosition() const; virtual bool setPosition(const Vec2i& position); @@ -106,6 +107,7 @@ private: bool m_isActive; bool m_isHovering; + bool m_childVisible; }; #endif // QT_GRAPH_NODE_H diff --git a/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp b/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp index 74c8c057..dcdd6b08 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp @@ -4,63 +4,11 @@ #include #include -#include "utility/messaging/type/MessageGraphNodeExpand.h" - #include "component/view/GraphViewStyle.h" #include "qt/graphics/QtRoundedRectItem.h" #include "qt/utility/QtDeviceScaledPixmap.h" -QtGraphNodeAccess::QtAccessToggle::QtAccessToggle(bool expanded, int invisibleSubNodeCount, QGraphicsItem* parent) - : QGraphicsRectItem(parent) -{ - const int iconHeight = 4; - m_icon = new QGraphicsPixmapItem(this); - - if (!expanded && !invisibleSubNodeCount) - { - this->hide(); - return; - } - else - { - QtDeviceScaledPixmap pixmap("data/gui/graph_view/images/arrow.png"); - pixmap.scaleToHeight(iconHeight); - - if (invisibleSubNodeCount) - { - QFont font; - font.setFamily(GraphViewStyle::getFontNameOfNumber().c_str()); - font.setPixelSize(GraphViewStyle::getFontSizeOfNumber()); - font.setWeight(QFont::Normal); - - m_number = new QGraphicsSimpleTextItem(this); - m_number->setFont(font); - - QString numberStr = QString::number(invisibleSubNodeCount); - m_number->setText(numberStr); - m_number->setPos( - -QFontMetrics(m_number->font()).width(numberStr) / 2, - -iconHeight - QFontMetrics(m_number->font()).height() - ); - } - else - { - pixmap.mirror(); - } - - m_icon->setPixmap(pixmap.pixmap()); - m_icon->setPos(-pixmap.width() / 2, -iconHeight); - } -} - -QtGraphNodeAccess::QtAccessToggle::~QtAccessToggle() -{ -} - - -QtGraphNodeAccess::QtGraphNodeAccess( - TokenComponentAccess::AccessType accessType, bool expanded, int invisibleSubNodeCount -) +QtGraphNodeAccess::QtGraphNodeAccess(TokenComponentAccess::AccessType accessType) : QtGraphNode() , m_access(accessType) , m_accessIconSize(20) @@ -73,7 +21,6 @@ QtGraphNodeAccess::QtGraphNodeAccess( pixmap.scaleToHeight(m_accessIconSize); m_accessIcon = new QGraphicsPixmapItem(pixmap.pixmap(), this); - m_accessToggle = new QtAccessToggle(expanded, invisibleSubNodeCount, this); } QtGraphNodeAccess::~QtGraphNodeAccess() @@ -90,29 +37,12 @@ TokenComponentAccess::AccessType QtGraphNodeAccess::getAccessType() const return m_access; } -void QtGraphNodeAccess::setSize(const Vec2i& size) -{ - QtGraphNode::setSize(size); - - m_accessToggle->setPos(m_rect->rect().width() / 2, m_rect->rect().height() - 5); -} - void QtGraphNodeAccess::addSubNode(const std::shared_ptr& node) { QtGraphNode::addSubNode(node); m_text->show(); } -void QtGraphNodeAccess::onClick() -{ - QtGraphNode* parent = getParent(); - - if (m_accessToggle->isVisible() && parent && parent->getData()) - { - MessageGraphNodeExpand(parent->getData()->getId(), m_access).dispatch(); - } -} - void QtGraphNodeAccess::updateStyle() { GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfAccessNode(); diff --git a/src/app/qt/view/graphElements/QtGraphNodeAccess.h b/src/app/qt/view/graphElements/QtGraphNodeAccess.h index 90022b7e..9bc6414e 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeAccess.h +++ b/src/app/qt/view/graphElements/QtGraphNodeAccess.h @@ -8,27 +8,13 @@ class QtGraphNodeAccess : public QtGraphNode { public: - class QtAccessToggle - : public QGraphicsRectItem - { - public: - QtAccessToggle(bool expanded, int invisibleSubNodeCount, QGraphicsItem* parent); - virtual ~QtAccessToggle(); - - private: - QGraphicsPixmapItem* m_icon; - QGraphicsSimpleTextItem* m_number; - }; - - QtGraphNodeAccess(TokenComponentAccess::AccessType accessType, bool expanded, int invisibleSubNodeCount); + QtGraphNodeAccess(TokenComponentAccess::AccessType accessType); virtual ~QtGraphNodeAccess(); virtual bool isAccessNode() const; TokenComponentAccess::AccessType getAccessType() const; - virtual void setSize(const Vec2i& size); virtual void addSubNode(const std::shared_ptr& node); - virtual void onClick(); virtual void updateStyle(); @@ -39,8 +25,6 @@ private: QGraphicsPixmapItem* m_accessIcon; int m_accessIconSize; - - QtAccessToggle* m_accessToggle; }; #endif // QT_GRAPH_NODE_ACCESS_H diff --git a/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp b/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp new file mode 100644 index 00000000..f4cb9703 --- /dev/null +++ b/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp @@ -0,0 +1,71 @@ +#include "qt/view/graphElements/QtGraphNodeExpandToggle.h" + +#include "utility/messaging/type/MessageGraphNodeExpand.h" + +#include "qt/graphics/QtRoundedRectItem.h" +#include "qt/utility/QtDeviceScaledPixmap.h" + +QtGraphNodeExpandToggle::QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount) + : m_allVisible(invisibleSubNodeCount == 0) +{ + const int iconHeight = 4; + m_icon = new QGraphicsPixmapItem(this); + + if (!expanded && !invisibleSubNodeCount) + { + this->hide(); + return; + } + else + { + QtDeviceScaledPixmap pixmap("data/gui/graph_view/images/arrow.png"); + pixmap.scaleToHeight(iconHeight); + + if (invisibleSubNodeCount) + { + QString numberStr = QString::number(invisibleSubNodeCount); + m_text->setText(numberStr); + } + else + { + pixmap.mirror(); + } + + m_icon->setPixmap(pixmap.pixmap()); + } +} + +QtGraphNodeExpandToggle::~QtGraphNodeExpandToggle() +{ +} + +bool QtGraphNodeExpandToggle::isExpandToggleNode() const +{ + return true; +} + +void QtGraphNodeExpandToggle::onClick() +{ + QtGraphNode* parent = getParent(); + + if (parent && parent->getData()) + { + MessageGraphNodeExpand(parent->getData()->getId()).dispatch(); + } +} + +void QtGraphNodeExpandToggle::updateStyle() +{ + GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfExpandToggleNode(); + setStyle(style); + + m_text->setPos( + (m_rect->rect().width() - QFontMetrics(m_text->font()).width(m_text->text())) / 2, + 5 + ); + + m_icon->setPos( + (m_rect->rect().width() - m_icon->pixmap().width() / QtDeviceScaledPixmap::devicePixelRatio()) / 2, + (m_allVisible ? 9 : 14) + ); +} diff --git a/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.h b/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.h new file mode 100644 index 00000000..959a9b9e --- /dev/null +++ b/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.h @@ -0,0 +1,25 @@ +#ifndef QT_EXPAND_TOGGLE_H +#define QT_EXPAND_TOGGLE_H + +#include + +#include "qt/view/graphElements/QtGraphNode.h" + +class QtGraphNodeExpandToggle + : public QtGraphNode +{ +public: + QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount); + virtual ~QtGraphNodeExpandToggle(); + + virtual bool isExpandToggleNode() const; + + virtual void onClick(); + virtual void updateStyle(); + +private: + QGraphicsPixmapItem* m_icon; + bool m_allVisible; +}; + +#endif // QT_EXPAND_TOGGLE_H diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index d60262d0..2ee64584 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -53,7 +53,7 @@ void GraphController::handleMessage(MessageFinishedParsing* message) void GraphController::handleMessage(MessageGraphNodeExpand* message) { - DummyNode* node = findDummyNodeAccessRecursive(m_dummyNodes, message->tokenId, message->access); + DummyNode* node = findDummyNodeRecursive(m_dummyNodes, message->tokenId); if (node) { if (node->autoExpanded) @@ -144,16 +144,22 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node) // there is a global root node with id 0 afaik, so here we actually want the one node below this global root Node* parent = node; - while(parent != NULL && parent->getParentNode() != NULL) + while (parent != NULL && parent->getParentNode() != NULL) { parent = parent->getParentNode(); } - if(parent != NULL) + if (parent != NULL) { result.topLevelAncestorId = parent->getId(); } + DummyNode* oldNode = findDummyNodeRecursive(m_dummyNodes, node->getId()); + if (oldNode) + { + result.expanded = oldNode->expanded; + } + node->forEachChildNode( [node, &result, this](Node* child) { @@ -196,12 +202,6 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node) accessNode.accessType = accessType; result.subNodes.push_back(accessNode); parent = &result.subNodes.back(); - - DummyNode* oldParent = findDummyNodeAccessRecursive(m_dummyNodes, node->getId(), accessType); - if (oldParent) - { - parent->expanded = oldParent->expanded; - } } } @@ -240,17 +240,9 @@ void GraphController::autoExpandActiveNode(const std::vector& activeTokenIds node = findDummyNodeRecursive(m_dummyNodes, activeTokenIds[0]); } - if (!node) + if (node && node->data->isType(Node::NODE_CLASS | Node::NODE_STRUCT)) { - return; - } - - if (node->data->isType(Node::NODE_CLASS | Node::NODE_STRUCT)) - { - for (DummyNode& subNode : node->subNodes) - { - subNode.autoExpanded = true; - } + node->autoExpanded = true; } } @@ -328,9 +320,10 @@ void GraphController::setActiveAndVisibility(const std::vector& activeTokenI void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds) const { node.visible = false; + node.childVisible = false; node.active = false; - if (node.data) + if (node.isGraphNode()) { node.active = find(activeTokenIds.begin(), activeTokenIds.end(), node.data->getId()) != activeTokenIds.end(); } @@ -343,34 +336,35 @@ void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector< bool GraphController::setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool aggregated) const { - bool childVisible = false; for (DummyNode& subNode : node.subNodes) { if (setNodeVisibilityRecursiveBottomUp(subNode, aggregated | node.aggregated)) { - childVisible = true; + node.childVisible = true; } } - if (node.active || node.connected || childVisible || (!aggregated && node.aggregated)) + if (node.active || node.connected || node.childVisible || (!aggregated && node.aggregated)) { - setNodeVisibilityRecursiveTopDown(node); + setNodeVisibilityRecursiveTopDown(node, false); } return node.visible; } -void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node) const +void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const { node.visible = true; - for (DummyNode& subNode : node.subNodes) + if ((node.isGraphNode() && node.isExpanded()) || + (node.isAccessNode() && parentExpanded) || + (node.isGraphNode() && node.data->isType(Node::NODE_ENUM)) || + (node.isGraphNode() && node.active && node.data->isType(Node::NODE_NAMESPACE | Node::NODE_UNDEFINED))) { - if (subNode.accessType != TokenComponentAccess::ACCESS_NONE || node.isExpanded() || - (node.data && node.data->isType(Node::NODE_ENUM)) || - (node.active && node.data && node.data->isType(Node::NODE_NAMESPACE | Node::NODE_UNDEFINED))) + for (DummyNode& subNode : node.subNodes) { - setNodeVisibilityRecursiveTopDown(subNode); + node.childVisible = true; + setNodeVisibilityRecursiveTopDown(subNode, node.isExpanded()); } } } @@ -387,23 +381,17 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const { GraphViewStyle::NodeMargins margins; - if (node.data) + if (node.isGraphNode()) { - margins = GraphViewStyle::getMarginsForNodeType(node.data->getType(), node.subNodes.size() > 0); + margins = GraphViewStyle::getMarginsForNodeType(node.data->getType(), node.childVisible); } - else + else if (node.isAccessNode()) { - node.invisibleSubNodeCount = 0; - for (const DummyNode& subNode : node.subNodes) - { - if (!subNode.visible) - { - node.invisibleSubNodeCount++; - } - } - - margins = GraphViewStyle::getMarginsOfAccessNode( - node.isExpanded(), node.subNodes.size(), node.invisibleSubNodeCount); + margins = GraphViewStyle::getMarginsOfAccessNode(); + } + else if (node.isExpandToggleNode()) + { + margins = GraphViewStyle::getMarginsOfExpandToggleNode(); } int y = 0; @@ -411,12 +399,19 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const int width = margins.minWidth; int height = 0; - if (node.data) + if (node.isGraphNode()) { width = margins.charWidth * node.data->getName().size(); + + if (node.data->isType(Node::NODE_CLASS | Node::NODE_STRUCT) && node.subNodes.size()) + { + addExpandToggleNode(node); + } } - bool layoutHorizontal = true; + // Horizontal layouting is currently not used, but left in place for experimentation. + bool layoutHorizontal = false; + for (DummyNode& subNode : node.subNodes) { if (!subNode.visible) @@ -426,15 +421,15 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const layoutNestingRecursive(subNode); - if (subNode.data || subNode.isExpanded() || subNode.invisibleSubNodeCount != subNode.subNodes.size()) + if (subNode.isExpandToggleNode()) { - layoutHorizontal = false; + width += margins.spacingX + subNode.size.x; } } for (DummyNode& subNode : node.subNodes) { - if (!subNode.visible) + if (!subNode.visible || subNode.isExpandToggleNode()) { continue; } @@ -476,13 +471,52 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const node.size.x = margins.left + width + margins.right; node.size.y = margins.top + y + height + margins.bottom; + + for (DummyNode& subNode : node.subNodes) + { + if (subNode.isExpandToggleNode()) + { + subNode.position.x = margins.left + width - subNode.size.x; + subNode.position.y = 6; + } + } +} + +void GraphController::addExpandToggleNode(DummyNode& node) const +{ + DummyNode expandNode; + expandNode.visible = true; + expandNode.expanded = node.expanded; + expandNode.autoExpanded = node.autoExpanded; + + for (size_t i = 0; i < node.subNodes.size(); i++) + { + DummyNode& subNode = node.subNodes[i]; + + if (subNode.isExpandToggleNode()) + { + node.subNodes.erase(node.subNodes.begin() + i); + i--; + continue; + } + + for (DummyNode& subSubNode : subNode.subNodes) + { + if (!subSubNode.visible) + { + expandNode.invisibleSubNodeCount++; + } + } + } + + node.subNodes.push_back(expandNode); } DummyNode* GraphController::findDummyNodeRecursive(std::vector& nodes, Id tokenId) { for (DummyNode& node : nodes) { - if (node.data && node.data->getId() == tokenId) + if (node.isGraphNode() && node.data->getId() == tokenId) { return &node; } @@ -505,7 +539,7 @@ DummyNode* GraphController::findDummyNodeAccessRecursive( { for (DummyNode& subNode : node->subNodes) { - if (subNode.accessType == type) + if (subNode.isAccessNode() && subNode.accessType == type) { return &subNode; } diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index c74a0a9a..13730214 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -12,6 +12,7 @@ #include "component/controller/Controller.h" #include "component/controller/GraphLayouter.h" #include "component/view/GraphView.h" +#include "data/graph/token_component/TokenComponentAccess.h" struct DummyNode; struct DummyEdge; @@ -48,10 +49,11 @@ private: void setActiveAndVisibility(const std::vector& activeTokenIds); void setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds) const; bool setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool aggregated) const; - void setNodeVisibilityRecursiveTopDown(DummyNode& node) const; + void setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const; void layoutNesting(); void layoutNestingRecursive(DummyNode& node) const; + void addExpandToggleNode(DummyNode& node) const; DummyNode* findDummyNodeRecursive(std::vector& nodes, Id tokenId); DummyNode* findDummyNodeAccessRecursive(std::vector& nodes, Id parentId, TokenComponentAccess::AccessType type); diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index 6397dd92..4ea3e2d7 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -102,7 +102,7 @@ size_t GraphViewStyle::getFontSizeOfAccessNode() return 11; } -size_t GraphViewStyle::getFontSizeOfNumber() +size_t GraphViewStyle::getFontSizeOfExpandToggleNode() { return 9; } @@ -117,7 +117,7 @@ std::string GraphViewStyle::getFontNameOfAccessNode() return "Myriad Pro"; } -std::string GraphViewStyle::getFontNameOfNumber() +std::string GraphViewStyle::getFontNameOfExpandToggleNode() { return "Myriad Pro"; } @@ -125,7 +125,8 @@ std::string GraphViewStyle::getFontNameOfNumber() GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType type, bool hasChildren) { NodeMargins margins; - margins.spacingX = margins.spacingY = 8; + margins.spacingX = 12; + margins.spacingY = 8; switch (type) { @@ -145,14 +146,14 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType case Node::NODE_FILE: if (hasChildren) { - margins.left = margins.right = 15; - margins.top = 30; + margins.left = margins.right = 10; + margins.top = 33; margins.bottom = 10; } else { margins.left = margins.right = 8; - margins.top = margins.bottom = 13; + margins.top = margins.bottom = 17; } break; @@ -177,37 +178,26 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType return margins; } -GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode( - bool expanded, size_t subNodeCount, size_t invisibleSubNodeCount -){ +GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode() +{ NodeMargins margins; margins.spacingX = margins.spacingY = 8; margins.left = margins.right = 10; margins.top = 40; + margins.bottom = 10; - if (invisibleSubNodeCount == subNodeCount) - { - margins.minWidth = 20; - margins.bottom = 10; - } - else - { - margins.minWidth = 82; + margins.minWidth = 82; - if (expanded) - { - margins.bottom = 15; - } - else if (invisibleSubNodeCount) - { - margins.bottom = 23; - } - else - { - margins.bottom = 10; - } - } + return margins; +} + +GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfExpandToggleNode() +{ + NodeMargins margins; + + margins.left = margins.right = margins.top = margins.bottom = 11; + margins.minWidth = 0; return margins; } @@ -279,14 +269,14 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( if (hasChildren) { style.cornerRadius = 20; - style.textOffset.x = 15; + style.textOffset.x = 10; style.textOffset.y = 8; } else { style.cornerRadius = 10; style.textOffset.x = 8; - style.textOffset.y = 4; + style.textOffset.y = 8; } break; @@ -337,6 +327,21 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfAccessNode() return style; } +GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfExpandToggleNode() +{ + NodeStyle style; + + style.color = "#FFFFFF"; + style.borderColor = "#00000000"; + + style.cornerRadius = 12; + + style.fontName = getFontNameOfExpandToggleNode(); + style.fontSize = getFontSizeOfExpandToggleNode(); + + return style; +} + GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(Edge::EdgeType type, bool isActive, bool isFocused) { EdgeStyle style; diff --git a/src/lib/component/view/GraphViewStyle.h b/src/lib/component/view/GraphViewStyle.h index a74f9b17..154ccb67 100644 --- a/src/lib/component/view/GraphViewStyle.h +++ b/src/lib/component/view/GraphViewStyle.h @@ -81,17 +81,19 @@ public: static size_t getFontSizeForNodeType(Node::NodeType type); static size_t getFontSizeOfAccessNode(); - static size_t getFontSizeOfNumber(); + static size_t getFontSizeOfExpandToggleNode(); static std::string getFontNameForNodeType(Node::NodeType type); static std::string getFontNameOfAccessNode(); - static std::string getFontNameOfNumber(); + static std::string getFontNameOfExpandToggleNode(); static NodeMargins getMarginsForNodeType(Node::NodeType type, bool hasChildren); - static NodeMargins getMarginsOfAccessNode(bool expanded, size_t subNodeCount, size_t invisibleSubNodeCount); + static NodeMargins getMarginsOfAccessNode(); + static NodeMargins getMarginsOfExpandToggleNode(); static NodeStyle getStyleForNodeType(Node::NodeType type, bool isActive, bool isFocused, bool hasChildren); static NodeStyle getStyleOfAccessNode(); + static NodeStyle getStyleOfExpandToggleNode(); static EdgeStyle getStyleForEdgeType(Edge::EdgeType type, bool isActive, bool isFocused); diff --git a/src/lib/component/view/graphElements/GraphNode.h b/src/lib/component/view/graphElements/GraphNode.h index 25374707..16715599 100644 --- a/src/lib/component/view/graphElements/GraphNode.h +++ b/src/lib/component/view/graphElements/GraphNode.h @@ -50,45 +50,65 @@ struct DummyNode { public: DummyNode() - : data(nullptr) - , accessType(TokenComponentAccess::ACCESS_NONE) + : visible(false) + , childVisible(false) + , topLevelAncestorId(0) + , tokenId(0) + , data(nullptr) , active(false) , connected(false) , aggregated(false) , expanded(false) , autoExpanded(false) + , accessType(TokenComponentAccess::ACCESS_NONE) , invisibleSubNodeCount(0) - , visible(false) - , topLevelAncestorId(0) - , tokenId(0) { } + bool isGraphNode() const + { + return data != nullptr; + } + + bool isAccessNode() const + { + return accessType != TokenComponentAccess::ACCESS_NONE; + } + + bool isExpandToggleNode() const + { + return !data && !isAccessNode(); + } + bool isExpanded() const { return expanded || autoExpanded; } - const Node* data; - TokenComponentAccess::AccessType accessType; - Vec2i position; Vec2i size; - bool active; - bool connected; - bool aggregated; - - bool expanded; - bool autoExpanded; - size_t invisibleSubNodeCount; - bool visible; + bool childVisible; Id topLevelAncestorId; Id tokenId; std::vector subNodes; + + // GraphNode + const Node* data; + bool active; + bool connected; + bool aggregated; + bool expanded; + bool autoExpanded; + + // AccessNode + TokenComponentAccess::AccessType accessType; + + // ExpandToggleNode + size_t invisibleSubNodeCount; }; #endif // GRAPH_NODE_H diff --git a/src/lib/utility/messaging/type/MessageGraphNodeExpand.h b/src/lib/utility/messaging/type/MessageGraphNodeExpand.h index 7ab7b062..52b0c423 100644 --- a/src/lib/utility/messaging/type/MessageGraphNodeExpand.h +++ b/src/lib/utility/messaging/type/MessageGraphNodeExpand.h @@ -3,14 +3,13 @@ #include "utility/messaging/Message.h" #include "utility/types.h" -#include "data/graph/token_component/TokenComponentAccess.h" -class MessageGraphNodeExpand: public Message +class MessageGraphNodeExpand + : public Message { public: - MessageGraphNodeExpand(Id tokenId, TokenComponentAccess::AccessType access) + MessageGraphNodeExpand(Id tokenId) : tokenId(tokenId) - , access(access) { } @@ -20,7 +19,6 @@ public: } const Id tokenId; - const TokenComponentAccess::AccessType access; }; #endif // MESSAGE_GRAPH_NODE_EXPAND_H