ui: graphView

Added basic graph view with simple nodes (just text, no edges or anything...)

fortune cookie message = Don't be afraid to take that big step.
This commit is contained in:
Manuel Dobusch
2014-07-02 16:14:56 +02:00
parent 5251e3ecb6
commit a8e32af5dd
16 changed files with 220 additions and 2 deletions
+5
View File
@@ -9,8 +9,13 @@ add_files(
qt/utility/utilityQt.cpp
qt/utility/utilityQt.h
qt/view/graphElements/QtGraphNode.cpp
qt/view/graphElements/QtGraphNode.h
qt/view/QtCodeView.cpp
qt/view/QtCodeView.h
qt/view/QtGraphView.cpp
qt/view/QtGraphView.h
qt/view/QtMainView.cpp
qt/view/QtMainView.h
+6
View File
@@ -1,6 +1,7 @@
#include "qt/QtGuiFactory.h"
#include "qt/view/QtCodeView.h"
#include "qt/view/QtGraphView.h"
#include "qt/view/QtMainView.h"
QtGuiFactory::QtGuiFactory()
@@ -20,3 +21,8 @@ std::shared_ptr<CodeView> QtGuiFactory::createCodeView(ViewLayout* viewLayout) c
{
return View::create<QtCodeView>(viewLayout);
}
std::shared_ptr<GraphView> QtGuiFactory::createGraphView(ViewLayout* viewLayout) const
{
return View::create<QtGraphView>(viewLayout);
}
+1
View File
@@ -11,6 +11,7 @@ public:
virtual std::shared_ptr<MainView> createMainView() const;
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const;
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const;
};
#endif // QT_GUI_FACTORY_H
+67
View File
@@ -0,0 +1,67 @@
#include "QtGraphView.h"
#include "qboxlayout.h"
#include "qgraphicsitem.h"
#include "qgraphicsproxywidget.h"
#include "qgraphicsscene.h"
#include "qgraphicsview.h"
#include "qpushbutton.h"
#include "qt/utility/utilityQt.h"
#include "qt/QtWidgetWrapper.h"
#include "qt/view/graphElements/QtGraphNode.h"
QtGraphView::QtGraphView(ViewLayout* viewLayout)
: GraphView(viewLayout)
{
}
QtGraphView::~QtGraphView()
{
}
void QtGraphView::createWidgetWrapper()
{
setWidgetWrapper(std::make_shared<QtWidgetWrapper>(std::make_shared<QFrame>()));
}
void QtGraphView::initGui()
{
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
utility::setWidgetBackgroundColor(widget, Colori(100, 20, 200, 255));
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
layout->setSpacing(3);
layout->setContentsMargins(3, 3, 3, 3);
widget->setLayout(layout);
QGraphicsScene* scene = new QGraphicsScene(widget);
QGraphicsView* view = new QGraphicsView(widget);
view->setScene(scene);
widget->layout()->addWidget(view);
}
void QtGraphView::addNode(const Vec2i& position, const std::string& name)
{
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
QLayout* layout = widget->layout();
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");
}
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef QT_GRAPH_VIEW_H
#define QT_GRAPH_VIEW_H
#include "component/view/GraphView.h"
class QtGraphView : public GraphView
{
public:
QtGraphView(ViewLayout* viewLayout);
virtual ~QtGraphView();
// View implementation
virtual void createWidgetWrapper();
virtual void initGui();
virtual void addNode(const Vec2i& position, const std::string& name);
};
#endif // QT_GRAPH_VIEW_H
@@ -0,0 +1,20 @@
#include "qt/view/graphElements/QtGraphNode.h"
#include "qgraphicsscene.h"
QtGraphNode::QtGraphNode(const Vec2i& position, const std::string& name)
{
this->setRect(position.x, position.y, 100, 100);
QBrush brush(Qt::lightGray);
this->setBrush(brush);
m_text = new QGraphicsTextItem(this);
m_text->setPos(position.x, position.y);
m_text->setPlainText(QString(name.c_str()));
}
QtGraphNode::~QtGraphNode()
{
}
@@ -0,0 +1,22 @@
#ifndef QT_GRAPH_NODE_H
#define QT_GRAPH_NODE_H
#include "qgraphicsitem.h"
#include "utility/math/Vector2.h"
#include "component/view/graphElements/GraphNode.h"
class QtGraphNode:
public GraphNode,
public QGraphicsRectItem
{
public:
QtGraphNode(const Vec2i& position, const std::string& name);
virtual ~QtGraphNode();
private:
QGraphicsTextItem* m_text;
};
#endif // QT_GRAPH_NODE_H
+7 -2
View File
@@ -21,15 +21,20 @@ add_files(
component/controller/Controller.cpp
component/controller/Controller.h
component/view/graphElements/GraphNode.cpp
component/view/graphElements/GraphNode.h
component/view/CodeView.cpp
component/view/CodeView.h
component/view/GraphView.cpp
component/view/GraphView.h
component/view/MainView.cpp
component/view/MainView.h
component/view/View.cpp
component/view/View.h
component/view/ViewLayout.cpp
component/view/ViewLayout.h
component/view/ViewLayout.h
component/Component.cpp
component/Component.h
component/ComponentFactory.cpp
+10
View File
@@ -2,6 +2,7 @@
#include "component/controller/CodeController.h"
#include "component/view/CodeView.h"
#include "component/view/GraphView.h"
#include "component/view/ViewLayout.h"
#include "gui/GuiFactory.h"
@@ -32,6 +33,15 @@ std::shared_ptr<Component> ComponentFactory::createCodeComponent()
return component;
}
std::shared_ptr<Component> ComponentFactory::createGraphComponent()
{
std::shared_ptr<View> view = m_guiFactory->createGraphView(m_viewLayout);
std::shared_ptr<Controller> controller = std::make_shared<CodeController>();
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
return component;
}
ComponentFactory::ComponentFactory()
{
}
+1
View File
@@ -22,6 +22,7 @@ public:
~ComponentFactory();
std::shared_ptr<Component> createCodeComponent();
std::shared_ptr<Component> createGraphComponent();
private:
ComponentFactory();
+8
View File
@@ -1,6 +1,7 @@
#include "component/ComponentManager.h"
#include "component/view/CodeView.h"
#include "component/view/GraphView.h"
#include "component/view/ViewLayout.h"
std::shared_ptr<ComponentManager> ComponentManager::create(
@@ -20,6 +21,13 @@ ComponentManager::~ComponentManager()
void ComponentManager::setup()
{
std::shared_ptr<Component> graphComponent = m_componentFactory->createGraphComponent();
GraphView* graphView = dynamic_cast<GraphView*>(graphComponent->getView());
graphView->addNode(Vec2i(-100, -100), "foo");
graphView->addNode(Vec2i(50, 50), "bar");
m_components.push_back(graphComponent);
std::shared_ptr<Component> codeComponent = m_componentFactory->createCodeComponent();
m_components.push_back(codeComponent);
+15
View File
@@ -0,0 +1,15 @@
#include "component/view/GraphView.h"
GraphView::GraphView(ViewLayout* viewLayout)
: View(viewLayout, Vec2i(100, 100))
{
}
GraphView::~GraphView()
{
}
std::string GraphView::getName() const
{
return "GraphView";
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef GRAPH_VIEW_H
#define GRAPH_VIEW_H
#include "component/view/View.h"
class GraphView : public View
{
public:
GraphView(ViewLayout* viewLayout);
virtual ~GraphView();
virtual std::string getName() const;
virtual void addNode(const Vec2i& position, const std::string& name) = 0;
};
#endif // GRAPH_VIEW_H
@@ -0,0 +1,9 @@
#include "component/view/graphElements/GraphNode.h"
GraphNode::GraphNode()
{
}
GraphNode::~GraphNode()
{
}
@@ -0,0 +1,11 @@
#ifndef GRAPH_NODE_H
#define GRAPH_NODE_H
class GraphNode
{
public:
GraphNode();
virtual ~GraphNode();
};
#endif // GRAPH_NODE_H
+2
View File
@@ -4,6 +4,7 @@
#include <memory>
class CodeView;
class GraphView;
class MainView;
class ViewLayout;
@@ -15,6 +16,7 @@ public:
virtual std::shared_ptr<MainView> createMainView() const = 0;
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const = 0;
};
#endif // GUI_FACTORY_H