ui: basic search view

- Added a basic SearchView (+ controller and qt implementation)
- SearchView can set the active element of other views by dispatching a message.
- SearchView adjusts its text when the active element is changed by other views.
- Added wrappers for Button and EditBox that allow the usage of simple callback functions.
This commit is contained in:
malte_langkabel
2014-07-04 13:43:27 +02:00
parent 9297ea6d6d
commit b1023ba4ac
22 changed files with 356 additions and 6 deletions
+4
View File
@@ -22,6 +22,8 @@ add_files(
component/controller/Controller.h
component/controller/GraphController.cpp
component/controller/GraphController.h
component/controller/SearchController.cpp
component/controller/SearchController.h
component/view/graphElements/GraphNode.cpp
component/view/graphElements/GraphNode.h
@@ -32,6 +34,8 @@ add_files(
component/view/GraphView.h
component/view/MainView.cpp
component/view/MainView.h
component/view/SearchView.cpp
component/view/SearchView.h
component/view/View.cpp
component/view/View.h
component/view/ViewLayout.cpp
+11
View File
@@ -3,8 +3,10 @@
#include "component/Component.h"
#include "component/controller/CodeController.h"
#include "component/controller/GraphController.h"
#include "component/controller/SearchController.h"
#include "component/view/CodeView.h"
#include "component/view/GraphView.h"
#include "component/view/SearchView.h"
#include "component/view/ViewLayout.h"
#include "gui/GuiFactory.h"
@@ -44,6 +46,15 @@ std::shared_ptr<Component> ComponentFactory::createGraphComponent()
return component;
}
std::shared_ptr<Component> ComponentFactory::createSearchComponent()
{
std::shared_ptr<SearchView> view = m_guiFactory->createSearchView(m_viewLayout);
std::shared_ptr<SearchController> controller = std::make_shared<SearchController>(m_graphAccess);
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
return component;
}
ComponentFactory::ComponentFactory()
{
}
+1
View File
@@ -23,6 +23,7 @@ public:
std::shared_ptr<Component> createCodeComponent();
std::shared_ptr<Component> createGraphComponent();
std::shared_ptr<Component> createSearchComponent();
private:
ComponentFactory();
+3 -1
View File
@@ -28,11 +28,13 @@ void ComponentManager::setup()
GraphView* graphView = graphComponent->getView<GraphView>();
graphView->addNode(Vec2i(-100, -100), "foo");
graphView->addNode(Vec2i(50, 50), "bar");
m_components.push_back(graphComponent);
std::shared_ptr<Component> codeComponent = m_componentFactory->createCodeComponent();
m_components.push_back(codeComponent);
std::shared_ptr<Component> searchComponent = m_componentFactory->createSearchComponent();
m_components.push_back(searchComponent);
}
ComponentManager::ComponentManager()
@@ -17,7 +17,9 @@ struct AnnotatedText
Id tokenId;
};
class CodeController: public Controller, public MessageListener<MessageActivateToken>
class CodeController
: public Controller
, public MessageListener<MessageActivateToken>
{
public:
CodeController(std::shared_ptr<LocationAccess> locationAccess);
@@ -0,0 +1,40 @@
#include "component/controller/SearchController.h"
#include "component/view/SearchView.h"
#include "data/access/GraphAccess.h"
#include "utility/messaging/type/MessageActivateToken.h"
SearchController::SearchController(std::shared_ptr<GraphAccess> graphAccess)
: m_graphAccess(graphAccess)
{
}
SearchController::~SearchController()
{
}
void SearchController::search(const std::string& s)
{
LOG_INFO("searching string: \"" + s + "\"");
Id nodeId = m_graphAccess->getIdForNodeWithName(s);
if (nodeId > 0)
{
LOG_INFO("Node with name \"" + s + "\" found.");
MessageActivateToken message(nodeId);
message.dispatch();
}
else
{
LOG_INFO("Node with name \"" + s + "\" not found.");
}
}
void SearchController::handleMessage(MessageActivateToken* message)
{
getView()->setText(m_graphAccess->getNameForNodeWithId(message->tokenId));
}
SearchView* SearchController::getView()
{
return Controller::getView<SearchView>();
}
@@ -0,0 +1,31 @@
#ifndef SEARCH_CONTROLLER_H
#define SEARCH_CONTROLLER_H
#include <string>
#include "component/controller/Controller.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageActivateToken.h"
class GraphAccess;
class SearchView;
class SearchController
: public Controller
, public MessageListener<MessageActivateToken>
{
public:
SearchController(std::shared_ptr<GraphAccess> graphAccess);
~SearchController();
void search(const std::string& s);
//void autocomplete(const std::string& s);
private:
virtual void handleMessage(MessageActivateToken* message);
SearchView* getView();
std::shared_ptr<GraphAccess> m_graphAccess;
};
#endif // SEARCH_CONTROLLER_H
+22
View File
@@ -0,0 +1,22 @@
#include "component/view/SearchView.h"
#include "component/controller/SearchController.h"
SearchView::SearchView(ViewLayout* viewLayout)
: View(viewLayout, Vec2i(100, 100))
{
}
SearchView::~SearchView()
{
}
std::string SearchView::getName() const
{
return "SearchView";
}
SearchController* SearchView::getController()
{
return View::getController<SearchController>();
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef SEARCH_VIEW_H
#define SEARCH_VIEW_H
#include "component/view/View.h"
class SearchController;
class SearchView : public View
{
public:
SearchView(ViewLayout* viewLayout);
virtual ~SearchView();
virtual std::string getName() const;
virtual void setText(const std::string& s) const = 0;
protected:
SearchController* getController();
};
#endif // SEARCH_VIEW_H
+13 -2
View File
@@ -175,9 +175,20 @@ void Storage::logLocations() const
LOG_INFO(str.str());
}
Token* Storage::getToken(Id tokenId) const
Id Storage::getIdForNodeWithName(const std::string& name) const
{
return m_graph.getTokenById(tokenId); // Todo: copy information.
Node* node = m_graph.findNode([&](Node* node){
return node->getName() == name;
});
return (node ? node->getId() : 0);
}
std::string Storage::getNameForNodeWithId(Id id) const
{
Node* node = m_graph.getNodeById(id);
return (node ? node->getName() : "");
}
TokenLocationCollection Storage::getTokenLocationsForTokenId(Id id) const
+4 -1
View File
@@ -45,8 +45,11 @@ public:
void logGraph() const;
void logLocations() const;
virtual Token* getToken(Id tokenId) const;
// GraphAccess implementation
virtual Id getIdForNodeWithName(const std::string& name) const;
virtual std::string getNameForNodeWithId(Id id) const;
// LocationAccess implementation
virtual TokenLocationCollection getTokenLocationsForTokenId(Id locationId) const;
virtual TokenLocationFile getTokenLocationsForLinesInFile(
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
+4 -1
View File
@@ -1,6 +1,8 @@
#ifndef GRAPH_ACCESS_H
#define GRAPH_ACCESS_H
#include <string>
#include "utility/types.h"
class Token;
@@ -10,7 +12,8 @@ class GraphAccess
public:
virtual ~GraphAccess();
virtual Token* getToken(Id tokenId) const = 0;
virtual Id getIdForNodeWithName(const std::string& name) const = 0;
virtual std::string getNameForNodeWithId(Id id) const = 0;
};
+2
View File
@@ -6,6 +6,7 @@
class CodeView;
class GraphView;
class MainView;
class SearchView;
class ViewLayout;
class GuiFactory
@@ -17,6 +18,7 @@ public:
virtual std::shared_ptr<MainView> createMainView() const = 0;
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<SearchView> createSearchView(ViewLayout* viewLayout) const = 0;
};
#endif // GUI_FACTORY_H