ui: Graph legend (issue #308, #540)

* Show graph legend via 'legend' command or '?' button in the lower right corner
* Legend is not interactive: nodes and edges not clickable or moveable
* CXX and Java node types are mixed
This commit is contained in:
Eberhard Graether
2018-07-23 16:55:58 +02:00
parent 83873f4dbf
commit ed0ade034e
42 changed files with 768 additions and 246 deletions
@@ -141,7 +141,7 @@ void QtAutocompletionDelegate::paint(QPainter* painter, const QStyleOptionViewIt
QString subtext = index.sibling(index.row(), index.column() + 2).data().toString();
QString type = index.sibling(index.row(), index.column() + 3).data().toString();
QList<QVariant> indices = index.sibling(index.row(), index.column() + 4).data().toList();
NodeType nodeType = utility::intToType(index.sibling(index.row(), index.column() + 5).data().toInt());
NodeType nodeType = NodeType::intToType(index.sibling(index.row(), index.column() + 5).data().toInt());
// define highlight colors
ColorScheme* scheme = ColorScheme::getInstance().get();
+15 -1
View File
@@ -20,6 +20,7 @@
#include "qt/utility/QtFileDialog.h"
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
#include "utility/messaging/type/activation/MessageActivateLegend.h"
#include "utility/messaging/type/code/MessageCodeShowDefinition.h"
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
#include "utility/messaging/type/MessageGraphNodeHide.h"
@@ -102,6 +103,12 @@ QtGraphicsView::QtGraphicsView(QWidget* parent)
m_zoomOutButton->setAutoRepeat(true);
m_zoomOutButton->setToolTip("Zoom out (" + modifierName + " + Mousewheel back)");
connect(m_zoomOutButton, &QPushButton::pressed, this, &QtGraphicsView::zoomOutPressed);
m_legendButton = new QtSelfRefreshIconButton(
"", ResourcePaths::getGuiPath().concatenate(L"graph_view/images/legend.png"), "search/button", this);
m_legendButton->setObjectName("legend_button");
m_legendButton->setToolTip("Show graph legend");
connect(m_legendButton, &QPushButton::clicked, this, &QtGraphicsView::legendClicked);
}
float QtGraphicsView::getZoomFactor() const
@@ -201,10 +208,12 @@ void QtGraphicsView::resizeEvent(QResizeEvent* event)
{
m_zoomState->setGeometry(QRect(31, event->size().height() - 27, 65, 19));
m_zoomInButton->setGeometry(QRect(8, event->size().height() - 50, 19, 19));
m_zoomOutButton->setGeometry(QRect(8, event->size().height() - 27, 19, 19));
m_zoomOutButton->setGeometry(QRect(8, event->size().height() - 27, 18, 19));
m_legendButton->setGeometry(QRect(event->size().width() - 24, event->size().height() - 24, 18, 18));
m_zoomInButton->setIconSize(QSize(15, 15));
m_zoomOutButton->setIconSize(QSize(15, 15));
m_legendButton->setIconSize(QSize(10, 10));
emit resized();
}
@@ -567,6 +576,11 @@ void QtGraphicsView::hideZoomLabel()
m_zoomState->hide();
}
void QtGraphicsView::legendClicked()
{
MessageActivateLegend().dispatch();
}
bool QtGraphicsView::moves() const
{
return m_up || m_down || m_left || m_right;
+4
View File
@@ -67,6 +67,8 @@ private slots:
void hideZoomLabel();
void legendClicked();
private:
bool moves() const;
@@ -104,6 +106,8 @@ private:
QtSelfRefreshIconButton* m_zoomInButton;
QtSelfRefreshIconButton* m_zoomOutButton;
QtSelfRefreshIconButton* m_legendButton;
float m_zoomInButtonSpeed;
float m_zoomOutButtonSpeed;
};
+20 -13
View File
@@ -339,7 +339,8 @@ void QtGraphView::rebuildGraph(
for (unsigned int i = 0; i < nodes.size(); i++)
{
QtGraphNode* node = createNodeRecursive(view, nullptr, nodes[i].get(), activeNodeCount > 1);
QtGraphNode* node =
createNodeRecursive(view, nullptr, nodes[i].get(), activeNodeCount > 1, !params.disableInteraction);
if (node)
{
m_nodes.push_back(node);
@@ -367,14 +368,15 @@ void QtGraphView::rebuildGraph(
{
if (!edge->data || !edge->data->isType(Edge::EDGE_AGGREGATION))
{
createEdge(view, edge.get(), &visibleEdgeIds, trailMode, offset, params.bezierEdges);
createEdge(
view, edge.get(), &visibleEdgeIds, trailMode, offset, params.bezierEdges, !params.disableInteraction);
}
}
for (const std::shared_ptr<DummyEdge>& edge : edges)
{
if (edge->data && edge->data->isType(Edge::EDGE_AGGREGATION))
{
createAggregationEdge(view, edge.get(), &visibleEdgeIds);
createAggregationEdge(view, edge.get(), &visibleEdgeIds, !params.disableInteraction);
}
}
@@ -965,7 +967,7 @@ QtGraphNode* QtGraphView::findNodeRecursive(const std::list<QtGraphNode*>& nodes
}
QtGraphNode* QtGraphView::createNodeRecursive(
QGraphicsView* view, QtGraphNode* parentNode, const DummyNode* node, bool multipleActive
QGraphicsView* view, QtGraphNode* parentNode, const DummyNode* node, bool multipleActive, bool interactive
){
if (!node->visible)
{
@@ -975,7 +977,8 @@ QtGraphNode* QtGraphView::createNodeRecursive(
QtGraphNode* newNode = nullptr;
if (node->isGraphNode())
{
newNode = new QtGraphNodeData(node->data, node->name, node->childVisible, node->getQualifierNode() != nullptr);
newNode = new QtGraphNodeData(
node->data, node->name, node->childVisible, node->getQualifierNode() != nullptr, interactive);
}
else if (node->isAccessNode())
{
@@ -995,7 +998,7 @@ QtGraphNode* QtGraphView::createNodeRecursive(
}
else if (node->isTextNode())
{
newNode = new QtGraphNodeText(node->name);
newNode = new QtGraphNodeText(node->name, node->fontSizeDiff);
}
else if (node->isGroupNode())
{
@@ -1013,7 +1016,10 @@ QtGraphNode* QtGraphView::createNodeRecursive(
newNode->setIsActive(node->active);
newNode->setMultipleActive(multipleActive);
newNode->addComponent(std::make_shared<QtGraphNodeComponentClickable>(newNode));
if (interactive)
{
newNode->addComponent(std::make_shared<QtGraphNodeComponentClickable>(newNode));
}
view->scene()->addItem(newNode);
@@ -1021,7 +1027,7 @@ QtGraphNode* QtGraphView::createNodeRecursive(
{
newNode->setParent(parentNode);
}
else if (!node->isTextNode())
else if (!node->isTextNode() && interactive)
{
newNode->addComponent(std::make_shared<QtGraphNodeComponentMoveable>(newNode));
}
@@ -1033,7 +1039,7 @@ QtGraphNode* QtGraphView::createNodeRecursive(
for (unsigned int i = 0; i < node->subNodes.size(); i++)
{
QtGraphNode* subNode = createNodeRecursive(view, newNode, node->subNodes[i].get(), multipleActive);
QtGraphNode* subNode = createNodeRecursive(view, newNode, node->subNodes[i].get(), multipleActive, interactive);
if (subNode)
{
newNode->addSubNode(subNode);
@@ -1051,7 +1057,8 @@ QtGraphEdge* QtGraphView::createEdge(
std::set<Id>* visibleEdgeIds,
Graph::TrailMode trailMode,
QPointF pathOffset,
bool useBezier)
bool useBezier,
bool interactive)
{
if (!edge->visible)
{
@@ -1064,7 +1071,7 @@ QtGraphEdge* QtGraphView::createEdge(
if (owner != nullptr && target != nullptr)
{
QtGraphEdge* qtEdge = new QtGraphEdge(
owner, target, edge->data, edge->getWeight(), edge->active && !useBezier, edge->layoutHorizontal,
owner, target, edge->data, edge->getWeight(), edge->active && !useBezier, interactive, edge->layoutHorizontal,
edge->getDirection());
if (trailMode != Graph::TRAIL_NONE)
@@ -1112,7 +1119,7 @@ QtGraphEdge* QtGraphView::createEdge(
}
QtGraphEdge* QtGraphView::createAggregationEdge(
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds)
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds, bool interactive)
{
if (!edge->visible)
{
@@ -1135,7 +1142,7 @@ QtGraphEdge* QtGraphView::createAggregationEdge(
return nullptr;
}
return createEdge(view, edge, visibleEdgeIds, Graph::TRAIL_NONE, QPointF(), false);
return createEdge(view, edge, visibleEdgeIds, Graph::TRAIL_NONE, QPointF(), false, interactive);
}
QRectF QtGraphView::itemsBoundingRect(const std::list<QtGraphNode*>& items) const
+3 -3
View File
@@ -103,12 +103,12 @@ private:
QtGraphNode* findNodeRecursive(const std::list<QtGraphNode*>& nodes, Id tokenId);
QtGraphNode* createNodeRecursive(
QGraphicsView* view, QtGraphNode* parentNode, const DummyNode* node, bool multipleActive);
QGraphicsView* view, QtGraphNode* parentNode, const DummyNode* node, bool multipleActive, bool interactive);
QtGraphEdge* createEdge(
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds, Graph::TrailMode trailMode,
QPointF pathOffset, bool useBezier);
QPointF pathOffset, bool useBezier, bool interactive);
QtGraphEdge* createAggregationEdge(
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds);
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds, bool interactive);
QRectF itemsBoundingRect(const std::list<QtGraphNode*>& items) const;
QRectF getSceneRect(const std::list<QtGraphNode*>& items) const;
+13 -9
View File
@@ -1,22 +1,19 @@
#include "qt/view/QtGraphViewStyleImpl.h"
#include <QFont>
#include <QFontMetrics>
#include "qt/view/graphElements/QtGraphNode.h"
#include "component/view/GraphViewStyle.h"
#include "utility/utilityApp.h"
QtGraphViewStyleImpl::~QtGraphViewStyleImpl()
float QtGraphViewStyleImpl::getCharWidth(const std::string& fontName, size_t fontSize)
{
return QFontMetrics(getFontForStyleType(fontName, fontSize)).width("QtGraphNode::QtGraphNode::QtGraphNode") / 37.0f;
}
float QtGraphViewStyleImpl::getCharWidth(NodeType::StyleType type)
float QtGraphViewStyleImpl::getCharHeight(const std::string& fontName, size_t fontSize)
{
return QFontMetrics(QtGraphNode::getFontForStyleType(type)).width("QtGraphNode::QtGraphNode::QtGraphNode") / 37.0f;
}
float QtGraphViewStyleImpl::getCharHeight(NodeType::StyleType type)
{
return QFontMetrics(QtGraphNode::getFontForStyleType(type)).height();
return QFontMetrics(getFontForStyleType(fontName, fontSize)).height();
}
float QtGraphViewStyleImpl::getGraphViewZoomDifferenceForPlatform()
@@ -28,3 +25,10 @@ float QtGraphViewStyleImpl::getGraphViewZoomDifferenceForPlatform()
return 1.25;
}
QFont QtGraphViewStyleImpl::getFontForStyleType(const std::string& fontName, size_t fontSize) const
{
QFont font(fontName.c_str());
font.setPixelSize(fontSize);
return font;
}
+10 -4
View File
@@ -3,14 +3,20 @@
#include "component/view/GraphViewStyleImpl.h"
class QFont;
class QtGraphViewStyleImpl
: public GraphViewStyleImpl
{
public:
virtual ~QtGraphViewStyleImpl();
virtual float getCharWidth(NodeType::StyleType type) override;
virtual float getCharHeight(NodeType::StyleType type) override;
virtual float getGraphViewZoomDifferenceForPlatform() override;
virtual ~QtGraphViewStyleImpl() = default;
float getCharWidth(const std::string& fontName, size_t fontSize) override;
float getCharHeight(const std::string& fontName, size_t fontSize) override;
float getGraphViewZoomDifferenceForPlatform() override;
private:
QFont getFontForStyleType(const std::string& fontName, size_t fontSize) const;
};
#endif // QT_GRAPH_VIEW_STYLE_IMPL_H
@@ -30,6 +30,7 @@ QtGraphEdge::QtGraphEdge(
const Edge* data,
size_t weight,
bool isActive,
bool isInteractive,
bool horizontal,
TokenComponentAggregation::Direction direction
)
@@ -44,6 +45,7 @@ QtGraphEdge::QtGraphEdge(
, m_direction(direction)
, m_isTrailEdge(false)
, m_useBezier(false)
, m_isInteractive(isInteractive)
, m_mousePos(0.0f, 0.0f)
, m_mouseMoved(false)
{
@@ -401,7 +403,7 @@ void QtGraphEdge::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
void QtGraphEdge::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
if (!m_mouseMoved)
if (!m_mouseMoved && m_isInteractive)
{
if (event->modifiers() & Qt::AltModifier)
{
@@ -27,6 +27,7 @@ public:
const Edge* data,
size_t weight,
bool isActive,
bool isInteractive,
bool horizontal,
TokenComponentAggregation::Direction direction);
virtual ~QtGraphEdge();
@@ -92,6 +93,7 @@ private:
std::vector<Vec4i> m_path;
bool m_useBezier;
bool m_isInteractive;
Vec2i m_mousePos;
bool m_mouseMoved;
@@ -37,13 +37,6 @@ void QtGraphNode::hideNode()
this->hide();
}
QFont QtGraphNode::getFontForStyleType(NodeType::StyleType type)
{
QFont font(GraphViewStyle::getFontNameForDataNode().c_str());
font.setPixelSize(GraphViewStyle::getFontSizeForStyleType(type));
return font;
}
QtGraphNode::QtGraphNode()
{
this->setPen(QPen(Qt::transparent));
@@ -31,8 +31,6 @@ public slots:
void hideNode();
public:
static QFont getFontForStyleType(NodeType::StyleType type);
QtGraphNode();
virtual ~QtGraphNode();
@@ -5,14 +5,16 @@
#include "utility/messaging/type/MessageDeactivateEdge.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageTooltipShow.h"
#include "utility/ResourcePaths.h"
#include "data/graph/token_component/TokenComponentFilePath.h"
QtGraphNodeData::QtGraphNodeData(const Node* data, const std::wstring& name, bool childVisible, bool hasQualifier)
QtGraphNodeData::QtGraphNodeData(const Node* data, const std::wstring& name, bool childVisible, bool hasQualifier, bool isInteractive)
: m_data(data)
, m_childVisible(childVisible)
, m_hasQualifier(hasQualifier)
, m_isInteractive(isInteractive)
{
this->setAcceptHoverEvents(true);
this->setName(name);
@@ -76,6 +78,26 @@ void QtGraphNodeData::updateStyle()
void QtGraphNodeData::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
MessageFocusIn(std::vector<Id>(1, m_data->getId()), TOOLTIP_ORIGIN_GRAPH).dispatch();
if (!m_isInteractive)
{
TooltipInfo info;
info.title = NodeType::getReadableTypeWString(m_data->getType().getType());
info.offset = Vec2i(10, 20);
if (!m_data->isDefined())
{
info.title = L"non-indexed " + info.title;
}
else if (m_data->isImplicit())
{
info.title = L"implicit " + info.title;
}
MessageTooltipShow msg(info, TOOLTIP_ORIGIN_GRAPH);
msg.setSendAsTask(true);
msg.dispatch();
}
}
void QtGraphNodeData::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
@@ -10,7 +10,7 @@ class QtGraphNodeData
{
Q_OBJECT
public:
QtGraphNodeData(const Node* data, const std::wstring& name, bool childVisible, bool hasQualifier);
QtGraphNodeData(const Node* data, const std::wstring& name, bool childVisible, bool hasQualifier, bool isInteractive);
virtual ~QtGraphNodeData();
const Node* getData() const;
@@ -32,6 +32,7 @@ private:
const Node* m_data;
bool m_childVisible;
bool m_hasQualifier;
bool m_isInteractive;
};
#endif // QT_GRAPH_NODE_DATA_H
@@ -1,6 +1,7 @@
#include "qt/view/graphElements/QtGraphNodeText.h"
QtGraphNodeText::QtGraphNodeText(const std::wstring& name)
QtGraphNodeText::QtGraphNodeText(const std::wstring& name, int fontSizeDiff)
: m_fontSizeDiff(fontSizeDiff)
{
setName(name);
}
@@ -16,5 +17,5 @@ bool QtGraphNodeText::isTextNode() const
void QtGraphNodeText::updateStyle()
{
setStyle(GraphViewStyle::getStyleOfTextNode());
setStyle(GraphViewStyle::getStyleOfTextNode(m_fontSizeDiff));
}
@@ -8,13 +8,16 @@ class QtGraphNodeText
{
Q_OBJECT
public:
QtGraphNodeText(const std::wstring& name);
QtGraphNodeText(const std::wstring& name, int fontSizeDiff);
virtual ~QtGraphNodeText();
// QtGraphNode implementation
virtual bool isTextNode() const;
virtual void updateStyle();
private:
int m_fontSizeDiff;
};
#endif // QT_GRAPH_NODE_TEXT_H