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:
Eberhard Graether
2014-07-02 12:25:51 +02:00
parent 3dabe009e0
commit fdba1b2a84
67 changed files with 424 additions and 888 deletions
+8 -13
View File
@@ -1,28 +1,23 @@
add_files(
APP_FILES
qt/element/QtArea.cpp
qt/element/QtArea.h
qt/element/QtCanvas.cpp
qt/element/QtCanvas.h
qt/element/QtLayout.cpp
qt/element/QtLayout.h
qt/element/QtMainWindow.cpp
qt/element/QtMainWindow.h
qt/utility/QtHighLighter.cpp
qt/utility/QtHighLighter.h
qt/utility/utilityQt.cpp
qt/utility/utilityQt.h
qt/view/QtCodeView.cpp
qt/view/QtCodeView.h
qt/view/QtMainView.cpp
qt/view/QtMainView.h
qt/QtGuiFactory.cpp
qt/QtGuiFactory.h
qt/QtWidgetWrapper.cpp
qt/QtWidgetWrapper.h
qt/QtElementFactory.cpp
qt/QtElementFactory.h
qt/QtWindow.cpp
qt/QtWindow.h
utility/utilityQt.cpp
utility/utilityQt.h
includesWindows.h
main.cpp
+3 -6
View File
@@ -4,17 +4,14 @@
#include "Application.h"
#include "includes.h"
#include "qt/QtElementFactory.h"
#include "qt/QtWindow.h"
#include "qt/QtGuiFactory.h"
int main(int argc, char *argv[])
{
QApplication qtApp(argc, argv);
std::shared_ptr<GuiElementFactory> elementFactory = std::make_shared<QtElementFactory>();
QtGuiFactory guiFactory;
std::shared_ptr<QtWindow> window = std::make_shared<QtWindow>();
std::shared_ptr<Application> app = Application::create(elementFactory, window);
std::shared_ptr<Application> app = Application::create(&guiFactory);
app->loadProject();
return qtApp.exec();
-38
View File
@@ -1,38 +0,0 @@
#include "qt/QtElementFactory.h"
#include "component/view/CodeView.h"
#include "qt/element/QtArea.h"
#include "qt/element/QtCanvas.h"
#include "qt/element/QtLayout.h"
#include "qt/view/QtCodeView.h"
#include "qt/QtWindow.h"
QtElementFactory::QtElementFactory()
{
}
QtElementFactory::~QtElementFactory()
{
}
std::shared_ptr<GuiArea> QtElementFactory::createArea() const
{
return std::make_shared<QtArea>();
}
std::shared_ptr<GuiCanvas> QtElementFactory::createCanvas(std::shared_ptr<GuiWindow> window) const
{
std::shared_ptr<GuiCanvas> canvas = std::make_shared<QtCanvas>();
window->setCanvas(canvas);
return canvas;
}
std::shared_ptr<GuiLayout> QtElementFactory::createLayout() const
{
return std::make_shared<QtLayout>();
}
std::shared_ptr<CodeView> QtElementFactory::createCodeView(std::shared_ptr<ViewManager> viewManager) const
{
return std::make_shared<QtCodeView>(viewManager);
}
-22
View File
@@ -1,22 +0,0 @@
#ifndef QT_ELEMENT_FACTORY_H
#define QT_ELEMENT_FACTORY_H
#include "gui/GuiElementFactory.h"
class CodeView;
class ViewManager;
class QtElementFactory: public GuiElementFactory
{
public:
QtElementFactory();
virtual ~QtElementFactory();
virtual std::shared_ptr<GuiArea> createArea() const;
virtual std::shared_ptr<GuiCanvas> createCanvas(std::shared_ptr<GuiWindow> window) const;
virtual std::shared_ptr<GuiLayout> createLayout() const;
virtual std::shared_ptr<CodeView> createCodeView(std::shared_ptr<ViewManager> viewManager) const;
};
# endif // QT_ELEMENT_FACTORY_H
+22
View File
@@ -0,0 +1,22 @@
#include "qt/QtGuiFactory.h"
#include "qt/view/QtCodeView.h"
#include "qt/view/QtMainView.h"
QtGuiFactory::QtGuiFactory()
{
}
QtGuiFactory::~QtGuiFactory()
{
}
std::shared_ptr<MainView> QtGuiFactory::createMainView() const
{
return std::make_shared<QtMainView>();
}
std::shared_ptr<CodeView> QtGuiFactory::createCodeView(ViewLayout* viewLayout) const
{
return View::create<QtCodeView>(viewLayout);
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef QT_GUI_FACTORY_H
#define QT_GUI_FACTORY_H
#include "gui/GuiFactory.h"
class QtGuiFactory: public GuiFactory
{
public:
QtGuiFactory();
virtual ~QtGuiFactory();
virtual std::shared_ptr<MainView> createMainView() const;
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const;
};
#endif // QT_GUI_FACTORY_H
+14 -15
View File
@@ -1,26 +1,25 @@
#include "qt/QtWidgetWrapper.h"
#include "gui/GuiElement.h"
#include "component/view/View.h"
#include "utility/logging/logging.h"
std::shared_ptr<QWidget> QtWidgetWrapper::getWidgetOfElement(std::shared_ptr<GuiElement> element)
QWidget* QtWidgetWrapper::getWidgetOfView(View* view)
{
return getWidgetOfElement(element.get());
}
QtWidgetWrapper* widgetWrapper = dynamic_cast<QtWidgetWrapper*>(view->getWidgetWrapper());
std::shared_ptr<QWidget> QtWidgetWrapper::getWidgetOfElement(GuiElement* element)
{
std::shared_ptr<QWidget> widget;
std::shared_ptr<QtWidgetWrapper> qtWidgetWrapper = std::dynamic_pointer_cast<QtWidgetWrapper>(element->getWidgetWrapper());
if (!qtWidgetWrapper || qtWidgetWrapper.use_count() == 0)
if (!widgetWrapper)
{
LOG_ERROR("Trying to get the qt widget of non qt gui element.");
LOG_ERROR("Trying to get the qt widget of non qt view.");
return nullptr;
}
else
if (!widgetWrapper->getWidget())
{
widget = qtWidgetWrapper->getWidget();
LOG_ERROR("The QtWidgetWrapper is not holdling a QWidget.");
return nullptr;
}
return widget;
return widgetWrapper->getWidget();
}
QtWidgetWrapper::QtWidgetWrapper(std::shared_ptr<QWidget> widget)
@@ -32,7 +31,7 @@ QtWidgetWrapper::~QtWidgetWrapper()
{
}
std::shared_ptr<QWidget> QtWidgetWrapper::getWidget()
QWidget* QtWidgetWrapper::getWidget()
{
return m_widget;
return m_widget.get();
}
+5 -6
View File
@@ -5,20 +5,19 @@
#include <QtWidgets/qwidget.h>
#include "gui/WidgetWrapper.h"
#include "gui/GuiWidgetWrapper.h"
class GuiElement;
class View;
class QtWidgetWrapper: public WidgetWrapper
class QtWidgetWrapper: public GuiWidgetWrapper
{
public:
static std::shared_ptr<QWidget> getWidgetOfElement(std::shared_ptr<GuiElement> element);
static std::shared_ptr<QWidget> getWidgetOfElement(GuiElement* element);
static QWidget* getWidgetOfView(View* view);
QtWidgetWrapper(std::shared_ptr<QWidget> widget);
virtual ~QtWidgetWrapper();
std::shared_ptr<QWidget> getWidget(); // not const because returned widget can be changed.
QWidget* getWidget();
private:
std::shared_ptr<QWidget> m_widget;
-19
View File
@@ -1,19 +0,0 @@
#include "qt/QtWindow.h"
#include "gui/GuiCanvas.h"
#include "QtWidgetWrapper.h"
QtWindow::QtWindow()
{
m_window.setObjectName("QtWindow");
m_window.show();
}
QtWindow::~QtWindow()
{
}
void QtWindow::setCanvas(std::shared_ptr<GuiCanvas> canvas)
{
m_window.setCentralWidget(QtWidgetWrapper::getWidgetOfElement(canvas).get());
}
-24
View File
@@ -1,24 +0,0 @@
#ifndef QT_WINDOW_H
#define QT_WINDOW_H
#include <memory>
#include <QtWidgets/QMainWindow>
#include "gui/GuiWindow.h"
class GuiCanvas;
class QtWindow: public GuiWindow
{
public:
QtWindow();
~QtWindow();
void setCanvas(std::shared_ptr<GuiCanvas> canvas);
private:
QMainWindow m_window;
};
# endif // QT_WINDOW_H
-43
View File
@@ -1,43 +0,0 @@
#include "qt/element/QtArea.h"
#include <qframe.h>
#include "qt/QtWidgetWrapper.h"
#include "utility/utilityQt.h"
QtArea::QtArea()
: GuiArea(std::make_shared<QtWidgetWrapper>(std::make_shared<QFrame>()))
{
}
QtArea::~QtArea()
{
}
void QtArea::setPosition(Vec2i position)
{
}
Vec2i QtArea::getPosition() const
{
return Vec2i();
}
void QtArea::setSize(Vec2i size)
{
}
Vec2i QtArea::getSize() const
{
return Vec2i();
}
void QtArea::setBackgroundColor(Colori color)
{
utility::setWidgetBackgroundColor(getWidget(), color);
}
std::shared_ptr<QWidget> QtArea::getWidget()
{
return QtWidgetWrapper::getWidgetOfElement(this);
}
-25
View File
@@ -1,25 +0,0 @@
#ifndef QT_AREA_H
#define QT_AREA_H
#include <qwidget.h>
#include "gui/GuiArea.h"
class QtArea: public GuiArea
{
public:
QtArea();
virtual ~QtArea();
virtual void setPosition(Vec2i position);
virtual Vec2i getPosition() const;
virtual void setSize(Vec2i size);
virtual Vec2i getSize() const;
virtual void setBackgroundColor(Colori color);
private:
std::shared_ptr<QWidget> getWidget();
};
# endif // QT_AREA_H
-59
View File
@@ -1,59 +0,0 @@
#include "qt/element/QtCanvas.h"
#include <qgroupbox.h>
#include <qlayout.h>
#include "qt/QtWidgetWrapper.h"
#include "utility/utilityQt.h"
QtCanvas::QtCanvas()
: GuiCanvas(std::make_shared<QtWidgetWrapper>(std::make_shared<QGroupBox>()))
{
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); // gets deleted by qt
getWidget()->setLayout(layout);
}
QtCanvas::~QtCanvas()
{
}
void QtCanvas::addChild(std::shared_ptr<GuiElement> element)
{
getWidget()->layout()->addWidget(QtWidgetWrapper::getWidgetOfElement(element).get());
}
void QtCanvas::removeChild(std::shared_ptr<GuiElement> element)
{
std::shared_ptr<QWidget> widgetToRemove = QtWidgetWrapper::getWidgetOfElement(element);
getWidget()->layout()->removeWidget(widgetToRemove.get());
widgetToRemove->setGeometry(0, 0, 0, 0);
}
void QtCanvas::setPosition(Vec2i position)
{
}
Vec2i QtCanvas::getPosition() const
{
return Vec2i();
}
void QtCanvas::setSize(Vec2i size)
{
}
Vec2i QtCanvas::getSize() const
{
return Vec2i();
}
void QtCanvas::setBackgroundColor(Colori color)
{
utility::setWidgetBackgroundColor(getWidget(), color);
}
std::shared_ptr<QWidget> QtCanvas::getWidget()
{
return QtWidgetWrapper::getWidgetOfElement(this);
}
-29
View File
@@ -1,29 +0,0 @@
#ifndef QT_CANVAS_H
#define QT_CANVAS_H
#include <qwidget.h>
#include <QtWidgets/QMainWindow>
#include "gui/GuiCanvas.h"
class QtCanvas: public GuiCanvas
{
public:
QtCanvas();
virtual ~QtCanvas();
virtual void addChild(std::shared_ptr<GuiElement> element);
virtual void removeChild(std::shared_ptr<GuiElement> element);
virtual void setPosition(Vec2i position);
virtual Vec2i getPosition() const;
virtual void setSize(Vec2i size);
virtual Vec2i getSize() const;
virtual void setBackgroundColor(Colori color);
private:
std::shared_ptr<QWidget> getWidget();
};
# endif // QT_CANVAS_H
-70
View File
@@ -1,70 +0,0 @@
#include "qt/element/QtLayout.h"
#include <qgroupbox.h>
#include <qlayout.h>
#include "qt/QtWidgetWrapper.h"
#include "utility/utilityQt.h"
QtLayout::QtLayout()
: GuiLayout(std::make_shared<QtWidgetWrapper>(std::make_shared<QGroupBox>()))
{
m_layout = new QBoxLayout(QBoxLayout::TopToBottom); // gets deleted by qt
getWidget()->setLayout(m_layout);
}
QtLayout::~QtLayout()
{
}
void QtLayout::setDirection(LayoutDirectionType direction)
{
switch (direction)
{
case LAYOUT_DIRECTION_HORIZONTAL:
m_layout->setDirection(QBoxLayout::LeftToRight);
case LAYOUT_DIRECTION_VERTICAL:
m_layout->setDirection(QBoxLayout::TopToBottom);
}
getWidget()->setLayout(m_layout);
}
void QtLayout::addChild(std::shared_ptr<GuiElement> element)
{
m_layout->addWidget(QtWidgetWrapper::getWidgetOfElement(element).get());
}
void QtLayout::removeChild(std::shared_ptr<GuiElement> element)
{
std::shared_ptr<QWidget> widgetToRemove = QtWidgetWrapper::getWidgetOfElement(element);
m_layout->removeWidget(widgetToRemove.get());
widgetToRemove->setGeometry(0, 0, 0, 0);
}
void QtLayout::setPosition(Vec2i position)
{
}
Vec2i QtLayout::getPosition() const
{
return Vec2i();
}
void QtLayout::setSize(Vec2i size)
{
}
Vec2i QtLayout::getSize() const
{
return Vec2i();
}
void QtLayout::setBackgroundColor(Colori color)
{
utility::setWidgetBackgroundColor(getWidget(), color);
}
std::shared_ptr<QWidget> QtLayout::getWidget()
{
return QtWidgetWrapper::getWidgetOfElement(this);
}
-33
View File
@@ -1,33 +0,0 @@
#ifndef QT_LAYOUT_H
#define QT_LAYOUT_H
#include <qwidget.h>
#include <qlayout.h>
#include "gui/GuiLayout.h"
class QtLayout: public GuiLayout
{
public:
QtLayout();
virtual ~QtLayout();
virtual void setDirection(LayoutDirectionType direction);
virtual void addChild(std::shared_ptr<GuiElement> element);
virtual void removeChild(std::shared_ptr<GuiElement> element);
virtual void setPosition(Vec2i position);
virtual Vec2i getPosition() const;
virtual void setSize(Vec2i size);
virtual Vec2i getSize() const;
virtual void setBackgroundColor(Colori color);
private:
std::shared_ptr<QWidget> getWidget();
QBoxLayout* m_layout;
};
# endif // QT_LAYOUT_H
+37
View File
@@ -0,0 +1,37 @@
#include "qt/element/QtMainWindow.h"
#include <QDockWidget>
#include "component/view/View.h"
#include "qt/QtWidgetWrapper.h"
QtMainWindow::QtMainWindow()
{
setObjectName("QtMainWindow");
setCentralWidget(nullptr);
}
QtMainWindow::~QtMainWindow()
{
}
void QtMainWindow::addView(View* view)
{
QDockWidget* dock = new QDockWidget(tr(view->getName().c_str()), this);
dock->setWidget(QtWidgetWrapper::getWidgetOfView(view));
addDockWidget(Qt::TopDockWidgetArea, dock);
m_dockWidgets.push_back(std::make_pair(view, dock));
}
void QtMainWindow::removeView(View* view)
{
for (size_t i = 0; i < m_dockWidgets.size(); i++)
{
if (m_dockWidgets[i].first == view)
{
removeDockWidget(m_dockWidgets[i].second);
m_dockWidgets.erase(m_dockWidgets.begin() + i);
return;
}
}
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef QT_MAIN_WINDOW_H
#define QT_MAIN_WINDOW_H
#include <utility>
#include <vector>
#include <QtWidgets/QMainWindow>
class QDockWidget;
class View;
class QtMainWindow: public QMainWindow
{
Q_OBJECT
public:
QtMainWindow();
~QtMainWindow();
void addView(View* view);
void removeView(View* view);
private:
std::vector<std::pair<View*, QDockWidget*> > m_dockWidgets;
};
#endif // QT_MAIN_WINDOW_H
@@ -2,7 +2,7 @@
namespace utility
{
void setWidgetBackgroundColor(std::shared_ptr<QWidget> widget, const Colori& color)
void setWidgetBackgroundColor(QWidget* widget, const Colori& color)
{
QPalette palette = widget->palette();
palette.setColor(widget->backgroundRole(), QColor(color.r, color.g, color.b, color.a));
@@ -10,4 +10,3 @@ namespace utility
widget->setAutoFillBackground(true);
}
}
@@ -8,7 +8,7 @@
namespace utility
{
void setWidgetBackgroundColor(std::shared_ptr<QWidget> widget, const Colori& color);
void setWidgetBackgroundColor(QWidget* widget, const Colori& color);
}
# endif // UTILITY_QT_H
+19 -10
View File
@@ -2,16 +2,29 @@
#include <QtWidgets>
#include "qt/element/QtArea.h"
#include "qt/QtWidgetWrapper.h"
#include "qt/utility/QtHighLighter.h"
#include "qt/utility/utilityQt.h"
QtCodeView::QtCodeView(std::shared_ptr<ViewManager> viewManager)
: CodeView(viewManager, std::make_shared<QtArea>())
QtCodeView::QtCodeView(ViewLayout* viewLayout)
: CodeView(viewLayout)
{
getRootElement()->setBackgroundColor(255, 125, 0, 255);
}
QtCodeView::~QtCodeView()
{
}
void QtCodeView::createWidgetWrapper()
{
setWidgetWrapper(std::make_shared<QtWidgetWrapper>(std::make_shared<QFrame>()));
}
void QtCodeView::initGui()
{
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
utility::setWidgetBackgroundColor(widget, Colori(255, 125, 0, 255));
std::shared_ptr<QWidget> widget = QtWidgetWrapper::getWidgetOfElement(getRootElement());
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
layout->setSpacing(3);
layout->setContentsMargins(3, 3, 3, 3);
@@ -22,10 +35,6 @@ QtCodeView::QtCodeView(std::shared_ptr<ViewManager> viewManager)
m_font.setPointSize(10);
}
QtCodeView::~QtCodeView()
{
}
void QtCodeView::addCodeSnippet(std::string str)
{
std::shared_ptr<Snippet> snippet = std::make_shared<Snippet>();
@@ -38,7 +47,7 @@ void QtCodeView::addCodeSnippet(std::string str)
snippet->textField->setPlainText(QString::fromUtf8(str.c_str()));
std::shared_ptr<QWidget> widget = QtWidgetWrapper::getWidgetOfElement(getRootElement());
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
widget->layout()->addWidget(snippet->textField.get());
m_snippets.push_back(snippet);
+5 -3
View File
@@ -3,7 +3,6 @@
#include <memory>
#include <vector>
#include <iostream>
#include <QFont>
@@ -11,14 +10,17 @@
class QtHighlighter;
class QTextEdit;
class ViewManager;
class QtCodeView: public CodeView
{
public:
QtCodeView(std::shared_ptr<ViewManager> viewManager);
QtCodeView(ViewLayout* viewLayout);
~QtCodeView();
// View implementation
virtual void createWidgetWrapper();
virtual void initGui();
// CodeView implementation
virtual void addCodeSnippet(std::string str);
virtual void clearCodeSnippets();
+33
View File
@@ -0,0 +1,33 @@
#include "qt/view/QtMainView.h"
#include "qt/element/QtMainWindow.h"
#include "utility/logging/logging.h"
QtMainView::QtMainView()
{
m_window = new QtMainWindow();
m_window->show();
}
QtMainView::~QtMainView()
{
}
void QtMainView::addView(View* view)
{
m_views.push_back(view);
m_window->addView(view);
}
void QtMainView::removeView(View* view)
{
std::vector<View*>::iterator it = std::find(m_views.begin(), m_views.end(), view);
if (it == m_views.end())
{
LOG_ERROR("View was not found.");
return;
}
m_window->removeView(view);
m_views.erase(it);
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef QT_MAIN_VIEW_H
#define QT_MAIN_VIEW_H
#include <memory>
#include <vector>
#include "component/view/MainView.h"
class QtMainWindow;
class View;
class QtMainView: public MainView
{
public:
QtMainView();
virtual ~QtMainView();
// ViewLayout implementation
void addView(View* view);
void removeView(View* view);
private:
QtMainWindow* m_window;
std::vector<View*> m_views;
};
#endif // QT_MAIN_VIEW_H
+7 -7
View File
@@ -1,23 +1,23 @@
#include "Application.h"
#include "gui/GuiCanvas.h"
#include "component/view/MainView.h"
#include "gui/GuiFactory.h"
#include "utility/logging/ConsoleLogger.h"
#include "utility/logging/LogManager.h"
std::shared_ptr<Application> Application::create(std::shared_ptr<GuiElementFactory> guiElementFactory, std::shared_ptr<GuiWindow> window)
std::shared_ptr<Application> Application::create(GuiFactory* guiFactory)
{
std::shared_ptr<ConsoleLogger> consoleLogger = std::make_shared<ConsoleLogger>();
LogManager::getInstance()->addLogger(consoleLogger);
std::shared_ptr<GuiCanvas> canvas = guiElementFactory->createCanvas(window);
canvas->setBackgroundColor(255, 0, 0, 255);
std::shared_ptr<Application> ptr(new Application());
ptr->m_viewManager = std::make_shared<ViewManager>(canvas);
ptr->m_codeAccess = std::make_shared<CodeAccess>();
ptr->m_graphAccess = std::make_shared<GraphAccess>();
ptr->m_mainView = guiFactory->createMainView();
ptr->m_componentManager =
ComponentManager::create(ptr->m_viewManager, guiElementFactory, ptr->m_codeAccess, ptr->m_graphAccess);
ComponentManager::create(guiFactory, ptr->m_mainView.get(), ptr->m_codeAccess, ptr->m_graphAccess);
return ptr;
}
+5 -5
View File
@@ -4,16 +4,17 @@
#include <memory>
#include "component/ComponentManager.h"
#include "component/view/ViewManager.h"
#include "data/access/CodeAccess.h"
#include "data/access/GraphAccess.h"
#include "gui/GuiElementFactory.h"
#include "Project.h"
class GuiFactory;
class MainView;
class Application
{
public:
static std::shared_ptr<Application> create(std::shared_ptr<GuiElementFactory> guiElementFactory, std::shared_ptr<GuiWindow> window);
static std::shared_ptr<Application> create(GuiFactory* guiFactory);
~Application();
@@ -27,9 +28,8 @@ private:
std::shared_ptr<CodeAccess> m_codeAccess;
std::shared_ptr<GraphAccess> m_graphAccess;
std::shared_ptr<MainView> m_mainView;
std::shared_ptr<ComponentManager> m_componentManager;
std::shared_ptr<ViewManager> m_viewManager;
};
#endif // APPLICATION_H
+10 -26
View File
@@ -20,17 +20,15 @@ add_files(
component/controller/CodeController.h
component/controller/Controller.cpp
component/controller/Controller.h
component/controller/DummyController.cpp
component/controller/DummyController.h
component/view/CodeView.cpp
component/view/CodeView.h
component/view/DummyView.cpp
component/view/DummyView.h
component/view/MainView.cpp
component/view/MainView.h
component/view/View.cpp
component/view/View.h
component/view/ViewManager.cpp
component/view/ViewManager.h
component/view/ViewLayout.cpp
component/view/ViewLayout.h
component/Component.cpp
component/Component.h
@@ -78,27 +76,11 @@ add_files(
data/Storage.cpp
data/Storage.h
gui/GuiArea.cpp
gui/GuiArea.h
gui/GuiCanvas.cpp
gui/GuiCanvas.h
gui/GuiContainer.cpp
gui/GuiContainer.h
gui/GuiControl.cpp
gui/GuiControl.h
gui/GuiElement.cpp
gui/GuiElement.h
gui/GuiElementFactory.cpp
gui/GuiElementFactory.h
gui/GuiLayout.cpp
gui/GuiLayout.h
gui/GuiWindow.cpp
gui/GuiWindow.h
gui/WidgetWrapper.cpp
gui/WidgetWrapper.h
gui/GuiFactory.cpp
gui/GuiFactory.h
gui/GuiWidgetWrapper.cpp
gui/GuiWidgetWrapper.h
utility/logging/PlainFileLogger.cpp
utility/logging/PlainFileLogger.h
utility/logging/ConsoleLogger.cpp
utility/logging/ConsoleLogger.h
utility/logging/FileLogger.cpp
@@ -111,6 +93,8 @@ add_files(
utility/logging/LogManagerImplementation.cpp
utility/logging/LogManagerImplementation.h
utility/logging/LogMessage.h
utility/logging/PlainFileLogger.cpp
utility/logging/PlainFileLogger.h
utility/math/Color.h
utility/math/Vector2.h
+7 -16
View File
@@ -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);
+7 -7
View File
@@ -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;
+8 -9
View File
@@ -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()
{
}
+7 -6
View File
@@ -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
+7 -2
View File
@@ -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";
}
+3 -5
View File
@@ -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;
};
-15
View File
@@ -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()
{
}
-19
View File
@@ -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
+9
View File
@@ -0,0 +1,9 @@
#include "component/view/MainView.h"
MainView::MainView()
{
}
MainView::~MainView()
{
}
+13
View File
@@ -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
+17 -11
View File
@@ -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)
{
}
+32 -6
View File
@@ -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
+9
View File
@@ -0,0 +1,9 @@
#include "component/view/ViewLayout.h"
ViewLayout::ViewLayout()
{
}
ViewLayout::~ViewLayout()
{
}
+16
View File
@@ -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
-31
View File
@@ -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);
}
}
-25
View File
@@ -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
-10
View File
@@ -1,10 +0,0 @@
#include "gui/GuiArea.h"
GuiArea::GuiArea(std::shared_ptr<WidgetWrapper> widgetWrapper)
: GuiControl(widgetWrapper)
{
}
GuiArea::~GuiArea()
{
}
-14
View File
@@ -1,14 +0,0 @@
#ifndef GUI_AREA_H
#define GUI_AREA_H
#include "gui/GuiControl.h"
class GuiArea: public GuiControl
{
public:
GuiArea(std::shared_ptr<WidgetWrapper> widgetWrapper);
virtual ~GuiArea();
};
#endif // GUI_AREA_H
-10
View File
@@ -1,10 +0,0 @@
#include "gui/GuiCanvas.h"
GuiCanvas::GuiCanvas(std::shared_ptr<WidgetWrapper> widgetWrapper)
: GuiContainer(widgetWrapper)
{
}
GuiCanvas::~GuiCanvas()
{
}
-13
View File
@@ -1,13 +0,0 @@
#ifndef GUI_CANVAS_H
#define GUI_CANVAS_H
#include "gui/GuiContainer.h"
class GuiCanvas: public GuiContainer
{
public:
GuiCanvas(std::shared_ptr<WidgetWrapper> widgetWrapper);
virtual ~GuiCanvas();
};
#endif // GUI_CANVAS_H
-10
View File
@@ -1,10 +0,0 @@
#include "gui/GuiContainer.h"
GuiContainer::GuiContainer(std::shared_ptr<WidgetWrapper> widgetWrapper)
: GuiElement(widgetWrapper)
{
}
GuiContainer::~GuiContainer()
{
}
-19
View File
@@ -1,19 +0,0 @@
#ifndef GUI_CONTAINER_H
#define GUI_CONTAINER_H
#include <vector>
#include "gui/GuiElement.h"
class GuiContainer: public GuiElement
{
public:
GuiContainer(std::shared_ptr<WidgetWrapper> widgetWrapper);
virtual ~GuiContainer();
virtual void addChild(std::shared_ptr<GuiElement> element) = 0;
virtual void removeChild(std::shared_ptr<GuiElement> element) = 0;
};
#endif // GUI_CONTAINER_H
-10
View File
@@ -1,10 +0,0 @@
#include "gui/GuiControl.h"
GuiControl::GuiControl(std::shared_ptr<WidgetWrapper> widgetWrapper)
: GuiElement(widgetWrapper)
{
}
GuiControl::~GuiControl()
{
}
-14
View File
@@ -1,14 +0,0 @@
#ifndef GUI_CONTROL_H
#define GUI_CONTROL_H
#include "gui/GuiElement.h"
class GuiControl: public GuiElement
{
public:
GuiControl(std::shared_ptr<WidgetWrapper> widgetWrapper);
virtual ~GuiControl();
};
#endif // GUI_CONTROL_H
-22
View File
@@ -1,22 +0,0 @@
#include "gui/GuiElement.h"
#include "gui/WidgetWrapper.h"
GuiElement::GuiElement(std::shared_ptr<WidgetWrapper> widgetWrapper)
: m_widgetWrapper(widgetWrapper)
{
}
GuiElement::~GuiElement()
{
}
void GuiElement::setBackgroundColor(int r, int g, int b, int a)
{
setBackgroundColor(Colori(r, g, b, a));
}
std::shared_ptr<WidgetWrapper> GuiElement::getWidgetWrapper()
{
return m_widgetWrapper;
}
-32
View File
@@ -1,32 +0,0 @@
#ifndef GUI_ELEMENT_H
#define GUI_ELEMENT_H
#include <memory>
#include "utility/math/Color.h"
#include "utility/math/Vector2.h"
class WidgetWrapper;
class GuiElement
{
public:
GuiElement(std::shared_ptr<WidgetWrapper> widgetWrapper);
virtual ~GuiElement();
virtual void setPosition(Vec2i position) = 0;
virtual Vec2i getPosition() const = 0;
virtual void setSize(Vec2i size) = 0;
virtual Vec2i getSize() const = 0;
virtual void setBackgroundColor(Colori color) = 0;
void setBackgroundColor(int r, int g, int b, int a);
//protected:
std::shared_ptr<WidgetWrapper> getWidgetWrapper();
private:
std::shared_ptr<WidgetWrapper> m_widgetWrapper;
};
#endif // GUI_ELEMENT_H
-5
View File
@@ -1,5 +0,0 @@
#include "gui/GuiElementFactory.h"
GuiElementFactory::~GuiElementFactory()
{
}
-27
View File
@@ -1,27 +0,0 @@
#ifndef GUI_ELEMENT_FACTORY_H
#define GUI_ELEMENT_FACTORY_H
#include <memory>
class CodeView;
class GuiArea;
class GuiCanvas;
class GuiLayout;
class GuiWindow;
class ViewManager;
class GuiElementFactory
{
public:
virtual ~GuiElementFactory();
virtual std::shared_ptr<GuiArea> createArea() const = 0;
virtual std::shared_ptr<GuiCanvas> createCanvas(std::shared_ptr<GuiWindow> window) const = 0;
virtual std::shared_ptr<GuiLayout> createLayout() const = 0;
virtual std::shared_ptr<CodeView> createCodeView(std::shared_ptr<ViewManager> viewManager) const = 0;
};
#endif // GUI_ELEMENT_FACTORY_H
+9
View File
@@ -0,0 +1,9 @@
#include "gui/GuiFactory.h"
GuiFactory::GuiFactory()
{
}
GuiFactory::~GuiFactory()
{
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef GUI_FACTORY_H
#define GUI_FACTORY_H
#include <memory>
class CodeView;
class MainView;
class ViewLayout;
class GuiFactory
{
public:
GuiFactory();
virtual ~GuiFactory();
virtual std::shared_ptr<MainView> createMainView() const = 0;
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const = 0;
};
#endif // GUI_FACTORY_H
-10
View File
@@ -1,10 +0,0 @@
#include "gui/GuiLayout.h"
GuiLayout::GuiLayout(std::shared_ptr<WidgetWrapper> widgetWrapper)
: GuiContainer(widgetWrapper)
{
}
GuiLayout::~GuiLayout()
{
}
-24
View File
@@ -1,24 +0,0 @@
#ifndef GUI_LAYOUT_H
#define GUI_LAYOUT_H
#include "gui/GuiContainer.h"
class GuiLayout: public GuiContainer
{
public:
enum LayoutDirectionType
{
LAYOUT_DIRECTION_HORIZONTAL,
LAYOUT_DIRECTION_VERTICAL
};
GuiLayout(std::shared_ptr<WidgetWrapper> widgetWrapper);
virtual ~GuiLayout();
virtual void setDirection(LayoutDirectionType direction) = 0;
virtual void addChild(std::shared_ptr<GuiElement> element) = 0;
virtual void removeChild(std::shared_ptr<GuiElement> element) = 0;
};
#endif // GUI_LAYOUT_H
+9
View File
@@ -0,0 +1,9 @@
#include "gui/GuiWidgetWrapper.h"
GuiWidgetWrapper::GuiWidgetWrapper()
{
}
GuiWidgetWrapper::~GuiWidgetWrapper()
{
}
+11
View File
@@ -0,0 +1,11 @@
#ifndef GUI_WIDGET_WRAPPER_H
#define GUI_WIDGET_WRAPPER_H
class GuiWidgetWrapper
{
public:
GuiWidgetWrapper();
virtual ~GuiWidgetWrapper();
};
#endif // GUI_WIDGET_WRAPPER_H
-11
View File
@@ -1,11 +0,0 @@
#include "gui/GuiWindow.h"
#include "gui/GuiCanvas.h"
GuiWindow::GuiWindow()
{
}
GuiWindow::~GuiWindow()
{
}
-17
View File
@@ -1,17 +0,0 @@
#ifndef GUI_WINDOW_H
#define GUI_WINDOW_H
#include <memory>
class GuiCanvas;
class GuiWindow
{
public:
GuiWindow();
virtual ~GuiWindow();
virtual void setCanvas(std::shared_ptr<GuiCanvas> canvas) = 0;
};
#endif // GUI_WINDOW_H
-9
View File
@@ -1,9 +0,0 @@
#include "gui/WidgetWrapper.h"
WidgetWrapper::WidgetWrapper()
{
}
WidgetWrapper::~WidgetWrapper()
{
}
-11
View File
@@ -1,11 +0,0 @@
#ifndef WIDGET_WRAPPER_H
#define WIDGET_WRAPPER_H
class WidgetWrapper
{
public:
WidgetWrapper();
virtual ~WidgetWrapper();
};
#endif // WIDGET_WRAPPER_H