From 400e2629d2679fdb5ad26f3a1dec1f06ebe2697c Mon Sep 17 00:00:00 2001 From: malte_langkabel Date: Wed, 2 Jul 2014 16:42:33 +0200 Subject: [PATCH] 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. --- bin/app/data/src/main.cpp | 7 ++ src/app/CMakeLists.txt | 1 + src/app/qt/utility/QtThreadedFunctor.h | 100 ++++++++++++++++++ src/app/qt/view/QtCodeView.cpp | 14 ++- src/app/qt/view/QtCodeView.h | 7 ++ src/lib/Application.cpp | 14 +-- src/lib/Application.h | 7 +- src/lib/CMakeLists.txt | 8 +- src/lib/Project.cpp | 21 ++-- src/lib/Project.h | 7 +- src/lib/component/Component.cpp | 17 ++- src/lib/component/Component.h | 24 ++++- src/lib/component/ComponentFactory.cpp | 12 ++- src/lib/component/ComponentFactory.h | 8 +- src/lib/component/ComponentManager.cpp | 9 +- src/lib/component/ComponentManager.h | 5 +- .../component/controller/CodeController.cpp | 38 +++++++ src/lib/component/controller/CodeController.h | 29 ++++- src/lib/component/controller/Controller.cpp | 9 ++ src/lib/component/controller/Controller.h | 21 ++++ .../component/controller/GraphController.cpp | 21 ++++ .../component/controller/GraphController.h | 22 ++++ src/lib/component/view/CodeView.cpp | 7 ++ src/lib/component/view/CodeView.h | 5 + src/lib/component/view/View.cpp | 5 + src/lib/component/view/View.h | 19 +++- src/lib/data/Storage.cpp | 10 ++ src/lib/data/Storage.h | 7 +- src/lib/data/access/CodeAccess.cpp | 1 - src/lib/data/access/CodeAccess.h | 9 -- src/lib/data/access/GraphAccess.cpp | 4 + src/lib/data/access/GraphAccess.h | 8 ++ src/lib/data/access/LocationAccess.cpp | 5 + src/lib/data/access/LocationAccess.h | 17 +++ src/lib/data/graph/Token.h | 2 +- src/lib/data/location/TokenLocation.h | 4 +- .../type/MessageActivateTokenLocation.h | 15 +++ 37 files changed, 441 insertions(+), 78 deletions(-) create mode 100644 bin/app/data/src/main.cpp create mode 100644 src/app/qt/utility/QtThreadedFunctor.h create mode 100644 src/lib/component/controller/GraphController.cpp create mode 100644 src/lib/component/controller/GraphController.h delete mode 100644 src/lib/data/access/CodeAccess.cpp delete mode 100644 src/lib/data/access/CodeAccess.h create mode 100644 src/lib/data/access/LocationAccess.cpp create mode 100644 src/lib/data/access/LocationAccess.h create mode 100644 src/lib/utility/messaging/type/MessageActivateTokenLocation.h diff --git a/bin/app/data/src/main.cpp b/bin/app/data/src/main.cpp new file mode 100644 index 00000000..04f24455 --- /dev/null +++ b/bin/app/data/src/main.cpp @@ -0,0 +1,7 @@ +int main() +{ + int a = 6; + int b = 7; + int c = a * b; + return 0; +} \ No newline at end of file diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 3f5e2e44..5834a485 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -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 diff --git a/src/app/qt/utility/QtThreadedFunctor.h b/src/app/qt/utility/QtThreadedFunctor.h new file mode 100644 index 00000000..0fe5ec23 --- /dev/null +++ b/src/app/qt/utility/QtThreadedFunctor.h @@ -0,0 +1,100 @@ +#ifndef QT_THREADED_FUCTOR_H +#define QT_THREADED_FUCTOR_H + +#include +#include + +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 callback) + { + m_callback = callback; + signalExecution(); + } + +private: + std::function m_callback; +}; + +template +class QtThreadedFunctor +{ +public: + QtThreadedFunctor(std::function 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 m_callback; +}; + +template +class QtThreadedFunctor +{ +public: + QtThreadedFunctor(std::function callback) : m_callback(callback) {} + + void operator()(T1 p1, T2 p2) + { + m_helper(std::bind(m_callback, p1, p2)); + } + +private: + QtThreadedFunctorHelper m_helper; + std::function m_callback; +}; + +template +class QtThreadedFunctor +{ +public: + QtThreadedFunctor(std::function callback) : m_callback(callback) {} + + void operator()(T1 p1) + { + m_helper(std::bind(m_callback, p1)); + } + +private: + QtThreadedFunctorHelper m_helper; + std::function m_callback; +}; + +template <> +class QtThreadedFunctor +{ +public: + QtThreadedFunctor(std::function callback) : m_callback(callback) {} + + void operator()() + { + m_helper(m_callback); + } + +private: + QtThreadedFunctorHelper m_helper; + std::function m_callback; +}; + +#endif // QT_THREADED_FUCTOR_H diff --git a/src/app/qt/view/QtCodeView.cpp b/src/app/qt/view/QtCodeView.cpp index a4f1554e..776ea774 100644 --- a/src/app/qt/view/QtCodeView.cpp +++ b/src/app/qt/view/QtCodeView.cpp @@ -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 = std::make_shared(); @@ -53,7 +65,7 @@ void QtCodeView::addCodeSnippet(std::string str) m_snippets.push_back(snippet); } -void QtCodeView::clearCodeSnippets() +void QtCodeView::doClearCodeSnippets() { m_snippets.clear(); } diff --git a/src/app/qt/view/QtCodeView.h b/src/app/qt/view/QtCodeView.h index fe8215ed..b481793f 100644 --- a/src/app/qt/view/QtCodeView.h +++ b/src/app/qt/view/QtCodeView.h @@ -7,6 +7,7 @@ #include #include "component/view/CodeView.h" +#include "qt/utility/QtThreadedFunctor.h" class QtHighlighter; class QTextEdit; @@ -33,7 +34,13 @@ private: }; std::vector> m_snippets; + void doAddCodeSnippet(std::string str); + void doClearCodeSnippets(); + QFont m_font; + + QtThreadedFunctor m_clearCodeSnippetsFunctor; + QtThreadedFunctor m_addCodeSnippetFunctor; }; # endif // QT_CODE_VIEW_H diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 8cfba9cc..767c9a85 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -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::create(GuiFactory* guiFactory) { - std::shared_ptr consoleLogger = std::make_shared(); + std::shared_ptr consoleLogger = std::make_shared(); // TODO: move to main LogManager::getInstance()->addLogger(consoleLogger); std::shared_ptr ptr(new Application()); - - ptr->m_codeAccess = std::make_shared(); - ptr->m_graphAccess = std::make_shared(); + ptr->m_storage = std::make_shared(); 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(); diff --git a/src/lib/Application.h b/src/lib/Application.h index b3988125..77588a50 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -4,12 +4,11 @@ #include #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 m_project; - - std::shared_ptr m_codeAccess; - std::shared_ptr m_graphAccess; + std::shared_ptr m_storage; std::shared_ptr m_mainView; std::shared_ptr m_componentManager; diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 1096ec67..adf2cdde 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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 diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index ab0020c2..aebad895 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -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::create( - std::shared_ptr codeAccess, - std::shared_ptr graphAccess + std::shared_ptr storage ) { std::shared_ptr ptr(new Project()); - ptr->m_codeAccess = codeAccess; - ptr->m_graphAccess = graphAccess; - - ptr->m_storage = std::make_shared(); - + ptr->m_storage = storage; return ptr; } @@ -38,16 +34,19 @@ void Project::parseCode() { if (ProjectSettings::getInstance()->getSourcePath() != "") { - std::vector extension; - extension.push_back(".cpp"); - extension.push_back(".h"); + std::vector 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(); } } diff --git a/src/lib/Project.h b/src/lib/Project.h index 646ebeed..f17933a0 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -3,8 +3,6 @@ #include -#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 create( - std::shared_ptr codeAccess, - std::shared_ptr graphAccess + std::shared_ptr storage ); ~Project(); @@ -27,8 +24,6 @@ private: Project operator=(const Project&); std::shared_ptr m_storage; - std::shared_ptr m_codeAccess; - std::shared_ptr m_graphAccess; }; #endif // PROJECT_H diff --git a/src/lib/component/Component.cpp b/src/lib/component/Component.cpp index 2165d18f..089bd3ff 100644 --- a/src/lib/component/Component.cpp +++ b/src/lib/component/Component.cpp @@ -1,21 +1,18 @@ #include "component/Component.h" +#include "component/view/View.h" +#include "component/controller/Controller.h" + Component::Component(std::shared_ptr view, std::shared_ptr 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); } diff --git a/src/lib/component/Component.h b/src/lib/component/Component.h index f5e7fe14..2c3037fa 100644 --- a/src/lib/component/Component.h +++ b/src/lib/component/Component.h @@ -3,8 +3,8 @@ #include -#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, std::shared_ptr controller); ~Component(); - Controller* getController() const; - View* getView() const; + template + ControllerType* getController() const; + + template + ViewType* getView() const; private: const std::shared_ptr m_controller; @@ -21,4 +24,17 @@ private: }; +template +ControllerType* Component::getController() const +{ + return dynamic_cast(m_controller.get()); +} + +template +ViewType* Component::getView() const +{ + return dynamic_cast(m_view.get()); +} + + #endif // COMPONENT_H diff --git a/src/lib/component/ComponentFactory.cpp b/src/lib/component/ComponentFactory.cpp index c53feb25..e144ddb9 100644 --- a/src/lib/component/ComponentFactory.cpp +++ b/src/lib/component/ComponentFactory.cpp @@ -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::create( GuiFactory* guiFactory, ViewLayout* viewLayout, - std::shared_ptr codeAccess, + std::shared_ptr locationAccess, std::shared_ptr graphAccess) { std::shared_ptr 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 ComponentFactory::createCodeComponent() { - std::shared_ptr view = m_guiFactory->createCodeView(m_viewLayout); - std::shared_ptr controller = std::make_shared(); + std::shared_ptr view = m_guiFactory->createCodeView(m_viewLayout); + std::shared_ptr controller = std::make_shared(m_locationAccess); std::shared_ptr component = std::make_shared(view, controller); return component; @@ -36,7 +38,7 @@ std::shared_ptr ComponentFactory::createCodeComponent() std::shared_ptr ComponentFactory::createGraphComponent() { std::shared_ptr view = m_guiFactory->createGraphView(m_viewLayout); - std::shared_ptr controller = std::make_shared(); + std::shared_ptr controller = std::make_shared(m_graphAccess); std::shared_ptr component = std::make_shared(view, controller); return component; diff --git a/src/lib/component/ComponentFactory.h b/src/lib/component/ComponentFactory.h index 2205c130..05298103 100644 --- a/src/lib/component/ComponentFactory.h +++ b/src/lib/component/ComponentFactory.h @@ -3,10 +3,10 @@ #include -#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 create( GuiFactory* guiFactory, ViewLayout* viewLayout, - std::shared_ptr codeAccess, + std::shared_ptr locationAccess, std::shared_ptr graphAccess); ~ComponentFactory(); @@ -31,7 +31,7 @@ private: GuiFactory* m_guiFactory; ViewLayout* m_viewLayout; - std::shared_ptr m_codeAccess; + std::shared_ptr m_locationAccess; std::shared_ptr m_graphAccess; }; diff --git a/src/lib/component/ComponentManager.cpp b/src/lib/component/ComponentManager.cpp index a8e58d0e..cf39d5a8 100644 --- a/src/lib/component/ComponentManager.cpp +++ b/src/lib/component/ComponentManager.cpp @@ -7,11 +7,12 @@ std::shared_ptr ComponentManager::create( GuiFactory* guiFactory, ViewLayout* viewLayout, - std::shared_ptr codeAccess, + std::shared_ptr locationAccess, std::shared_ptr graphAccess) { std::shared_ptr 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 graphComponent = m_componentFactory->createGraphComponent(); - GraphView* graphView = dynamic_cast(graphComponent->getView()); + GraphView* graphView = graphComponent->getView(); graphView->addNode(Vec2i(-100, -100), "foo"); graphView->addNode(Vec2i(50, 50), "bar"); @@ -31,7 +32,7 @@ void ComponentManager::setup() std::shared_ptr codeComponent = m_componentFactory->createCodeComponent(); m_components.push_back(codeComponent); - CodeView* codeView = dynamic_cast(codeComponent->getView()); + CodeView* codeView = codeComponent->getView(); codeView->addCodeSnippet("class HelloWorld;"); codeView->addCodeSnippet("static int n = 42; // the answer."); // codeView->clearCodeSnippets(); diff --git a/src/lib/component/ComponentManager.h b/src/lib/component/ComponentManager.h index 7b8a945e..3305b90c 100644 --- a/src/lib/component/ComponentManager.h +++ b/src/lib/component/ComponentManager.h @@ -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 create( GuiFactory* guiFactory, ViewLayout* viewLayout, - std::shared_ptr codeAccess, + std::shared_ptr locationAccess, std::shared_ptr graphAccess); ~ComponentManager(); @@ -34,5 +34,4 @@ private: std::vector > m_components; }; - #endif // COMPONENT_MANAGER_H diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index a5ed2f46..4650d36e 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -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) + : 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::createFromFile(tokenLocation->getFilePath()); + getView()->addCodeSnippet(textAccess->getText()); + } +} + +void CodeController::handleMessage(MessageActivateTokenLocation* message) +{ + setActiveTokenLocationId(1); +} + +CodeView* CodeController::getView() +{ + return Controller::getView(); +} diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index 14f85e35..7c6040c9 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -1,10 +1,35 @@ #ifndef CODE_CONTROLLER_H #define CODE_CONTROLLER_H -#include "component/controller/Controller.h" +#include -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 +{ +public: + CodeController(std::shared_ptr locationAccess); + ~CodeController(); + + void setActiveTokenLocationId(Id id); + +private: + virtual void handleMessage(MessageActivateTokenLocation* message); + CodeView* getView(); + + std::shared_ptr m_locationAccess; }; diff --git a/src/lib/component/controller/Controller.cpp b/src/lib/component/controller/Controller.cpp index 8acc34d3..d3be3d22 100644 --- a/src/lib/component/controller/Controller.cpp +++ b/src/lib/component/controller/Controller.cpp @@ -1,5 +1,14 @@ #include "component/controller/Controller.h" +Controller::Controller() +{ +} + Controller::~Controller() { } + +void Controller::setComponent(Component* component) +{ + m_component = component; +} diff --git a/src/lib/component/controller/Controller.h b/src/lib/component/controller/Controller.h index 2c048f8e..605562a9 100644 --- a/src/lib/component/controller/Controller.h +++ b/src/lib/component/controller/Controller.h @@ -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 + ViewType* getView(); + +private: + Component* m_component; + }; +template +ViewType* Controller::getView() +{ + if (m_component) + return m_component->getView(); + return NULL; +} + #endif // CONTROLLER_H diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp new file mode 100644 index 00000000..97af40c4 --- /dev/null +++ b/src/lib/component/controller/GraphController.cpp @@ -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) + : m_graphAccess(graphAccess) +{ +} + +GraphController::~GraphController() +{ +} + +GraphView* GraphController::getView() +{ + return Controller::getView(); +} diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h new file mode 100644 index 00000000..338c0b4f --- /dev/null +++ b/src/lib/component/controller/GraphController.h @@ -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); + ~GraphController(); + +private: + GraphView* getView(); + + std::shared_ptr m_graphAccess; +}; + + +#endif // GRAPH_CONTROLLER_H diff --git a/src/lib/component/view/CodeView.cpp b/src/lib/component/view/CodeView.cpp index 8641739f..3d69651f 100644 --- a/src/lib/component/view/CodeView.cpp +++ b/src/lib/component/view/CodeView.cpp @@ -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(); +} diff --git a/src/lib/component/view/CodeView.h b/src/lib/component/view/CodeView.h index 7d9a8105..70135ff9 100644 --- a/src/lib/component/view/CodeView.h +++ b/src/lib/component/view/CodeView.h @@ -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 diff --git a/src/lib/component/view/View.cpp b/src/lib/component/view/View.cpp index e946e40b..d133a1e3 100644 --- a/src/lib/component/view/View.cpp +++ b/src/lib/component/view/View.cpp @@ -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; diff --git a/src/lib/component/view/View.h b/src/lib/component/view/View.h index 50bfa9ad..98ac9346 100644 --- a/src/lib/component/view/View.h +++ b/src/lib/component/view/View.h @@ -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 + ControllerType* getController(); private: + Component* m_component; ViewLayout* const m_viewLayout; std::shared_ptr m_widgetWrapper; Vec2i m_minSize; @@ -52,4 +59,14 @@ std::shared_ptr View::create(ViewLayout* viewLayout) return ptr; } +template +ControllerType* View::getController() +{ + if (m_component) + { + return m_component->getController(); + } + return NULL; +} + #endif // VIEW_H diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 32d21924..6af6bd8f 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -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) diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index d529c720..6cb61c84 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -4,11 +4,13 @@ #include #include +#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); diff --git a/src/lib/data/access/CodeAccess.cpp b/src/lib/data/access/CodeAccess.cpp deleted file mode 100644 index 39db9130..00000000 --- a/src/lib/data/access/CodeAccess.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "data/access/CodeAccess.h" diff --git a/src/lib/data/access/CodeAccess.h b/src/lib/data/access/CodeAccess.h deleted file mode 100644 index 4a78425b..00000000 --- a/src/lib/data/access/CodeAccess.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef CODE_ACCESS_H -#define CODE_ACCESS_H - -class CodeAccess -{ -}; - - -#endif // CODE_ACCESS_H diff --git a/src/lib/data/access/GraphAccess.cpp b/src/lib/data/access/GraphAccess.cpp index ebc225b7..1ef17825 100644 --- a/src/lib/data/access/GraphAccess.cpp +++ b/src/lib/data/access/GraphAccess.cpp @@ -1 +1,5 @@ #include "data/access/GraphAccess.h" + +GraphAccess::~GraphAccess() +{ +} diff --git a/src/lib/data/access/GraphAccess.h b/src/lib/data/access/GraphAccess.h index e89cb779..dea85aae 100644 --- a/src/lib/data/access/GraphAccess.h +++ b/src/lib/data/access/GraphAccess.h @@ -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; }; diff --git a/src/lib/data/access/LocationAccess.cpp b/src/lib/data/access/LocationAccess.cpp new file mode 100644 index 00000000..a8cd1451 --- /dev/null +++ b/src/lib/data/access/LocationAccess.cpp @@ -0,0 +1,5 @@ +#include "data/access/LocationAccess.h" + +LocationAccess::~LocationAccess() +{ +} diff --git a/src/lib/data/access/LocationAccess.h b/src/lib/data/access/LocationAccess.h new file mode 100644 index 00000000..91c316cc --- /dev/null +++ b/src/lib/data/access/LocationAccess.h @@ -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 diff --git a/src/lib/data/graph/Token.h b/src/lib/data/graph/Token.h index 7f8eefda..d8489b07 100644 --- a/src/lib/data/graph/Token.h +++ b/src/lib/data/graph/Token.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 m_locationIds; }; diff --git a/src/lib/data/location/TokenLocation.h b/src/lib/data/location/TokenLocation.h index f4f6ada1..8a9f7d1e 100644 --- a/src/lib/data/location/TokenLocation.h +++ b/src/lib/data/location/TokenLocation.h @@ -40,9 +40,9 @@ public: std::shared_ptr 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; diff --git a/src/lib/utility/messaging/type/MessageActivateTokenLocation.h b/src/lib/utility/messaging/type/MessageActivateTokenLocation.h new file mode 100644 index 00000000..85dcaf86 --- /dev/null +++ b/src/lib/utility/messaging/type/MessageActivateTokenLocation.h @@ -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 +{ +public: + static const std::string getStaticType() + { + return "MessageActivateTokenLocation"; + } +}; + +#endif // MESSAGE_ACTIVATE_TOKEN_LOCATION_H