ui: Hide nodes and edges from graph via context menu action or Alt + Click (issue #472)

* show all context menu actions, but disable unavailable
* added hide action to undo redo stack
This commit is contained in:
Eberhard Graether
2017-11-26 12:54:42 +01:00
parent 9e7e9176cb
commit 0d5c19db00
21 changed files with 402 additions and 87 deletions
+6 -7
View File
@@ -581,14 +581,13 @@ void QtCodeArea::contextMenuEvent(QContextMenuEvent* event)
{
m_eventPosition = event->pos();
m_setIDECursorPositionAction->setEnabled(!getSourceLocationFile()->getFilePath().empty());
QtContextMenu menu(event, this);
if (!getSourceLocationFile()->getFilePath().empty())
{
menu.addSeparator();
menu.addFileActions(getSourceLocationFile()->getFilePath());
menu.addSeparator();
menu.addAction(m_setIDECursorPositionAction);
}
menu.addSeparator();
menu.addFileActions(getSourceLocationFile()->getFilePath());
menu.addSeparator();
menu.addAction(m_setIDECursorPositionAction);
menu.show();
}
}
@@ -128,14 +128,8 @@ void QtCodeFileTitleButton::updateTexts()
void QtCodeFileTitleButton::contextMenuEvent(QContextMenuEvent* event)
{
QtContextMenu menu(event, this);
menu.addSeparator();
if (!m_filePath.empty())
{
menu.addFileActions(m_filePath);
}
else if (text().size())
FilePath path = m_filePath;
if (text().size())
{
Project* currentProject = Application::getInstance()->getCurrentProject().get();
if (!currentProject)
@@ -143,9 +137,12 @@ void QtCodeFileTitleButton::contextMenuEvent(QContextMenuEvent* event)
return;
}
menu.addFileActions(currentProject->getProjectSettingsFilePath());
path = currentProject->getProjectSettingsFilePath();
}
QtContextMenu menu(event, this);
menu.addSeparator();
menu.addFileActions(path);
menu.show();
}
+78 -29
View File
@@ -10,6 +10,7 @@
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include "qt/view/graphElements/QtGraphEdge.h"
#include "qt/view/graphElements/QtGraphNode.h"
#include "qt/view/graphElements/QtGraphNodeData.h"
#include "qt/view/graphElements/QtGraphNodeBundle.h"
@@ -18,6 +19,7 @@
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
#include "utility/messaging/type/MessageGraphNodeHide.h"
#include "utility/utilityApp.h"
#include "utility/ResourcePaths.h"
@@ -57,6 +59,16 @@ QtGraphicsView::QtGraphicsView(QWidget* parent)
m_copyNodeNameAction->setToolTip(tr("Copies the name of this node to the clipboard"));
connect(m_copyNodeNameAction, &QAction::triggered, this, &QtGraphicsView::copyNodeName);
m_hideNodeAction = new QAction(tr("Hide Node (Alt + Left Click)"), this);
m_hideNodeAction->setStatusTip(tr("Hide the node from this graph"));
m_hideNodeAction->setToolTip(tr("Hide the node from this graph"));
connect(m_hideNodeAction, &QAction::triggered, this, &QtGraphicsView::hideNode);
m_hideEdgeAction = new QAction(tr("Hide Edge (Alt + Left Click)"), this);
m_hideEdgeAction->setStatusTip(tr("Hide the edge from this graph"));
m_hideEdgeAction->setToolTip(tr("Hide the edge from this graph"));
connect(m_hideEdgeAction, &QAction::triggered, this, &QtGraphicsView::hideEdge);
m_bookmarkNodeAction = new QAction(tr("Bookmark Node"), this);
m_bookmarkNodeAction->setStatusTip(tr("Create a bookmark for this node"));
m_bookmarkNodeAction->setToolTip(tr("Create a bookmark for this node"));
@@ -113,6 +125,20 @@ QtGraphNode* QtGraphicsView::getNodeAtCursorPosition() const
return node;
}
QtGraphEdge* QtGraphicsView::getEdgeAtCursorPosition() const
{
QtGraphEdge* edge = nullptr;
QPointF point = mapToScene(mapFromGlobal(QCursor::pos()));
QGraphicsItem* item = scene()->itemAt(point, QTransform());
if (item)
{
edge = dynamic_cast<QtGraphEdge*>(item->parentItem());
}
return edge;
}
void QtGraphicsView::ensureVisibleAnimated(const QRectF& rect, int xmargin, int ymargin)
{
int xval = horizontalScrollBar()->value();
@@ -302,51 +328,64 @@ void QtGraphicsView::wheelEvent(QWheelEvent* event)
void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event)
{
m_clipboardNodeName = "";
m_hideNodeId = 0;
m_hideEdgeId = 0;
m_bookmarkNodeId = 0;
FilePath clipboardFilePath;
QtGraphNode* node = getNodeAtCursorPosition();
while (node)
if (node)
{
QtGraphNodeData* dataNode = dynamic_cast<QtGraphNodeData*>(node);
if (dataNode)
while (node)
{
m_clipboardNodeName = dataNode->getName();
m_bookmarkNodeId = dataNode->getTokenId();
clipboardFilePath = dataNode->getFilePath();
m_hideNodeId = node->getTokenId();
QtGraphNodeData* dataNode = dynamic_cast<QtGraphNodeData*>(node);
if (dataNode)
{
m_clipboardNodeName = dataNode->getName();
m_bookmarkNodeId = dataNode->getTokenId();
clipboardFilePath = dataNode->getFilePath();
break;
}
else if (dynamic_cast<QtGraphNodeBundle*>(node))
{
m_clipboardNodeName = node->getName();
break;
}
node = node->getParent();
}
else if (dynamic_cast<QtGraphNodeBundle*>(node))
}
else
{
QtGraphEdge* edge = getEdgeAtCursorPosition();
if (edge)
{
m_clipboardNodeName = node->getName();
break;
m_hideEdgeId = edge->getTokenId();
}
node = node->getParent();
}
m_hideNodeAction->setEnabled(m_hideNodeId);
m_hideEdgeAction->setEnabled(m_hideEdgeId);
m_bookmarkNodeAction->setEnabled(m_bookmarkNodeId);
m_copyNodeNameAction->setEnabled(m_clipboardNodeName.size());
QtContextMenu menu(event, this);
menu.addSeparator();
menu.addAction(m_exportGraphAction);
if (m_bookmarkNodeId)
{
menu.addSeparator();
menu.addAction(m_bookmarkNodeAction);
}
menu.addSeparator();
menu.addAction(m_hideEdgeAction);
menu.addAction(m_hideNodeAction);
menu.addAction(m_bookmarkNodeAction);
if (!m_clipboardNodeName.empty() || !clipboardFilePath.empty())
{
menu.addSeparator();
}
if (!m_clipboardNodeName.empty())
{
menu.addAction(m_copyNodeNameAction);
}
if (!clipboardFilePath.empty())
{
menu.addFileActions(clipboardFilePath);
}
menu.addSeparator();
menu.addAction(m_copyNodeNameAction);
menu.addFileActions(clipboardFilePath);
menu.show();
}
@@ -439,6 +478,16 @@ void QtGraphicsView::copyNodeName()
QApplication::clipboard()->setText(m_clipboardNodeName.c_str());
}
void QtGraphicsView::hideNode()
{
MessageGraphNodeHide(m_hideNodeId).dispatch();
}
void QtGraphicsView::hideEdge()
{
MessageGraphNodeHide(m_hideEdgeId).dispatch();
}
void QtGraphicsView::bookmarkNode()
{
MessageDisplayBookmarkCreator(m_bookmarkNodeId).dispatch();
+8
View File
@@ -9,6 +9,7 @@
#include "utility/types.h"
class QTimer;
class QtGraphEdge;
class QtGraphNode;
class QtGraphicsView
@@ -25,6 +26,7 @@ public:
void setSceneRect(const QRectF& rect);
QtGraphNode* getNodeAtCursorPosition() const;
QtGraphEdge* getEdgeAtCursorPosition() const;
void ensureVisibleAnimated(const QRectF& rect, int xmargin = 50, int ymargin = 50);
@@ -56,6 +58,8 @@ private slots:
void exportGraph();
void copyNodeName();
void hideNode();
void hideEdge();
void bookmarkNode();
void zoomInPressed();
@@ -81,6 +85,8 @@ private:
bool m_shift;
std::string m_clipboardNodeName;
Id m_hideNodeId;
Id m_hideEdgeId;
Id m_bookmarkNodeId;
std::shared_ptr<QTimer> m_timer;
@@ -89,6 +95,8 @@ private:
QAction* m_exportGraphAction;
QAction* m_copyNodeNameAction;
QAction* m_hideNodeAction;
QAction* m_hideEdgeAction;
QAction* m_bookmarkNodeAction;
QPushButton* m_zoomState;
+3
View File
@@ -54,6 +54,9 @@ void QtContextMenu::addFileActions(FilePath filePath)
{
s_filePath = filePath;
s_copyFullPathAction->setEnabled(!s_filePath.empty());
s_openContainingFolderAction->setEnabled(!s_filePath.empty());
addAction(s_copyFullPathAction);
addAction(s_openContainingFolderAction);
}
@@ -16,6 +16,7 @@
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageGraphNodeBundleSplit.h"
#include "utility/messaging/type/MessageGraphNodeHide.h"
#include "utility/messaging/type/MessageTooltipShow.h"
#include "utility/messaging/type/MessageTooltipHide.h"
#include "utility/utility.h"
@@ -80,6 +81,16 @@ QtGraphNode* QtGraphEdge::getTarget()
return m_target;
}
Id QtGraphEdge::getTokenId() const
{
if (getData())
{
return getData()->getId();
}
return 0;
}
void QtGraphEdge::updateLine()
{
QtGraphNode* owner = m_owner;
@@ -269,6 +280,16 @@ void QtGraphEdge::onClick()
}
}
void QtGraphEdge::onHide()
{
Id tokenId = getTokenId();
if (tokenId)
{
MessageGraphNodeHide(tokenId).dispatch();
}
}
void QtGraphEdge::focusIn()
{
if (!m_isFocused)
@@ -328,7 +349,14 @@ void QtGraphEdge::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
if (!m_mouseMoved)
{
this->onClick();
if (event->modifiers() & Qt::AltModifier)
{
this->onHide();
}
else
{
this->onClick();
}
}
}
@@ -35,6 +35,8 @@ public:
QtGraphNode* getOwner();
QtGraphNode* getTarget();
Id getTokenId() const;
void updateLine();
bool getIsActive() const;
@@ -44,6 +46,7 @@ public:
void setIsFocused(bool isFocused);
void onClick();
void onHide();
void focusIn();
void focusOut();
@@ -11,6 +11,7 @@
#include "qt/utility/utilityQt.h"
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponent.h"
#include "qt/view/graphElements/QtGraphEdge.h"
#include "utility/messaging/type/MessageGraphNodeHide.h"
#include "utility/ResourcePaths.h"
#include "utility/utilityString.h"
@@ -345,6 +346,20 @@ void QtGraphNode::onClick()
{
}
void QtGraphNode::onHide()
{
Id tokenId = getTokenId();
if (tokenId)
{
MessageGraphNodeHide(tokenId).dispatch();
}
else if (getParent())
{
getParent()->onHide();
}
}
void QtGraphNode::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
event->ignore();
@@ -92,6 +92,7 @@ public:
virtual void addSubNode(QtGraphNode* node);
virtual void onClick();
virtual void onHide();
virtual void moved(const Vec2i& oldPosition);
virtual void updateStyle() = 0;
@@ -35,7 +35,14 @@ void QtGraphNodeComponentClickable::nodeMouseReleaseEvent(QGraphicsSceneMouseEve
{
if (!m_mouseMoved)
{
m_graphNode->onClick();
if (event->modifiers() & Qt::AltModifier)
{
m_graphNode->onHide();
}
else
{
m_graphNode->onClick();
}
event->accept();
}
}