ui: Create bookmarks from graph context menu for node under mouse cursor (issue #373)

bug id = 373
This commit is contained in:
Eberhard Graether
2017-05-15 00:45:50 +02:00
parent 6de0021f70
commit c94b5f34a3
13 changed files with 103 additions and 64 deletions
@@ -22,7 +22,6 @@ const std::string BookmarkController::s_defaultCategoryName = "default";
BookmarkController::BookmarkController(StorageAccess* storageAccess)
: m_storageAccess(storageAccess)
, m_bookmarkCache(storageAccess)
, m_hasBookmarkForActiveToken(false)
{
}
@@ -35,8 +34,6 @@ void BookmarkController::clear()
m_activeNodeIds.clear();
m_activeEdgeIds.clear();
m_hasBookmarkForActiveToken = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CANNOT_CREATE);
}
@@ -66,16 +63,16 @@ std::vector<std::string> BookmarkController::getActiveTokenDisplayNames() const
}
}
std::vector<std::string> BookmarkController::getDisplayNamesForNodeId(Id nodeId) const
{
return std::vector<std::string>({ getNodeDisplayName(nodeId) });
}
std::vector<BookmarkCategory> BookmarkController::getAllBookmarkCategories() const
{
return m_storageAccess->getAllBookmarkCategories();
}
bool BookmarkController::hasBookmarkForActiveToken() const
{
return m_hasBookmarkForActiveToken;
}
std::shared_ptr<Bookmark> BookmarkController::getBookmarkForActiveToken() const
{
if (!m_activeEdgeIds.empty())
@@ -103,6 +100,19 @@ std::shared_ptr<Bookmark> BookmarkController::getBookmarkForActiveToken() const
return std::shared_ptr<Bookmark>();
}
std::shared_ptr<Bookmark> BookmarkController::getBookmarkForNodeId(Id nodeId) const
{
for (std::shared_ptr<NodeBookmark> nodeBookmark: getAllNodeBookmarks())
{
if (nodeBookmark->getNodeIds().size() == 1 && nodeBookmark->getNodeIds()[0] == nodeId)
{
return std::make_shared<NodeBookmark>(*(nodeBookmark.get()));
}
}
return std::shared_ptr<Bookmark>();
}
bool BookmarkController::canCreateBookmark() const
{
return m_activeNodeIds.size() || m_activeEdgeIds.size();
@@ -191,7 +201,7 @@ void BookmarkController::handleMessage(MessageActivateBookmark* message)
for (Id nodeId: bookmark->getNodeIds())
{
activateNodes.addNode(nodeId, NameHierarchy());
activateNodes.addNode(nodeId, m_storageAccess->getNameHierarchyForNodeId(nodeId));
}
activateNodes.dispatch();
@@ -210,12 +220,10 @@ void BookmarkController::handleMessage(MessageActivateTokens* message)
if (getBookmarkForActiveToken())
{
m_hasBookmarkForActiveToken = true;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
}
else
{
m_hasBookmarkForActiveToken = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
}
}
@@ -227,12 +235,10 @@ void BookmarkController::handleMessage(MessageActivateTokens* message)
if (getBookmarkForActiveToken())
{
m_hasBookmarkForActiveToken = true;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
}
else
{
m_hasBookmarkForActiveToken = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
}
}
@@ -248,17 +254,7 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
{
LOG_INFO_STREAM(<< "Creating Edge Bookmark");
std::string displayName = message->displayName;
if (displayName.empty())
{
std::vector<std::string> activeEdgeDisplayNames = getActiveEdgeDisplayNames();
if (!activeEdgeDisplayNames.empty())
{
displayName = activeEdgeDisplayNames.front();
}
}
EdgeBookmark bookmark(0, displayName, message->comment, TimePoint::now(), category);
EdgeBookmark bookmark(0, message->displayName, message->comment, TimePoint::now(), category);
bookmark.setEdgeIds(m_activeEdgeIds);
if (!m_activeNodeIds.empty())
@@ -276,24 +272,20 @@ void BookmarkController::handleMessage(MessageCreateBookmark* message)
{
LOG_INFO_STREAM(<< "Creating Node Bookmark");
std::string displayName = message->displayName;
if (displayName.empty())
NodeBookmark bookmark(0, message->displayName, message->comment, TimePoint::now(), category);
if (message->nodeId)
{
std::vector<std::string> activeNodeDisplayNames = getActiveNodeDisplayNames();
if (!activeNodeDisplayNames.empty())
{
displayName = activeNodeDisplayNames.front();
}
bookmark.addNodeId(message->nodeId);
}
else
{
bookmark.setNodeIds(m_activeNodeIds);
}
NodeBookmark bookmark(0, displayName, message->comment, TimePoint::now(), category);
bookmark.setNodeIds(m_activeNodeIds);
m_storageAccess->addNodeBookmark(bookmark);
}
m_bookmarkCache.clear();
m_hasBookmarkForActiveToken = true;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
getView<BookmarkView>()->update();
}
@@ -315,7 +307,6 @@ void BookmarkController::handleMessage(MessageDeleteBookmark* message)
if (!getBookmarkForActiveToken())
{
m_hasBookmarkForActiveToken = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
}
@@ -330,7 +321,6 @@ void BookmarkController::handleMessage(MessageDeleteBookmarkCategory* message)
if (!getBookmarkForActiveToken())
{
m_hasBookmarkForActiveToken = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
}
@@ -347,7 +337,6 @@ void BookmarkController::handleMessage(MessageDeleteBookmarkForActiveTokens* mes
cleanBookmarkCategories();
m_hasBookmarkForActiveToken = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
getView<BookmarkView>()->update();
}
@@ -50,10 +50,12 @@ public:
const MessageDisplayBookmarks::BookmarkFilter& filter, const MessageDisplayBookmarks::BookmarkOrder& order) const;
std::vector<std::string> getActiveTokenDisplayNames() const;
std::vector<std::string> getDisplayNamesForNodeId(Id nodeId) const;
std::vector<BookmarkCategory> getAllBookmarkCategories() const;
bool hasBookmarkForActiveToken() const;
std::shared_ptr<Bookmark> getBookmarkForActiveToken() const;
std::shared_ptr<Bookmark> getBookmarkForNodeId(Id nodeId) const;
bool canCreateBookmark() const;
@@ -118,7 +120,6 @@ private:
std::vector<Id> m_activeNodeIds;
std::vector<Id> m_activeEdgeIds;
bool m_hasBookmarkForActiveToken;
};
#endif // BOOKMARK_CONTROLLER_H
+25 -4
View File
@@ -46,18 +46,39 @@ void BookmarkView::handleMessage(MessageDisplayBookmarks* message)
void BookmarkView::handleMessage(MessageDisplayBookmarkCreator* message)
{
if (!getController()->canCreateBookmark())
if (!getController()->canCreateBookmark() && !message->nodeId)
{
return;
}
if (getController()->hasBookmarkForActiveToken())
if (message->nodeId)
{
displayBookmarkEditor(getController()->getBookmarkForActiveToken(), getController()->getAllBookmarkCategories());
if (getController()->getBookmarkForNodeId(message->nodeId) != nullptr)
{
displayBookmarkEditor(
getController()->getBookmarkForNodeId(message->nodeId),
getController()->getAllBookmarkCategories()
);
}
else
{
displayBookmarkCreator(
getController()->getDisplayNamesForNodeId(message->nodeId),
getController()->getAllBookmarkCategories(),
message->nodeId
);
}
}
else
{
displayBookmarkCreator(getController()->getActiveTokenDisplayNames(), getController()->getAllBookmarkCategories());
if (getController()->getBookmarkForActiveToken() != nullptr)
{
displayBookmarkEditor(getController()->getBookmarkForActiveToken(), getController()->getAllBookmarkCategories());
}
else
{
displayBookmarkCreator(getController()->getActiveTokenDisplayNames(), getController()->getAllBookmarkCategories(), 0);
}
}
}
+1 -1
View File
@@ -46,7 +46,7 @@ private:
virtual void handleMessage(MessageDisplayBookmarkEditor* message);
virtual void displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks) = 0;
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories) = 0;
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories, Id nodeId) = 0;
virtual void displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories) = 0;
MessageDisplayBookmarks::BookmarkFilter m_filter;
@@ -7,10 +7,11 @@ class MessageCreateBookmark
: public Message<MessageCreateBookmark>
{
public:
MessageCreateBookmark(const std::string& comment, const std::string& displayName, const std::string& categoryName)
MessageCreateBookmark(const std::string& comment, const std::string& displayName, const std::string& categoryName, Id nodeId)
: comment(comment)
, displayName(displayName)
, categoryName(categoryName)
, nodeId(nodeId)
{
}
@@ -26,6 +27,7 @@ public:
const std::string comment;
const std::string displayName;
const std::string categoryName;
const Id nodeId;
};
#endif // MESSAGE_CREATE_BOOKMARK_H
@@ -8,6 +8,12 @@ class MessageDisplayBookmarkCreator
{
public:
MessageDisplayBookmarkCreator()
: nodeId(0)
{
}
MessageDisplayBookmarkCreator(Id nodeId)
: nodeId(nodeId)
{
}
@@ -15,6 +21,8 @@ public:
{
return "MessageDisplayBookmarkCreator";
}
Id nodeId;
};
#endif // MESSAGE_DISPLAY_BOOKMARK_CREATOR_H
@@ -8,12 +8,11 @@ class MessageEditBookmark
: public Message<MessageEditBookmark>
{
public:
MessageEditBookmark(const Id id, const std::string& comment, const std::string& displayName, const std::string& categoryName, const bool isEdge)
MessageEditBookmark(Id id, const std::string& comment, const std::string& displayName, const std::string& categoryName)
: bookmarkId(id)
, comment(comment)
, displayName(displayName)
, categoryName(categoryName)
, isEdge(isEdge)
{
}
@@ -30,7 +29,6 @@ public:
const std::string comment;
const std::string displayName;
const std::string categoryName;
const bool isEdge;
};
#endif // MESSAGE_EDIT_BOOKMARK_H
@@ -17,6 +17,7 @@
#include "qt/utility/QtContextMenu.h"
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
#include "utility/ResourcePaths.h"
QtGraphicsView::QtGraphicsView(QWidget* parent)
@@ -52,6 +53,11 @@ QtGraphicsView::QtGraphicsView(QWidget* parent)
m_copyNodeNameAction->setToolTip(tr("Copies the name of this node to the clipboard"));
connect(m_copyNodeNameAction, SIGNAL(triggered()), this, SLOT(copyNodeName()));
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"));
connect(m_bookmarkNodeAction, SIGNAL(triggered()), this, SLOT(bookmarkNode()));
m_zoomInButton = new QPushButton(this);
m_zoomInButton->setObjectName("zoom_in_button");
m_zoomInButton->setAutoRepeat(true);
@@ -277,6 +283,7 @@ void QtGraphicsView::wheelEvent(QWheelEvent* event)
void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event)
{
m_clipboardNodeName = "";
m_bookmarkNodeId = 0;
FilePath clipboardFilePath;
QtGraphNode* node = getNodeAtCursorPosition();
@@ -286,6 +293,7 @@ void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event)
if (dataNode)
{
m_clipboardNodeName = dataNode->getName();
m_bookmarkNodeId = dataNode->getTokenId();
clipboardFilePath = dataNode->getFilePath();
}
else if (dynamic_cast<QtGraphNodeBundle*>(node))
@@ -300,6 +308,12 @@ void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event)
menu.addSeparator();
menu.addAction(m_exportGraphAction);
if (m_bookmarkNodeId)
{
menu.addSeparator();
menu.addAction(m_bookmarkNodeAction);
}
if (!m_clipboardNodeName.empty() || !clipboardFilePath.empty())
{
menu.addSeparator();
@@ -455,6 +469,11 @@ void QtGraphicsView::copyNodeName()
QApplication::clipboard()->setText(m_clipboardNodeName.c_str());
}
void QtGraphicsView::bookmarkNode()
{
MessageDisplayBookmarkCreator(m_bookmarkNodeId).dispatch();
}
void QtGraphicsView::zoomInPressed()
{
updateZoom(m_zoomInButtonSpeed);
+5
View File
@@ -6,6 +6,8 @@
#include <QGraphicsView>
#include <QPushButton>
#include "utility/types.h"
class QTimer;
class QtGraphNode;
@@ -51,6 +53,7 @@ private slots:
void exportGraph();
void copyNodeName();
void bookmarkNode();
void zoomInPressed();
void zoomOutPressed();
@@ -72,12 +75,14 @@ private:
bool m_shift;
std::string m_clipboardNodeName;
Id m_bookmarkNodeId;
std::shared_ptr<QTimer> m_timer;
std::shared_ptr<QTimer> m_timerStopper;
QAction* m_exportGraphAction;
QAction* m_copyNodeNameAction;
QAction* m_bookmarkNodeAction;
QPushButton* m_zoomInButton;
QPushButton* m_zoomOutButton;
+3 -2
View File
@@ -191,7 +191,7 @@ void QtBookmarkView::displayBookmarks(const std::vector<std::shared_ptr<Bookmark
);
}
void QtBookmarkView::displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories)
void QtBookmarkView::displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories, Id nodeId)
{
m_onQtThread(
[=]()
@@ -213,6 +213,8 @@ void QtBookmarkView::displayBookmarkCreator(const std::vector<std::string>& name
bookmarkCreator->setDisplayName(displayName);
bookmarkCreator->setBookmarkCategories(categories);
bookmarkCreator->setNodeId(nodeId);
bookmarkCreator->show();
bookmarkCreator->raise();
}
@@ -230,7 +232,6 @@ void QtBookmarkView::displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, c
bookmarkCreator->setComment(bookmark->getComment());
bookmarkCreator->setBookmarkCategories(categories);
bookmarkCreator->setCurrentBookmarkCategory(bookmark->getCategory());
bookmarkCreator->setIsEdge((dynamic_cast<EdgeBookmark*>(bookmark.get()) != nullptr));
bookmarkCreator->show();
bookmarkCreator->raise();
+1 -1
View File
@@ -35,7 +35,7 @@ private slots:
private:
virtual void displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks);
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories);
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories, Id nodeId);
virtual void displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories);
void setStyleSheet();
+5 -9
View File
@@ -19,6 +19,7 @@ QtBookmarkCreator::QtBookmarkCreator(QWidget* parent, bool edit, Id id)
, m_edit(edit)
, m_bookmarkId(id)
, m_categoryCount(0)
, m_nodeId(0)
{
}
@@ -151,14 +152,9 @@ void QtBookmarkCreator::setCurrentBookmarkCategory(const BookmarkCategory& categ
}
}
bool QtBookmarkCreator::getIsEdge() const
void QtBookmarkCreator::setNodeId(Id nodeId)
{
return m_isEdge;
}
void QtBookmarkCreator::setIsEdge(const bool isEdge)
{
m_isEdge = isEdge;
m_nodeId = nodeId;
}
void QtBookmarkCreator::resizeEvent(QResizeEvent* event)
@@ -177,11 +173,11 @@ void QtBookmarkCreator::handleNext()
if (m_edit)
{
MessageEditBookmark(
m_bookmarkId, qComment.toStdString(), qDisplayName.toStdString(), qCategory.toStdString(), m_isEdge).dispatch();
m_bookmarkId, qComment.toStdString(), qDisplayName.toStdString(), qCategory.toStdString()).dispatch();
}
else
{
MessageCreateBookmark(qComment.toStdString(), qDisplayName.toStdString(), qCategory.toStdString()).dispatch();
MessageCreateBookmark(qComment.toStdString(), qDisplayName.toStdString(), qCategory.toStdString(), m_nodeId).dispatch();
}
MessageStatus("Creating Bookmark for active Token").dispatch();
+2 -3
View File
@@ -31,8 +31,7 @@ public:
void setBookmarkCategories(const std::vector<BookmarkCategory>& categories);
void setCurrentBookmarkCategory(const BookmarkCategory& category);
bool getIsEdge() const;
void setIsEdge(const bool isEdge);
void setNodeId(Id nodeId);
protected:
virtual void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
@@ -54,7 +53,7 @@ private:
int m_categoryCount;
bool m_isEdge;
Id m_nodeId;
QWidget* m_headerBackground;
};