logic: random fixes and improvements

* added new logos to setup ui
* changed wording in status messages and bundle nodes
* removed ununsed Vector.h
* save NameHierarchy to SearchMatch
* fixed NameHierarchyElement retrieval for name elements without parent
* fixed match weight to score last letters higher
This commit is contained in:
Eberhard Graether
2015-10-06 16:21:03 +02:00
parent 8d3112d5a9
commit 0fba3f5cf9
32 changed files with 107 additions and 98 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ QLineEdit:disabled {
}
#form {
background-color: rgba(255, 255, 255, 220);
background-color: rgba(255, 255, 255, 150);
}
#form QLabel {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

+1 -1
View File
@@ -44,7 +44,7 @@ QVariant QtAutocompletionModel::data(const QModelIndex &index, int role) const
switch (index.column())
{
case 0:
return QString::fromStdString(match.fullName);
return QString::fromStdString(match.getFullName());
case 1:
return QString::fromStdString(match.typeName);
case 2:
+10 -10
View File
@@ -395,7 +395,7 @@ void QtSmartSearchBox::onTextEdited(const QString& text)
}
}
if (match.fullName.size() && !m_allowMultipleElements)
if (match.nameHierarchy.size() && !m_allowMultipleElements)
{
clearMatches();
matchesChanged = true;
@@ -403,7 +403,7 @@ void QtSmartSearchBox::onTextEdited(const QString& text)
if (matchesChanged)
{
setEditText(QString::fromStdString(match.fullName));
setEditText(QString::fromStdString(match.getFullName()));
updateElements();
}
else
@@ -411,7 +411,7 @@ void QtSmartSearchBox::onTextEdited(const QString& text)
layoutElements();
}
if (match.fullName.size() || m_elements.size())
if (match.nameHierarchy.size() || m_elements.size())
{
requestAutoCompletions();
}
@@ -442,7 +442,7 @@ void QtSmartSearchBox::onAutocompletionActivated(const SearchMatch& match)
{
addMatchAndUpdate(match);
if (match.fullName.size())
if (match.nameHierarchy.size())
{
search();
}
@@ -512,7 +512,7 @@ void QtSmartSearchBox::moveCursorTo(int target)
void QtSmartSearchBox::addMatch(const SearchMatch& match)
{
if (!match.fullName.size())
if (!match.nameHierarchy.size())
{
return;
}
@@ -522,7 +522,7 @@ void QtSmartSearchBox::addMatch(const SearchMatch& match)
if (completer()->popup()->isVisible())
{
const SearchMatch* mPtr = dynamic_cast<QtAutocompletionList*>(completer())->getSearchMatchAt(0);
if (mPtr && utility::equalsCaseInsensitive(match.fullName, mPtr->fullName))
if (mPtr && utility::equalsCaseInsensitive(match.getFullName(), mPtr->getFullName()))
{
matchPtr = mPtr;
}
@@ -539,7 +539,7 @@ void QtSmartSearchBox::addMatch(const SearchMatch& match)
void QtSmartSearchBox::addMatchAndUpdate(const SearchMatch& match)
{
if (match.fullName.size())
if (match.nameHierarchy.size())
{
m_oldText.clear();
clearLineEdit();
@@ -586,7 +586,7 @@ void QtSmartSearchBox::editElement(QtSearchElement* element)
}
}
std::string name = m_matches[m_cursorIndex].fullName;
std::string name = m_matches[m_cursorIndex].getFullName();
m_matches.erase(m_matches.begin() + m_cursorIndex);
setEditText(QString::fromStdString(name));
@@ -605,7 +605,7 @@ void QtSmartSearchBox::updateElements()
for (const SearchMatch& match : m_matches)
{
std::string name = match.fullName;
std::string name = match.getFullName();
name = utility::replace(name, "&", "&&");
std::shared_ptr<QtSearchElement> element = std::make_shared<QtSearchElement>(QString::fromStdString(name), this);
@@ -739,7 +739,7 @@ std::string QtSmartSearchBox::getSelectedString() const
{
if (m_elements[i]->isChecked())
{
str += m_matches[i].fullName;
str += m_matches[i].getFullName();
}
}
return str;
@@ -45,7 +45,7 @@ Id QtGraphNodeData::getTokenId() const
void QtGraphNodeData::onClick()
{
MessageActivateNodes message;
message.addNode(m_data->getId(), m_data->getType(), m_data->getFullName());
message.addNode(m_data->getId(), m_data->getType(), m_data->getNameHierarchy());
message.dispatch();
}
+1 -2
View File
@@ -36,7 +36,6 @@ QtSettingsWindow::QtSettingsWindow(QWidget *parent, int displacement)
"border: 1px solid lightgray;"
"border-radius: 15px; "
"background: white; "
"background-image: url(:/data/gui/icon/logo_1024_1024.png); "
"}";
m_window->setStyleSheet(frameStyle.c_str());
m_window->setObjectName("SettingWindow");
@@ -106,7 +105,7 @@ void QtSettingsWindow::mouseReleaseEvent(QMouseEvent *event)
void QtSettingsWindow::setupForm()
{
QtDeviceScaledPixmap coati_logo("data/gui/startscreen/logo.png");
QtDeviceScaledPixmap coati_logo("data/gui/startscreen/logo_blurry.png");
coati_logo.scaleToWidth(400);
QLabel* coatiLogoLabel = new QLabel(m_window);
coatiLogoLabel->setPixmap(coati_logo.pixmap());
+2 -2
View File
@@ -34,7 +34,7 @@ void QtStartScreen::setup()
{
setStyleSheet(utility::getStyleSheet("data/gui/startscreen/startscreen.css").c_str());
QtDeviceScaledPixmap coati_logo("data/gui/startscreen/logo_schriftzug.png");
QtDeviceScaledPixmap coati_logo("data/gui/startscreen/logo.png");
coati_logo.scaleToWidth(200);
QLabel* coatiLogoLabel = new QLabel(this);
coatiLogoLabel->setPixmap(coati_logo.pixmap());
@@ -58,7 +58,7 @@ void QtStartScreen::setup()
recentProjectsLabel->setObjectName("recentLabel");
int position = 290;
QIcon cpp_icon("data/gui/startscreen/Icon_CPP.png");
QIcon cpp_icon("data/gui/startscreen/icon_cpp.png");
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
for (size_t i = 0; i < recentProjects.size() && i < 7; i++)
{
-1
View File
@@ -297,7 +297,6 @@ add_files(
utility/utility.h
utility/utilityString.cpp
utility/utilityString.h
utility/Vector.h
Application.cpp
Application.h
@@ -218,6 +218,7 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node)
result.topLevelAncestorId = parent->getId();
}
// Expand nodes that were expanded before.
DummyNode* oldNode = findDummyNodeRecursive(m_dummyNodes, node->getId());
if (oldNode)
{
@@ -300,7 +301,7 @@ void GraphController::autoExpandActiveNode(const std::vector<Id>& activeTokenIds
node = findDummyNodeRecursive(m_dummyNodes, activeTokenIds[0]);
}
if (node && node->data->isType(Node::NODE_CLASS | Node::NODE_STRUCT | Node::NODE_ENUM))
if (node)
{
node->expanded = true;
}
@@ -414,7 +415,7 @@ void GraphController::bundleNodes()
return isTypeNodeWithSingleAggregation(node, TokenComponentAggregation::DIRECTION_BACKWARD);
},
3,
"Used Types"
"Referenced Types"
);
bundleNodesMatching(
@@ -423,7 +424,7 @@ void GraphController::bundleNodes()
return isTypeNodeWithSingleAggregation(node, TokenComponentAggregation::DIRECTION_FORWARD);
},
3,
"Using Types"
"Referencing Types"
);
bundleNodesMatching(
@@ -458,7 +459,7 @@ void GraphController::bundleNodes()
return false;
},
3,
1,
"Undefined Symbols"
);
}
@@ -152,6 +152,11 @@ void BucketGrid::createBuckets(std::vector<DummyNode>& nodes, const std::vector<
DummyNode* owner = findTopMostDummyNodeRecursive(nodes, edge->ownerId);
DummyNode* target = findTopMostDummyNodeRecursive(nodes, edge->targetId);
if (edge->getDirection() == TokenComponentAggregation::DIRECTION_BACKWARD)
{
std::swap(owner, target);
}
bool removeEdge = false;
if (!owner || !target)
{
+15 -7
View File
@@ -497,7 +497,7 @@ Id SqliteStorage::getNameHierarchyElementIdByName(const std::string& name, Id pa
else
{
return getFirstResult<Id>(
"SELECT id FROM name_hierarchy_element WHERE name == '" + name + "';"
"SELECT id FROM name_hierarchy_element WHERE name == '" + name + "' AND parent_id IS NULL;"
);
}
}
@@ -540,14 +540,22 @@ NameHierarchy SqliteStorage::getNameHierarchyById(const Id id) const
"SELECT name, parent_id FROM name_hierarchy_element WHERE id == " + std::to_string(id) + ";"
).c_str());
const std::string elementName = q.getStringField(0, "");
const Id parentId = q.getIntField(1, 0);
NameHierarchy nameHierarchy;
NameHierarchy nameHierarchy = (parentId > 0) ? getNameHierarchyById(parentId) : NameHierarchy();
if (elementName.size() > 0)
if (!q.eof())
{
nameHierarchy.push(std::make_shared<NameElement>(elementName));
const std::string elementName = q.getStringField(0, "");
const Id parentId = q.getIntField(1, 0);
if (parentId > 0)
{
nameHierarchy = getNameHierarchyById(parentId);
}
if (elementName.size() > 0)
{
nameHierarchy.push(std::make_shared<NameElement>(elementName));
}
}
return nameHierarchy;
+13 -35
View File
@@ -719,14 +719,7 @@ Id Storage::getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) co
for (size_t i = 0; i < nameHierarchy.size(); i++)
{
Id parentId = currentId;
currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameHierarchy[i]->getFullName(), parentId);
if (currentId == 0)
{
currentId = parentId;
break;
}
currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameHierarchy[i]->getFullName(), currentId);
}
return m_sqliteStorage.getNodeByNameId(currentId).id;
@@ -799,16 +792,11 @@ std::vector<SearchMatch> Storage::getSearchMatchesForTokenIds(const std::vector<
if (m_sqliteStorage.isFile(tokenId))
{
StorageFile file = m_sqliteStorage.getFileById(tokenId);
match.fullName = m_tokenIndex.getNameHierarchyForTokenId(tokenId).getFullName();
match.nodeType = Node::NODE_FILE;
}
else if (m_sqliteStorage.isNode(tokenId))
{
StorageNode node = m_sqliteStorage.getNodeById(tokenId);
match.fullName = m_tokenIndex.getNameHierarchyForTokenId(tokenId).getFullName();
match.nodeType = Node::intToType(node.type);
}
else
@@ -817,6 +805,7 @@ std::vector<SearchMatch> Storage::getSearchMatchesForTokenIds(const std::vector<
}
match.tokenIds.insert(tokenId);
match.nameHierarchy = m_tokenIndex.getNameHierarchyForTokenId(tokenId);
match.searchType = SearchMatch::SEARCH_TOKEN;
matches.push_back(match);
@@ -954,13 +943,8 @@ std::vector<Id> Storage::getTokenIdsForMatches(const std::vector<SearchMatch>& m
std::set<Id> idSet;
for (const SearchMatch& match : matches)
{
std::vector<SearchMatch> ms = getAutocompletionMatches("", match.fullName);
for (size_t i = 0; i < ms.size(); i++)
{
utility::append(idSet, ms[i].tokenIds);
break;
}
SearchNode* searchNode = m_tokenIndex.getNode(match.nameHierarchy);
utility::append(idSet, searchNode->getTokenIds());
}
std::vector<Id> ids;
@@ -1187,25 +1171,22 @@ std::shared_ptr<TextAccess> Storage::getFileContent(const FilePath& filePath) co
Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, bool distinct)
{
addNameHierarchyElements(nameHierarchy);
std::vector<Id> nameIds = addNameHierarchyElements(nameHierarchy);
Id parentNameHierarchyElementId = 0;
Id parentNodeId = 0;
for (size_t i = 0; i < nameHierarchy.size(); i++)
for (size_t i = 0; i < nameIds.size(); i++)
{
Id nameId = nameIds[i];
bool lastName = (i == nameHierarchy.size() - 1);
Node::NodeType type = (lastName ? nodeType : Node::NODE_UNDEFINED);
Id nameHierarchyElementId =
m_sqliteStorage.getNameHierarchyElementIdByName(nameHierarchy[i]->getFullName(), parentNameHierarchyElementId);
const StorageNode node = m_sqliteStorage.getNodeByNameId(nameHierarchyElementId);
const StorageNode node = m_sqliteStorage.getNodeByNameId(nameId);
Id nodeId = node.id;
if (nodeId == 0 || (lastName && distinct))
{
nodeId = m_sqliteStorage.addNode(Node::typeToInt(type), nameHierarchyElementId);
nodeId = m_sqliteStorage.addNode(Node::typeToInt(type), nameId);
if (parentNodeId != 0)
{
@@ -1221,7 +1202,6 @@ Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarch
}
}
parentNameHierarchyElementId = nameHierarchyElementId;
parentNodeId = nodeId;
}
@@ -1242,8 +1222,9 @@ Id Storage::addNodeHierarchyWithDistinctSignature(Node::NodeType type, const Par
return nodeId;
}
Id Storage::addNameHierarchyElements(NameHierarchy nameHierarchy)
std::vector<Id> Storage::addNameHierarchyElements(NameHierarchy nameHierarchy)
{
std::vector<Id> nameIds;
Id parentId = 0;
bool nodeMayExist = true;
@@ -1256,10 +1237,6 @@ Id Storage::addNameHierarchyElements(NameHierarchy nameHierarchy)
{
nodeId = m_sqliteStorage.getNameHierarchyElementIdByName(elementName, parentId);
}
else
{
nodeId = 0;
}
if (nodeId == 0)
{
@@ -1267,10 +1244,11 @@ Id Storage::addNameHierarchyElements(NameHierarchy nameHierarchy)
nodeMayExist = false;
}
nameIds.push_back(nodeId);
parentId = nodeId;
}
return parentId;
return nameIds;
}
int Storage::addSourceLocation(int elementNodeId, const ParseLocation& location, bool isScope)
+1 -1
View File
@@ -163,7 +163,7 @@ public:
private:
Id addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, bool distinct = false);
Id addNodeHierarchyWithDistinctSignature(Node::NodeType type, const ParseFunction& function);
Id addNameHierarchyElements(NameHierarchy nameHierarchy);
std::vector<Id> addNameHierarchyElements(NameHierarchy nameHierarchy);
int addSourceLocation(int elementNodeId, const ParseLocation& location, bool isScope = false);
Id addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type);
+1 -2
View File
@@ -45,12 +45,11 @@ void TaskCleanStorage::exit()
ss << "clearing files done, ";
ss << std::setprecision(2) << std::fixed << utility::duration(m_start) << " seconds";
MessageStatus(ss.str()).dispatch();
}
void TaskCleanStorage::interrupt()
{
MessageStatus("Clearing file interrupted", false, true).dispatch();
MessageStatus("clearing files interrupted", false, true).dispatch();
}
void TaskCleanStorage::revert()
+3 -2
View File
@@ -63,7 +63,7 @@ Task::TaskState TaskParseCxx::update()
}
std::stringstream ss;
ss << "parsing (ESC to quit): [";
ss << "analyzing files (ESC to quit): [";
ss << fileRegister->getParsedFilesCount() << "/" << fileRegister->getFilesCount() << "] ";
ss << sourcePath;
@@ -85,7 +85,7 @@ Task::TaskState TaskParseCxx::update()
void TaskParseCxx::exit()
{
MessageStatus("Building search index").dispatch();
MessageStatus("building search index").dispatch();
m_client->finishParsing();
@@ -101,6 +101,7 @@ void TaskParseCxx::exit()
void TaskParseCxx::interrupt()
{
MessageStatus("analyzing files interrupted", false, true).dispatch();
}
void TaskParseCxx::revert()
+12
View File
@@ -79,6 +79,18 @@ SearchNode* SearchIndex::addNode(NameHierarchy nameHierarchy)
return nullptr;
}
SearchNode* SearchIndex::getNode(const NameHierarchy& nameHierarchy) const
{
std::deque<Id> nameIds = m_dictionary.getWordIdsConst(nameHierarchy);
if (nameIds.size())
{
return m_root.getNodeRecursive(&nameIds).get();
}
return nullptr;
}
SearchNode* SearchIndex::getNode(const std::string& fullName) const
{
std::deque<Id> nameIds = m_dictionary.getWordIdsConst(fullName, DELIMITER);
+1
View File
@@ -29,6 +29,7 @@ public:
const std::string& getWord(Id wordId) const;
SearchNode* addNode(NameHierarchy nameHierarchy);
SearchNode* getNode(const NameHierarchy& nameHierarchy) const;
SearchNode* getNode(const std::string& fullName) const;
SearchNode* getNode(const SearchNode* searchNode) const;
+9 -5
View File
@@ -38,21 +38,20 @@ std::string SearchMatch::searchMatchesToString(const std::vector<SearchMatch>& m
for (size_t i = 0; i < matches.size(); i++)
{
ss << '@' << matches[i].fullName;
ss << '@' << matches[i].getFullName();
}
return ss.str();
}
SearchMatch::SearchMatch()
: fullName("")
, typeName("")
: typeName("")
, searchType(SEARCH_NONE)
{
}
SearchMatch::SearchMatch(const std::string& query)
: fullName(query)
: nameHierarchy(query)
, typeName("")
, searchType(SEARCH_NONE)
{
@@ -65,7 +64,7 @@ bool SearchMatch::isValid() const
void SearchMatch::print(std::ostream& ostream) const
{
ostream << weight << '\t' << fullName << std::endl << '\t';
ostream << weight << '\t' << nameHierarchy.getFullName() << std::endl << '\t';
size_t i = 0;
for (size_t index : indices)
{
@@ -80,6 +79,11 @@ void SearchMatch::print(std::ostream& ostream) const
ostream << std::endl;
}
std::string SearchMatch::getFullName() const
{
return nameHierarchy.getFullName();
}
std::string SearchMatch::getNodeTypeAsString() const
{
return Node::getTypeString(nodeType);
+2 -1
View File
@@ -31,10 +31,11 @@ struct SearchMatch
void print(std::ostream& ostream) const;
std::string getFullName() const;
std::string getNodeTypeAsString() const;
std::string getSearchTypeName() const;
std::string fullName;
NameHierarchy nameHierarchy;
std::string typeName;
Node::NodeType nodeType;
+2 -2
View File
@@ -255,7 +255,7 @@ void SearchNode::removeSearchNode(SearchNode* node)
SearchMatch SearchNode::fuzzyMatchData(const std::string& query, const SearchNode* parent) const
{
SearchMatch data;
data.fullName = getFullName();
data.nameHierarchy = getNameHierarchy();
data.tokenIds = m_tokenIds;
data.weight = 0;
@@ -364,7 +364,7 @@ std::pair<size_t, size_t> SearchNode::fuzzyMatch(
weight += 20;
}
if (last == '_' || next == '_')
if (last == '_' || next == '_' || next == '\0')
{
weight += 20;
}
-16
View File
@@ -1,16 +0,0 @@
#ifndef VECTOR_H
#define VECTOR_H
struct Vec4i
{
Vec4i(int x, int y, int z, int w)
: x(x)
, y(y)
, z(z)
, w(w)
{}
int x, y, z, w;
};
#endif // VECTOR_H
@@ -7,7 +7,8 @@
#include "utility/messaging/Message.h"
#include "utility/messaging/type/MessageStatus.h"
class MessageFinishedParsing: public Message<MessageFinishedParsing>
class MessageFinishedParsing
: public Message<MessageFinishedParsing>
{
public:
MessageFinishedParsing(size_t fileCount, size_t totalFileCount, float parseTime, size_t errorCount)
@@ -33,7 +34,7 @@ public:
std::string getStatusStr() const
{
std::stringstream ss;
ss << "Parsing Finished: ";
ss << "Finished analysis: ";
ss << fileCount << "/" << totalFileCount << " files, ";
ss << std::setprecision(2) << std::fixed << parseTime << " seconds, ";
ss << errorCount << " error(s)";
+1 -1
View File
@@ -166,6 +166,6 @@ void TaskScheduler::handleMessage(MessageInterruptTasks* message)
std::lock_guard<std::mutex> lock(m_tasksMutex);
if (m_tasks.size())
{
MessageStatus("Stop running tasks...").dispatch();
MessageStatus("Stop running tasks...", false, true).dispatch();
}
}
+13
View File
@@ -1,5 +1,6 @@
#include "utility/text/Dictionary.h"
#include "data/name/NameHierarchy.h"
#include "utility/utilityString.h"
Dictionary::Dictionary()
@@ -84,6 +85,18 @@ std::deque<Id> Dictionary::getWordIdsConst(const std::string& wordList, const st
return ids;
}
std::deque<Id> Dictionary::getWordIdsConst(const NameHierarchy& nameHierarchy) const
{
std::deque<Id> ids;
for (size_t i = 0; i < nameHierarchy.size(); i++)
{
ids.push_back(getWordIdConst(nameHierarchy[i]->getFullName()));
}
return ids;
}
const std::string& Dictionary::getWord(Id id) const
{
std::unordered_map<Id, std::string>::const_iterator it = m_words.find(id);
+3
View File
@@ -9,6 +9,8 @@
#include "utility/types.h"
class NameHierarchy;
class Dictionary
{
public:
@@ -25,6 +27,7 @@ public:
std::deque<Id> getWordIds(const std::string& wordList, const std::string& delimiter);
std::deque<Id> getWordIdsConst(const std::string& wordList, const std::string& delimiter) const;
std::deque<Id> getWordIdsConst(const NameHierarchy& nameHierarchy) const;
// Note: References to values in an unordered_map don't change on rehashing so they can be saved and used elsewhere.
const std::string& getWord(Id id) const;
+2 -2
View File
@@ -254,8 +254,8 @@ public:
matches = index.runFuzzySearchAndGetMatches("uml");
TS_ASSERT_EQUALS(2, matches.size());
TS_ASSERT_EQUALS("util::math::floor", matches[0].fullName);
TS_ASSERT_EQUALS("util::math::ceil", matches[1].fullName);
TS_ASSERT_EQUALS("util::math::ceil", matches[0].fullName);
TS_ASSERT_EQUALS("util::math::floor", matches[1].fullName);
}
void test_fuzzy_matching_in_hierarchy_respects_collin()