logic: code controller communication
- Replaced CodeAccess with LocationAccess. - Implemented basic functionality for CodeController. - Added messaging to the project. - Added QtThreadedFunctor to enable our Messaging thread to invoke calls on the QtThread. - Added GraphController. fortune cookie message = Good news from someone dear is coming soon.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
int main()
|
||||
{
|
||||
int a = 6;
|
||||
int b = 7;
|
||||
int c = a * b;
|
||||
return 0;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ add_files(
|
||||
|
||||
qt/utility/QtHighLighter.cpp
|
||||
qt/utility/QtHighLighter.h
|
||||
qt/utility/QtThreadedFunctor.h
|
||||
qt/utility/utilityQt.cpp
|
||||
qt/utility/utilityQt.h
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
#ifndef QT_THREADED_FUCTOR_H
|
||||
#define QT_THREADED_FUCTOR_H
|
||||
|
||||
#include <functional>
|
||||
#include <QObject>
|
||||
|
||||
class QtThreadedFunctorHelper: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void signalExecution();
|
||||
|
||||
private slots:
|
||||
void execute()
|
||||
{
|
||||
m_callback();
|
||||
}
|
||||
|
||||
public:
|
||||
QtThreadedFunctorHelper()
|
||||
{
|
||||
QObject::connect(this, SIGNAL(signalExecution()), this, SLOT(execute()));
|
||||
}
|
||||
|
||||
void operator()(std::function<void(void)> callback)
|
||||
{
|
||||
m_callback = callback;
|
||||
signalExecution();
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void(void)> m_callback;
|
||||
};
|
||||
|
||||
template <typename T1 = void, typename T2 = void, typename T3 = void>
|
||||
class QtThreadedFunctor
|
||||
{
|
||||
public:
|
||||
QtThreadedFunctor(std::function<void(T1, T2, T3)> callback) : m_callback(callback) {}
|
||||
|
||||
void operator()(T1 p1, T2 p2, T3 p3)
|
||||
{
|
||||
m_helper(std::bind(m_callback, p1, p2, p3));
|
||||
}
|
||||
|
||||
private:
|
||||
QtThreadedFunctorHelper m_helper;
|
||||
std::function<void(T1, T2, T3)> m_callback;
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
class QtThreadedFunctor<T1, T2, void>
|
||||
{
|
||||
public:
|
||||
QtThreadedFunctor(std::function<void(T1, T2)> callback) : m_callback(callback) {}
|
||||
|
||||
void operator()(T1 p1, T2 p2)
|
||||
{
|
||||
m_helper(std::bind(m_callback, p1, p2));
|
||||
}
|
||||
|
||||
private:
|
||||
QtThreadedFunctorHelper m_helper;
|
||||
std::function<void(T1, T2)> m_callback;
|
||||
};
|
||||
|
||||
template <typename T1>
|
||||
class QtThreadedFunctor<T1, void, void>
|
||||
{
|
||||
public:
|
||||
QtThreadedFunctor(std::function<void(T1)> callback) : m_callback(callback) {}
|
||||
|
||||
void operator()(T1 p1)
|
||||
{
|
||||
m_helper(std::bind(m_callback, p1));
|
||||
}
|
||||
|
||||
private:
|
||||
QtThreadedFunctorHelper m_helper;
|
||||
std::function<void(T1)> m_callback;
|
||||
};
|
||||
|
||||
template <>
|
||||
class QtThreadedFunctor<void, void, void>
|
||||
{
|
||||
public:
|
||||
QtThreadedFunctor(std::function<void(void)> callback) : m_callback(callback) {}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
m_helper(m_callback);
|
||||
}
|
||||
|
||||
private:
|
||||
QtThreadedFunctorHelper m_helper;
|
||||
std::function<void(void)> m_callback;
|
||||
};
|
||||
|
||||
#endif // QT_THREADED_FUCTOR_H
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||
: CodeView(viewLayout)
|
||||
, m_clearCodeSnippetsFunctor(std::bind(&QtCodeView::doClearCodeSnippets, this))
|
||||
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -36,6 +38,16 @@ void QtCodeView::initGui()
|
||||
}
|
||||
|
||||
void QtCodeView::addCodeSnippet(std::string str)
|
||||
{
|
||||
m_addCodeSnippetFunctor(str);
|
||||
}
|
||||
|
||||
void QtCodeView::clearCodeSnippets()
|
||||
{
|
||||
m_clearCodeSnippetsFunctor();
|
||||
}
|
||||
|
||||
void QtCodeView::doAddCodeSnippet(std::string str)
|
||||
{
|
||||
std::shared_ptr<Snippet> snippet = std::make_shared<Snippet>();
|
||||
|
||||
@@ -53,7 +65,7 @@ void QtCodeView::addCodeSnippet(std::string str)
|
||||
m_snippets.push_back(snippet);
|
||||
}
|
||||
|
||||
void QtCodeView::clearCodeSnippets()
|
||||
void QtCodeView::doClearCodeSnippets()
|
||||
{
|
||||
m_snippets.clear();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <QFont>
|
||||
|
||||
#include "component/view/CodeView.h"
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
|
||||
class QtHighlighter;
|
||||
class QTextEdit;
|
||||
@@ -33,7 +34,13 @@ private:
|
||||
};
|
||||
std::vector<std::shared_ptr<Snippet>> m_snippets;
|
||||
|
||||
void doAddCodeSnippet(std::string str);
|
||||
void doClearCodeSnippets();
|
||||
|
||||
QFont m_font;
|
||||
|
||||
QtThreadedFunctor<void> m_clearCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<std::string> m_addCodeSnippetFunctor;
|
||||
};
|
||||
|
||||
# endif // QT_CODE_VIEW_H
|
||||
|
||||
@@ -1,39 +1,41 @@
|
||||
#include "Application.h"
|
||||
|
||||
#include "component/view/MainView.h"
|
||||
#include "data/Storage.h"
|
||||
#include "gui/GuiFactory.h"
|
||||
#include "utility/logging/ConsoleLogger.h"
|
||||
#include "utility/logging/LogManager.h"
|
||||
#include "utility/messaging/MessageQueue.h"
|
||||
|
||||
std::shared_ptr<Application> Application::create(GuiFactory* guiFactory)
|
||||
{
|
||||
std::shared_ptr<ConsoleLogger> consoleLogger = std::make_shared<ConsoleLogger>();
|
||||
std::shared_ptr<ConsoleLogger> consoleLogger = std::make_shared<ConsoleLogger>(); // TODO: move to main
|
||||
LogManager::getInstance()->addLogger(consoleLogger);
|
||||
|
||||
std::shared_ptr<Application> ptr(new Application());
|
||||
|
||||
ptr->m_codeAccess = std::make_shared<CodeAccess>();
|
||||
ptr->m_graphAccess = std::make_shared<GraphAccess>();
|
||||
ptr->m_storage = std::make_shared<Storage>();
|
||||
|
||||
ptr->m_mainView = guiFactory->createMainView();
|
||||
ptr->m_componentManager =
|
||||
ComponentManager::create(guiFactory, ptr->m_mainView.get(), ptr->m_codeAccess, ptr->m_graphAccess);
|
||||
ComponentManager::create(guiFactory, ptr->m_mainView.get(), ptr->m_storage, ptr->m_storage);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Application::Application()
|
||||
{
|
||||
MessageQueue::getInstance()->startMessageLoopThreaded();
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
MessageQueue::getInstance()->stopMessageLoop();
|
||||
}
|
||||
|
||||
void Application::loadProject()
|
||||
{
|
||||
m_componentManager->setup();
|
||||
m_project = Project::create(m_codeAccess, m_graphAccess);
|
||||
m_project = Project::create(m_storage);
|
||||
|
||||
m_project->loadProjectSettings("data/ProjectSettings.xml");
|
||||
m_project->parseCode();
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
#include <memory>
|
||||
|
||||
#include "component/ComponentManager.h"
|
||||
#include "data/access/CodeAccess.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
#include "Project.h"
|
||||
|
||||
class GuiFactory;
|
||||
class MainView;
|
||||
class Storage;
|
||||
|
||||
class Application
|
||||
{
|
||||
@@ -24,9 +23,7 @@ private:
|
||||
Application();
|
||||
|
||||
std::shared_ptr<Project> m_project;
|
||||
|
||||
std::shared_ptr<CodeAccess> m_codeAccess;
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
std::shared_ptr<Storage> m_storage;
|
||||
|
||||
std::shared_ptr<MainView> m_mainView;
|
||||
std::shared_ptr<ComponentManager> m_componentManager;
|
||||
|
||||
@@ -20,6 +20,8 @@ add_files(
|
||||
component/controller/CodeController.h
|
||||
component/controller/Controller.cpp
|
||||
component/controller/Controller.h
|
||||
component/controller/GraphController.cpp
|
||||
component/controller/GraphController.h
|
||||
|
||||
component/view/graphElements/GraphNode.cpp
|
||||
component/view/graphElements/GraphNode.h
|
||||
@@ -42,8 +44,8 @@ add_files(
|
||||
component/ComponentManager.cpp
|
||||
component/ComponentManager.h
|
||||
|
||||
data/access/CodeAccess.cpp
|
||||
data/access/CodeAccess.h
|
||||
data/access/LocationAccess.cpp
|
||||
data/access/LocationAccess.h
|
||||
data/access/GraphAccess.cpp
|
||||
data/access/GraphAccess.h
|
||||
|
||||
@@ -106,6 +108,8 @@ add_files(
|
||||
utility/math/Vector4.h
|
||||
utility/math/VectorBase.h
|
||||
|
||||
utility/messaging/type/MessageActivateTokenLocation.h
|
||||
|
||||
utility/messaging/Message.h
|
||||
utility/messaging/MessageBase.h
|
||||
utility/messaging/MessageListener.h
|
||||
|
||||
+10
-11
@@ -5,19 +5,15 @@
|
||||
|
||||
#include "data/parser/cxx/CxxParser.h"
|
||||
#include "utility/FileSystem.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenLocation.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
std::shared_ptr<Project> Project::create(
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess
|
||||
std::shared_ptr<Storage> storage
|
||||
)
|
||||
{
|
||||
std::shared_ptr<Project> ptr(new Project());
|
||||
ptr->m_codeAccess = codeAccess;
|
||||
ptr->m_graphAccess = graphAccess;
|
||||
|
||||
ptr->m_storage = std::make_shared<Storage>();
|
||||
|
||||
ptr->m_storage = storage;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -38,16 +34,19 @@ void Project::parseCode()
|
||||
{
|
||||
if (ProjectSettings::getInstance()->getSourcePath() != "")
|
||||
{
|
||||
std::vector<std::string> extension;
|
||||
extension.push_back(".cpp");
|
||||
extension.push_back(".h");
|
||||
std::vector<std::string> extensions;
|
||||
extensions.push_back(".cpp");
|
||||
extensions.push_back(".h");
|
||||
|
||||
CxxParser parser(m_storage);
|
||||
parser.parseFiles(
|
||||
FileSystem::getSourceFilesFromDirectory(ProjectSettings::getInstance()->getSourcePath(), extension)
|
||||
FileSystem::getSourceFilesFromDirectory(ProjectSettings::getInstance()->getSourcePath(), extensions)
|
||||
);
|
||||
|
||||
m_storage->logGraph();
|
||||
m_storage->logLocations();
|
||||
|
||||
MessageActivateTokenLocation message;
|
||||
message.dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-6
@@ -3,8 +3,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "data/access/CodeAccess.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
#include "data/Storage.h"
|
||||
#include "ProjectSettings.h"
|
||||
|
||||
@@ -12,8 +10,7 @@ class Project
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<Project> create(
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess
|
||||
std::shared_ptr<Storage> storage
|
||||
);
|
||||
|
||||
~Project();
|
||||
@@ -27,8 +24,6 @@ private:
|
||||
Project operator=(const Project&);
|
||||
|
||||
std::shared_ptr<Storage> m_storage;
|
||||
std::shared_ptr<CodeAccess> m_codeAccess;
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
};
|
||||
|
||||
#endif // PROJECT_H
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
#include "component/Component.h"
|
||||
|
||||
#include "component/view/View.h"
|
||||
#include "component/controller/Controller.h"
|
||||
|
||||
Component::Component(std::shared_ptr<View> view, std::shared_ptr<Controller> controller)
|
||||
: m_controller(controller)
|
||||
, m_view(view)
|
||||
{
|
||||
m_controller->setComponent(this);
|
||||
m_view->setComponent(this);
|
||||
}
|
||||
|
||||
Component::~Component()
|
||||
{
|
||||
}
|
||||
|
||||
Controller* Component::getController() const
|
||||
{
|
||||
return m_controller.get();
|
||||
}
|
||||
|
||||
View* Component::getView() const
|
||||
{
|
||||
return m_view.get();
|
||||
m_controller->setComponent(NULL);
|
||||
m_view->setComponent(NULL);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
#include "component/view/View.h"
|
||||
class View;
|
||||
class Controller;
|
||||
|
||||
class Component
|
||||
{
|
||||
@@ -12,8 +12,11 @@ public:
|
||||
Component(std::shared_ptr<View> view, std::shared_ptr<Controller> controller);
|
||||
~Component();
|
||||
|
||||
Controller* getController() const;
|
||||
View* getView() const;
|
||||
template <typename ControllerType>
|
||||
ControllerType* getController() const;
|
||||
|
||||
template <typename ViewType>
|
||||
ViewType* getView() const;
|
||||
|
||||
private:
|
||||
const std::shared_ptr<Controller> m_controller;
|
||||
@@ -21,4 +24,17 @@ private:
|
||||
};
|
||||
|
||||
|
||||
template <typename ControllerType>
|
||||
ControllerType* Component::getController() const
|
||||
{
|
||||
return dynamic_cast<ControllerType*>(m_controller.get());
|
||||
}
|
||||
|
||||
template <typename ViewType>
|
||||
ViewType* Component::getView() const
|
||||
{
|
||||
return dynamic_cast<ViewType*>(m_view.get());
|
||||
}
|
||||
|
||||
|
||||
#endif // COMPONENT_H
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "component/ComponentFactory.h"
|
||||
|
||||
#include "component/Component.h"
|
||||
#include "component/controller/CodeController.h"
|
||||
#include "component/controller/GraphController.h"
|
||||
#include "component/view/CodeView.h"
|
||||
#include "component/view/GraphView.h"
|
||||
#include "component/view/ViewLayout.h"
|
||||
@@ -9,13 +11,13 @@
|
||||
std::shared_ptr<ComponentFactory> ComponentFactory::create(
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<LocationAccess> locationAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess)
|
||||
{
|
||||
std::shared_ptr<ComponentFactory> ptr(new ComponentFactory());
|
||||
ptr->m_guiFactory = guiFactory;
|
||||
ptr->m_viewLayout = viewLayout;
|
||||
ptr->m_codeAccess = codeAccess;
|
||||
ptr->m_locationAccess = locationAccess;
|
||||
ptr->m_graphAccess = graphAccess;
|
||||
return ptr;
|
||||
}
|
||||
@@ -26,8 +28,8 @@ ComponentFactory::~ComponentFactory()
|
||||
|
||||
std::shared_ptr<Component> ComponentFactory::createCodeComponent()
|
||||
{
|
||||
std::shared_ptr<View> view = m_guiFactory->createCodeView(m_viewLayout);
|
||||
std::shared_ptr<Controller> controller = std::make_shared<CodeController>();
|
||||
std::shared_ptr<CodeView> view = m_guiFactory->createCodeView(m_viewLayout);
|
||||
std::shared_ptr<CodeController> controller = std::make_shared<CodeController>(m_locationAccess);
|
||||
|
||||
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
|
||||
return component;
|
||||
@@ -36,7 +38,7 @@ std::shared_ptr<Component> ComponentFactory::createCodeComponent()
|
||||
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<GraphController> controller = std::make_shared<GraphController>(m_graphAccess);
|
||||
|
||||
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
|
||||
return component;
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "component/Component.h"
|
||||
#include "data/access/CodeAccess.h"
|
||||
#include "data/access/LocationAccess.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
|
||||
class Component;
|
||||
class GuiFactory;
|
||||
class ViewLayout;
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
static std::shared_ptr<ComponentFactory> create(
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<LocationAccess> locationAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess);
|
||||
|
||||
~ComponentFactory();
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
GuiFactory* m_guiFactory;
|
||||
ViewLayout* m_viewLayout;
|
||||
|
||||
std::shared_ptr<CodeAccess> m_codeAccess;
|
||||
std::shared_ptr<LocationAccess> m_locationAccess;
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
std::shared_ptr<ComponentManager> ComponentManager::create(
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<LocationAccess> locationAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess)
|
||||
{
|
||||
std::shared_ptr<ComponentManager> ptr(new ComponentManager());
|
||||
ptr->m_componentFactory = ComponentFactory::create(guiFactory, viewLayout, codeAccess, graphAccess);
|
||||
ptr->m_componentFactory = ComponentFactory::create(guiFactory, viewLayout, locationAccess, graphAccess);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ ComponentManager::~ComponentManager()
|
||||
void ComponentManager::setup()
|
||||
{
|
||||
std::shared_ptr<Component> graphComponent = m_componentFactory->createGraphComponent();
|
||||
GraphView* graphView = dynamic_cast<GraphView*>(graphComponent->getView());
|
||||
GraphView* graphView = graphComponent->getView<GraphView>();
|
||||
graphView->addNode(Vec2i(-100, -100), "foo");
|
||||
graphView->addNode(Vec2i(50, 50), "bar");
|
||||
|
||||
@@ -31,7 +32,7 @@ void ComponentManager::setup()
|
||||
std::shared_ptr<Component> codeComponent = m_componentFactory->createCodeComponent();
|
||||
m_components.push_back(codeComponent);
|
||||
|
||||
CodeView* codeView = dynamic_cast<CodeView*>(codeComponent->getView());
|
||||
CodeView* codeView = codeComponent->getView<CodeView>();
|
||||
codeView->addCodeSnippet("class HelloWorld;");
|
||||
codeView->addCodeSnippet("static int n = 42; // the answer.");
|
||||
// codeView->clearCodeSnippets();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "component/Component.h"
|
||||
#include "component/ComponentFactory.h"
|
||||
#include "data/access/CodeAccess.h"
|
||||
#include "data/access/LocationAccess.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
|
||||
class GuiFactory;
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
static std::shared_ptr<ComponentManager> create(
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<CodeAccess> codeAccess,
|
||||
std::shared_ptr<LocationAccess> locationAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess);
|
||||
|
||||
~ComponentManager();
|
||||
@@ -34,5 +34,4 @@ private:
|
||||
std::vector<std::shared_ptr<Component> > m_components;
|
||||
};
|
||||
|
||||
|
||||
#endif // COMPONENT_MANAGER_H
|
||||
|
||||
@@ -1 +1,39 @@
|
||||
#include "component/controller/CodeController.h"
|
||||
|
||||
#include "component/view/CodeView.h"
|
||||
#include "data/access/LocationAccess.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
|
||||
CodeController::CodeController(std::shared_ptr<LocationAccess> locationAccess)
|
||||
: m_locationAccess(locationAccess)
|
||||
{
|
||||
}
|
||||
|
||||
CodeController::~CodeController()
|
||||
{
|
||||
}
|
||||
|
||||
void CodeController::setActiveTokenLocationId(Id id)
|
||||
{
|
||||
TokenLocation* tokenLocation = m_locationAccess->getTokenLocation(id);
|
||||
if (tokenLocation)
|
||||
{
|
||||
getView()->clearCodeSnippets();
|
||||
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(tokenLocation->getFilePath());
|
||||
getView()->addCodeSnippet(textAccess->getText());
|
||||
}
|
||||
}
|
||||
|
||||
void CodeController::handleMessage(MessageActivateTokenLocation* message)
|
||||
{
|
||||
setActiveTokenLocationId(1);
|
||||
}
|
||||
|
||||
CodeView* CodeController::getView()
|
||||
{
|
||||
return Controller::getView<CodeView>();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,35 @@
|
||||
#ifndef CODE_CONTROLLER_H
|
||||
#define CODE_CONTROLLER_H
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
#include <string>
|
||||
|
||||
class CodeController: public Controller
|
||||
#include "component/controller/Controller.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenLocation.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class CodeView;
|
||||
class LocationAccess;
|
||||
|
||||
struct AnnotatedText
|
||||
{
|
||||
std::string text;
|
||||
Id tokenId;
|
||||
};
|
||||
|
||||
class CodeController: public Controller, public MessageListener<MessageActivateTokenLocation>
|
||||
{
|
||||
public:
|
||||
CodeController(std::shared_ptr<LocationAccess> locationAccess);
|
||||
~CodeController();
|
||||
|
||||
void setActiveTokenLocationId(Id id);
|
||||
|
||||
private:
|
||||
virtual void handleMessage(MessageActivateTokenLocation* message);
|
||||
CodeView* getView();
|
||||
|
||||
std::shared_ptr<LocationAccess> m_locationAccess;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
#include "component/controller/Controller.h"
|
||||
|
||||
Controller::Controller()
|
||||
{
|
||||
}
|
||||
|
||||
Controller::~Controller()
|
||||
{
|
||||
}
|
||||
|
||||
void Controller::setComponent(Component* component)
|
||||
{
|
||||
m_component = component;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,32 @@
|
||||
#ifndef CONTROLLER_H
|
||||
#define CONTROLLER_H
|
||||
|
||||
#include "component/Component.h"
|
||||
|
||||
class Controller
|
||||
{
|
||||
public:
|
||||
Controller();
|
||||
virtual ~Controller();
|
||||
|
||||
void setComponent(Component* component);
|
||||
|
||||
protected:
|
||||
template <typename ViewType>
|
||||
ViewType* getView();
|
||||
|
||||
private:
|
||||
Component* m_component;
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <typename ViewType>
|
||||
ViewType* Controller::getView()
|
||||
{
|
||||
if (m_component)
|
||||
return m_component->getView<ViewType>();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif // CONTROLLER_H
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "component/controller/GraphController.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)
|
||||
{
|
||||
}
|
||||
|
||||
GraphController::~GraphController()
|
||||
{
|
||||
}
|
||||
|
||||
GraphView* GraphController::getView()
|
||||
{
|
||||
return Controller::getView<GraphView>();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef GRAPH_CONTROLLER_H
|
||||
#define GRAPH_CONTROLLER_H
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
|
||||
class GraphView;
|
||||
class GraphAccess;
|
||||
|
||||
class GraphController: public Controller
|
||||
{
|
||||
public:
|
||||
GraphController(std::shared_ptr<GraphAccess> graphAccess);
|
||||
~GraphController();
|
||||
|
||||
private:
|
||||
GraphView* getView();
|
||||
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
};
|
||||
|
||||
|
||||
#endif // GRAPH_CONTROLLER_H
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "component/view/CodeView.h"
|
||||
|
||||
#include "component/controller/CodeController.h"
|
||||
|
||||
CodeView::CodeView(ViewLayout* viewLayout)
|
||||
: View(viewLayout, Vec2i(100, 100))
|
||||
{
|
||||
@@ -13,3 +15,8 @@ std::string CodeView::getName() const
|
||||
{
|
||||
return "CodeView";
|
||||
}
|
||||
|
||||
CodeController* CodeView::getController()
|
||||
{
|
||||
return View::getController<CodeController>();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "component/view/View.h"
|
||||
|
||||
class CodeController;
|
||||
|
||||
class CodeView: public View
|
||||
{
|
||||
public:
|
||||
@@ -13,6 +15,9 @@ public:
|
||||
|
||||
virtual void addCodeSnippet(std::string str) = 0;
|
||||
virtual void clearCodeSnippets() = 0;
|
||||
|
||||
private:
|
||||
CodeController* getController();
|
||||
};
|
||||
|
||||
#endif // CODE_VIEW_H
|
||||
|
||||
@@ -18,6 +18,11 @@ GuiWidgetWrapper* View::getWidgetWrapper()
|
||||
return m_widgetWrapper.get();
|
||||
}
|
||||
|
||||
void View::setComponent(Component* component)
|
||||
{
|
||||
m_component = component;
|
||||
}
|
||||
|
||||
int View::getMinWidth() const
|
||||
{
|
||||
return m_minSize.x;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
class GuiWidgetWrapper;
|
||||
class ViewLayout;
|
||||
class Component;
|
||||
|
||||
class View
|
||||
{
|
||||
@@ -26,14 +27,20 @@ public:
|
||||
|
||||
virtual void initGui() = 0;
|
||||
|
||||
void setComponent(Component* component);
|
||||
|
||||
int getMinWidth() const;
|
||||
int getMinHeight() const;
|
||||
Vec2i getMinSize() const;
|
||||
|
||||
protected:
|
||||
View(ViewLayout* viewLayout, const Vec2i& minSize);
|
||||
View(ViewLayout* viewLayout, const Vec2i& minSize); // make public
|
||||
|
||||
template <typename ControllerType>
|
||||
ControllerType* getController();
|
||||
|
||||
private:
|
||||
Component* m_component;
|
||||
ViewLayout* const m_viewLayout;
|
||||
std::shared_ptr<GuiWidgetWrapper> m_widgetWrapper;
|
||||
Vec2i m_minSize;
|
||||
@@ -52,4 +59,14 @@ std::shared_ptr<T> View::create(ViewLayout* viewLayout)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename ControllerType>
|
||||
ControllerType* View::getController()
|
||||
{
|
||||
if (m_component)
|
||||
{
|
||||
return m_component->getController<ControllerType>();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif // VIEW_H
|
||||
|
||||
@@ -173,6 +173,16 @@ void Storage::logLocations() const
|
||||
LOG_INFO(str.str());
|
||||
}
|
||||
|
||||
Token* Storage::getToken(Id tokenId)
|
||||
{
|
||||
return m_graph.getTokenById(tokenId);
|
||||
}
|
||||
|
||||
TokenLocation* Storage::getTokenLocation(Id locationId)
|
||||
{
|
||||
return m_locationCollection.findTokenLocationById(locationId);
|
||||
}
|
||||
|
||||
Edge::AccessType Storage::convertAccessType(ParserClient::AccessType access) const
|
||||
{
|
||||
switch (access)
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "data/access/GraphAccess.h"
|
||||
#include "data/access/LocationAccess.h"
|
||||
#include "data/graph/Graph.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/parser/ParserClient.h"
|
||||
|
||||
class Storage: public ParserClient
|
||||
class Storage: public ParserClient, public GraphAccess, public LocationAccess
|
||||
{
|
||||
public:
|
||||
Storage();
|
||||
@@ -40,6 +42,9 @@ public:
|
||||
void logGraph() const;
|
||||
void logLocations() const;
|
||||
|
||||
virtual Token* getToken(Id tokenId);
|
||||
virtual TokenLocation* getTokenLocation(Id locationId);
|
||||
|
||||
private:
|
||||
Edge::AccessType convertAccessType(ParserClient::AccessType access) const;
|
||||
TokenLocation* addTokenLocation(Token* token, const ParseLocation& location);
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "data/access/CodeAccess.h"
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef CODE_ACCESS_H
|
||||
#define CODE_ACCESS_H
|
||||
|
||||
class CodeAccess
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
#endif // CODE_ACCESS_H
|
||||
@@ -1 +1,5 @@
|
||||
#include "data/access/GraphAccess.h"
|
||||
|
||||
GraphAccess::~GraphAccess()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
#ifndef GRAPH_ACCESS_H
|
||||
#define GRAPH_ACCESS_H
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class Token;
|
||||
|
||||
class GraphAccess
|
||||
{
|
||||
public:
|
||||
virtual ~GraphAccess();
|
||||
|
||||
virtual Token* getToken(Id tokenId) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "data/access/LocationAccess.h"
|
||||
|
||||
LocationAccess::~LocationAccess()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef LOCATION_ACCESS_H
|
||||
#define LOCATION_ACCESS_H
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocation;
|
||||
|
||||
class LocationAccess
|
||||
{
|
||||
public:
|
||||
virtual ~LocationAccess();
|
||||
virtual TokenLocation* getTokenLocation(Id locationId) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // LOCATION_ACCESS_H
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
Token(const Token&);
|
||||
void operator=(const Token&);
|
||||
|
||||
const Id m_id;
|
||||
const Id m_id; // own id
|
||||
|
||||
std::vector<Id> m_locationIds;
|
||||
};
|
||||
|
||||
@@ -40,9 +40,9 @@ public:
|
||||
std::shared_ptr<TokenLocation> createPlainCopy(TokenLocationLine* line) const;
|
||||
|
||||
private:
|
||||
static Id s_locationId;
|
||||
static Id s_locationId; // next free own id
|
||||
|
||||
const Id m_id;
|
||||
const Id m_id; // own id
|
||||
const Id m_tokenId;
|
||||
|
||||
TokenLocationLine* const m_line;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef MESSAGE_ACTIVATE_TOKEN_LOCATION_H
|
||||
#define MESSAGE_ACTIVATE_TOKEN_LOCATION_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
|
||||
class MessageActivateTokenLocation: public Message<MessageActivateTokenLocation>
|
||||
{
|
||||
public:
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageActivateTokenLocation";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MESSAGE_ACTIVATE_TOKEN_LOCATION_H
|
||||
Reference in New Issue
Block a user