ui: search view autocompletion

- Implemented autocompletion for the QtSearchView.
- Added: MessageFinishedParsing that will be dispatched by the Project after the parsing step is done.
- Moved the initial MessageActivateToken from the Project to the Application.
- Added getNamesForNodesWithNamePrefix() to GraphAccess.
This commit is contained in:
malte_langkabel
2014-07-07 11:25:46 +02:00
parent a70a9009cc
commit c02767362f
18 changed files with 162 additions and 11 deletions
+4
View File
@@ -7,6 +7,7 @@
#include "utility/logging/ConsoleLogger.h"
#include "utility/logging/LogManager.h"
#include "utility/messaging/MessageQueue.h"
#include "utility/messaging/type/MessageActivateToken.h"
std::shared_ptr<Application> Application::create(GuiFactory* guiFactory)
{
@@ -42,4 +43,7 @@ void Application::loadProject()
m_project->loadProjectSettings("data/ProjectSettings.xml");
m_project->parseCode();
MessageActivateToken message(1);
message.dispatch();
}
+2 -2
View File
@@ -5,7 +5,7 @@
#include "data/parser/cxx/CxxParser.h"
#include "utility/FileSystem.h"
#include "utility/messaging/type/MessageActivateToken.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/logging/logging.h"
std::shared_ptr<Project> Project::create(
@@ -46,7 +46,7 @@ void Project::parseCode()
m_storage->logGraph();
m_storage->logLocations();
MessageActivateToken message(1);
MessageFinishedParsing message;
message.dispatch();
}
}
@@ -2,7 +2,6 @@
#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)
@@ -34,6 +33,11 @@ void SearchController::handleMessage(MessageActivateToken* message)
getView()->setText(m_graphAccess->getNameForNodeWithId(message->tokenId));
}
void SearchController::handleMessage(MessageFinishedParsing* message)
{
getView()->setAutocompletionList(m_graphAccess->getNamesForNodesWithNamePrefix(""));
}
SearchView* SearchController::getView()
{
return Controller::getView<SearchView>();
@@ -6,6 +6,7 @@
#include "component/controller/Controller.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageActivateToken.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
class GraphAccess;
class SearchView;
@@ -13,6 +14,7 @@ class SearchView;
class SearchController
: public Controller
, public MessageListener<MessageActivateToken>
, public MessageListener<MessageFinishedParsing>
{
public:
SearchController(std::shared_ptr<GraphAccess> graphAccess);
@@ -23,6 +25,7 @@ public:
private:
virtual void handleMessage(MessageActivateToken* message);
virtual void handleMessage(MessageFinishedParsing* message);
SearchView* getView();
std::shared_ptr<GraphAccess> m_graphAccess;
+2 -1
View File
@@ -13,7 +13,8 @@ public:
virtual std::string getName() const;
virtual void setText(const std::string& s) const = 0;
virtual void setText(const std::string& s) = 0;
virtual void setAutocompletionList(const std::vector<std::string>& autocompletionList) = 0;
protected:
SearchController* getController();
+15
View File
@@ -8,6 +8,7 @@
#include "data/parser/ParseLocation.h"
#include "data/parser/ParseVariable.h"
#include "utility/logging/logging.h"
#include "utility/utilityString.h"
Storage::Storage()
{
@@ -191,6 +192,20 @@ std::string Storage::getNameForNodeWithId(Id id) const
return (node ? node->getName() : "");
}
std::vector<std::string> Storage::getNamesForNodesWithNamePrefix(const std::string& prefix) const
{
std::vector<std::string> names;
m_graph.forEachNode([&](Node* node){
const std::string& nodeName = node->getName();
if (utility::isPrefix(prefix, nodeName))
{
names.push_back(nodeName);
}
});
return names;
}
TokenLocationCollection Storage::getTokenLocationsForTokenId(Id id) const
{
TokenLocationCollection ret;
+1
View File
@@ -48,6 +48,7 @@ public:
// GraphAccess implementation
virtual Id getIdForNodeWithName(const std::string& name) const;
virtual std::string getNameForNodeWithId(Id id) const;
virtual std::vector<std::string> getNamesForNodesWithNamePrefix(const std::string& prefix) const;
// LocationAccess implementation
virtual TokenLocationCollection getTokenLocationsForTokenId(Id locationId) const;
+2
View File
@@ -2,6 +2,7 @@
#define GRAPH_ACCESS_H
#include <string>
#include <vector>
#include "utility/types.h"
@@ -14,6 +15,7 @@ public:
virtual Id getIdForNodeWithName(const std::string& name) const = 0;
virtual std::string getNameForNodeWithId(Id id) const = 0;
virtual std::vector<std::string> getNamesForNodesWithNamePrefix(const std::string& prefix) const = 0;
};
@@ -17,7 +17,6 @@ public:
return "MessageActivateToken";
}
public:
const Id tokenId;
};
@@ -0,0 +1,19 @@
#ifndef MESSAGE_FINISHED_PARSING_H
#define MESSAGE_FINISHED_PARSING_H
#include "utility/messaging/Message.h"
class MessageFinishedParsing: public Message<MessageFinishedParsing>
{
public:
MessageFinishedParsing()
{
}
static const std::string getStaticType()
{
return "MessageFinishedParsing";
}
};
#endif // MESSAGE_FINISHED_PARSING_H
+8
View File
@@ -23,4 +23,12 @@ namespace utility
return vec;
}
bool isPrefix(const std::string& prefix, const std::string& text)
{
typedef std::pair<std::string::const_iterator, std::string::const_iterator> ResType;
ResType res = std::mismatch(prefix.begin(), prefix.end(), text.begin());
return res.first == prefix.end();
}
}
+2
View File
@@ -8,6 +8,8 @@ namespace utility
{
std::vector<std::string> split(const std::string& str, char delimiter);
std::vector<std::string> split(const std::string& str, const std::string& delimiter);
bool isPrefix(const std::string& prefix, const std::string& text);
}
#endif // UTILITY_STRING_H