Skip to content

Commit 7e88d7b

Browse files
committed
GUI: Add simple log view.
Adding a simple log view which shows log messages the core code emits.
1 parent f5024a7 commit 7e88d7b

File tree

10 files changed

+183
-5
lines changed

10 files changed

+183
-5
lines changed

gui/gui.pro

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ FORMS = main.ui \
2626
settings.ui \
2727
file.ui \
2828
projectfile.ui \
29-
about.ui
29+
about.ui \
30+
logview.ui
3031

3132
TRANSLATIONS = cppcheck_fi.ts \
3233
cppcheck_nl.ts \
@@ -60,7 +61,9 @@ HEADERS += mainwindow.h \
6061
txtreport.h \
6162
xmlreport.h \
6263
translationhandler.h \
63-
csvreport.h
64+
csvreport.h \
65+
logview.h
66+
6467
SOURCES += main.cpp \
6568
mainwindow.cpp\
6669
checkthread.cpp \
@@ -81,7 +84,8 @@ SOURCES += main.cpp \
8184
txtreport.cpp \
8285
xmlreport.cpp \
8386
translationhandler.cpp \
84-
csvreport.cpp
87+
csvreport.cpp \
88+
logview.cpp
8589

8690
win32 {
8791
RC_FILE = cppcheck-gui.rc

gui/logview.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "logview.h"
20+
21+
LogView::LogView(QWidget *parent)
22+
{
23+
mUI.setupUi(this);
24+
setWindowFlags(Qt::Tool);
25+
}
26+
27+
void LogView::AppendLine(const QString &line)
28+
{
29+
mUI.mLogEdit->appendPlainText(line);
30+
}

gui/logview.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef LOGVIEW_H
20+
#define LOGVIEW_H
21+
22+
#include <QWidget>
23+
#include "ui_logview.h"
24+
25+
/// @addtogroup GUI
26+
/// @{
27+
28+
/**
29+
* @brief A tool window that shows checking log.
30+
*
31+
*/
32+
class LogView : public QWidget
33+
{
34+
Q_OBJECT
35+
public:
36+
LogView(QWidget *parent = 0);
37+
38+
/**
39+
* @brief Append new log file to view.
40+
* @param line String to add.
41+
*
42+
*/
43+
void AppendLine(const QString &line);
44+
45+
private:
46+
Ui::LogView mUI;
47+
};
48+
49+
/// @}
50+
51+
#endif // LOGVIEW_H

gui/logview.ui

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>LogView</class>
4+
<widget class="QWidget" name="LogView">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="contextMenuPolicy">
14+
<enum>Qt::NoContextMenu</enum>
15+
</property>
16+
<property name="windowTitle">
17+
<string>Checking Log</string>
18+
</property>
19+
<layout class="QVBoxLayout" name="verticalLayout">
20+
<item>
21+
<widget class="QPlainTextEdit" name="mLogEdit">
22+
<property name="undoRedoEnabled">
23+
<bool>false</bool>
24+
</property>
25+
<property name="readOnly">
26+
<bool>true</bool>
27+
</property>
28+
</widget>
29+
</item>
30+
</layout>
31+
</widget>
32+
<resources/>
33+
<connections/>
34+
</ui>

gui/main.ui

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<addaction name="mActionCollapseAll"/>
101101
<addaction name="mActionExpandAll"/>
102102
<addaction name="separator"/>
103+
<addaction name="mActionViewLog"/>
103104
</widget>
104105
<widget class="QMenu" name="mMenuLanguage">
105106
<property name="title">
@@ -365,6 +366,14 @@
365366
<string>&amp;New Project File...</string>
366367
</property>
367368
</action>
369+
<action name="mActionViewLog">
370+
<property name="text">
371+
<string>&amp;Log View</string>
372+
</property>
373+
<property name="toolTip">
374+
<string>Log View</string>
375+
</property>
376+
</action>
368377
</widget>
369378
<customwidgets>
370379
<customwidget>

gui/mainwindow.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "projectfile.h"
3434
#include "project.h"
3535
#include "report.h"
36+
#include "logview.h"
3637
#include "../lib/filelister.h"
3738

3839
// HTMLHelp is only available in Windows
@@ -45,12 +46,14 @@ MainWindow::MainWindow() :
4546
mSettings(new QSettings("Cppcheck", "Cppcheck-GUI", this)),
4647
mApplications(new ApplicationList(this)),
4748
mTranslation(new TranslationHandler(this)),
48-
mLanguages(new QActionGroup(this))
49+
mLanguages(new QActionGroup(this)),
50+
mLogView(NULL)
4951
{
5052
mUI.setupUi(this);
5153
mUI.mResults->Initialize(mSettings, mApplications);
5254

5355
mThread = new ThreadHandler(this);
56+
mLogView = new LogView(this);
5457

5558
connect(mUI.mActionQuit, SIGNAL(triggered()), this, SLOT(close()));
5659
connect(mUI.mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles()));
@@ -65,6 +68,7 @@ MainWindow::MainWindow() :
6568
connect(mUI.mActionUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll()));
6669
connect(mUI.mActionCollapseAll, SIGNAL(triggered()), mUI.mResults, SLOT(CollapseAllResults()));
6770
connect(mUI.mActionExpandAll, SIGNAL(triggered()), mUI.mResults, SLOT(ExpandAllResults()));
71+
connect(mUI.mActionViewLog, SIGNAL(triggered()), this, SLOT(ShowLogView()));
6872

