Skip to content

Commit b674247

Browse files
committed
Added messagebox to inform user about not found/non visible errors.
1 parent de0bea3 commit b674247

File tree

8 files changed

+169
-21
lines changed

8 files changed

+169
-21
lines changed

gui/applicationdialog.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,14 @@ void ApplicationDialog::Ok()
123123
{
124124
if (mName->text().isEmpty() || mPath->text().isEmpty())
125125
{
126-
QMessageBox msgBox;
127-
msgBox.setText("You must specify a name and a path for the application!");
128-
msgBox.exec();
126+
QMessageBox msg(QMessageBox::Warning,
127+
tr("Cppcheck"),
128+
tr("You must specify a name and a path for the application!"),
129+
QMessageBox::Ok,
130+
this);
131+
132+
msg.exec();
133+
129134
}
130135
else
131136
{

gui/mainwindow.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <QMenuBar>
2525
#include <QMessageBox>
2626
#include <QToolBar>
27+
#include <QKeySequence>
2728
#include "aboutdialog.h"
2829
#include "../src/filelister.h"
2930
#include "../src/cppcheckexecutor.h"
@@ -132,6 +133,11 @@ MainWindow::MainWindow() :
132133
toolbar->addAction(&mActionSettings);
133134
toolbar->addAction(&mActionAbout);
134135

136+
mActionReCheck.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
137+
mActionCheckDirectory.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
138+
mActionSave.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
139+
mActionAbout.setShortcut(QKeySequence(Qt::Key_F1));
140+
135141
LoadSettings();
136142
mThread.Initialize(&mResults);
137143
setWindowTitle(tr("Cppcheck"));
@@ -209,9 +215,15 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
209215

210216
if (fileNames.isEmpty())
211217
{
212-
QMessageBox msgBox;
213-
msgBox.setText("No suitable files found to check!");
214-
msgBox.exec();
218+
219+
QMessageBox msg(QMessageBox::Warning,
220+
tr("Cppcheck"),
221+
tr("No suitable files found to check!"),
222+
QMessageBox::Ok,
223+
this);
224+
225+
msg.exec();
226+
215227
return;
216228
}
217229

@@ -306,7 +318,8 @@ void MainWindow::ProgramSettings()
306318
dialog.SaveCheckboxValues();
307319
mResults.UpdateSettings(dialog.ShowFullPath(),
308320
dialog.SaveFullPath(),
309-
dialog.SaveAllErrors());
321+
dialog.SaveAllErrors(),
322+
dialog.ShowNoErrorsMessage());
310323
}
311324
}
312325

@@ -375,11 +388,18 @@ void MainWindow::closeEvent(QCloseEvent *event)
375388
event->accept();
376389
else
377390
{
378-
QString msg(tr("Cannot exit while checking.\n\n" \
379-
"Stop the checking before exiting."));
380-
QMessageBox *box = new QMessageBox(QMessageBox::Warning,
381-
tr("cppcheck"), msg);
382-
box->show();
391+
QString text(tr("Cannot exit while checking.\n\n" \
392+
"Stop the checking before exiting."));
393+
394+
QMessageBox msg(QMessageBox::Warning,
395+
tr("Cppcheck"),
396+
text,
397+
QMessageBox::Ok,
398+
this);
399+
400+
msg.exec();
401+
402+
383403
event->ignore();
384404
}
385405
}

