From bedd85fa505bee475c416ec1d69f4ff50d8c520a Mon Sep 17 00:00:00 2001 From: Akhilesh Nema Date: Wed, 23 Dec 2015 10:28:07 +0100 Subject: [PATCH] Fixed #1459 (GUI: Allow re-checking selected files/folders) --- gui/mainwindow.cpp | 38 ++++++++++++++++++++++++++++---- gui/mainwindow.h | 13 +++++++++++ gui/resultstree.cpp | 51 ++++++++++++++++++++++++++++++++----------- gui/resultstree.h | 17 ++++++++++++++- gui/resultsview.cpp | 5 +++-- gui/resultsview.h | 9 +++++++- gui/threadhandler.cpp | 29 +++++++++++++++++++----- gui/threadhandler.h | 32 +++++++++++++++++++++++++-- 8 files changed, 166 insertions(+), 28 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 992f33c34..07f21620b 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -62,9 +62,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mExiting(false) { mUI.setupUi(this); - mUI.mResults->Initialize(mSettings, mApplications); - mThread = new ThreadHandler(this); + mUI.mResults->Initialize(mSettings, mApplications, mThread); // Filter timer to delay filtering results slightly while typing mFilterTimer = new QTimer(this); @@ -122,6 +121,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : connect(mThread, SIGNAL(Done()), this, SLOT(CheckDone())); connect(mUI.mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded())); connect(mUI.mResults, SIGNAL(ResultsHidden(bool)), mUI.mActionShowHidden, SLOT(setEnabled(bool))); + connect(mUI.mResults, SIGNAL(CheckSelected(QStringList)), this, SLOT(PerformSelectedFilesCheck(QStringList))); connect(mUI.mMenuView, SIGNAL(aboutToShow()), this, SLOT(AboutToShowViewMenu())); // File menu @@ -388,7 +388,8 @@ void MainWindow::DoCheckFiles(const QStringList &files) if (mProject) qDebug() << "Checking project file" << mProject->GetProjectFile()->GetFilename(); - mThread->Check(checkSettings, false); + mThread->SetCheckFiles(true); + mThread->Check(checkSettings, true); } void MainWindow::CheckCode(const QString& code, const QString& filename) @@ -797,6 +798,29 @@ void MainWindow::ReCheckAll() ReCheck(true); } +void MainWindow::ReCheckSelected(QStringList files, bool all) +{ + if (files.empty()) + return; + if(mThread->IsChecking()) + return; + + // Clear details, statistics and progress + mUI.mResults->Clear(false); + for (int i = 0; i < files.size(); ++i) + mUI.mResults->Clear(files[i]); + CheckLockDownUI(); // lock UI while checking + mUI.mResults->CheckingStarted(files.size()); + mThread->SetCheckFiles(files); + + // Saving last check start time, otherwise unchecked modified files will not be + // considered in "Modified Files Check" performed after "Selected Files Check" + // TODO: Should we store per file CheckStartTime? + QDateTime saveCheckStartTime = mThread->GetCheckStartTime(); + mThread->Check(GetCppcheckSettings(), all); + mThread->SetCheckStartTime(saveCheckStartTime); +} + void MainWindow::ReCheck(bool all) { const QStringList files = mThread->GetReCheckFiles(all); @@ -816,7 +840,8 @@ void MainWindow::ReCheck(bool all) if (mProject) qDebug() << "Rechecking project file" << mProject->GetProjectFile()->GetFilename(); - mThread->Check(GetCppcheckSettings(), !all); + mThread->SetCheckFiles(all); + mThread->Check(GetCppcheckSettings(), all); } void MainWindow::ClearResults() @@ -993,6 +1018,11 @@ void MainWindow::ShowAuthors() dlg->exec(); } +void MainWindow::PerformSelectedFilesCheck(QStringList selectedFilesList) +{ + ReCheckSelected(selectedFilesList, true); +} + void MainWindow::Save() { QString selectedFilter; diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 40bf5bf8d..c29989049 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -84,6 +84,12 @@ public slots: */ void ReCheckAll(); + /** + * @brief Slot to recheck selected files + * @param selectedFilesList list of selected files + */ + void PerformSelectedFilesCheck(QStringList selectedFilesList); + /** * @brief Slot to recheck modified files * @@ -319,6 +325,13 @@ private: */ void ReCheck(bool all); + /** + * @brief Recheck selected files + * @param files list of selected files + * @param all true if all files of list, false if modified files of list + */ + void ReCheckSelected(QStringList files, bool all); + /** * @brief Check the project. * @param project Pointer to the project to check. diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 310b29330..af828ffe8 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -45,6 +45,7 @@ #include "report.h" #include "application.h" #include "showtypes.h" +#include "threadhandler.h" ResultsTree::ResultsTree(QWidget * parent) : QTreeView(parent), @@ -74,10 +75,11 @@ void ResultsTree::keyPressEvent(QKeyEvent *event) QTreeView::keyPressEvent(event); } -void ResultsTree::Initialize(QSettings *settings, ApplicationList *list) +void ResultsTree::Initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler) { mSettings = settings; mApplications = list; + mThread = checkThreadHandler; LoadSettings(); } @@ -552,6 +554,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) } //Create an action for the application + QAction *recheckSelectedFiles = new QAction(tr("Recheck"), &menu); QAction *copyfilename = new QAction(tr("Copy filename"), &menu); QAction *copypath = new QAction(tr("Copy full path"), &menu); QAction *copymessage = new QAction(tr("Copy message"), &menu); @@ -568,7 +571,12 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) hideallid->setDisabled(true); opencontainingfolder->setDisabled(true); } + if(mThread->IsChecking()) + recheckSelectedFiles->setDisabled(true); + else + recheckSelectedFiles->setDisabled(false); + menu.addAction(recheckSelectedFiles); menu.addAction(copyfilename); menu.addAction(copypath); menu.addAction(copymessage); @@ -577,6 +585,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) menu.addAction(hideallid); menu.addAction(opencontainingfolder); + connect(recheckSelectedFiles, SIGNAL(triggered()), this, SLOT(RecheckSelectedFiles())); connect(copyfilename, SIGNAL(triggered()), this, SLOT(CopyFilename())); connect(copypath, SIGNAL(triggered()), this, SLOT(CopyFullPath())); connect(copymessage, SIGNAL(triggered()), this, SLOT(CopyMessage())); @@ -588,20 +597,22 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) //Start the menu menu.exec(e->globalPos()); + index = indexAt(e->pos()); + if (index.isValid()) { + mContextItem = mModel.itemFromIndex(index); + if (mContextItem && mApplications->GetApplicationCount() > 0 && mContextItem->parent()) { + //Disconnect all signals + for (int i = 0; i < actions.size(); i++) { - if (mContextItem && mApplications->GetApplicationCount() > 0 && mContextItem->parent()) { - //Disconnect all signals - for (int i = 0; i < actions.size(); i++) { + disconnect(actions[i], SIGNAL(triggered()), signalMapper, SLOT(map())); + } - disconnect(actions[i], SIGNAL(triggered()), signalMapper, SLOT(map())); + disconnect(signalMapper, SIGNAL(mapped(int)), + this, SLOT(Context(int))); + //And remove the signal mapper + delete signalMapper; } - - disconnect(signalMapper, SIGNAL(mapped(int)), - this, SLOT(Context(int))); - //And remove the signal mapper - delete signalMapper; } - } } @@ -781,8 +792,7 @@ void ResultsTree::HideResult() return; QModelIndexList selectedRows = mSelectionModel->selectedRows(); - QModelIndex index; - foreach (index, selectedRows) { + foreach (QModelIndex index, selectedRows) { QStandardItem *item = mModel.itemFromIndex(index); //Set the "hide" flag for this item QVariantMap data = item->data().toMap(); @@ -794,6 +804,21 @@ void ResultsTree::HideResult() } } +void ResultsTree::RecheckSelectedFiles() +{ + if (!mSelectionModel) + return; + + QModelIndexList selectedRows = mSelectionModel->selectedRows(); + QStringList selectedItems; + foreach (QModelIndex index, selectedRows) { + QStandardItem *item = mModel.itemFromIndex(index); + QVariantMap data = item->data().toMap(); + selectedItems<parent()) { diff --git a/gui/resultstree.h b/gui/resultstree.h index 79d23c36a..46102763e 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -35,6 +35,7 @@ class ErrorLine; class QModelIndex; class QWidget; class QItemSelectionModel; +class ThreadHandler; /// @addtogroup GUI /// @{ @@ -49,7 +50,7 @@ class ResultsTree : public QTreeView { public: explicit ResultsTree(QWidget * parent = 0); virtual ~ResultsTree(); - void Initialize(QSettings *settings, ApplicationList *list); + void Initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler); /** * @brief Add a new item to the tree @@ -172,6 +173,13 @@ signals: */ void ResultsHidden(bool hidden); + /** + * @brief Signal to perform selected files recheck + * + * @param selectedItems list of selected files + */ + void CheckSelected(QStringList selectedItems); + /** * @brief Signal for selection change in result tree. * @@ -224,6 +232,12 @@ protected slots: */ void HideResult(); + /** + * @brief Slot for rechecking selected files + * + */ + void RecheckSelectedFiles(); + /** * @brief Slot for context menu item to hide all messages with the current message Id * @@ -472,6 +486,7 @@ protected: private: QItemSelectionModel *mSelectionModel; + ThreadHandler *mThread; }; /// @} #endif // RESULTSTREE_H diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 04a4f27f8..7afadc8c2 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -49,10 +49,11 @@ ResultsView::ResultsView(QWidget * parent) : mUI.setupUi(this); connect(mUI.mTree, SIGNAL(ResultsHidden(bool)), this, SIGNAL(ResultsHidden(bool))); + connect(mUI.mTree, SIGNAL(CheckSelected(QStringList)), this, SIGNAL(CheckSelected(QStringList))); connect(mUI.mTree, SIGNAL(SelectionChanged(const QModelIndex &)), this, SLOT(UpdateDetails(const QModelIndex &))); } -void ResultsView::Initialize(QSettings *settings, ApplicationList *list) +void ResultsView::Initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler) { mUI.mProgress->setMinimum(0); mUI.mProgress->setVisible(false); @@ -61,7 +62,7 @@ void ResultsView::Initialize(QSettings *settings, ApplicationList *list) mUI.mVerticalSplitter->restoreState(state); mShowNoErrorsMessage = settings->value(SETTINGS_SHOW_NO_ERRORS, true).toBool(); - mUI.mTree->Initialize(settings, list); + mUI.mTree->Initialize(settings, list, checkThreadHandler); } ResultsView::~ResultsView() diff --git a/gui/resultsview.h b/gui/resultsview.h index e1f5f10dd..f715f3568 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -45,7 +45,7 @@ class ResultsView : public QWidget { public: explicit ResultsView(QWidget * parent = 0); - void Initialize(QSettings *settings, ApplicationList *list); + void Initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler); virtual ~ResultsView(); /** @@ -181,6 +181,13 @@ signals: */ void ResultsHidden(bool hidden); + /** + * @brief Signal to perform recheck of selected files + * + * @param selectedFilesList list of selected files + */ + void CheckSelected(QStringList selectedFilesList); + public slots: /** diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index b5b788da3..42759501d 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -51,13 +51,22 @@ void ThreadHandler::SetFiles(const QStringList &files) mLastFiles = files; } -void ThreadHandler::Check(const Settings &settings, bool recheck) +void ThreadHandler::SetCheckFiles(bool all) { - if (recheck && mRunningThreadCount == 0) { - // only recheck changed files - mResults.SetFiles(GetReCheckFiles(false)); + if (mRunningThreadCount == 0) { + mResults.SetFiles(GetReCheckFiles(all)); } +} +void ThreadHandler::SetCheckFiles(QStringList files) +{ + if (mRunningThreadCount == 0) { + mResults.SetFiles(files); + } +} + +void ThreadHandler::Check(const Settings &settings, bool all) +{ if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0 || settings._jobs == 0) { qDebug() << "Can't start checking if there's no files to check or if check is in progress."; emit Done(); @@ -190,7 +199,7 @@ int ThreadHandler::GetPreviousScanDuration() const QStringList ThreadHandler::GetReCheckFiles(bool all) const { - if (mLastCheckTime.isNull()) + if (mLastCheckTime.isNull() || all) return mLastFiles; std::set modified; @@ -243,3 +252,13 @@ bool ThreadHandler::NeedsReCheck(const QString &filename, std::set &mod return false; } + +QDateTime ThreadHandler::GetCheckStartTime() const +{ + return mCheckStartTime; +} + +void ThreadHandler::SetCheckStartTime(QDateTime checkStartTime) +{ + mCheckStartTime = checkStartTime; +} diff --git a/gui/threadhandler.h b/gui/threadhandler.h index b97d9605a..b82408d74 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -87,9 +87,23 @@ public: * @brief Start the threads to check the files * * @param settings Settings for checking - * @param recheck Should we reuse the files we checked earlier + * @param all true if all files, false if modified files */ - void Check(const Settings &settings, bool recheck); + void Check(const Settings &settings, bool all); + + /** + * @brief Set files to check + * + * @param all true if all files, false if modified files + */ + void SetCheckFiles(bool all); + + /** + * @brief Set selected files to check + * + * @param files list of files to be checked + */ + void SetCheckFiles(QStringList files); /** * @brief Is checking running? @@ -125,6 +139,20 @@ public: */ QStringList GetReCheckFiles(bool all) const; + /** + * @brief Get start time of last check + * + * @return start time of last check + */ + QDateTime GetCheckStartTime() const; + + /** + * @brief Set start time of check + * + * @param checkStartTime saved start time of the last check + */ + void SetCheckStartTime(QDateTime checkStartTime); + signals: /** * @brief Signal that all threads are done