Added messagebox to inform user about not found/non visible errors.

This commit is contained in:
Vesa Pikki 2009-06-09 10:51:27 +03:00
parent de0bea3479
commit b67424785f
8 changed files with 169 additions and 21 deletions

View File

@ -123,9 +123,14 @@ void ApplicationDialog::Ok()
{ {
if (mName->text().isEmpty() || mPath->text().isEmpty()) if (mName->text().isEmpty() || mPath->text().isEmpty())
{ {
QMessageBox msgBox; QMessageBox msg(QMessageBox::Warning,
msgBox.setText("You must specify a name and a path for the application!"); tr("Cppcheck"),
msgBox.exec(); tr("You must specify a name and a path for the application!"),
QMessageBox::Ok,
this);
msg.exec();
} }
else else
{ {

View File

@ -24,6 +24,7 @@
#include <QMenuBar> #include <QMenuBar>
#include <QMessageBox> #include <QMessageBox>
#include <QToolBar> #include <QToolBar>
#include <QKeySequence>
#include "aboutdialog.h" #include "aboutdialog.h"
#include "../src/filelister.h" #include "../src/filelister.h"
#include "../src/cppcheckexecutor.h" #include "../src/cppcheckexecutor.h"
@ -132,6 +133,11 @@ MainWindow::MainWindow() :
toolbar->addAction(&mActionSettings); toolbar->addAction(&mActionSettings);
toolbar->addAction(&mActionAbout); toolbar->addAction(&mActionAbout);
mActionReCheck.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
mActionCheckDirectory.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
mActionSave.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
mActionAbout.setShortcut(QKeySequence(Qt::Key_F1));
LoadSettings(); LoadSettings();
mThread.Initialize(&mResults); mThread.Initialize(&mResults);
setWindowTitle(tr("Cppcheck")); setWindowTitle(tr("Cppcheck"));
@ -209,9 +215,15 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
if (fileNames.isEmpty()) if (fileNames.isEmpty())
{ {
QMessageBox msgBox;
msgBox.setText("No suitable files found to check!"); QMessageBox msg(QMessageBox::Warning,
msgBox.exec(); tr("Cppcheck"),
tr("No suitable files found to check!"),
QMessageBox::Ok,
this);
msg.exec();
return; return;
} }
@ -306,7 +318,8 @@ void MainWindow::ProgramSettings()
dialog.SaveCheckboxValues(); dialog.SaveCheckboxValues();
mResults.UpdateSettings(dialog.ShowFullPath(), mResults.UpdateSettings(dialog.ShowFullPath(),
dialog.SaveFullPath(), dialog.SaveFullPath(),
dialog.SaveAllErrors()); dialog.SaveAllErrors(),
dialog.ShowNoErrorsMessage());
} }
} }
@ -375,11 +388,18 @@ void MainWindow::closeEvent(QCloseEvent *event)
event->accept(); event->accept();
else else
{ {
QString msg(tr("Cannot exit while checking.\n\n" \ QString text(tr("Cannot exit while checking.\n\n" \
"Stop the checking before exiting.")); "Stop the checking before exiting."));
QMessageBox *box = new QMessageBox(QMessageBox::Warning,
tr("cppcheck"), msg); QMessageBox msg(QMessageBox::Warning,
box->show(); tr("Cppcheck"),
text,
QMessageBox::Ok,
this);
msg.exec();
event->ignore(); event->ignore();
} }
} }

View File

@ -29,7 +29,8 @@ ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) :
mSettings(settings), mSettings(settings),
mApplications(list), mApplications(list),
mContextItem(0), mContextItem(0),
mCheckPath("") mCheckPath(""),
mVisibleErrors(false)
{ {
setModel(&mModel); setModel(&mModel);
QStringList labels; QStringList labels;
@ -76,6 +77,13 @@ void ResultsTree::AddErrorItem(const QString &file,
} }
bool hide = !mShowTypes[SeverityToShowType(severity)]; bool hide = !mShowTypes[SeverityToShowType(severity)];
//if there is at least on error that is not hidden, we have a visible error
if (!hide)
{
mVisibleErrors = true;
}
//Create the base item for the error and ensure it has a proper //Create the base item for the error and ensure it has a proper
//file item as a parent //file item as a parent
QStandardItem *item = AddBacktraceFiles(EnsureFileItem(realfile, hide), QStandardItem *item = AddBacktraceFiles(EnsureFileItem(realfile, hide),
@ -226,6 +234,7 @@ void ResultsTree::ShowResults(ShowTypes type, bool show)
void ResultsTree::RefreshTree() void ResultsTree::RefreshTree()
{ {
mVisibleErrors = false;
//Get the amount of files in the tree //Get the amount of files in the tree
int filecount = mModel.rowCount(); int filecount = mModel.rowCount();
@ -261,6 +270,11 @@ void ResultsTree::RefreshTree()
//Check if this error should be hidden //Check if this error should be hidden
bool hide = !mShowTypes[VariantToShowType(data["severity"])]; bool hide = !mShowTypes[VariantToShowType(data["severity"])];
if (!hide)
{
mVisibleErrors = true;
}
//Hide/show accordingly //Hide/show accordingly
setRowHidden(j, file->index(), hide); setRowHidden(j, file->index(), hide);
@ -370,9 +384,10 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
//If there are now application's specified, tell the user about it //If there are now application's specified, tell the user about it
if (mApplications.GetApplicationCount() == 0) if (mApplications.GetApplicationCount() == 0)
{ {
QMessageBox msgBox; QMessageBox msg(QMessageBox::Warning,
msgBox.setText("You can open this error by specifying applications in program's settings."); tr("Cppcheck"),
msgBox.exec(); tr("You can open this error by specifying applications in program's settings."));
msg.exec();
return; return;
} }
@ -421,6 +436,7 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
msgbox.setWindowTitle("Cppcheck"); msgbox.setWindowTitle("Cppcheck");
msgbox.setText(text); msgbox.setText(text);
msgbox.setIcon(QMessageBox::Critical); msgbox.setIcon(QMessageBox::Critical);
msgbox.exec(); msgbox.exec();
} }
} }
@ -689,3 +705,8 @@ void ResultsTree::RefreshFilePaths()
RefreshFilePaths(mModel.item(i, 0)); RefreshFilePaths(mModel.item(i, 0));
} }
} }
bool ResultsTree::VisibleErrors()
{
return mVisibleErrors;
}

