ui: Colors in SearchView

Show the right colors in SearchView for the different NodeTypes or QueryNodeTyps

Note: add colors to your Applcationsettings like in the template

fortune cookie message = recognition will come from unexpected sources
This commit is contained in:
Andreas Stallinger
2015-03-04 11:55:25 +01:00
parent 284fb336a6
commit da1a6d69c4
32 changed files with 455 additions and 100 deletions
+25
View File
@@ -83,6 +83,31 @@ void ApplicationSettings::setCodeActiveLinkColor(Colori color)
setValue<std::string>("code/ActiveLinkColor", color.toString());
}
std::string ApplicationSettings::getNodeTypeColor(Node::NodeType type, const std::string& state) const
{
std::string path = "colors/" + Node::getTypeString(type) + "/" + state;
return getValue<std::string>(path, "#FFFFFF");
}
void ApplicationSettings::setNodeTypeColor(Node::NodeType type, const std::string& color, const std::string& state)
{
std::string path = "colors/" + Node::getTypeString(type) + "/" + state;
setValue<std::string>(path, color);
}
std::string ApplicationSettings::getQueryNodeTypeColor(QueryNode::QueryNodeType type, const std::string& state) const
{
std::string path = "colors/" + QueryNode::queryNodeTypeToString(type) + "/" + state;
return getValue<std::string>(path, "#FFFFFF");
}
void ApplicationSettings::setQueryNodeTypeColor(QueryNode::QueryNodeType type,
const std::string& color, const std::string& state)
{
std::string path = "colors/" + QueryNode::queryNodeTypeToString(type) + "/" + state;
setValue<std::string>(path, color);
}
ApplicationSettings::ApplicationSettings()
{
}
+8
View File
@@ -5,6 +5,8 @@
#include "Settings.h"
#include "utility/math/Color.h"
#include "data/graph/Node.h"
#include "data/query/QueryNode.h"
class ApplicationSettings: public Settings
{
@@ -34,6 +36,12 @@ public:
Colori getCodeActiveLinkColor() const;
void setCodeActiveLinkColor(Colori color);
std::string getNodeTypeColor(Node::NodeType type, const std::string& state = "normal") const;
void setNodeTypeColor(Node::NodeType type, const std::string& color, const std::string& state = "normal");
std::string getQueryNodeTypeColor(QueryNode::QueryNodeType type , const std::string& state = "normal") const;
void setQueryNodeTypeColor(QueryNode::QueryNodeType type, const std::string& color, const std::string& state = "normal");
private:
ApplicationSettings();
ApplicationSettings(const ApplicationSettings&);
@@ -13,15 +13,19 @@ SearchController::~SearchController()
{
}
#include <iostream>
void SearchController::handleMessage(MessageActivateTokens* message)
{
if (!m_ignoreNextMessageActivateTokens && message->tokenIds.size())
{
SearchMatch match;
match.fullName = m_graphAccess->getNameForNodeWithId(message->tokenIds[0]);
match.nodeType = m_graphAccess->getNodeTypeForNodeWithId(message->tokenIds[0]);
match.tokenIds.insert(message->tokenIds[0]);
match.queryNodeType = QueryNode::QUERYNODETYPE_TOKEN;
getView()->setText(match.encodeForQuery());
getView()->setMatch(match);
}
m_ignoreNextMessageActivateTokens = false;
+1
View File
@@ -15,6 +15,7 @@ public:
virtual std::string getName() const;
virtual void setText(const std::string& s) = 0;
virtual void setMatch(const SearchMatch& m) = 0;
virtual void setFocus() = 0;
virtual void setAutocompletionList(const std::vector<SearchMatch>& autocompletionList) = 0;
+20
View File
@@ -686,6 +686,20 @@ std::string Storage::getNameForNodeWithId(Id id) const
}
}
Node::NodeType Storage::getNodeTypeForNodeWithId(Id id) const
{
Token* token = m_graph.getTokenById(id);
if(!token)
{
return Node::NODE_UNDEFINED;
}
if(!token->isEdge())
{
return dynamic_cast<Node*>(token)->getType();
}
return Node::NODE_UNDEFINED;
}
std::vector<SearchMatch> Storage::getAutocompletionMatches(const std::string& query, const std::string& word) const
{
SearchResults tokenResults;
@@ -711,11 +725,17 @@ std::vector<SearchMatch> Storage::getAutocompletionMatches(const std::string& qu
{
if (!match.tokenIds.size())
{
match.queryNodeType = QueryNode::QUERYNODETYPE_COMMAND;
continue;
}
Token* token = m_graph.getTokenById(*match.tokenIds.cbegin());
if(!token->isEdge())
{
match.nodeType = dynamic_cast<Node*>(token)->getType();
}
match.typeName = token->getTypeString();
match.queryNodeType = QueryNode::QUERYNODETYPE_TOKEN;
}
return matches;
+1
View File
@@ -108,6 +108,7 @@ public:
// GraphAccess implementation
virtual Id getIdForNodeWithName(const std::string& fullName) const;
virtual std::string getNameForNodeWithId(Id id) const;
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
virtual std::vector<SearchMatch> getAutocompletionMatches(
const std::string& query, const std::string& word) const;
+1
View File
@@ -16,6 +16,7 @@ public:
virtual Id getIdForNodeWithName(const std::string& name) const = 0;
virtual std::string getNameForNodeWithId(Id id) const = 0;
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const = 0;
virtual std::vector<SearchMatch> getAutocompletionMatches(
const std::string& query, const std::string& word) const = 0;
+9
View File
@@ -37,6 +37,15 @@ Id GraphAccessProxy::getIdForNodeWithName(const std::string& name) const
return 0;
}
Node::NodeType GraphAccessProxy::getNodeTypeForNodeWithId(Id id) const
{
if(hasSubject())
{
return m_subject->getNodeTypeForNodeWithId(id);
}
return Node::NODE_UNDEFINED;
}
std::string GraphAccessProxy::getNameForNodeWithId(Id id) const
{
if (hasSubject())
+1
View File
@@ -15,6 +15,7 @@ public:
// GraphAccess implementation
virtual Id getIdForNodeWithName(const std::string& name) const;
virtual std::string getNameForNodeWithId(Id id) const;
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
virtual std::vector<SearchMatch> getAutocompletionMatches(
const std::string& query, const std::string& word) const;
+3 -3
View File
@@ -317,7 +317,7 @@ void Node::addComponentSignature(std::shared_ptr<TokenComponentSignature> compon
}
}
std::string Node::getTypeString(NodeType type) const
std::string Node::getTypeString(NodeType type)
{
switch (type)
{
@@ -346,11 +346,11 @@ std::string Node::getTypeString(NodeType type) const
case NODE_ENUM:
return "enum";
case NODE_ENUM_CONSTANT:
return "enum constant";
return "enum_constant";
case NODE_TYPEDEF:
return "typedef";
case NODE_TEMPLATE_PARAMETER_TYPE:
return "template parameter type";
return "template_parameter_type";
case NODE_FILE:
return "file";
}
+2 -1
View File
@@ -42,6 +42,8 @@ public:
NODE_FILE = 0x8000
};
static std::string getTypeString(NodeType type);
Node(NodeType type, std::shared_ptr<TokenComponentName> nameComponent);
Node(const Node& other);
virtual ~Node();
@@ -85,7 +87,6 @@ public:
void addComponentSignature(std::shared_ptr<TokenComponentSignature> component);
// Logging.
std::string getTypeString(NodeType type) const;
virtual std::string getTypeString() const;
std::string getAsString() const;
+2 -1
View File
@@ -54,7 +54,8 @@ std::map<std::string, QueryCommand::CommandType> QueryCommand::getCommandTypeMap
}
QueryCommand::QueryCommand(std::string name)
: m_type(COMMAND_INVALID)
: QueryNode(QueryNode::QUERYNODETYPE_COMMAND)
, m_type(COMMAND_INVALID)
{
name.erase(std::remove(name.begin(), name.end(), BOUNDARY), name.end());
m_name = name;
+28 -2
View File
@@ -1,7 +1,8 @@
#include "data/query/QueryNode.h"
QueryNode::QueryNode()
: m_isGroup(false)
QueryNode::QueryNode(QueryNodeType queryNodeType)
: m_nodeType(queryNodeType)
, m_isGroup(false)
, m_isComplete(true)
{
}
@@ -56,3 +57,28 @@ void QueryNode::setIsComplete(bool isComplete)
{
m_isComplete = isComplete;
}
QueryNode::QueryNodeType QueryNode::getQueryNodeType() const
{
return m_nodeType;
}
std::string QueryNode::queryNodeTypeToString(const QueryNodeType& type)
{
switch(type)
{
case QUERYNODETYPE_NONE:
return "none";
case QUERYNODETYPE_COMMAND:
return "command";
case QUERYNODETYPE_TOKEN:
return "token";
case QUERYNODETYPE_OPERATOR:
return "operator";
}
}
std::string QueryNode::getQueryNodeTypeAsString() const
{
return queryNodeTypeToString(m_nodeType);
}
+16 -1
View File
@@ -7,7 +7,17 @@
class QueryNode
{
public:
QueryNode();
enum QueryNodeType
{
QUERYNODETYPE_NONE,
QUERYNODETYPE_TOKEN,
QUERYNODETYPE_COMMAND,
QUERYNODETYPE_OPERATOR
};
static std::string queryNodeTypeToString(const QueryNodeType& type);
QueryNode(QueryNodeType queryNodeType = QUERYNODETYPE_NONE);
virtual ~QueryNode();
virtual bool isCommand() const = 0;
@@ -16,6 +26,7 @@ public:
virtual bool derivedIsComplete() const = 0;
virtual std::string getName() const = 0;
virtual void print(std::ostream& ostream) const = 0;
@@ -27,7 +38,11 @@ public:
bool isComplete() const;
void setIsComplete(bool isComplete);
QueryNodeType getQueryNodeType() const;
std::string getQueryNodeTypeAsString() const;
private:
QueryNodeType m_nodeType;
bool m_isGroup;
bool m_isComplete;
};
+2 -1
View File
@@ -56,7 +56,8 @@ char QueryOperator::getOperator(OperatorType t)
}
QueryOperator::QueryOperator(OperatorType type, bool isImplicit)
: m_type(type)
: QueryNode(QueryNode::QUERYNODETYPE_OPERATOR)
, m_type(type)
, m_isImplicit(isImplicit)
{
}
+1
View File
@@ -6,6 +6,7 @@
#include "utility/utilityString.h"
QueryToken::QueryToken(std::string name)
: QueryNode(QueryNode::QUERYNODETYPE_TOKEN)
{
name.erase(std::remove(name.begin(), name.end(), BOUNDARY), name.end());
std::deque<std::string> names = utility::split(name, DELIMITER);
+10 -5
View File
@@ -67,22 +67,27 @@ std::string QueryTree::getTokenName(const std::string& token)
return token;
}
std::string QueryTree::getTokenTypeName(const std::string& token)
std::string QueryTree::getTokenTypeName(const QueryNode::QueryNodeType& type)
{
return QueryNode::queryNodeTypeToString(type);
}
QueryNode::QueryNodeType QueryTree::getTokenType(const std::string& token)
{
if (token.size() > 2 && token.front() == QueryToken::BOUNDARY && token.back() == QueryToken::BOUNDARY)
{
return "token";
return QueryNode::QUERYNODETYPE_TOKEN;
}
else if (token.size() > 2 && token.front() == QueryCommand::BOUNDARY && token.back() == QueryCommand::BOUNDARY)
{
return "command";
return QueryNode::QUERYNODETYPE_COMMAND;
}
else if (token.size() == 1 && QueryOperator::getOperatorType(token.front()) != QueryOperator::OPERATOR_NONE)
{
return "operator";
return QueryNode::QUERYNODETYPE_OPERATOR;
}
return "none";
return QueryNode::QUERYNODETYPE_NONE;
}
QueryTree::QueryTree()
+3 -1
View File
@@ -6,6 +6,7 @@
#include <ostream>
#include <string>
#include "data/query/QueryNode.h"
#include "data/query/QueryOperator.h"
class QueryTree
@@ -13,7 +14,8 @@ class QueryTree
public:
static std::deque<std::string> tokenizeQuery(const std::string& query);
static std::string getTokenName(const std::string& token);
static std::string getTokenTypeName(const std::string& token);
static QueryNode::QueryNodeType getTokenType(const std::string& token);
static std::string getTokenTypeName(const QueryNode::QueryNodeType& token);
QueryTree();
QueryTree(const std::string& query);
+96 -10
View File
@@ -1,11 +1,25 @@
#include "data/search/SearchMatch.h"
#include <sstream>
#include "utility/logging/logging.h"
#include <cstdlib>
#include "data/query/QueryCommand.h"
#include "data/query/QueryOperator.h"
#include "data/query/QueryToken.h"
#include "utility/logging/logging.h"
#include "utility/utilityString.h"
SearchMatch::SearchMatch()
: fullName("")
, typeName("")
, queryNodeType(QueryNode::QUERYNODETYPE_NONE)
{
}
SearchMatch::SearchMatch(const std::string& query)
{
decodeFromQuery(query);
}
void SearchMatch::log(const std::vector<SearchMatch>& matches, const std::string& query)
{
@@ -39,17 +53,89 @@ void SearchMatch::print(std::ostream& ostream) const
std::string SearchMatch::encodeForQuery() const
{
if (!tokenIds.size())
switch(queryNodeType)
{
case QueryNode::QUERYNODETYPE_COMMAND:
return QueryCommand::BOUNDARY + fullName + QueryCommand::BOUNDARY;
case QueryNode::QUERYNODETYPE_TOKEN:
{
std::stringstream ss;
ss << QueryToken::BOUNDARY << fullName;
ss << QueryToken::DELIMITER << nodeType;
for (Id tokenId : tokenIds)
{
ss << QueryToken::DELIMITER << tokenId;
}
ss << QueryToken::BOUNDARY;
return ss.str();
}
std::stringstream ss;
ss << QueryToken::BOUNDARY << fullName;
for (Id tokenId : tokenIds)
{
ss << QueryToken::DELIMITER << tokenId;
case QueryNode::QUERYNODETYPE_OPERATOR:
case QueryNode::QUERYNODETYPE_NONE:
return fullName;
}
ss << QueryToken::BOUNDARY;
return ss.str();
}
void SearchMatch::decodeFromQuery(std::string query)
{
if (query.size() > 2 && query.front() == QueryToken::BOUNDARY && query.back() == QueryToken::BOUNDARY)
{
queryNodeType = QueryNode::QUERYNODETYPE_TOKEN;
query.erase(query.begin());
query.pop_back();
}
else if (query.size() > 2 && query.front() == QueryCommand::BOUNDARY && query.back() == QueryCommand::BOUNDARY)
{
queryNodeType = QueryNode::QUERYNODETYPE_COMMAND;
query.erase(query.begin());
query.pop_back();
}
else if (query.size() == 1 && QueryOperator::getOperatorType(query.front()) != QueryOperator::OPERATOR_NONE)
{
queryNodeType = QueryNode::QUERYNODETYPE_OPERATOR;
}
else
{
queryNodeType = QueryNode::QUERYNODETYPE_NONE;
}
std::vector<std::string> queryParts = utility::splitToVector(query, QueryToken::DELIMITER);
fullName = queryParts[0];
if(queryParts.size() > 1)
{
for(int i = 2; i < queryParts.size(); ++i)
{
tokenIds.insert(std::strtoul(queryParts[i].c_str(),nullptr,0));
}
}
}
std::deque<SearchMatch> SearchMatch::stringDequeToSearchMatchDeque(const std::deque<std::string>& stringDeque)
{
std::deque<SearchMatch> matchDeque;
for(std::string str : stringDeque)
{
matchDeque.push_back(SearchMatch(str));
}
return matchDeque;
}
std::deque<std::string> SearchMatch::searchMatchDequeToStringDeque(const std::deque<SearchMatch>& searchMatchDeque)
{
std::deque<std::string> stringDeque;
for(SearchMatch match : searchMatchDeque)
{
stringDeque.push_back(match.encodeForQuery());
}
return stringDeque;
}
std::string SearchMatch::getNodeTypeAsString() const
{
return Node::getTypeString(nodeType);
}
+16
View File
@@ -1,25 +1,41 @@
#ifndef SEARCH_MATCH_H
#define SEARCH_MATCH_H
#include <deque>
#include <ostream>
#include <set>
#include <string>
#include <vector>
#include "data/graph/Node.h"
#include "data/query/QueryNode.h"
#include "utility/types.h"
struct SearchMatch
{
static void log(const std::vector<SearchMatch>& matches, const std::string& query);
static std::deque<SearchMatch> stringDequeToSearchMatchDeque(const std::deque<std::string>& deque);
static std::deque<std::string> searchMatchDequeToStringDeque(const std::deque<SearchMatch>& deque);
SearchMatch();
SearchMatch(const std::string& query);
void print(std::ostream& ostream) const;
std::string encodeForQuery() const;
void decodeFromQuery(std::string query);
std::string getNodeTypeAsString() const;
std::string fullName;
std::string typeName;
Node::NodeType nodeType;
QueryNode::QueryNodeType queryNodeType;
std::set<Id> tokenIds;
std::vector<size_t> indices;
size_t weight;
};
#endif // SEARCH_MATCH_H
+1
View File
@@ -8,6 +8,7 @@ SearchResult::SearchResult()
{
}
SearchResult::SearchResult(size_t weight, const SearchNode* node, const SearchNode* parent)
: weight(weight)
, node(node)