gui/resultstree.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) :
2929
mSettings(settings),
3030
mApplications(list),
3131
mContextItem(0),
32-
mCheckPath("")
32+
mCheckPath(""),
33+
mVisibleErrors(false)
3334
{
3435
setModel(&mModel);
3536
QStringList labels;
@@ -76,6 +77,13 @@ void ResultsTree::AddErrorItem(const QString &file,
7677
}
7778

7879
bool hide = !mShowTypes[SeverityToShowType(severity)];
80+
81+
//if there is at least on error that is not hidden, we have a visible error
82+
if (!hide)
83+
{
84+
mVisibleErrors = true;
85+
}
86+
7987
//Create the base item for the error and ensure it has a proper
8088
//file item as a parent
8189
QStandardItem *item = AddBacktraceFiles(EnsureFileItem(realfile, hide),
@@ -226,6 +234,7 @@ void ResultsTree::ShowResults(ShowTypes type, bool show)
226234

227235
void ResultsTree::RefreshTree()
228236
{
237+
mVisibleErrors = false;
229238
//Get the amount of files in the tree
230239
int filecount = mModel.rowCount();
231240

@@ -261,6 +270,11 @@ void ResultsTree::RefreshTree()
261270
//Check if this error should be hidden
262271
bool hide = !mShowTypes[VariantToShowType(data["severity"])];
263272

273+
if (!hide)
274+
{
275+
mVisibleErrors = true;
276+
}
277+
264278
//Hide/show accordingly
265279
setRowHidden(j, file->index(), hide);
266280

@@ -370,9 +384,10 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
370384
//If there are now application's specified, tell the user about it
371385
if (mApplications.GetApplicationCount() == 0)
372386
{
373-
QMessageBox msgBox;
374-
msgBox.setText("You can open this error by specifying applications in program's settings.");
375-
msgBox.exec();
387+
QMessageBox msg(QMessageBox::Warning,
388+
tr("Cppcheck"),
389+
tr("You can open this error by specifying applications in program's settings."));
390+
msg.exec();
376391
return;
377392
}
378393

@@ -421,6 +436,7 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
421436
msgbox.setWindowTitle("Cppcheck");
422437
msgbox.setText(text);
423438
msgbox.setIcon(QMessageBox::Critical);
439+
424440
msgbox.exec();
425441
}
426442
}
@@ -689,3 +705,8 @@ void ResultsTree::RefreshFilePaths()
689705
RefreshFilePaths(mModel.item(i, 0));
690706
}
691707
}
708+
709+
bool ResultsTree::VisibleErrors()
710+
{
711+
return mVisibleErrors;
712+
}

gui/resultstree.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ class ResultsTree : public QTreeView
9393
* @param dir Directory we are checking
9494
*/
9595
void SetCheckDirectory(const QString &dir);
96+
97+
/**
98+
* @brief Check if there are any visible errors
99+
* @return true if there is at least one visible error
100+
*/
101+
bool VisibleErrors();
102+
96103
protected slots:
97104
/**
98105
* @brief Slot to quickstart an error with default application
@@ -107,6 +114,7 @@ protected slots:
107114
* @param application Index of the application to open the error
108115
*/
109116
void Context(int application);
117+
110118
protected:
111119

112120
/**
@@ -313,6 +321,13 @@ protected slots:
313321
*
314322
*/
315323
QString mCheckPath;
324+
325+
/**
326+
* @brief Are there any visible errors
327+
*
328+
*/
329+
bool mVisibleErrors;
330+
316331
private:
317332
};
318333

gui/resultsview.cpp

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
#include <QDebug>
2222
#include <QVBoxLayout>
2323
#include <QFile>
24+
#include <QMessageBox>
2425

25-
ResultsView::ResultsView(QSettings &settings, ApplicationList &list)
26+
ResultsView::ResultsView(QSettings &settings, ApplicationList &list) :
27+
mErrorsFound(false),
28+
mShowNoErrorsMessage(true)
2629
{
2730
QVBoxLayout *layout = new QVBoxLayout();
2831
setLayout(layout);
@@ -35,6 +38,8 @@ ResultsView::ResultsView(QSettings &settings, ApplicationList &list)
3538
mTree = new ResultsTree(settings, list);
3639
layout->addWidget(mTree);
3740

41+
mShowNoErrorsMessage = settings.value(tr("Show no errors message"), true).toBool();
42+
3843
}
3944

4045
ResultsView::~ResultsView()
@@ -46,6 +51,11 @@ ResultsView::~ResultsView()
4651
void ResultsView::Clear()
4752
{
4853
mTree->Clear();
54+
mErrorsFound = false;
55+
56+
//Clear the progressbar
57+
mProgress->setMaximum(100);
58+
mProgress->setValue(0);
4959
}
5060

5161