View File

@ -93,6 +93,13 @@ public:
* @param dir Directory we are checking * @param dir Directory we are checking
*/ */
void SetCheckDirectory(const QString &dir); void SetCheckDirectory(const QString &dir);
/**
* @brief Check if there are any visible errors
* @return true if there is at least one visible error
*/
bool VisibleErrors();
protected slots: protected slots:
/** /**
* @brief Slot to quickstart an error with default application * @brief Slot to quickstart an error with default application
@ -107,6 +114,7 @@ protected slots:
* @param application Index of the application to open the error * @param application Index of the application to open the error
*/ */
void Context(int application); void Context(int application);
protected: protected:
/** /**
@ -313,6 +321,13 @@ protected:
* *
*/ */
QString mCheckPath; QString mCheckPath;
/**
* @brief Are there any visible errors
*
*/
bool mVisibleErrors;
private: private:
}; };

View File

@ -21,8 +21,11 @@
#include <QDebug> #include <QDebug>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QFile> #include <QFile>
#include <QMessageBox>
ResultsView::ResultsView(QSettings &settings, ApplicationList &list) ResultsView::ResultsView(QSettings &settings, ApplicationList &list) :
mErrorsFound(false),
mShowNoErrorsMessage(true)
{ {
QVBoxLayout *layout = new QVBoxLayout(); QVBoxLayout *layout = new QVBoxLayout();
setLayout(layout); setLayout(layout);
@ -35,6 +38,8 @@ ResultsView::ResultsView(QSettings &settings, ApplicationList &list)
mTree = new ResultsTree(settings, list); mTree = new ResultsTree(settings, list);
layout->addWidget(mTree); layout->addWidget(mTree);
mShowNoErrorsMessage = settings.value(tr("Show no errors message"), true).toBool();
} }
ResultsView::~ResultsView() ResultsView::~ResultsView()
@ -46,6 +51,11 @@ ResultsView::~ResultsView()
void ResultsView::Clear() void ResultsView::Clear()
{ {
mTree->Clear(); mTree->Clear();
mErrorsFound = false;
//Clear the progressbar
mProgress->setMaximum(100);
mProgress->setValue(0);
} }
@ -57,6 +67,32 @@ void ResultsView::Progress(int value, int max)
if (value >= max) if (value >= max)
{ {
mProgress->setVisible(false); mProgress->setVisible(false);
//Should we inform user of non visible/not found errors?
if (mShowNoErrorsMessage)
{ //Tell user that we found no errors
if (!mErrorsFound)
{
QMessageBox msg(QMessageBox::Information,
tr("Cppcheck"),
tr("No errors found."),
QMessageBox::Ok,
this);
msg.exec();
} //If we have errors but they aren't visible, tell user about it
else if (!mTree->VisibleErrors())
{
QString text = tr("Errors found from the file, but they are configured to be hidden.\n"\
"To toggle what kind of errors are shown, open view menu.");
QMessageBox msg(QMessageBox::Information,
tr("Cppcheck"),
text,
QMessageBox::Ok,
this);
msg.exec();
}
}
} }
else else
{ {
@ -71,6 +107,7 @@ void ResultsView::Error(const QString &file,
const QVariantList &lines, const QVariantList &lines,
const QString &id) const QString &id)
{ {
mErrorsFound = true;
mTree->AddErrorItem(file, severity, message, files, lines, id); mTree->AddErrorItem(file, severity, message, files, lines, id);
emit GotResults(); emit GotResults();
} }
@ -92,6 +129,13 @@ void ResultsView::ExpandAllResults()
void ResultsView::Save(const QString &filename, bool xml) void ResultsView::Save(const QString &filename, bool xml)
{ {
if (!mErrorsFound)
{
QMessageBox msgBox;
msgBox.setText("No errors found, nothing to save.");
msgBox.exec();
}
QFile file(filename); QFile file(filename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{ {
@ -105,9 +149,11 @@ void ResultsView::Save(const QString &filename, bool xml)
void ResultsView::UpdateSettings(bool showFullPath, void ResultsView::UpdateSettings(bool showFullPath,
bool saveFullPath, bool saveFullPath,
bool saveAllErrors) bool saveAllErrors,
bool showNoErrorsMessage)
{ {
mTree->UpdateSettings(showFullPath, saveFullPath, saveAllErrors); mTree->UpdateSettings(showFullPath, saveFullPath, saveAllErrors);
mShowNoErrorsMessage = showNoErrorsMessage;
} }
void ResultsView::SetCheckDirectory(const QString &dir) void ResultsView::SetCheckDirectory(const QString &dir)

View File

@ -70,7 +70,10 @@ public:
* @param saveFullPath Save full path of files in reports * @param saveFullPath Save full path of files in reports
* @param saveAllErrors Save all visible errors * @param saveAllErrors Save all visible errors
*/ */
void UpdateSettings(bool showFullPath, bool saveFullPath, bool saveAllErrors); void UpdateSettings(bool showFullPath,
bool saveFullPath,
bool saveAllErrors,
bool showNoErrorsMessage);
/** /**
* @brief Set the directory we are checking * @brief Set the directory we are checking
@ -138,6 +141,16 @@ protected:
*/ */
QProgressBar *mProgress; QProgressBar *mProgress;
/**
* @brief Have any errors been found
*/
bool mErrorsFound;
/**
* @brief Should we show a "No errors found dialog" everytime no errors were found?
*/
bool mShowNoErrorsMessage;
private: private:
}; };

View File

@ -79,7 +79,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
//Force //Force
mForce = AddCheckbox(layout, mForce = AddCheckbox(layout,
tr("Force checking on files that have \"too many\" configurations"), tr("Check all #ifdef configurations"),
tr("Check force"), tr("Check force"),
false); false);
@ -88,6 +88,11 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
tr("Show full path"), tr("Show full path"),
false); false);
mShowNoErrorsMessage = AddCheckbox(layout,
tr("Show \"No errors found\" message when no errors found"),
tr("Show no errors message"),
true);
layout->addStretch(); layout->addStretch();
general->setLayout(layout); general->setLayout(layout);
@ -115,7 +120,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list
connect(modify, SIGNAL(clicked()), connect(modify, SIGNAL(clicked()),
this, SLOT(ModifyApplication())); this, SLOT(ModifyApplication()));
QPushButton *def = new QPushButton(tr("Make default application")); QPushButton *def = new QPushButton(tr("Set as default application"));
appslayout->addWidget(def); appslayout->addWidget(def);
connect(def, SIGNAL(clicked()), connect(def, SIGNAL(clicked()),
this, SLOT(DefaultApplication())); this, SLOT(DefaultApplication()));
@ -205,6 +210,7 @@ void SettingsDialog::SaveCheckboxValues()
SaveCheckboxValue(mSaveAllErrors, tr("Save all errors")); SaveCheckboxValue(mSaveAllErrors, tr("Save all errors"));
SaveCheckboxValue(mSaveFullPath, tr("Save full path")); SaveCheckboxValue(mSaveFullPath, tr("Save full path"));
SaveCheckboxValue(mShowFullPath, tr("Show full path")); SaveCheckboxValue(mShowFullPath, tr("Show full path"));
SaveCheckboxValue(mShowNoErrorsMessage, tr("Show no errors message"));
} }
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
@ -303,3 +309,11 @@ bool SettingsDialog::SaveAllErrors()
{ {
return CheckStateToBool(mSaveAllErrors->checkState()); return CheckStateToBool(mSaveAllErrors->checkState());
} }
bool SettingsDialog::ShowNoErrorsMessage()
{
return CheckStateToBool(mShowNoErrorsMessage->checkState());
}

View File

@ -64,6 +64,14 @@ public:
*/ */
bool SaveFullPath(); bool SaveFullPath();
/**
* @brief Get checkbox value for mNoErrorsMessage
*
* @return Should "no errors message" be hidden
*/
bool ShowNoErrorsMessage();
/** /**
* @brief Get checkbox value for mSaveAllErrors * @brief Get checkbox value for mSaveAllErrors
* *
@ -191,6 +199,12 @@ protected:
*/ */
QCheckBox *mShowFullPath; QCheckBox *mShowFullPath;
/**
* @brief Show a message dialog when no errors are found (false)
*
*/
QCheckBox *mShowNoErrorsMessage;
/** /**
* @brief List of all applications that can be started when right clicking * @brief List of all applications that can be started when right clicking
* an error * an error