logic: Scroll active definition to top of code view is possible
* don't log hande message * fixed graph gets animated when using next and previous code reference shortcuts * fixed message scroll code handling
This commit is contained in:
@@ -275,6 +275,31 @@ uint QtCodeArea::getLineNumberForLocationId(Id locationId) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
int QtCodeArea::getStartLineNumberOfFirstActiveScope() const
|
||||
{
|
||||
int firstActiveLine = 0;
|
||||
for (const Annotation& annotation : m_annotations)
|
||||
{
|
||||
if (annotation.locationType == LocationType::LOCATION_SCOPE && annotation.isActive)
|
||||
{
|
||||
if (firstActiveLine && firstActiveLine != annotation.startLine)
|
||||
{
|
||||
return annotation.startLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getStartLineNumber();
|
||||
}
|
||||
}
|
||||
else if (annotation.isActive)
|
||||
{
|
||||
firstActiveLine = annotation.startLine;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRectF QtCodeArea::getLineRectForLineNumber(uint lineNumber) const
|
||||
{
|
||||
if (lineNumber < getStartLineNumber())
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
void setIsActiveFile(bool isActiveFile);
|
||||
|
||||
uint getLineNumberForLocationId(Id locationId) const;
|
||||
int getStartLineNumberOfFirstActiveScope() const;
|
||||
QRectF getLineRectForLineNumber(uint lineNumber) const;
|
||||
|
||||
std::string getCode() const;
|
||||
|
||||
@@ -273,6 +273,24 @@ QtCodeSnippet* QtCodeFile::getFileSnippet() const
|
||||
return m_fileSnippet.get();
|
||||
}
|
||||
|
||||
std::pair<QtCodeSnippet*, int> QtCodeFile::getFirstSnippetWithActiveScope() const
|
||||
{
|
||||
std::pair<QtCodeSnippet*, int> result(nullptr, 0);
|
||||
|
||||
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
|
||||
{
|
||||
int startLineNumber = snippet->getStartLineNumberOfFirstActiveScope();
|
||||
if (startLineNumber != 0)
|
||||
{
|
||||
result.first = snippet.get();
|
||||
result.second = startLineNumber;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool QtCodeFile::isCollapsed() const
|
||||
{
|
||||
return m_locationFile != nullptr;
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
QtCodeSnippet* getSnippetForLine(unsigned int line) const;
|
||||
QtCodeSnippet* getFileSnippet() const;
|
||||
|
||||
std::pair<QtCodeSnippet*, int> getFirstSnippetWithActiveScope() const;
|
||||
|
||||
bool isCollapsed() const;
|
||||
|
||||
void requestContent() const;
|
||||
|
||||
@@ -127,3 +127,24 @@ QtCodeFile* QtCodeFileList::getFile(const FilePath filePath)
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
std::pair<QtCodeSnippet*, int> QtCodeFileList::getFirstSnippetWithActiveScope() const
|
||||
{
|
||||
std::pair<QtCodeSnippet*, int> result(nullptr, 0);
|
||||
|
||||
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
||||
{
|
||||
if (filePtr->isCollapsed())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result = filePtr->getFirstSnippetWithActiveScope();
|
||||
if (result.first != nullptr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
void onWindowFocus();
|
||||
|
||||
QtCodeFile* getFile(const FilePath filePath);
|
||||
std::pair<QtCodeSnippet*, int> getFirstSnippetWithActiveScope() const;
|
||||
|
||||
private:
|
||||
QtCodeSnippet* getFirstActiveSnippet() const;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/messaging/type/MessageCodeViewExpandedInitialFiles.h"
|
||||
#include "utility/messaging/type/MessageScrollCode.h"
|
||||
#include "utility/messaging/type/MessageShowReference.h"
|
||||
|
||||
@@ -82,8 +83,8 @@ QtCodeNavigator::QtCodeNavigator(QWidget* parent)
|
||||
m_scrollSpeedChangeListener.setScrollBar(m_scrollArea->verticalScrollBar());
|
||||
|
||||
connect(m_scrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(scrolled(int)));
|
||||
connect(this, SIGNAL(shouldScrollToSnippet(QtCodeSnippet*, uint)),
|
||||
this, SLOT(scrollToSnippet(QtCodeSnippet*, uint)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(shouldScrollToSnippet(QtCodeSnippet*, uint, bool)),
|
||||
this, SLOT(scrollToSnippet(QtCodeSnippet*, uint, bool)), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QtCodeNavigator::~QtCodeNavigator()
|
||||
@@ -357,6 +358,11 @@ void QtCodeNavigator::setupFiles()
|
||||
}
|
||||
}
|
||||
|
||||
if (filePathsToExpand.size())
|
||||
{
|
||||
MessageCodeViewExpandedInitialFiles().dispatch();
|
||||
}
|
||||
|
||||
m_refIndex = 0;
|
||||
updateRefLabel();
|
||||
}
|
||||
@@ -396,7 +402,7 @@ void QtCodeNavigator::showLocation(const FilePath& filePath, Id locationId, bool
|
||||
void QtCodeNavigator::scrollToValue(int value)
|
||||
{
|
||||
m_value = value;
|
||||
QTimer::singleShot(100, this, SLOT(setValue()));
|
||||
QTimer::singleShot(1000, this, SLOT(setValue()));
|
||||
}
|
||||
|
||||
void QtCodeNavigator::scrollToLine(const FilePath& filePath, unsigned int line)
|
||||
@@ -417,7 +423,7 @@ void QtCodeNavigator::scrollToLine(const FilePath& filePath, unsigned int line)
|
||||
}
|
||||
else if (file->getFileSnippet())
|
||||
{
|
||||
emit shouldScrollToSnippet(file->getFileSnippet(), line);
|
||||
emit shouldScrollToSnippet(file->getFileSnippet(), line, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -454,20 +460,30 @@ void QtCodeNavigator::scrollToLocation(QtCodeFile* file, Id locationId, bool scr
|
||||
{
|
||||
if (locationId)
|
||||
{
|
||||
emit shouldScrollToSnippet(snippet, snippet->getLineNumberForLocationId(locationId));
|
||||
emit shouldScrollToSnippet(snippet, snippet->getLineNumberForLocationId(locationId), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit shouldScrollToSnippet(snippet, 1);
|
||||
emit shouldScrollToSnippet(snippet, 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeNavigator::scrollToDefinition()
|
||||
{
|
||||
std::pair<QtCodeSnippet*, int> result = m_list->getFirstSnippetWithActiveScope();
|
||||
|
||||
if (result.first != nullptr)
|
||||
{
|
||||
emit shouldScrollToSnippet(result.first, result.second, true);
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeNavigator::scrollToSnippetIfRequested()
|
||||
{
|
||||
if (m_scrollToFile && m_scrollToLine)
|
||||
{
|
||||
emit shouldScrollToSnippet(m_scrollToFile->getSnippetForLine(m_scrollToLine), m_scrollToLine);
|
||||
emit shouldScrollToSnippet(m_scrollToFile->getSnippetForLine(m_scrollToLine), m_scrollToLine, false);
|
||||
}
|
||||
else if (m_scrollToFile && m_scrollToFile->hasSnippets())
|
||||
{
|
||||
@@ -490,11 +506,11 @@ void QtCodeNavigator::scrolled(int value)
|
||||
MessageScrollCode(value).dispatch();
|
||||
}
|
||||
|
||||
void QtCodeNavigator::scrollToSnippet(QtCodeSnippet* snippet, uint lineNumber)
|
||||
void QtCodeNavigator::scrollToSnippet(QtCodeSnippet* snippet, uint lineNumber, bool onTop)
|
||||
{
|
||||
if (lineNumber)
|
||||
{
|
||||
this->ensureWidgetVisibleAnimated(snippet, snippet->getLineRectForLineNumber(lineNumber));
|
||||
this->ensureWidgetVisibleAnimated(snippet, snippet->getLineRectForLineNumber(lineNumber), onTop);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,7 +585,7 @@ void QtCodeNavigator::updateRefLabel()
|
||||
m_nextButton->setEnabled(n > 1);
|
||||
}
|
||||
|
||||
void QtCodeNavigator::ensureWidgetVisibleAnimated(QWidget *childWidget, QRectF rect)
|
||||
void QtCodeNavigator::ensureWidgetVisibleAnimated(QWidget *childWidget, QRectF rect, bool onTop)
|
||||
{
|
||||
QScrollArea* area = m_scrollArea;
|
||||
|
||||
@@ -594,6 +610,15 @@ void QtCodeNavigator::ensureWidgetVisibleAnimated(QWidget *childWidget, QRectF r
|
||||
QScrollBar* scrollBar = area->verticalScrollBar();
|
||||
int value = focusRect.center().y() - visibleRect.center().y();
|
||||
|
||||
if (onTop)
|
||||
{
|
||||
value = focusRect.top() - visibleRect.top();
|
||||
if (value < 50)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollBar && value != 0)
|
||||
{
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(scrollBar, "value");
|
||||
|
||||
@@ -72,16 +72,17 @@ public:
|
||||
void scrollToValue(int value);
|
||||
void scrollToLine(const FilePath& filePath, unsigned int line);
|
||||
void scrollToLocation(QtCodeFile* file, Id locationId, bool scrollTo);
|
||||
void scrollToDefinition();
|
||||
|
||||
void scrollToSnippetIfRequested();
|
||||
void requestScrollToLine(QtCodeFile* file, unsigned int line);
|
||||
|
||||
signals:
|
||||
void shouldScrollToSnippet(QtCodeSnippet* widget, uint lineNumber);
|
||||
void shouldScrollToSnippet(QtCodeSnippet* widget, uint lineNumber, bool onTop);
|
||||
|
||||
private slots:
|
||||
void scrolled(int value);
|
||||
void scrollToSnippet(QtCodeSnippet* snippet, uint lineNumber);
|
||||
void scrollToSnippet(QtCodeSnippet* snippet, uint lineNumber, bool onTop);
|
||||
void setValue();
|
||||
|
||||
void previousReference();
|
||||
@@ -98,7 +99,7 @@ private:
|
||||
void showCurrentReference();
|
||||
void updateRefLabel();
|
||||
|
||||
void ensureWidgetVisibleAnimated(QWidget *childWidget, QRectF rect);
|
||||
void ensureWidgetVisibleAnimated(QWidget *childWidget, QRectF rect, bool onTop);
|
||||
|
||||
void handleMessage(MessageCodeReference* message);
|
||||
void handleMessage(MessageWindowFocus* message);
|
||||
|
||||
@@ -160,6 +160,11 @@ uint QtCodeSnippet::getLineNumberForLocationId(Id locationId) const
|
||||
return m_codeArea->getLineNumberForLocationId(locationId);
|
||||
}
|
||||
|
||||
int QtCodeSnippet::getStartLineNumberOfFirstActiveScope() const
|
||||
{
|
||||
return m_codeArea->getStartLineNumberOfFirstActiveScope();
|
||||
}
|
||||
|
||||
QRectF QtCodeSnippet::getLineRectForLineNumber(uint lineNumber) const
|
||||
{
|
||||
return m_codeArea->getLineRectForLineNumber(lineNumber);
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
void setIsActiveFile(bool isActiveFile);
|
||||
|
||||
uint getLineNumberForLocationId(Id locationId) const;
|
||||
int getStartLineNumberOfFirstActiveScope() const;
|
||||
QRectF getLineRectForLineNumber(uint lineNumber) const;
|
||||
|
||||
std::string getCode() const;
|
||||
|
||||
@@ -124,6 +124,16 @@ void QtCodeView::scrollToLine(const FilePath filePath, unsigned int line)
|
||||
m_scrollToLineFunctor(filePath, line);
|
||||
}
|
||||
|
||||
void QtCodeView::scrollToDefinition()
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
m_widget->scrollToDefinition();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtCodeView::doRefreshView()
|
||||
{
|
||||
setStyleSheet();
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
|
||||
virtual void scrollToValue(int value);
|
||||
virtual void scrollToLine(const FilePath filePath, unsigned int line);
|
||||
virtual void scrollToDefinition();
|
||||
|
||||
private:
|
||||
void doRefreshView();
|
||||
@@ -89,6 +90,8 @@ private:
|
||||
QtThreadedFunctor<int> m_scrollToValueFunctor;
|
||||
QtThreadedFunctor<const FilePath, unsigned int> m_scrollToLineFunctor;
|
||||
|
||||
QtThreadedLambdaFunctor m_onQtThread;
|
||||
|
||||
QtCodeNavigator* m_widget;
|
||||
|
||||
std::vector<ErrorInfo> m_errorInfos;
|
||||
|
||||
Reference in New Issue
Block a user