ui: Abstracting the UI on view level instead of element level
This change switches the view creation architecture from element based creation in the lib to view based creation in the app. This avoids wrapping of the Qt elements and instead defines interfaces for the different View implementations. * GuiElementFactory was renamed to GuiFactory and is now responsible for View creation instead of Element creation. * WidgetWrappers are now used on Views to access their root widget. * Removed DummyView and DummyController. * Removed GuiElement and corresponding QtElement files. * Removed ViewManager, functionality is now handled via MainView. * Added MainView, where Views are registered via the ViewLayout interface. * Added QtMainWindow, derived from QMainWindow and instantiated by QtMainView, which displays the Views as QDockWidgets. fortune cookie message = All your hard work will soon pay off.
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
#include "component/ComponentFactory.h"
|
||||
|
||||
#include "component/controller/CodeController.h"
|
||||
#include "component/controller/DummyController.h"
|
||||
#include "component/view/CodeView.h"
|
||||
#include "component/view/DummyView.h"
|
||||
#include "component/view/ViewLayout.h"
|
||||
#include "gui/GuiFactory.h"
|
||||
|
||||
std::shared_ptr<ComponentFactory> ComponentFactory::create(
|
||||
std::shared_ptr<ViewManager> viewManager,
|
||||
std::shared_ptr<GuiElementFactory> guiElementFactory,
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess)
|
||||
{
|
||||
std::shared_ptr<ComponentFactory> ptr(new ComponentFactory());
|
||||
ptr->m_viewManger = viewManager;
|
||||
ptr->m_guiElementFactory = guiElementFactory;
|
||||
ptr->m_guiFactory = guiFactory;
|
||||
ptr->m_viewLayout = viewLayout;
|
||||
ptr->m_codeAccess = codeAccess;
|
||||
ptr->m_graphAccess = graphAccess;
|
||||
return ptr;
|
||||
@@ -23,18 +23,9 @@ ComponentFactory::~ComponentFactory()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> ComponentFactory::createDummyComponent()
|
||||
{
|
||||
std::shared_ptr<View> view = std::make_shared<DummyView>(m_viewManger, m_guiElementFactory);
|
||||
std::shared_ptr<Controller> controller = std::make_shared<DummyController>();
|
||||
|
||||
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
|
||||
return component;
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> ComponentFactory::createCodeComponent()
|
||||
{
|
||||
std::shared_ptr<View> view = m_guiElementFactory->createCodeView(m_viewManger);
|
||||
std::shared_ptr<View> view = m_guiFactory->createCodeView(m_viewLayout);
|
||||
std::shared_ptr<Controller> controller = std::make_shared<CodeController>();
|
||||
|
||||
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
|
||||
|
||||
@@ -4,31 +4,31 @@
|
||||
#include <memory>
|
||||
|
||||
#include "component/Component.h"
|
||||
#include "component/view/ViewManager.h"
|
||||
#include "data/access/CodeAccess.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
#include "gui/GuiElementFactory.h"
|
||||
|
||||
class GuiFactory;
|
||||
class ViewLayout;
|
||||
|
||||
class ComponentFactory
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<ComponentFactory> create(
|
||||
std::shared_ptr<ViewManager> viewManager,
|
||||
std::shared_ptr<GuiElementFactory> guiElementFactory,
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess);
|
||||
|
||||
~ComponentFactory();
|
||||
|
||||
std::shared_ptr<Component> createDummyComponent();
|
||||
std::shared_ptr<Component> createCodeComponent();
|
||||
|
||||
private:
|
||||
ComponentFactory();
|
||||
ComponentFactory(const ComponentFactory&);
|
||||
|
||||
std::shared_ptr<ViewManager> m_viewManger;
|
||||
std::shared_ptr<GuiElementFactory> m_guiElementFactory;
|
||||
GuiFactory* m_guiFactory;
|
||||
ViewLayout* m_viewLayout;
|
||||
|
||||
std::shared_ptr<CodeAccess> m_codeAccess;
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
#include "component/ComponentManager.h"
|
||||
|
||||
#include "component/view/CodeView.h"
|
||||
#include "component/view/ViewLayout.h"
|
||||
|
||||
std::shared_ptr<ComponentManager> ComponentManager::create(
|
||||
std::shared_ptr<ViewManager> viewManager,
|
||||
std::shared_ptr<GuiElementFactory> guiElementFactory,
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess)
|
||||
{
|
||||
std::shared_ptr<ComponentManager> ptr(new ComponentManager());
|
||||
ptr->m_componentFactory = ComponentFactory::create(viewManager, guiElementFactory, codeAccess, graphAccess);
|
||||
ptr->m_componentFactory = ComponentFactory::create(guiFactory, viewLayout, codeAccess, graphAccess);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ComponentManager::~ComponentManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ComponentManager::setup()
|
||||
{
|
||||
m_components.push_back(m_componentFactory->createDummyComponent());
|
||||
|
||||
std::shared_ptr<Component> codeComponent = m_componentFactory->createCodeComponent();
|
||||
m_components.push_back(codeComponent);
|
||||
|
||||
@@ -29,7 +32,3 @@ void ComponentManager::setup()
|
||||
ComponentManager::ComponentManager()
|
||||
{
|
||||
}
|
||||
|
||||
ComponentManager::~ComponentManager()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -4,19 +4,20 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "data/access/CodeAccess.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
#include "component/Component.h"
|
||||
#include "component/ComponentFactory.h"
|
||||
#include "component/view/ViewManager.h"
|
||||
#include "gui/GuiElementFactory.h"
|
||||
#include "data/access/CodeAccess.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
|
||||
class GuiFactory;
|
||||
class ViewLayout;
|
||||
|
||||
class ComponentManager
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<ComponentManager> create(
|
||||
std::shared_ptr<ViewManager> viewManager,
|
||||
std::shared_ptr<GuiElementFactory> guiElementFactory,
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess);
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "component/controller/DummyController.h"
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef DUMMY_CONTROLLER_H
|
||||
#define DUMMY_CONTROLLER_H
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
|
||||
class DummyController: public Controller
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
#endif // DUMMY_CONTROLLER_H
|
||||
@@ -1,10 +1,15 @@
|
||||
#include "component/view/CodeView.h"
|
||||
|
||||
CodeView::CodeView(std::shared_ptr<ViewManager> viewManager, std::shared_ptr<GuiElement> rootElement)
|
||||
: View(viewManager, rootElement, Vec2i(100, 100))
|
||||
CodeView::CodeView(ViewLayout* viewLayout)
|
||||
: View(viewLayout, Vec2i(100, 100))
|
||||
{
|
||||
}
|
||||
|
||||
CodeView::~CodeView()
|
||||
{
|
||||
}
|
||||
|
||||
std::string CodeView::getName() const
|
||||
{
|
||||
return "CodeView";
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
#ifndef CODE_VIEW_H
|
||||
#define CODE_VIEW_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "component/view/View.h"
|
||||
|
||||
class GuiElementFactory;
|
||||
|
||||
class CodeView: public View
|
||||
{
|
||||
public:
|
||||
CodeView(std::shared_ptr<ViewManager> viewManager, std::shared_ptr<GuiElement> rootElement);
|
||||
CodeView(ViewLayout* viewLayout);
|
||||
virtual ~CodeView();
|
||||
|
||||
virtual std::string getName() const;
|
||||
|
||||
virtual void addCodeSnippet(std::string str) = 0;
|
||||
virtual void clearCodeSnippets() = 0;
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#include "component/view/DummyView.h"
|
||||
|
||||
#include "gui/GuiArea.h"
|
||||
#include "gui/GuiElementFactory.h"
|
||||
|
||||
DummyView::DummyView(std::shared_ptr<ViewManager> viewManager, std::shared_ptr<GuiElementFactory> guiElementFactory)
|
||||
: View(viewManager, guiElementFactory->createArea(), Vec2i(100, 100))
|
||||
, m_guiElementFactory(guiElementFactory)
|
||||
{
|
||||
getRootElement()->setBackgroundColor(0, 255, 0, 255);
|
||||
}
|
||||
|
||||
DummyView::~DummyView()
|
||||
{
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifndef DUMMY_VIEW_H
|
||||
#define DUMMY_VIEW_H
|
||||
|
||||
#include "component/view/View.h"
|
||||
|
||||
class GuiElementFactory;
|
||||
|
||||
class DummyView: public View
|
||||
{
|
||||
public:
|
||||
DummyView(std::shared_ptr<ViewManager> viewManager, std::shared_ptr<GuiElementFactory> guiElementFactory);
|
||||
virtual ~DummyView();
|
||||
|
||||
private:
|
||||
std::shared_ptr<GuiElementFactory> m_guiElementFactory;
|
||||
};
|
||||
|
||||
|
||||
#endif // DUMMY_VIEW_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "component/view/MainView.h"
|
||||
|
||||
MainView::MainView()
|
||||
{
|
||||
}
|
||||
|
||||
MainView::~MainView()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef MAIN_VIEW_H
|
||||
#define MAIN_VIEW_H
|
||||
|
||||
#include "component/view/ViewLayout.h"
|
||||
|
||||
class MainView: public ViewLayout
|
||||
{
|
||||
public:
|
||||
MainView();
|
||||
virtual ~MainView();
|
||||
};
|
||||
|
||||
#endif // MAIN_VIEW_H
|
||||
@@ -1,22 +1,21 @@
|
||||
#include "component/view/View.h"
|
||||
#include "component/view/ViewManager.h"
|
||||
|
||||
View::View(std::shared_ptr<ViewManager> viewManager, std::shared_ptr<GuiElement> rootElement, const Vec2i& minSize)
|
||||
: m_viewManager(viewManager)
|
||||
, m_rootElement(rootElement)
|
||||
, m_minSize(minSize)
|
||||
{
|
||||
m_viewManager->addView(this);
|
||||
}
|
||||
#include "component/view/ViewLayout.h"
|
||||
#include "gui/GuiWidgetWrapper.h"
|
||||
|
||||
View::~View()
|
||||
{
|
||||
m_viewManager->removeView(this);
|
||||
m_viewLayout->removeView(this);
|
||||
}
|
||||
|
||||
std::shared_ptr<GuiElement> View::getRootElement()
|
||||
void View::setWidgetWrapper(std::shared_ptr<GuiWidgetWrapper> widgetWrapper)
|
||||
{
|
||||
return m_rootElement;
|
||||
m_widgetWrapper = widgetWrapper;
|
||||
}
|
||||
|
||||
GuiWidgetWrapper* View::getWidgetWrapper()
|
||||
{
|
||||
return m_widgetWrapper.get();
|
||||
}
|
||||
|
||||
int View::getMinWidth() const
|
||||
@@ -33,3 +32,10 @@ Vec2i View::getMinSize() const
|
||||
{
|
||||
return m_minSize;
|
||||
}
|
||||
|
||||
View::View(ViewLayout* viewLayout, const Vec2i& minSize)
|
||||
: m_viewLayout(viewLayout)
|
||||
, m_widgetWrapper(nullptr)
|
||||
, m_minSize(minSize)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2,28 +2,54 @@
|
||||
#define VIEW_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "component/view/ViewLayout.h"
|
||||
#include "utility/math/Vector2.h"
|
||||
|
||||
class GuiElement;
|
||||
class ViewManager;
|
||||
class GuiWidgetWrapper;
|
||||
class ViewLayout;
|
||||
|
||||
class View
|
||||
{
|
||||
public:
|
||||
View(std::shared_ptr<ViewManager> viewManager, std::shared_ptr<GuiElement> rootElement, const Vec2i& minSize);
|
||||
template<typename T>
|
||||
static std::shared_ptr<T> create(ViewLayout* viewLayout);
|
||||
|
||||
virtual ~View();
|
||||
|
||||
std::shared_ptr<GuiElement> getRootElement();
|
||||
virtual std::string getName() const = 0;
|
||||
|
||||
virtual void createWidgetWrapper() = 0;
|
||||
void setWidgetWrapper(std::shared_ptr<GuiWidgetWrapper> widgetWrapper);
|
||||
GuiWidgetWrapper* getWidgetWrapper();
|
||||
|
||||
virtual void initGui() = 0;
|
||||
|
||||
int getMinWidth() const;
|
||||
int getMinHeight() const;
|
||||
Vec2i getMinSize() const;
|
||||
|
||||
protected:
|
||||
View(ViewLayout* viewLayout, const Vec2i& minSize);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ViewManager> m_viewManager;
|
||||
std::shared_ptr<GuiElement> m_rootElement;
|
||||
ViewLayout* const m_viewLayout;
|
||||
std::shared_ptr<GuiWidgetWrapper> m_widgetWrapper;
|
||||
Vec2i m_minSize;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::shared_ptr<T> View::create(ViewLayout* viewLayout)
|
||||
{
|
||||
std::shared_ptr<T> ptr = std::make_shared<T>(viewLayout);
|
||||
|
||||
ptr->createWidgetWrapper();
|
||||
ptr->initGui();
|
||||
|
||||
viewLayout->addView(ptr.get());
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endif // VIEW_H
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "component/view/ViewLayout.h"
|
||||
|
||||
ViewLayout::ViewLayout()
|
||||
{
|
||||
}
|
||||
|
||||
ViewLayout::~ViewLayout()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef VIEW_LAYOUT_H
|
||||
#define VIEW_LAYOUT_H
|
||||
|
||||
class View;
|
||||
|
||||
class ViewLayout
|
||||
{
|
||||
public:
|
||||
ViewLayout();
|
||||
virtual ~ViewLayout();
|
||||
|
||||
virtual void addView(View* view) = 0;
|
||||
virtual void removeView(View* view) = 0;
|
||||
};
|
||||
|
||||
#endif // VIEW_LAYOUT_H
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "component/view/ViewManager.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "gui/GuiCanvas.h"
|
||||
#include "View.h"
|
||||
|
||||
ViewManager::ViewManager(std::shared_ptr<GuiCanvas> canvas)
|
||||
: m_canvas(canvas)
|
||||
{
|
||||
}
|
||||
|
||||
ViewManager::~ViewManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ViewManager::addView(View* view)
|
||||
{
|
||||
m_views.push_back(view);
|
||||
m_canvas->addChild(view->getRootElement());
|
||||
}
|
||||
|
||||
void ViewManager::removeView(View* view)
|
||||
{
|
||||
std::vector<View*>::iterator it = std::find(m_views.begin(), m_views.end(), view);
|
||||
if (it != m_views.end())
|
||||
{
|
||||
m_canvas->removeChild((*it)->getRootElement());
|
||||
m_views.erase(it);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef VIEW_MANAGER_H
|
||||
#define VIEW_MANAGER_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class GuiCanvas;
|
||||
class View;
|
||||
|
||||
class ViewManager
|
||||
{
|
||||
public:
|
||||
ViewManager(std::shared_ptr<GuiCanvas> canvas);
|
||||
~ViewManager();
|
||||
|
||||
void addView(View* view);
|
||||
void removeView(View* view);
|
||||
|
||||
private:
|
||||
std::shared_ptr<GuiCanvas> m_canvas;
|
||||
std::vector<View*> m_views;
|
||||
};
|
||||
|
||||
|
||||
#endif // VIEW_MANAGER_H
|
||||
Reference in New Issue
Block a user