From b67424785f2ba71f9c12ae62e2c5fd8202c14658 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Tue, 9 Jun 2009 10:51:27 +0300 Subject: [PATCH] Added messagebox to inform user about not found/non visible errors. --- gui/applicationdialog.cpp | 11 ++++++--- gui/mainwindow.cpp | 38 ++++++++++++++++++++++------- gui/resultstree.cpp | 29 +++++++++++++++++++---- gui/resultstree.h | 15 ++++++++++++ gui/resultsview.cpp | 50 +++++++++++++++++++++++++++++++++++++-- gui/resultsview.h | 15 +++++++++++- gui/settingsdialog.cpp | 18 ++++++++++++-- gui/settingsdialog.h | 14 +++++++++++ 8 files changed, 169 insertions(+), 21 deletions(-) diff --git a/gui/applicationdialog.cpp b/gui/applicationdialog.cpp index e941ee421..8c6eb554b 100644 --- a/gui/applicationdialog.cpp +++ b/gui/applicationdialog.cpp @@ -123,9 +123,14 @@ void ApplicationDialog::Ok() { if (mName->text().isEmpty() || mPath->text().isEmpty()) { - QMessageBox msgBox; - msgBox.setText("You must specify a name and a path for the application!"); - msgBox.exec(); + QMessageBox msg(QMessageBox::Warning, + tr("Cppcheck"), + tr("You must specify a name and a path for the application!"), + QMessageBox::Ok, + this); + + msg.exec(); + } else { diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index e7e9be5c2..640c65104 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "aboutdialog.h" #include "../src/filelister.h" #include "../src/cppcheckexecutor.h" @@ -132,6 +133,11 @@ MainWindow::MainWindow() : toolbar->addAction(&mActionSettings); 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(); mThread.Initialize(&mResults); setWindowTitle(tr("Cppcheck")); @@ -209,9 +215,15 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) if (fileNames.isEmpty()) { - QMessageBox msgBox; - msgBox.setText("No suitable files found to check!"); - msgBox.exec(); + + QMessageBox msg(QMessageBox::Warning, + tr("Cppcheck"), + tr("No suitable files found to check!"), + QMessageBox::Ok, + this); + + msg.exec(); + return; } @@ -306,7 +318,8 @@ void MainWindow::ProgramSettings() dialog.SaveCheckboxValues(); mResults.UpdateSettings(dialog.ShowFullPath(), dialog.SaveFullPath(), - dialog.SaveAllErrors()); + dialog.SaveAllErrors(), + dialog.ShowNoErrorsMessage()); } } @@ -375,11 +388,18 @@ void MainWindow::closeEvent(QCloseEvent *event) event->accept(); else { - QString msg(tr("Cannot exit while checking.\n\n" \ - "Stop the checking before exiting.")); - QMessageBox *box = new QMessageBox(QMessageBox::Warning, - tr("cppcheck"), msg); - box->show(); + QString text(tr("Cannot exit while checking.\n\n" \ + "Stop the checking before exiting.")); + + QMessageBox msg(QMessageBox::Warning, + tr("Cppcheck"), + text, + QMessageBox::Ok, + this); + + msg.exec(); + + event->ignore(); } } diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index d17cb44b0..17a937aec 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -29,7 +29,8 @@ ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) : mSettings(settings), mApplications(list), mContextItem(0), - mCheckPath("") + mCheckPath(""), + mVisibleErrors(false) { setModel(&mModel); QStringList labels; @@ -76,6 +77,13 @@ void ResultsTree::AddErrorItem(const QString &file, } 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 //file item as a parent QStandardItem *item = AddBacktraceFiles(EnsureFileItem(realfile, hide), @@ -226,6 +234,7 @@ void ResultsTree::ShowResults(ShowTypes type, bool show) void ResultsTree::RefreshTree() { + mVisibleErrors = false; //Get the amount of files in the tree int filecount = mModel.rowCount(); @@ -261,6 +270,11 @@ void ResultsTree::RefreshTree() //Check if this error should be hidden bool hide = !mShowTypes[VariantToShowType(data["severity"])]; + if (!hide) + { + mVisibleErrors = true; + } + //Hide/show accordingly 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 (mApplications.GetApplicationCount() == 0) { - QMessageBox msgBox; - msgBox.setText("You can open this error by specifying applications in program's settings."); - msgBox.exec(); + QMessageBox msg(QMessageBox::Warning, + tr("Cppcheck"), + tr("You can open this error by specifying applications in program's settings.")); + msg.exec(); return; } @@ -421,6 +436,7 @@ void ResultsTree::StartApplication(QStandardItem *target, int application) msgbox.setWindowTitle("Cppcheck"); msgbox.setText(text); msgbox.setIcon(QMessageBox::Critical); + msgbox.exec(); } } @@ -689,3 +705,8 @@ void ResultsTree::RefreshFilePaths() RefreshFilePaths(mModel.item(i, 0)); } } + +bool ResultsTree::VisibleErrors() +{ + return mVisibleErrors; +} diff --git a/gui/resultstree.h b/gui/resultstree.h index 0b711c7a0..9e1da3c18 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -93,6 +93,13 @@ public: * @param dir Directory we are checking */ 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: /** * @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 */ void Context(int application); + protected: /** @@ -313,6 +321,13 @@ protected: * */ QString mCheckPath; + + /** + * @brief Are there any visible errors + * + */ + bool mVisibleErrors; + private: }; diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 2194bede4..38e7213d2 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -21,8 +21,11 @@ #include #include #include +#include -ResultsView::ResultsView(QSettings &settings, ApplicationList &list) +ResultsView::ResultsView(QSettings &settings, ApplicationList &list) : + mErrorsFound(false), + mShowNoErrorsMessage(true) { QVBoxLayout *layout = new QVBoxLayout(); setLayout(layout); @@ -35,6 +38,8 @@ ResultsView::ResultsView(QSettings &settings, ApplicationList &list) mTree = new ResultsTree(settings, list); layout->addWidget(mTree); + mShowNoErrorsMessage = settings.value(tr("Show no errors message"), true).toBool(); + } ResultsView::~ResultsView() @@ -46,6 +51,11 @@ ResultsView::~ResultsView() void ResultsView::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) { 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 { @@ -71,6 +107,7 @@ void ResultsView::Error(const QString &file, const QVariantList &lines, const QString &id) { + mErrorsFound = true; mTree->AddErrorItem(file, severity, message, files, lines, id); emit GotResults(); } @@ -92,6 +129,13 @@ void ResultsView::ExpandAllResults() 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); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -105,9 +149,11 @@ void ResultsView::Save(const QString &filename, bool xml) void ResultsView::UpdateSettings(bool showFullPath, bool saveFullPath, - bool saveAllErrors) + bool saveAllErrors, + bool showNoErrorsMessage) { mTree->UpdateSettings(showFullPath, saveFullPath, saveAllErrors); + mShowNoErrorsMessage = showNoErrorsMessage; } void ResultsView::SetCheckDirectory(const QString &dir) diff --git a/gui/resultsview.h b/gui/resultsview.h index 261938174..f6bcf829b 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -70,7 +70,10 @@ public: * @param saveFullPath Save full path of files in reports * @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 @@ -138,6 +141,16 @@ protected: */ 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: }; diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index b47a9e9b7..c1c8720e8 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -79,7 +79,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list //Force mForce = AddCheckbox(layout, - tr("Force checking on files that have \"too many\" configurations"), + tr("Check all #ifdef configurations"), tr("Check force"), false); @@ -88,6 +88,11 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list tr("Show full path"), false); + mShowNoErrorsMessage = AddCheckbox(layout, + tr("Show \"No errors found\" message when no errors found"), + tr("Show no errors message"), + true); + layout->addStretch(); general->setLayout(layout); @@ -115,7 +120,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list connect(modify, SIGNAL(clicked()), this, SLOT(ModifyApplication())); - QPushButton *def = new QPushButton(tr("Make default application")); + QPushButton *def = new QPushButton(tr("Set as default application")); appslayout->addWidget(def); connect(def, SIGNAL(clicked()), this, SLOT(DefaultApplication())); @@ -205,6 +210,7 @@ void SettingsDialog::SaveCheckboxValues() SaveCheckboxValue(mSaveAllErrors, tr("Save all errors")); SaveCheckboxValue(mSaveFullPath, tr("Save full path")); SaveCheckboxValue(mShowFullPath, tr("Show full path")); + SaveCheckboxValue(mShowNoErrorsMessage, tr("Show no errors message")); } void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) @@ -303,3 +309,11 @@ bool SettingsDialog::SaveAllErrors() { return CheckStateToBool(mSaveAllErrors->checkState()); } + +bool SettingsDialog::ShowNoErrorsMessage() +{ + return CheckStateToBool(mShowNoErrorsMessage->checkState()); +} + + + diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index 0fb0e3443..ccd3ab1c3 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -64,6 +64,14 @@ public: */ bool SaveFullPath(); + + /** + * @brief Get checkbox value for mNoErrorsMessage + * + * @return Should "no errors message" be hidden + */ + bool ShowNoErrorsMessage(); + /** * @brief Get checkbox value for mSaveAllErrors * @@ -191,6 +199,12 @@ protected: */ 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 * an error