logic: search bar duplicates

* When a location is clicked in the code that has more than one TokenLocations pointing to the same element, only one instance of the element is displayed in the search bar.
This commit is contained in:
malte_langkabel
2016-02-22 14:17:53 +01:00
parent fc1a43c1a5
commit e054df2e71
3 changed files with 20 additions and 10 deletions
+4 -4
View File
@@ -881,7 +881,7 @@ std::vector<Id> Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) c
std::vector<Id> Storage::getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const
{
std::vector<Id> nodeIds;
std::set<Id> nodeIds;
for (Id locationId : locationIds)
{
@@ -890,15 +890,15 @@ std::vector<Id> Storage::getNodeIdsForLocationIds(const std::vector<Id>& locatio
StorageEdge edge = m_sqliteStorage.getEdgeById(elementId);
if (edge.id != 0) // here we test if location is an edge.
{
nodeIds.push_back(edge.targetNodeId);
nodeIds.insert(edge.targetNodeId);
}
else
{
nodeIds.push_back(elementId);
nodeIds.insert(elementId);
}
}
return nodeIds;
return utility::toVector(nodeIds);
}
std::vector<Id> Storage::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
+11
View File
@@ -33,6 +33,9 @@ namespace utility
template<typename T>
std::vector<T> toVector(const std::deque<T>& d);
template<typename T>
std::vector<T> toVector(const std::set<T>& d);
template<typename T>
std::vector<std::string> toStrings(const std::vector<T>& d);
@@ -81,6 +84,14 @@ std::vector<T> utility::toVector(const std::deque<T>& d)
return v;
}
template<typename T>
std::vector<T> utility::toVector(const std::set<T>& d)
{
std::vector<T> v;
v.insert(v.begin(), d.begin(), d.end());
return v;
}
template<typename T>
std::vector<std::string> utility::toStrings(const std::vector<T>& d)
{
+5 -6
View File
@@ -419,7 +419,6 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
if (Qt::KeyboardModifier::ControlModifier && QApplication::keyboardModifiers())
{
// std::pair<int, int> lineColumn = toLineColumn(this->cursorForPosition(event->pos()).position());
m_eventPosition = event->pos();
setIDECursorPosition();
}
@@ -429,7 +428,7 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
std::vector<const Annotation*> annotations = getAnnotationsForPosition(cursor.position());
std::vector<Id> locationIds;
std::vector<Id> tokenIds;
std::set<Id> tokenIds;
bool allActive = true;
for (const Annotation* annotation : annotations)
@@ -445,7 +444,7 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
}
if (annotation->tokenId > 0)
{
tokenIds.push_back(annotation->tokenId);
tokenIds.insert(annotation->tokenId);
}
}
@@ -458,9 +457,9 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
{
MessageActivateTokenLocations(locationIds).dispatch();
}
else if (tokenIds.size())
else if (tokenIds.size()) // fallback for links in project description
{
MessageActivateTokenIds(tokenIds).dispatch();
MessageActivateTokenIds(utility::toVector(tokenIds)).dispatch();
}
}
}
@@ -878,4 +877,4 @@ void QtCodeArea::createActions()
m_setIDECursorPositionAction->setStatusTip(tr("Set the IDE Cursor to this code position"));
m_setIDECursorPositionAction->setToolTip(tr("Set the IDE Cursor to this code position"));
connect(m_setIDECursorPositionAction, SIGNAL(triggered()), this, SLOT(setIDECursorPosition()));
}
}