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
+32 -2
View File
@@ -4,6 +4,8 @@
#include "component/view/GraphView.h"
#include "component/view/ViewLayout.h"
#include "data/location/TokenLocationFile.h"
std::shared_ptr<ComponentManager> ComponentManager::create(
GuiFactory* guiFactory,
ViewLayout* viewLayout,
@@ -33,8 +35,36 @@ void ComponentManager::setup()
m_components.push_back(codeComponent);
CodeView* codeView = codeComponent->getView<CodeView>();
codeView->addCodeSnippet("class HelloWorld;");
codeView->addCodeSnippet("static int n = 42; // the answer.");
std::string code =
"class HelloWorld;\n"
"static int n = 42; // the answer.\n"
"\n"
"int sum(int a, int b)\n"
"{\n"
" return a + b;\n"
"}\n";
TokenLocationFile locationFile("test.cpp");
locationFile.addTokenLocation(1, 1, 7, 1, 16);
locationFile.addTokenLocation(2, 2, 8, 2, 10);
locationFile.addTokenLocation(3, 2, 12, 2, 12);
locationFile.addTokenLocation(4, 4, 1, 7, 1);
codeView->addCodeSnippet(code, locationFile, 1);
std::string code2 =
"const char* name = new char[10];\n"
"\n"
"name = \"MetaVizz\\0\";";
TokenLocationFile locationFile2("test.cpp");
locationFile2.addTokenLocation(5, 123, 1, 123, 11);
locationFile2.addTokenLocation(6, 123, 13, 123, 16);
locationFile2.addTokenLocation(7, 125, 1, 125, 4);
codeView->addCodeSnippet(code2, locationFile2, 123);
// codeView->clearCodeSnippets();
}