ui: Show namespace label on left side of graph nodes
* Added arrow indicating namespace and package name on left side of node * Show namespace label when hovering arrow * Activate namespace when clicking label * New design for namespace nodes
This commit is contained in:
@@ -90,6 +90,8 @@ add_files(
|
||||
qt/view/graphElements/QtGraphNodeData.h
|
||||
qt/view/graphElements/QtGraphNodeExpandToggle.cpp
|
||||
qt/view/graphElements/QtGraphNodeExpandToggle.h
|
||||
qt/view/graphElements/QtGraphNodeQualifier.cpp
|
||||
qt/view/graphElements/QtGraphNodeQualifier.h
|
||||
|
||||
qt/view/QtCodeView.cpp
|
||||
qt/view/QtCodeView.h
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "qt/view/graphElements/QtGraphNodeBundle.h"
|
||||
#include "qt/view/graphElements/QtGraphNodeData.h"
|
||||
#include "qt/view/graphElements/QtGraphNodeExpandToggle.h"
|
||||
#include "qt/view/graphElements/QtGraphNodeQualifier.h"
|
||||
|
||||
QtGraphView::QtGraphView(ViewLayout* viewLayout)
|
||||
: GraphView(viewLayout)
|
||||
@@ -344,7 +345,7 @@ std::shared_ptr<QtGraphNode> QtGraphView::createNodeRecursive(
|
||||
std::shared_ptr<QtGraphNode> newNode;
|
||||
if (node->isGraphNode())
|
||||
{
|
||||
newNode = std::make_shared<QtGraphNodeData>(node->data, node->name, node->hasParent, node->childVisible);
|
||||
newNode = std::make_shared<QtGraphNodeData>(node->data, node->name, node->hasParent, node->childVisible, node->hasQualifier);
|
||||
}
|
||||
else if (node->isAccessNode())
|
||||
{
|
||||
@@ -358,6 +359,10 @@ std::shared_ptr<QtGraphNode> QtGraphView::createNodeRecursive(
|
||||
{
|
||||
newNode = std::make_shared<QtGraphNodeBundle>(node->tokenId, node->getBundledNodeCount(), node->name);
|
||||
}
|
||||
else if (node->isQualifierNode())
|
||||
{
|
||||
newNode = std::make_shared<QtGraphNodeQualifier>(node->qualifierName);
|
||||
}
|
||||
|
||||
newNode->setPosition(node->position);
|
||||
newNode->setSize(node->size);
|
||||
|
||||
@@ -183,8 +183,6 @@ bool QtGraphNode::getIsActive() const
|
||||
void QtGraphNode::setIsActive(bool isActive)
|
||||
{
|
||||
m_isActive = isActive;
|
||||
|
||||
updateStyle();
|
||||
}
|
||||
|
||||
void QtGraphNode::setMultipleActive(bool multipleActive)
|
||||
@@ -250,6 +248,11 @@ bool QtGraphNode::isBundleNode() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QtGraphNode::isQualifierNode() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Id QtGraphNode::getTokenId() const
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
std::list<std::shared_ptr<QtGraphNode>> getSubNodes() const;
|
||||
|
||||
Vec2i getPosition() const;
|
||||
bool setPosition(const Vec2i& position);
|
||||
virtual bool setPosition(const Vec2i& position);
|
||||
|
||||
Vec2i getSize() const;
|
||||
void setSize(const Vec2i& size);
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
virtual bool isAccessNode() const;
|
||||
virtual bool isExpandToggleNode() const;
|
||||
virtual bool isBundleNode() const;
|
||||
virtual bool isQualifierNode() const;
|
||||
|
||||
virtual Id getTokenId() const;
|
||||
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
|
||||
#include "data/graph/token_component/TokenComponentSignature.h"
|
||||
|
||||
QtGraphNodeData::QtGraphNodeData(const Node* data, const std::string& name, bool hasParent, bool childVisible)
|
||||
QtGraphNodeData::QtGraphNodeData(const Node* data, const std::string& name, bool hasParent, bool childVisible, bool hasQualifier)
|
||||
: m_data(data)
|
||||
, m_childVisible(childVisible)
|
||||
, m_hasQualifier(hasQualifier)
|
||||
{
|
||||
this->setAcceptHoverEvents(true);
|
||||
|
||||
@@ -80,7 +81,7 @@ void QtGraphNodeData::moved(const Vec2i& oldPosition)
|
||||
void QtGraphNodeData::updateStyle()
|
||||
{
|
||||
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleForNodeType(
|
||||
m_data->getType(), m_data->isExplicit(), m_isActive, m_isHovering, m_childVisible);
|
||||
m_data->getType(), m_data->isExplicit(), m_isActive, m_isHovering, m_childVisible, m_hasQualifier);
|
||||
setStyle(style);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class QtGraphNodeData
|
||||
: public QtGraphNode
|
||||
{
|
||||
public:
|
||||
QtGraphNodeData(const Node* data, const std::string& name, bool hasParent, bool childVisible);
|
||||
QtGraphNodeData(const Node* data, const std::string& name, bool hasParent, bool childVisible, bool hasQualifier);
|
||||
virtual ~QtGraphNodeData();
|
||||
|
||||
const Node* getData() const;
|
||||
@@ -28,6 +28,7 @@ protected:
|
||||
private:
|
||||
const Node* m_data;
|
||||
bool m_childVisible;
|
||||
bool m_hasQualifier;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPH_NODE_DATA_H
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
#include "qt/view/graphElements/QtGraphNodeQualifier.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
#include <QPen>
|
||||
|
||||
#include "utility/messaging/type/MessageActivateNodes.h"
|
||||
|
||||
#include "data/name/NameHierarchy.h"
|
||||
|
||||
QtGraphNodeQualifier::QtGraphNodeQualifier(const NameHierarchy& name)
|
||||
: m_qualifierName(name)
|
||||
{
|
||||
this->setAcceptHoverEvents(true);
|
||||
|
||||
m_background = new QGraphicsRectItem(this);
|
||||
m_leftBorder = new QGraphicsRectItem(this);
|
||||
m_rightArrow = new QGraphicsPolygonItem(this);
|
||||
m_rightArrowSmall = new QGraphicsPolygonItem(this);
|
||||
|
||||
QFont font;
|
||||
font.setFamily(GraphViewStyle::getFontNameForNodeType(Node::NODE_UNDEFINED).c_str());
|
||||
font.setPixelSize(GraphViewStyle::getFontSizeOfQualifier());
|
||||
font.setWeight(QFont::Normal);
|
||||
|
||||
m_name = new QGraphicsSimpleTextItem(this);
|
||||
m_name->setFont(font);
|
||||
m_name->setText(QString::fromStdString(name.getQualifiedName()));
|
||||
}
|
||||
|
||||
QtGraphNodeQualifier::~QtGraphNodeQualifier()
|
||||
{
|
||||
}
|
||||
|
||||
bool QtGraphNodeQualifier::isQualifierNode() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QtGraphNodeQualifier::setPosition(const Vec2i& pos)
|
||||
{
|
||||
int width = QFontMetrics(m_name->font()).width(m_name->text()) + 10;
|
||||
int height = QFontMetrics(m_name->font()).height() + 2;
|
||||
int arrowWidth = height * 0.85;
|
||||
|
||||
float smallFactor = 0.5f;
|
||||
int arrowOffset = arrowWidth * smallFactor;
|
||||
|
||||
m_background->setRect(pos.x - width - arrowWidth + arrowOffset, pos.y - height / 2, width, height);
|
||||
|
||||
m_name->setPos(pos.x - width - arrowWidth + arrowOffset + 6, pos.y - height / 2 + 1);
|
||||
m_leftBorder->setRect(pos.x - width - arrowWidth + arrowOffset, pos.y - height / 2, 2, height);
|
||||
|
||||
QPolygonF poly;
|
||||
poly.append(QPointF(-arrowWidth, -height / 2 - 0.5));
|
||||
poly.append(QPointF(-arrowWidth, height / 2 + 0.5));
|
||||
poly.append(QPointF(0, 0));
|
||||
m_rightArrow->setPolygon(poly);
|
||||
m_rightArrow->setPos(pos.x + arrowOffset, pos.y);
|
||||
|
||||
QPolygonF polySmall;
|
||||
polySmall.append(QPointF(-arrowWidth * smallFactor, -height * smallFactor / 2));
|
||||
polySmall.append(QPointF(-arrowWidth * smallFactor, height * smallFactor / 2));
|
||||
polySmall.append(QPointF(0, 0));
|
||||
m_rightArrowSmall->setPolygon(polySmall);
|
||||
m_rightArrowSmall->setPos(pos.x + arrowOffset + 1, pos.y);
|
||||
|
||||
m_pos = pos;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QtGraphNodeQualifier::onClick()
|
||||
{
|
||||
MessageActivateNodes msg;
|
||||
msg.addNode(m_qualifierName);
|
||||
msg.dispatch();
|
||||
}
|
||||
|
||||
void QtGraphNodeQualifier::updateStyle()
|
||||
{
|
||||
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfQualifier();
|
||||
|
||||
this->setBrush(Qt::transparent);
|
||||
this->setPen(QPen(Qt::transparent));
|
||||
|
||||
m_background->setBrush(QColor(style.color.fill.c_str()));
|
||||
m_background->setPen(QPen(QColor(style.color.border.c_str()), 1));
|
||||
|
||||
m_name->setBrush(QColor(style.color.text.c_str()));
|
||||
|
||||
QRectF rect = m_leftBorder->rect();
|
||||
rect.setWidth(style.borderWidth);
|
||||
m_leftBorder->setRect(rect);
|
||||
|
||||
m_leftBorder->setBrush(QColor(style.color.border.c_str()));
|
||||
m_leftBorder->setPen(QPen(Qt::transparent));
|
||||
|
||||
m_rightArrow->setBrush(QColor(style.color.border.c_str()));
|
||||
m_rightArrow->setPen(QPen(Qt::transparent));
|
||||
|
||||
m_rightArrowSmall->setBrush(QColor(style.color.border.c_str()));
|
||||
m_rightArrowSmall->setPen(QPen(Qt::transparent));
|
||||
|
||||
hoverLeaveEvent(nullptr);
|
||||
}
|
||||
|
||||
void QtGraphNodeQualifier::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
|
||||
{
|
||||
int width = QFontMetrics(m_name->font()).width(m_name->text()) + 10;
|
||||
int height = QFontMetrics(m_name->font()).height() + 2;
|
||||
int arrowWidth = height * 0.85;
|
||||
float smallFactor = 0.5f;
|
||||
int arrowOffset = arrowWidth * smallFactor;
|
||||
|
||||
setRect(m_pos.x - width - arrowWidth + arrowOffset, m_pos.y - height / 2, width + arrowWidth, height);
|
||||
|
||||
m_background->show();
|
||||
m_name->show();
|
||||
m_leftBorder->show();
|
||||
m_rightArrow->show();
|
||||
m_rightArrowSmall->hide();
|
||||
|
||||
QPointF p = mapToScene(pos());
|
||||
this->setParentItem(nullptr);
|
||||
this->setPos(p);
|
||||
this->setZValue(100);
|
||||
}
|
||||
|
||||
void QtGraphNodeQualifier::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
|
||||
{
|
||||
int height = QFontMetrics(m_name->font()).height() + 2;
|
||||
int arrowWidth = height * 0.85;
|
||||
float smallFactor = 0.5f;
|
||||
int arrowOffset = arrowWidth * smallFactor;
|
||||
|
||||
setRect(m_pos.x - arrowWidth + arrowOffset, m_pos.y - height / 2, arrowWidth, height);
|
||||
|
||||
m_background->hide();
|
||||
m_name->hide();
|
||||
m_leftBorder->hide();
|
||||
m_rightArrow->hide();
|
||||
m_rightArrowSmall->show();
|
||||
|
||||
this->setParentItem(m_parentNode.lock().get());
|
||||
this->setPos(QPointF(0, 0));
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef QT_GRAPH_NODE_QUALIFIER_H
|
||||
#define QT_GRAPH_NODE_QUALIFIER_H
|
||||
|
||||
#include <QGraphicsPolygonItem>
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
|
||||
class QtGraphNodeQualifier
|
||||
: public QtGraphNode
|
||||
{
|
||||
public:
|
||||
QtGraphNodeQualifier(const NameHierarchy& name);
|
||||
virtual ~QtGraphNodeQualifier();
|
||||
|
||||
// QtGraphNode implementation
|
||||
virtual bool isQualifierNode() const;
|
||||
|
||||
virtual bool setPosition(const Vec2i& pos);
|
||||
|
||||
virtual void onClick();
|
||||
virtual void updateStyle();
|
||||
|
||||
protected:
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
|
||||
|
||||
private:
|
||||
const NameHierarchy m_qualifierName;
|
||||
|
||||
QGraphicsRectItem* m_background;
|
||||
QGraphicsRectItem* m_leftBorder;
|
||||
QGraphicsPolygonItem* m_rightArrow;
|
||||
QGraphicsPolygonItem* m_rightArrowSmall;
|
||||
QGraphicsSimpleTextItem* m_name;
|
||||
|
||||
Vec2i m_pos;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPH_NODE_QUALIFIER_H
|
||||
Reference in New Issue
Block a user