ui: Improved QtCodeView to annotate code

Added some features to QTCodeSnippet:
* Code is now annotated using information from TokenLocationFile
* Start of line numbering can be set
* Clicking on an annotation in the code gives the corresponding Token Id

fortune cookie message = Your kindness will be repaid.
This commit is contained in:
Eberhard Graether
2014-07-03 10:35:30 +02:00
parent e63106b13b
commit 4c7bbbe28e
8 changed files with 316 additions and 15 deletions
+14 -6
View File
@@ -1,7 +1,10 @@
#include "qt/view/QtCodeView.h"
#include <iostream>
#include <QtWidgets>
#include "data/location/TokenLocationFile.h"
#include "qt/element/QtCodeSnippet.h"
#include "qt/QtWidgetWrapper.h"
#include "qt/utility/QtHighLighter.h"
#include "qt/utility/utilityQt.h"
@@ -9,7 +12,7 @@
QtCodeView::QtCodeView(ViewLayout* viewLayout)
: CodeView(viewLayout)
, m_clearCodeSnippetsFunctor(std::bind(&QtCodeView::doClearCodeSnippets, this))
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1))
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))
{
}
@@ -37,9 +40,9 @@ void QtCodeView::initGui()
m_font.setPointSize(10);
}
void QtCodeView::addCodeSnippet(std::string str)
void QtCodeView::addCodeSnippet(const std::string& str, const TokenLocationFile& locationFile, int startLineNumber)
{
m_addCodeSnippetFunctor(str);
m_addCodeSnippetFunctor(str, locationFile, startLineNumber);
}
void QtCodeView::clearCodeSnippets()
@@ -47,17 +50,22 @@ void QtCodeView::clearCodeSnippets()
m_clearCodeSnippetsFunctor();
}
void QtCodeView::doAddCodeSnippet(std::string str)
void QtCodeView::activateToken(Id tokenId) const
{
std::cout << "TODO: activate Token: " << tokenId << std::endl;
}
void QtCodeView::doAddCodeSnippet(const std::string& str, const TokenLocationFile& locationFile, int startLineNumber)
{
std::shared_ptr<Snippet> snippet = std::make_shared<Snippet>();
snippet->textField = std::make_shared<QTextEdit>();
snippet->textField = std::make_shared<QtCodeSnippet>(this, startLineNumber);
snippet->textField->setReadOnly(true);
snippet->textField->setFont(m_font);
snippet->highlighter = std::make_shared<QtHighlighter>(snippet->textField->document());
snippet->textField->setPlainText(QString::fromUtf8(str.c_str()));
snippet->textField->annotateText(locationFile);
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
widget->layout()->addWidget(snippet->textField.get());