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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user