From af8a178b7160196d63afeec7b17b4eb01c9efc87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 14 Sep 2010 20:56:33 +0200 Subject: [PATCH] cppcheck-verify: added code editor that highlight the errors --- verify/cppcheck-verify.pro | 10 ++++------ verify/mainwindow.cpp | 20 ++++++++------------ verify/mainwindow.h | 1 - verify/mainwindow.ui | 19 ++++++++++++++++--- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/verify/cppcheck-verify.pro b/verify/cppcheck-verify.pro index 7d65a2f7b..15373457b 100644 --- a/verify/cppcheck-verify.pro +++ b/verify/cppcheck-verify.pro @@ -1,7 +1,6 @@ TARGET = cppcheck-verify TEMPLATE = app INCLUDEPATH += ../lib - SOURCES += main.cpp \ mainwindow.cpp \ ../lib/tokenize.cpp \ @@ -13,8 +12,8 @@ SOURCES += main.cpp \ ../lib/filelister_win32.cpp \ ../lib/filelister_unix.cpp \ ../lib/filelister.cpp \ - ../lib/errorlogger.cpp - + ../lib/errorlogger.cpp \ + codeeditor.cpp HEADERS += mainwindow.h \ ../lib/tokenize.h \ ../lib/token.h \ @@ -25,7 +24,6 @@ HEADERS += mainwindow.h \ ../lib/filelister_win32.h \ ../lib/filelister_unix.h \ ../lib/filelister.h \ - ../lib/errorlogger.h - + ../lib/errorlogger.h \ + codeeditor.h FORMS += mainwindow.ui - diff --git a/verify/mainwindow.cpp b/verify/mainwindow.cpp index 18d5c321f..77e0d49d1 100644 --- a/verify/mainwindow.cpp +++ b/verify/mainwindow.cpp @@ -98,29 +98,25 @@ void MainWindow::open() // show report.. { std::ostringstream report; - report << std::string(8,' '); - unsigned int lineno = 1; std::ifstream fin(fileName.c_str()); for (unsigned char c = readChar(fin); fin.good(); c = readChar(fin)) { + if (c & 0x80) + continue; report << c; - if (c == '\n') - { - ++lineno; - if (errorlines.find(lineno) != errorlines.end()) - report << std::string(6,'!') << " "; - else - report << std::string(8,' '); - } } - ui->plainTextEdit->setPlainText(QString::fromStdString(report.str())); + ui->codeEditor->setPlainText(QString::fromStdString(report.str())); + + QList errorLines; + for (std::set::const_iterator it = errorlines.begin(); it != errorlines.end(); ++it) + errorLines.push_back(*it); + ui->codeEditor->highlightErrors(errorLines); } } - /** * Check that array indexes are within bounds * 1. Locate array access through: [ .. ] diff --git a/verify/mainwindow.h b/verify/mainwindow.h index 34db65a84..4866421cf 100644 --- a/verify/mainwindow.h +++ b/verify/mainwindow.h @@ -40,5 +40,4 @@ private slots: private: Ui::MainWindow *ui; }; - #endif // MAINWINDOW_H diff --git a/verify/mainwindow.ui b/verify/mainwindow.ui index 5a93f241f..c639257e7 100644 --- a/verify/mainwindow.ui +++ b/verify/mainwindow.ui @@ -16,9 +16,15 @@ - - - ab + + + QPlainTextEdit::NoWrap + + + true + + + 4 @@ -57,6 +63,13 @@ + + + CodeEditor + QPlainTextEdit +
codeeditor.h
+
+