Skip to content

Commit de0dd0a

Browse files
committed
Fixed issues pointed out by Reijo.
The number of threads is now atleast 1. Added a very simple about dialog with version number and license. Replaced all CppCheck's with Cppcheck. Renamed "show more errors" to "show possible false positives" in the menu. User created application now has to have a name and a path.
1 parent 2d8b08d commit de0dd0a

9 files changed

Lines changed: 91 additions & 20 deletions

gui/applicationdialog.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <QLabel>
2525
#include <QFileDialog>
2626
#include <QDebug>
27+
#include <QMessageBox>
2728

2829

2930
ApplicationDialog::ApplicationDialog(const QString &name,
@@ -66,7 +67,7 @@ ApplicationDialog::ApplicationDialog(const QString &name,
6667

6768
//Connect OK buttons
6869
connect(ok, SIGNAL(clicked()),
69-
this, SLOT(accept()));
70+
this, SLOT(Ok()));
7071
connect(cancel, SIGNAL(clicked()),
7172
this, SLOT(reject()));
7273
setLayout(layout);
@@ -105,3 +106,15 @@ QString ApplicationDialog::GetPath()
105106
{
106107
return mPath->text();
107108
}
109+
110+
void ApplicationDialog::Ok()
111+
{
112+
if (mName->text().isEmpty() || mPath->text().isEmpty()) {
113+
QMessageBox msgBox;
114+
msgBox.setText("You must specify a name and a path for the application!");
115+
msgBox.exec();
116+
} else {
117+
accept();
118+
}
119+
}
120+

gui/applicationdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class ApplicationDialog : public QDialog
6161
*/
6262
QString GetPath();
6363
protected slots:
64+
void Ok();
6465

6566
/**
6667
* @brief Slot to browse for an application

gui/applicationlist.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ void ApplicationList::SetApplicationType(const int index,
100100

101101
void ApplicationList::AddApplicationType(const QString &name, const QString &path)
102102
{
103+
if (name.isEmpty() || path.isEmpty()) {
104+
return;
105+
}
106+
103107
ApplicationType type;
104108
type.Name = name;
105109
type.Path = path;

gui/checkthread.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
CheckThread::CheckThread(ThreadResult &result) :
2525
mResult(result),
26-
mCppCheck(result)
26+
mCppcheck(result)
2727
{
2828
//ctor
2929
}
@@ -35,7 +35,7 @@ CheckThread::~CheckThread()
3535

3636
void CheckThread::Check(Settings settings)
3737
{
38-
mCppCheck.settings(settings);
38+
mCppcheck.settings(settings);
3939
start();
4040
}
4141

@@ -47,9 +47,9 @@ void CheckThread::run()
4747
while (!file.isEmpty())
4848
{
4949
qDebug() << "Checking file" << file;
50-
mCppCheck.addFile(file.toStdString());
51-
mCppCheck.check();
52-
mCppCheck.clearFiles();
50+
mCppcheck.addFile(file.toStdString());
51+
mCppcheck.check();
52+
mCppcheck.clearFiles();
5353
emit FileChecked(file);
5454

5555
file = mResult.GetNextFile();

gui/checkthread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class CheckThread : public QThread
6363
protected:
6464
ThreadResult &mResult;
6565
/**
66-
* @brief CppCheck itself
66+
* @brief Cppcheck itself
6767
*
6868
*/
69-
CppCheck mCppCheck;
69+
CppCheck mCppcheck;
7070
private:
7171
};
7272

gui/mainwindow.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,26 @@
2323
#include <QMenu>
2424
#include <QDirIterator>
2525
#include <QMenuBar>
26+
#include <QMessageBox>
2627
#include "../src/filelister.h"
27-
28+
#include "../src/cppcheckexecutor.h"
2829

2930
MainWindow::MainWindow() :
30-
mSettings(tr("CppCheck"), tr("CppCheck-GUI")),
31+
mSettings(tr("Cppcheck"), tr("Cppcheck-GUI")),
3132
mActionExit(tr("E&xit"), this),
3233
mActionCheckFiles(tr("&Check files(s)"), this),
3334
mActionClearResults(tr("Clear &results"), this),
3435
mActionReCheck(tr("Recheck files"), this),
3536
mActionCheckDirectory(tr("Check &directory"), this),
3637
mActionSettings(tr("&Settings"), this),
37-
mActionShowAll(tr("Show &more errors"), this),
38+
mActionShowAll(tr("show possible false positives"), this),
3839
mActionShowSecurity(tr("Show &security errors"), this),
3940
mActionShowStyle(tr("Show s&tyle errors"), this),
4041
mActionShowUnused(tr("Show errors on &unused functions"), this),
4142
mActionShowErrors(tr("Show &common errors"), this),
4243
mActionShowCheckAll(tr("Check all"), this),
4344
mActionShowUncheckAll(tr("Uncheck all"), this),
45+
mActionAbout(tr("About"), this),
4446
mResults(mSettings, mApplications)
4547
{
4648
QMenu *menu = menuBar()->addMenu(tr("&File"));
@@ -69,6 +71,9 @@ MainWindow::MainWindow() :
6971
QMenu *menuprogram = menuBar()->addMenu(tr("&Program"));
7072
menuprogram->addAction(&mActionSettings);
7173

74+
QMenu *menuHelp = menuBar()->addMenu(tr("&Help"));
75+
menuHelp->addAction(&mActionAbout);
76+
7277
setCentralWidget(&mResults);
7378

7479

@@ -87,10 +92,13 @@ MainWindow::MainWindow() :
8792
connect(&mActionShowUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll()));
8893

