ui: graph view edges

Added simple edges to the graph view. Also fixed a memory leak source in QtMainWindow.

fortune cookie message = Good health will be with you.
This commit is contained in:
Manuel Dobusch
2014-07-04 14:11:09 +02:00
parent b1023ba4ac
commit 610aa2eb09
15 changed files with 290 additions and 23 deletions
+55 -13
View File
@@ -10,6 +10,7 @@
#include "qt/utility/utilityQt.h"
#include "qt/QtWidgetWrapper.h"
#include "qt/view/graphElements/QtGraphEdge.h"
#include "qt/view/graphElements/QtGraphNode.h"
QtGraphView::QtGraphView(ViewLayout* viewLayout)
@@ -44,7 +45,59 @@ void QtGraphView::initGui()
widget->layout()->addWidget(view);
}
void QtGraphView::addNode(const Vec2i& position, const std::string& name)
std::weak_ptr<GraphNode> QtGraphView::addNode(const Vec2i& position, const std::string& name)
{
QGraphicsView* view = getView();
if (view != NULL)
{
std::shared_ptr<QtGraphNode> node = std::make_shared<QtGraphNode>(position, name);
view->scene()->addItem(node.get());
node->setFlag(QGraphicsItem::ItemIsMovable);
m_nodes.push_back(node);
return node;
}
else
{
LOG_WARNING("Unable to retrieve view from widget");
return std::weak_ptr<QtGraphNode>();
}
}
void QtGraphView::addEdge(const std::weak_ptr<GraphNode>& owner, const std::weak_ptr<GraphNode>& target)
{
QGraphicsView* view = getView();
if (view != NULL)
{
std::shared_ptr<GraphNode> o = owner.lock();
std::shared_ptr<GraphNode> t = target.lock();
if (o != NULL && t != NULL)
{
std::shared_ptr<QtGraphEdge> edge = std::make_shared<QtGraphEdge>(owner, target);
view->scene()->addItem(edge.get());
m_edges.push_back(edge);
o->addOutEdge(edge);
t->addInEdge(edge);
}
else
{
LOG_WARNING("Either the owner or target node could not be locked, make sure they still exist!");
}
}
else
{
LOG_WARNING("Unable to retrieve view from widget");
}
}
QGraphicsView* QtGraphView::getView()
{
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
@@ -52,16 +105,5 @@ void QtGraphView::addNode(const Vec2i& position, const std::string& name)
QObjectList children = widget->children();
QGraphicsView* view = widget->findChild<QGraphicsView*>("");
if(view != NULL)
{
QtGraphNode* node = new QtGraphNode(position, name);
view->scene()->addItem(node);
node->setFlag(QGraphicsItem::ItemIsMovable);
}
else
{
LOG_WARNING("Unable to retrieve view from widget");
}
return widget->findChild<QGraphicsView*>("");
}