ui: activating multiple overlapping source locations

All overlapping source locations will be activated and the corresponding nodes highlighted, with all of their names
displayed in the search bar.
This commit is contained in:
Eberhard Graether
2015-09-11 14:52:39 +02:00
parent 0fc80d2a52
commit 6e835bd5f5
20 changed files with 191 additions and 114 deletions
+33 -11
View File
@@ -6,7 +6,7 @@
#include <QPushButton>
#include <QToolTip>
#include "utility/messaging/type/MessageActivateTokenLocation.h"
#include "utility/messaging/type/MessageActivateTokenLocations.h"
#include "utility/messaging/type/MessageShowFile.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
@@ -234,11 +234,11 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
if (event->button() == Qt::LeftButton)
{
QTextCursor cursor = this->cursorForPosition(event->pos());
const Annotation* annotation = findAnnotationForPosition(cursor.position());
std::vector<Id> locationIds = findLocationIdsForPosition(cursor.position());
if (annotation && !annotation->isScope)
if (locationIds.size())
{
MessageActivateTokenLocation(annotation->locationId).dispatch();
MessageActivateTokenLocations(locationIds).dispatch();
}
}
}
@@ -254,6 +254,8 @@ void QtCodeArea::mouseDoubleClickEvent(QMouseEvent* event)
void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
{
QTextCursor cursor = this->cursorForPosition(event->pos());
m_hoveredLocationIds = findLocationIdsForPosition(cursor.position());
const Annotation* annotation = findAnnotationForPosition(cursor.position());
if (annotation && annotation->isScope)
@@ -268,12 +270,15 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
setHoveredAnnotation(annotation);
const std::vector<std::string>& errorMessages = m_fileWidget->getErrorMessages();
if (annotation && errorMessages.size() > annotation->tokenId)
{
QToolTip::showText(event->globalPos(), QString::fromStdString(errorMessages[annotation->tokenId]));
}
}
else if (m_hoveredLocationIds.size())
{
updateContent();
}
}
void QtCodeArea::updateLineNumberAreaWidth(int /* newBlockCount */)
@@ -339,6 +344,21 @@ const QtCodeArea::Annotation* QtCodeArea::findAnnotationForPosition(int pos) con
return annotationPtr;
}
std::vector<Id> QtCodeArea::findLocationIdsForPosition(int pos) const
{
std::vector<Id> locationIds;
for (const Annotation& annotation : m_annotations)
{
if (!annotation.isScope && pos >= annotation.start && pos <= annotation.end)
{
locationIds.push_back(annotation.locationId);
}
}
return locationIds;
}
void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFile)
{
locationFile->forEachStartTokenLocation(
@@ -390,7 +410,8 @@ void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFi
void QtCodeArea::annotateText()
{
Id focusedTokenId = m_fileWidget->getFocusedTokenId();
const std::vector<Id>& ids = m_fileWidget->getActiveTokenIds();
const std::vector<Id>& activeIds = m_fileWidget->getActiveTokenIds();
const std::vector<Id>& hoverIds = m_hoveredLocationIds;
const std::vector<std::string>& errorMessages = m_fileWidget->getErrorMessages();
std::vector<ScopeAnnotation> scopeAnnotations;
@@ -407,11 +428,12 @@ void QtCodeArea::annotateText()
for (const Annotation& annotation: m_annotations)
{
bool isActive = std::find(ids.begin(), ids.end(), annotation.tokenId) != ids.end();
bool isActive = std::find(activeIds.begin(), activeIds.end(), annotation.tokenId) != activeIds.end();
bool isHovered = std::find(hoverIds.begin(), hoverIds.end(), annotation.locationId) != hoverIds.end();
bool isFocused = (annotation.tokenId == focusedTokenId);
QColor color;
if (&annotation == m_hoveredAnnotation && errorMessages.size())
if (isHovered && errorMessages.size())
{
color = activeErrorColor;
}
@@ -419,7 +441,7 @@ void QtCodeArea::annotateText()
{
color = errorColor;
}
else if (isActive || isFocused)
else if (isActive || isFocused || isHovered)
{
color = activeLocationColor;
}
@@ -440,7 +462,7 @@ void QtCodeArea::annotateText()
selection.cursor.setPosition(annotation.end, QTextCursor::KeepAnchor);
scopeAnnotation.endLine = selection.cursor.blockNumber();
if (annotation.isScope || (isActive && ids.size() == 1))
if (annotation.isScope || (isActive && activeIds.size() == 1))
{
if (isActive || isFocused)
{
@@ -453,7 +475,7 @@ void QtCodeArea::annotateText()
}
}
if (!annotation.isScope || (isActive && ids.size() == 1 && scopeAnnotation.startLine == scopeAnnotation.endLine))
if (!annotation.isScope || (isActive && activeIds.size() == 1 && scopeAnnotation.startLine == scopeAnnotation.endLine))
{
extraSelections.append(selection);
}
+3
View File
@@ -102,6 +102,8 @@ private:
};
const Annotation* findAnnotationForPosition(int pos) const;
std::vector<Id> findLocationIdsForPosition(int pos) const;
void createAnnotations(std::shared_ptr<TokenLocationFile> locationFile);
void annotateText();
@@ -126,6 +128,7 @@ private:
std::vector<ScopeAnnotation> m_scopeAnnotations;
const Annotation* m_hoveredAnnotation;
std::vector<Id> m_hoveredLocationIds;
int m_digits;
};
+5
View File
@@ -62,3 +62,8 @@ void QtMainView::setStatusBar(QStatusBar* statusbar)
{
m_window->setStatusBar(statusbar);
}
void QtMainView::showStartScreen()
{
m_window->showStartScreen();
}
+3
View File
@@ -29,6 +29,9 @@ public:
virtual QStatusBar* getStatusBar();
virtual void setStatusBar(QStatusBar* statusBar);
// MainView implementation
virtual void showStartScreen();
private:
std::shared_ptr<QtMainWindow> m_window;
std::vector<View*> m_views;
@@ -1,6 +1,6 @@
#include "qt/view/graphElements/QtGraphNodeData.h"
#include "utility/messaging/type/MessageActivateNode.h"
#include "utility/messaging/type/MessageActivateNodes.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageGraphNodeMove.h"
@@ -42,7 +42,9 @@ Id QtGraphNodeData::getTokenId() const
void QtGraphNodeData::onClick()
{
MessageActivateNode(m_data->getId(), m_data->getType(), m_data->getFullName()).dispatch();
MessageActivateNodes message;
message.addNode(m_data->getId(), m_data->getType(), m_data->getFullName());
message.dispatch();
}
void QtGraphNodeData::moved(const Vec2i& oldPosition)
+1 -5
View File
@@ -53,11 +53,7 @@ void QtMainWindow::init()
{
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
if (appSettings->getUserHasSeenSettings())
{
showStartScreen();
}
else
if (!appSettings->getUserHasSeenSettings())
{
openSettings();
m_startScreenWasVisible = true;