@@ -57,6 +67,32 @@ void ResultsView::Progress(int value, int max)
5767
if (value >= max)
5868
{
5969
mProgress->setVisible(false);
70+
//Should we inform user of non visible/not found errors?
71+
if (mShowNoErrorsMessage)
72+
{ //Tell user that we found no errors
73+
if (!mErrorsFound)
74+
{
75+
QMessageBox msg(QMessageBox::Information,
76+
tr("Cppcheck"),
77+
tr("No errors found."),
78+
QMessageBox::Ok,
79+
this);
80+
81+
msg.exec();
82+
} //If we have errors but they aren't visible, tell user about it
83+
else if (!mTree->VisibleErrors())
84+
{
85+
QString text = tr("Errors found from the file, but they are configured to be hidden.\n"\
86+
"To toggle what kind of errors are shown, open view menu.");
87+
QMessageBox msg(QMessageBox::Information,
88+
tr("Cppcheck"),
89+
text,
90+
QMessageBox::Ok,
91+
this);
92+
93+
msg.exec();
94+
}
95+
}
6096
}
6197
else
6298
{
@@ -71,6 +107,7 @@ void ResultsView::Error(const QString &file,
71107
const QVariantList &lines,
72108
const QString &id)
73109
{
110+
mErrorsFound = true;
74111
mTree->AddErrorItem(file, severity, message, files, lines, id);
75112
emit GotResults();
76113
}
@@ -92,6 +129,13 @@ void ResultsView::ExpandAllResults()
92129

93130
void ResultsView::Save(const QString &filename, bool xml)
94131
{
132+
if (!mErrorsFound)
133+
{
134+
QMessageBox msgBox;
135+
msgBox.setText("No errors found, nothing to save.");
136+
msgBox.exec();
137+
}
138+
95139
QFile file(filename);
96140
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
97141
{
@@ -105,9 +149,11 @@ void ResultsView::Save(const QString &filename, bool xml)
105149

106150
void ResultsView::UpdateSettings(bool showFullPath,
107151
bool saveFullPath,
108-
bool saveAllErrors)
152+
bool saveAllErrors,
153+
bool showNoErrorsMessage)
109154
{
110155
mTree->UpdateSettings(showFullPath, saveFullPath, saveAllErrors);
156+
mShowNoErrorsMessage = showNoErrorsMessage;
111157
}
112158

113159
void ResultsView::SetCheckDirectory(const QString &dir)

gui/resultsview.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ class ResultsView : public QWidget
7070
* @param saveFullPath Save full path of files in reports
7171
* @param saveAllErrors Save all visible errors
7272
*/
73-
void UpdateSettings(bool showFullPath, bool saveFullPath, bool saveAllErrors);
73+
void UpdateSettings(bool showFullPath,
74+
bool saveFullPath,
75+
bool saveAllErrors,
76+
bool showNoErrorsMessage);
7477

7578
/**
7679
* @brief Set the directory we are checking
@@ -138,6 +141,16 @@ public slots:
138141
*/
139142
QProgressBar *mProgress;
140143

144+
/**
145+
* @brief Have any errors been found
146+
*/
147+
bool mErrorsFound;
148+
149+
/**
150+
* @brief Should we show a "No errors found dialog" everytime no errors were found?
151+
*/
152+
bool mShowNoErrorsMessage;
153+
141154
private:
142155
};
143156

gui/settingsdialog.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
7979

8080
//Force
8181
mForce = AddCheckbox(layout,
82-
tr("Force checking on files that have \"too many\" configurations"),
82+
tr("Check all #ifdef configurations"),
8383
tr("Check force"),
8484
false);
8585

@@ -88,6 +88,11 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
8888
tr("Show full path"),
8989
false);
9090

91+
mShowNoErrorsMessage = AddCheckbox(layout,
92+
tr("Show \"No errors found\" message when no errors found"),
93+
tr("Show no errors message"),
94+
true);
95+
9196
layout->addStretch();
9297
general->setLayout(layout);
9398

@@ -115,7 +120,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
115120
connect(modify, SIGNAL(clicked()),
116121
this, SLOT(ModifyApplication()));
117122

118-
QPushButton *def = new QPushButton(tr("Make default application"));
123+
QPushButton *def = new QPushButton(tr("Set as default application"));
119124
appslayout->addWidget(def);
120125
connect(def, SIGNAL(clicked()),
121126
this, SLOT(DefaultApplication()));
@@ -205,6 +210,7 @@ void SettingsDialog::SaveCheckboxValues()
205210
SaveCheckboxValue(mSaveAllErrors, tr("Save all errors"));
206211
SaveCheckboxValue(mSaveFullPath, tr("Save full path"));
207212
SaveCheckboxValue(mShowFullPath, tr("Show full path"));
213+
SaveCheckboxValue(mShowNoErrorsMessage, tr("Show no errors message"));
208214
}
209215

210216
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
@@ -303,3 +309,11 @@ bool SettingsDialog::SaveAllErrors()
303309
{
304310
return CheckStateToBool(mSaveAllErrors->checkState());
305311
}
312+
313+
bool SettingsDialog::ShowNoErrorsMessage()
314+
{
315+
return CheckStateToBool(mShowNoErrorsMessage->checkState());
316+
}
317+
318+
319+

0 commit comments

Comments
 (0)