ui: Added shortcuts for navigating to next and previous reference in code view

* Added new class QtCodeNavigator between QtCodeView and QtCodeFileList that handles active ids and navigation
* Pass all files as initially collapsed to code view and decide in QtCodeNavigator which ones show content
* Rewrote requesting of active snippet display to top down approach
* Display other locations focused when active location changes
* Show corresponding edges when navigating references
This commit is contained in:
Eberhard Graether
2016-08-09 13:29:14 +02:00
parent 210c5b1245
commit d0a063a3b6
32 changed files with 1037 additions and 599 deletions
+118
View File
@@ -0,0 +1,118 @@
#ifndef QT_CODE_NAVIGATOR_H
#define QT_CODE_NAVIGATOR_H
#include <QWidget>
#include <QScrollArea>
#include "qt/element/QtCodeFileList.h"
#include "qt/utility/QtThreadedFunctor.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageCodeReference.h"
class QLabel;
class QPushButton;
class TokenLocationCollection;
class TokenLocationFile;
class QtCodeNavigator
: public QWidget
, public MessageListener<MessageCodeReference>
{
Q_OBJECT
public:
QtCodeNavigator(QWidget* parent = nullptr);
virtual ~QtCodeNavigator();
void addCodeSnippet(const CodeSnippetParams& params, bool insert = false);
void addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime);
void clearCodeSnippets();
const std::vector<Id>& getCurrentActiveTokenIds() const;
void setCurrentActiveTokenIds(const std::vector<Id>& currentActiveTokenIds);
const std::vector<Id>& getCurrentActiveLocationIds() const;
void setCurrentActiveLocationIds(const std::vector<Id>& currentActiveLocationIds);
const std::vector<Id>& getActiveTokenIds() const;
void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
const std::vector<Id>& getActiveLocalSymbolIds() const;
void setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds);
const std::vector<Id>& getFocusedTokenIds() const;
void setFocusedTokenIds(const std::vector<Id>& focusedTokenIds);
std::vector<std::string> getErrorMessages() const;
void setErrorInfos(const std::vector<ErrorInfo>& errorInfos);
bool hasErrors() const;
size_t getFatalErrorCountForFile(const FilePath& filePath) const;
void showActiveSnippet(
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo);
void focusTokenIds(const std::vector<Id>& focusedTokenIds);
void defocusTokenIds();
void setFileMinimized(const FilePath path);
void setFileSnippets(const FilePath path);
void setFileMaximized(const FilePath path);
void setupFiles();
void updateFiles();
void showContents();
void scrollToValue(int value);
void scrollToLine(std::string filename, unsigned int line);
void scrollToSnippetIfRequested();
private slots:
void scrolled(int value);
void scrollToSnippet(QtCodeSnippet* snippet, uint lineNumber);
void setValue();
void previousReference();
void nextReference();
private:
struct Reference
{
FilePath filePath;
Id tokenId;
Id locationId;
};
void showCurrentReference();
void updateRefLabel();
void ensureWidgetVisibleAnimated(QWidget *childWidget, QRectF rect);
void handleMessage(MessageCodeReference* message);
void doSwitchReference(MessageCodeReference::ReferenceType type);
QtThreadedFunctor<MessageCodeReference::ReferenceType> m_switchReferenceFunctor;
QScrollArea* m_scrollArea;
QtCodeFileList* m_list;
std::vector<Id> m_currentActiveTokenIds;
std::vector<Id> m_currentActiveLocationIds;
std::vector<Id> m_activeTokenIds;
std::vector<Id> m_activeLocalSymbolIds;
std::vector<Id> m_focusedTokenIds;
std::vector<ErrorInfo> m_errorInfos;
int m_value;
QLabel* m_refLabel;
QPushButton* m_prevButton;
QPushButton* m_nextButton;
std::vector<Reference> m_references;
size_t m_refIndex;
};
#endif // QT_CODE_NAVIGATOR_H