8994
connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck()));
95+
96+
connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About()));
97+
9098
connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone()));
9199
LoadSettings();
92100
mThread.Initialize(&mResults);
93-
setWindowTitle(tr("CppCheck"));
101+
setWindowTitle(tr("Cppcheck"));
94102
}
95103

96104
MainWindow::~MainWindow()
@@ -161,7 +169,7 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
161169
mThread.SetFiles(RemoveUnacceptedFiles(fileNames));
162170
mSettings.setValue(tr("Check path"), dialog.directory().absolutePath());
163171
EnableCheckButtons(false);
164-
mThread.Check(GetCppCheckSettings(), false);
172+
mThread.Check(GetCppcheckSettings(), false);
165173
}
166174
}
167175

@@ -175,7 +183,7 @@ void MainWindow::CheckDirectory()
175183
DoCheckFiles(QFileDialog::DirectoryOnly);
176184
}
177185

178-
Settings MainWindow::GetCppCheckSettings()
186+
Settings MainWindow::GetCppcheckSettings()
179187
{
180188
Settings result;
181189
result._debug = false;
@@ -188,6 +196,11 @@ Settings MainWindow::GetCppCheckSettings()
188196
result._unusedFunctions = true;
189197
result._security = true;
190198
result._jobs = mSettings.value(tr("Check threads"), 1).toInt();
199+
200+
if (result._jobs <= 0) {
201+
result._jobs = 1;
202+
}
203+
191204
return result;
192205
}
193206

@@ -248,7 +261,7 @@ void MainWindow::ReCheck()
248261
{
249262
ClearResults();
250263
EnableCheckButtons(false);
251-
mThread.Check(GetCppCheckSettings(), true);
264+
mThread.Check(GetCppcheckSettings(), true);
252265
}
253266

254267
void MainWindow::ClearResults()
@@ -316,3 +329,23 @@ void MainWindow::ToggleAllChecked(bool checked)
316329
mActionShowErrors.setChecked(checked);
317330
ShowErrors(checked);
318331
}
332+
333+
void MainWindow::About()
334+
{
335+
//TODO make a "GetVersionNumber" function to core cppcheck
336+
CppCheckExecutor exec;
337+
CppCheck check(exec);
338+
const char *argv[] = {"","--version"};
339+
QString version = check.parseFromArgs(2, argv).c_str();
340+
version.replace("Cppcheck ","");
341+
342+
QMessageBox msgBox;
343+
msgBox.setWindowTitle(tr("About..."));
344+
msgBox.setText(QString("Cppcheck - A tool for static C/C++ code analysis.\nVersion %1\n\n" \
345+
"This program is licensed under the terms\n" \
346+
"of the GNU General Public License version 3\n" \
347+
"Available online under:\n" \
348+
"http://www.gnu.org/licenses/gpl-3.0.html\n\nSee AUTHORS file for the list of developers." \
349+
).arg(version));
350+
msgBox.exec();
351+
}

gui/mainwindow.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ public slots:
114114
*/
115115
void ProgramSettings();
116116

117+
/**
118+
* @brief Slot to open program's about dialog
119+
*
120+
*/
121+
void About();
122+
117123
protected slots:
118124

119125
/**
@@ -155,7 +161,7 @@ protected slots:
155161
*
156162
* @return Default cppcheck settings
157163
*/
158-
Settings GetCppCheckSettings();
164+
Settings GetCppcheckSettings();
159165

160166
/**
161167
* @brief Removes all unaccepted (by cppcheck core) files from the list
@@ -262,6 +268,12 @@ protected slots:
262268
*/
263269
QAction mActionShowUncheckAll;
264270

271+
/**
272+
* @brief Action show about dialog
273+
*
274+
*/
275+
QAction mActionAbout;
276+
265277

266278

267279
/**

gui/resultstree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
348348

349349
void ResultsTree::StartApplication(QStandardItem *target, int application)
350350
{
351-
if (target && application >= 0 && application < mApplications.GetApplicationCount())
351+
if (target && application >= 0 && application < mApplications.GetApplicationCount() && target->parent())
352352
{
353353
QVariantMap data = target->data().toMap();
354354

gui/settingsdialog.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
6868
//Number of jobs
6969
QHBoxLayout *jobsLayout = new QHBoxLayout();
7070
mJobs = new QLineEdit(programSettings.value(tr("Check threads"), 1).toString());
71+
mJobs->setValidator(new QIntValidator(1,9999,this));
72+
7173
jobsLayout->addWidget(new QLabel(tr("Number of threads: ")));
7274
jobsLayout->addWidget(mJobs);
73-
mJobs->setValidator(new QIntValidator(this));
75+
76+
77+
7478
layout->addLayout(jobsLayout);
7579

7680
//Force
@@ -169,7 +173,12 @@ void SettingsDialog::SaveSettings()
169173

170174
void SettingsDialog::SaveCheckboxValues()
171175
{
172-
mSettings.setValue(tr("Check threads"), mJobs->text().toInt());
176+
int jobs = mJobs->text().toInt();
177+
if (jobs <= 0) {
178+
jobs = 1;
179+
}
180+
181+
mSettings.setValue(tr("Check threads"), jobs);
173182
SaveCheckboxValue(mForce, tr("Check force"));
174183
}
175184

@@ -197,7 +206,6 @@ void SettingsDialog::DeleteApplication()
197206

198207
foreach(item, selected)
199208
{
200-
qDebug() << item;
201209
mApplications.RemoveApplication(mListWidget->row(item));
202210
mListWidget->clear();
203211
PopulateListWidget();

0 commit comments

Comments
 (0)