ui: GraphView can set active tokenId on node clicked

By now the graph displays the active node, without neighbours or anything, and clicking a node sets the active token id to the clicked nodes id.

fortune cookie message = Be prepared to accept an exciting opportunity in the future.
This commit is contained in:
Manuel Dobusch
2014-07-07 16:53:44 +02:00
parent e38914887d
commit 0f60a9a556
14 changed files with 215 additions and 62 deletions
+2 -2
View File
@@ -27,9 +27,9 @@ void ComponentManager::setup()
std::shared_ptr<Component> graphComponent = m_componentFactory->createGraphComponent();
GraphView* graphView = graphComponent->getView<GraphView>();
std::weak_ptr<GraphNode> node0 = graphView->addNode(Vec2i(-50, -50), "foo");
/*std::weak_ptr<GraphNode> node0 = graphView->addNode(Vec2i(-50, -50), "foo");
graphView->addEdge(node0, graphView->addNode(Vec2i(100, 100), "bar"));
graphView->addEdge(node0, graphView->addNode(Vec2i(50, -50), "war production co-ordinating commitee"));
graphView->addEdge(node0, graphView->addNode(Vec2i(50, -50), "war production co-ordinating commitee"));*/
m_components.push_back(graphComponent);
@@ -1,11 +1,12 @@
#include "component/controller/GraphController.h"
#include "component/view/graphElements/GraphEdge.h"
#include "component/view/graphElements/GraphNode.h"
#include "component/view/GraphView.h"
#include "data/access/GraphAccess.h"
#include "utility/logging/logging.h"
GraphController::GraphController(std::shared_ptr<GraphAccess> graphAccess)
: m_graphAccess(graphAccess)
{
@@ -15,6 +16,24 @@ GraphController::~GraphController()
{
}
void GraphController::handleMessage(MessageActivateToken* message)
{
GraphView* view = getView();
if (view != NULL)
{
std::string name = m_graphAccess->getNameForNodeWithId(message->tokenId);
DummyNode node(name, message->tokenId, Vec2i(0,0));
std::vector<DummyNode> nodes;
nodes.push_back(node);
std::vector<DummyEdge> edges;
view->rebuildGraph(nodes, edges);
}
}
GraphView* GraphController::getView()
{
return Controller::getView<GraphView>();
@@ -1,18 +1,24 @@
#ifndef GRAPH_CONTROLLER_H
#define GRAPH_CONTROLLER_H
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageActivateToken.h"
#include "component/controller/Controller.h"
class GraphView;
class GraphAccess;
class GraphController: public Controller
class GraphController:
public Controller,
public MessageListener<MessageActivateToken>
{
public:
GraphController(std::shared_ptr<GraphAccess> graphAccess);
~GraphController();
private:
virtual void handleMessage(MessageActivateToken* message);
GraphView* getView();
std::shared_ptr<GraphAccess> m_graphAccess;
+5 -2
View File
@@ -6,6 +6,8 @@
#include "component/view/View.h"
struct DummyEdge;
struct DummyNode;
class GraphEdge;
class GraphNode;
@@ -17,8 +19,9 @@ public:
virtual std::string getName() const;
virtual std::weak_ptr<GraphNode> addNode(const Vec2i& position, const std::string& name) = 0;
virtual void addEdge(const std::weak_ptr<GraphNode>& owner, const std::weak_ptr<GraphNode>& target) = 0;
virtual void rebuildGraph(const std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges) = 0;
virtual void clear() = 0;
protected:
std::list<std::shared_ptr<GraphNode> > m_nodes;
@@ -1,6 +1,10 @@
#ifndef GRAPH_EDGE_H
#define GRAPH_EDGE_H
#include <memory>
class GraphNode;
class GraphEdge
{
public:
@@ -11,4 +15,18 @@ public:
virtual void targetMoved() = 0;
};
// temporary data structure for (visual) graph creation process
struct DummyEdge
{
public:
DummyEdge(const std::weak_ptr<GraphNode> o, const std::weak_ptr<GraphNode> t)
: owner(o)
, target(t)
{
}
std::weak_ptr<GraphNode> owner;
std::weak_ptr<GraphNode> target;
};
#endif // GRAPH_EDGE_H
@@ -1,9 +1,15 @@
#include "component/view/graphElements/GraphNode.h"
GraphNode::GraphNode()
GraphNode::GraphNode(const Id tokenId)
: m_tokenId(tokenId)
{
}
GraphNode::~GraphNode()
{
}
Id GraphNode::getTokenId()
{
return m_tokenId;
}
@@ -1,22 +1,47 @@
#ifndef GRAPH_NODE_H
#define GRAPH_NODE_H
#include <memory>
#include "utility/math/Vector2.h"
#include "utility/types.h"
class GraphEdge;
class GraphNode
{
public:
GraphNode();
GraphNode(const Id tokenId);
virtual ~GraphNode();
virtual std::string getName() = 0;
Id getTokenId();
virtual Vec2i getPosition() = 0;
virtual void addOutEdge(const std::shared_ptr<GraphEdge>& edge) = 0;
virtual void addInEdge(const std::weak_ptr<GraphEdge>& edge) = 0;
virtual void removeOutEdge(const std::shared_ptr<GraphEdge>& edge) = 0;
protected:
Id m_tokenId;
};
struct DummyNode
{
public:
DummyNode(const std::string& n, const Id tId, const Vec2i& p)
: name(n)
, tokenId(tId)
, position(p)
{
}
std::string name;
Id tokenId;
Vec2i position;
std::weak_ptr<GraphNode> actualNode;
};
#endif // GRAPH_NODE_H