diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ce900e4230a..13193957258 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -40,6 +40,7 @@ #include "projectfile.h" #include "projectfiledialog.h" #include "report.h" +#include "resultstree.h" #include "resultsview.h" #include "scratchpad.h" #include "settings.h" @@ -230,10 +231,13 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : loadSettings(); mThread->initialize(mUI->mResults); - if (mProjectFile) + if (mProjectFile) { + enableProjectActions(true); formatAndSetTitle(tr("Project:") + ' ' + mProjectFile->getFilename()); - else + } else { + enableProjectActions(false); formatAndSetTitle(); + } mUI->mActionComplianceReport->setVisible(isCppcheckPremium()); @@ -242,7 +246,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mUI->mActionPrint->setShortcut(QKeySequence::Print); enableResultsButtons(); enableProjectOpenActions(true); - enableProjectActions(false); // Must setup MRU menu before CLI param handling as it can load a // project file and update MRU menu. @@ -263,9 +266,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : handleCLIParams(args); } - mUI->mActionCloseProjectFile->setEnabled(mProjectFile != nullptr); - mUI->mActionEditProjectFile->setEnabled(mProjectFile != nullptr); - for (int i = 0; i < mPlatforms.getCount(); i++) { PlatformData platform = mPlatforms.mPlatforms[i]; auto *action = new QAction(this); @@ -588,6 +588,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons } mUI->mResults->clear(true); + mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Analysis); mThread->clearFiles(); mUI->mResults->checkingStarted(p.fileSettings.size()); @@ -651,6 +652,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar QStringList fileNames = pathList.getFileList(); mUI->mResults->clear(true); + mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Analysis); mThread->clearFiles(); if (fileNames.isEmpty()) { @@ -1486,6 +1488,7 @@ void MainWindow::loadResults(const QString &selectedFile) closeProjectFile(); mIsLogfileLoaded = true; mUI->mResults->clear(true); + mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Log); mUI->mActionReanalyzeModified->setEnabled(false); mUI->mActionReanalyzeAll->setEnabled(false); mUI->mResults->readErrorsXml(selectedFile); @@ -1776,7 +1779,6 @@ void MainWindow::stopAnalysis() { mThread->stop(); mUI->mResults->stopAnalysis(); - mUI->mResults->disableProgressbar(); const QString &lastResults = getLastResults(); if (!lastResults.isEmpty()) { mUI->mResults->updateFromOldReport(lastResults); @@ -1830,8 +1832,10 @@ void MainWindow::loadProjectFile(const QString &filePath) addProjectMRU(filePath); mIsLogfileLoaded = false; - mUI->mActionCloseProjectFile->setEnabled(true); - mUI->mActionEditProjectFile->setEnabled(true); + mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Analysis); + mUI->mActionReanalyzeModified->setEnabled(true); + mUI->mActionReanalyzeAll->setEnabled(true); + enableProjectActions(true); delete mProjectFile; mProjectFile = new ProjectFile(filePath, this); mProjectFile->setActiveProject(); diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index dd3d9bb1550..e27a67c405e 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -765,7 +765,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) auto *hideallid = new QAction(tr("Hide all with id"), &menu); auto *opencontainingfolder = new QAction(tr("Open containing folder"), &menu); - if (selectedFiles == 0 || mThread->isChecking()) + if (selectedFiles == 0 || mThread->isChecking() || mResultsSource == ResultsSource::Log) recheckAction->setDisabled(true); if (selectedResults == 0) @@ -774,7 +774,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) if (selectedResults == 0 || multipleSelection) hideallid->setDisabled(true); - if (multipleSelection) + if (multipleSelection || mResultsSource == ResultsSource::Log) opencontainingfolder->setDisabled(true); menu.addAction(recheckAction); @@ -1424,12 +1424,16 @@ void ResultsTree::setCheckDirectory(const QString &dir) mCheckPath = dir; } - const QString& ResultsTree::getCheckDirectory() const { return mCheckPath; } +void ResultsTree::setResultsSource(ResultsSource source) +{ + mResultsSource = source; +} + QString ResultsTree::stripPath(const QString &path, bool saving) const { if ((!saving && mShowFullPath) || (saving && mSaveFullPath)) { diff --git a/gui/resultstree.h b/gui/resultstree.h index 840d56f5abc..8978e10cddc 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -47,7 +47,6 @@ enum class Severity : std::uint8_t; /// @addtogroup GUI /// @{ - /** * @brief Cppcheck's results are shown in this tree * @@ -139,6 +138,24 @@ class ResultsTree : public QTreeView { const QString& getCheckDirectory() const; + /** + * @brief Results source for analysis results in the results tree. + */ + enum class ResultsSource : std::uint8_t { + /** Results from a project, files, or directory check */ + Analysis, + /** Saved results from a log file */ + Log, + }; + + /** + * @brief Set the source type of the current results. This + * affects the actions that are allowed on them. + * + * @param source The results source type. + */ + void setResultsSource(ResultsSource source); + /** * @brief Check if there are any visible results in view. * @return true if there is at least one visible warning/error. @@ -508,6 +525,12 @@ protected slots: */ QString mCheckPath; + /** + * @brief The type of source of the current results + * + */ + ResultsSource mResultsSource{ResultsSource::Analysis}; + /** * @brief Are there any visible errors * diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 6b3b497489d..d200017fa50 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -159,6 +159,11 @@ void ResultsView::setReportType(ReportType reportType) { mUI->mTree->setReportType(reportType); } +void ResultsView::setResultsSource(ResultsTree::ResultsSource source) +{ + mUI->mTree->setResultsSource(source); +} + void ResultsView::progress(int value, const QString& description) { mUI->mProgress->setValue(value); @@ -389,11 +394,6 @@ void ResultsView::translate() mUI->mTree->translate(); } -void ResultsView::disableProgressbar() -{ - mUI->mProgress->setEnabled(false); -} - void ResultsView::readErrorsXml(const QString &filename) { mSuccess = false; // Don't know if results come from an aborted analysis diff --git a/gui/resultsview.h b/gui/resultsview.h index b28fcffe0f4..20ef0813615 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -21,6 +21,7 @@ #define RESULTSVIEW_H #include "report.h" +#include "resultstree.h" #include "showtypes.h" #include @@ -197,8 +198,6 @@ class ResultsView : public QWidget { */ bool isSuccess() const; - void disableProgressbar(); - /** * @brief Read errors from report XML file. * @param filename Report file to read. @@ -222,6 +221,13 @@ class ResultsView : public QWidget { void setReportType(ReportType reportType); + /** + * @brief Set the results source type for the results tree. + * + * @param source The results source type. + */ + void setResultsSource(ResultsTree::ResultsSource source); + signals: /**