6973
connect(mUI.mActionRecheck, SIGNAL(triggered()), this, SLOT(ReCheck()));
7074

@@ -114,6 +118,7 @@ MainWindow::MainWindow() :
114118

115119
MainWindow::~MainWindow()
116120
{
121+
delete mLogView;
117122
}
118123

119124
void MainWindow::CreateLanguageMenuItems()
@@ -731,3 +736,21 @@ void MainWindow::NewProjectFile()
731736
prj.Edit();
732737
}
733738
}
739+
740+
void MainWindow::ShowLogView()
741+
{
742+
if (mLogView == NULL)
743+
mLogView = new LogView(this);
744+
745+
mLogView->show();
746+
if (!mLogView->isActiveWindow())
747+
mLogView->activateWindow();
748+
}
749+
750+
void MainWindow::Log(const QString &logline)
751+
{
752+
if (mLogView)
753+
{
754+
mLogView->AppendLine(logline);
755+
}
756+
}

gui/mainwindow.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "ui_main.h"
3434
class ThreadHandler;
35+
class LogView;
3536

3637
/// @addtogroup GUI
3738
/// @{
@@ -143,6 +144,12 @@ public slots:
143144
*/
144145
void OpenProjectFile();
145146

147+
/**
148+
* @brief Slot for showing the log view.
149+
*
150+
*/
151+
void ShowLogView();
152+
146153
protected slots:
147154

148155
/**
@@ -190,6 +197,12 @@ protected slots:
190197
*/
191198
void OpenHelpContents();
192199

200+
/**
201+
* @brief Add new line to log.
202+
*
203+
*/
204+
void Log(const QString &logline);
205+
193206
protected:
194207

195208
/**
@@ -325,6 +338,11 @@ protected slots:
325338
*/
326339
QString mCurrentDirectory;
327340

341+
/**
342+
* @brief Log view..
343+
*/
344+
LogView *mLogView;
345+
328346
};
329347
/// @}
330348
#endif // MAINWINDOW_H

gui/threadhandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ void ThreadHandler::Initialize(ResultsView *view)
144144
connect(&mResults, SIGNAL(Error(const ErrorItem &)),
145145
view, SLOT(Error(const ErrorItem &)));
146146

147+
connect(&mResults, SIGNAL(Log(const QString &)),
148+
parent(), SLOT(Log(const QString &)));
147149
}
148150

149151
void ThreadHandler::LoadSettings(QSettings &settings)

gui/threadresult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ThreadResult::~ThreadResult()
3333

3434
void ThreadResult::reportOut(const std::string &outmsg)
3535
{
36-
Q_UNUSED(outmsg);
36+
emit Log(QString::fromStdString(outmsg));
3737
}
3838

3939
void ThreadResult::FileChecked(const QString &file)

gui/threadresult.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public slots:
9393
*/
9494
void Error(const ErrorItem &item);
9595

96+
/**
97+
* @brief Signal of a new log message
98+
*
99+
* @param logline Log line
100+
*/
101+
void Log(const QString &logline);
102+
96103
protected:
97104

98105
/**

0 commit comments

Comments
 (0)