cppcheck-verify: added code editor that highlight the errors

This commit is contained in:
Daniel Marjamäki 2010-09-14 20:56:33 +02:00
parent 2387ed49f3
commit af8a178b71
4 changed files with 28 additions and 22 deletions

View File

@ -1,7 +1,6 @@
TARGET = cppcheck-verify TARGET = cppcheck-verify
TEMPLATE = app TEMPLATE = app
INCLUDEPATH += ../lib INCLUDEPATH += ../lib
SOURCES += main.cpp \ SOURCES += main.cpp \
mainwindow.cpp \ mainwindow.cpp \
../lib/tokenize.cpp \ ../lib/tokenize.cpp \
@ -13,8 +12,8 @@ SOURCES += main.cpp \
../lib/filelister_win32.cpp \ ../lib/filelister_win32.cpp \
../lib/filelister_unix.cpp \ ../lib/filelister_unix.cpp \
../lib/filelister.cpp \ ../lib/filelister.cpp \
../lib/errorlogger.cpp ../lib/errorlogger.cpp \
codeeditor.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
../lib/tokenize.h \ ../lib/tokenize.h \
../lib/token.h \ ../lib/token.h \
@ -25,7 +24,6 @@ HEADERS += mainwindow.h \
../lib/filelister_win32.h \ ../lib/filelister_win32.h \
../lib/filelister_unix.h \ ../lib/filelister_unix.h \
../lib/filelister.h \ ../lib/filelister.h \
../lib/errorlogger.h ../lib/errorlogger.h \
codeeditor.h
FORMS += mainwindow.ui FORMS += mainwindow.ui

View File

@ -98,29 +98,25 @@ void MainWindow::open()
// show report.. // show report..
{ {
std::ostringstream report; std::ostringstream report;
report << std::string(8,' ');
unsigned int lineno = 1;
std::ifstream fin(fileName.c_str()); std::ifstream fin(fileName.c_str());
for (unsigned char c = readChar(fin); fin.good(); c = readChar(fin)) for (unsigned char c = readChar(fin); fin.good(); c = readChar(fin))
{ {
if (c & 0x80)
continue;
report << c; report << c;
if (c == '\n')
{
++lineno;
if (errorlines.find(lineno) != errorlines.end())
report << std::string(6,'!') << " ";
else
report << std::string(8,' ');
} }
} ui->codeEditor->setPlainText(QString::fromStdString(report.str()));
ui->plainTextEdit->setPlainText(QString::fromStdString(report.str()));
QList<int> errorLines;
for (std::set<unsigned int>::const_iterator it = errorlines.begin(); it != errorlines.end(); ++it)
errorLines.push_back(*it);
ui->codeEditor->highlightErrors(errorLines);
} }
} }
/** /**
* Check that array indexes are within bounds * Check that array indexes are within bounds
* 1. Locate array access through: [ .. ] * 1. Locate array access through: [ .. ]

View File

@ -40,5 +40,4 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -16,9 +16,15 @@
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QPlainTextEdit" name="plainTextEdit"> <widget class="CodeEditor" name="codeEditor">
<property name="plainText"> <property name="lineWrapMode">
<string>ab</string> <enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="tabStopWidth">
<number>4</number>
</property> </property>
</widget> </widget>
</item> </item>
@ -57,6 +63,13 @@
</action> </action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>CodeEditor</class>
<extends>QPlainTextEdit</extends>
<header>codeeditor.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>