Skip to content

Commit be84139

Browse files
authored
Fix #14030 (GUI: Options are not enabled and disabled correctly) (#7693)
1 parent 98884b5 commit be84139

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

gui/mainwindow.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "projectfile.h"
4141
#include "projectfiledialog.h"
4242
#include "report.h"
43+
#include "resultstree.h"
4344
#include "resultsview.h"
4445
#include "scratchpad.h"
4546
#include "settings.h"
@@ -230,10 +231,13 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
230231
loadSettings();
231232

232233
mThread->initialize(mUI->mResults);
233-
if (mProjectFile)
234+
if (mProjectFile) {
235+
enableProjectActions(true);
234236
formatAndSetTitle(tr("Project:") + ' ' + mProjectFile->getFilename());
235-
else
237+
} else {
238+
enableProjectActions(false);
236239
formatAndSetTitle();
240+
}
237241

238242
mUI->mActionComplianceReport->setVisible(isCppcheckPremium());
239243

@@ -242,7 +246,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
242246
mUI->mActionPrint->setShortcut(QKeySequence::Print);
243247
enableResultsButtons();
244248
enableProjectOpenActions(true);
245-
enableProjectActions(false);
246249

247250
// Must setup MRU menu before CLI param handling as it can load a
248251
// project file and update MRU menu.
@@ -263,9 +266,6 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
263266
handleCLIParams(args);
264267
}
265268

266-
mUI->mActionCloseProjectFile->setEnabled(mProjectFile != nullptr);
267-
mUI->mActionEditProjectFile->setEnabled(mProjectFile != nullptr);
268-
269269
for (int i = 0; i < mPlatforms.getCount(); i++) {
270270
PlatformData platform = mPlatforms.mPlatforms[i];
271271
auto *action = new QAction(this);
@@ -588,6 +588,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
588588
}
589589

590590
mUI->mResults->clear(true);
591+
mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Analysis);
591592
mThread->clearFiles();
592593

593594
mUI->mResults->checkingStarted(p.fileSettings.size());
@@ -651,6 +652,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
651652
QStringList fileNames = pathList.getFileList();
652653

653654
mUI->mResults->clear(true);
655+
mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Analysis);
654656
mThread->clearFiles();
655657

656658
if (fileNames.isEmpty()) {
@@ -1486,6 +1488,7 @@ void MainWindow::loadResults(const QString &selectedFile)
14861488
closeProjectFile();
14871489
mIsLogfileLoaded = true;
14881490
mUI->mResults->clear(true);
1491+
mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Log);
14891492
mUI->mActionReanalyzeModified->setEnabled(false);
14901493
mUI->mActionReanalyzeAll->setEnabled(false);
14911494
mUI->mResults->readErrorsXml(selectedFile);
@@ -1776,7 +1779,6 @@ void MainWindow::stopAnalysis()
17761779
{
17771780
mThread->stop();
17781781
mUI->mResults->stopAnalysis();
1779-
mUI->mResults->disableProgressbar();
17801782
const QString &lastResults = getLastResults();
17811783
if (!lastResults.isEmpty()) {
17821784
mUI->mResults->updateFromOldReport(lastResults);
@@ -1830,8 +1832,10 @@ void MainWindow::loadProjectFile(const QString &filePath)
18301832
addProjectMRU(filePath);
18311833

18321834
mIsLogfileLoaded = false;
1833-
mUI->mActionCloseProjectFile->setEnabled(true);
1834-
mUI->mActionEditProjectFile->setEnabled(true);
1835+
mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Analysis);
1836+
mUI->mActionReanalyzeModified->setEnabled(true);
1837+
mUI->mActionReanalyzeAll->setEnabled(true);
1838+
enableProjectActions(true);
18351839
delete mProjectFile;
18361840
mProjectFile = new ProjectFile(filePath, this);
18371841
mProjectFile->setActiveProject();

gui/resultstree.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
765765
auto *hideallid = new QAction(tr("Hide all with id"), &menu);
766766
auto *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
767767

768-
if (selectedFiles == 0 || mThread->isChecking())
768+
if (selectedFiles == 0 || mThread->isChecking() || mResultsSource == ResultsSource::Log)
769769
recheckAction->setDisabled(true);
770770

771771
if (selectedResults == 0)
@@ -774,7 +774,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
774774
if (selectedResults == 0 || multipleSelection)
775775
hideallid->setDisabled(true);
776776

777-
if (multipleSelection)
777+
if (multipleSelection || mResultsSource == ResultsSource::Log)
778778
opencontainingfolder->setDisabled(true);
779779

780780
menu.addAction(recheckAction);
@@ -1424,12 +1424,16 @@ void ResultsTree::setCheckDirectory(const QString &dir)
14241424
mCheckPath = dir;
14251425
}
14261426

1427-
14281427
const QString& ResultsTree::getCheckDirectory() const
14291428
{
14301429
return mCheckPath;
14311430
}
14321431

1432+
void ResultsTree::setResultsSource(ResultsSource source)
1433+
{
1434+
mResultsSource = source;
1435+
}
1436+
14331437
QString ResultsTree::stripPath(const QString &path, bool saving) const
14341438
{
14351439
if ((!saving && mShowFullPath) || (saving && mSaveFullPath)) {

gui/resultstree.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ enum class Severity : std::uint8_t;
4747
/// @addtogroup GUI
4848
/// @{
4949

50-
5150
/**
5251
* @brief Cppcheck's results are shown in this tree
5352
*
@@ -139,6 +138,24 @@ class ResultsTree : public QTreeView {
139138

140139
const QString& getCheckDirectory() const;
141140

141+
/**
142+
* @brief Results source for analysis results in the results tree.
143+
*/
144+
enum class ResultsSource : std::uint8_t {
145+
/** Results from a project, files, or directory check */
146+
Analysis,
147+
/** Saved results from a log file */
148+
Log,
149+
};
150+
151+
/**
152+
* @brief Set the source type of the current results. This
153+
* affects the actions that are allowed on them.
154+
*
155+
* @param source The results source type.
156+
*/
157+
void setResultsSource(ResultsSource source);
158+
142159
/**
143160
* @brief Check if there are any visible results in view.
144161
* @return true if there is at least one visible warning/error.
@@ -508,6 +525,12 @@ protected slots:
508525
*/
509526
QString mCheckPath;
510527

528+
/**
529+
* @brief The type of source of the current results
530+
*
531+
*/
532+
ResultsSource mResultsSource{ResultsSource::Analysis};
533+
511534
/**
512535
* @brief Are there any visible errors
513536
*

gui/resultsview.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ void ResultsView::setReportType(ReportType reportType) {
159159
mUI->mTree->setReportType(reportType);
160160
}
161161

162+
void ResultsView::setResultsSource(ResultsTree::ResultsSource source)
163+
{
164+
mUI->mTree->setResultsSource(source);
165+
}
166+
162167
void ResultsView::progress(int value, const QString& description)
163168
{
164169
mUI->mProgress->setValue(value);
@@ -389,11 +394,6 @@ void ResultsView::translate()
389394
mUI->mTree->translate();
390395
}
391396

392-
void ResultsView::disableProgressbar()
393-
{
394-
mUI->mProgress->setEnabled(false);
395-
}
396-
397397
void ResultsView::readErrorsXml(const QString &filename)
398398
{
399399
mSuccess = false; // Don't know if results come from an aborted analysis

gui/resultsview.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define RESULTSVIEW_H
2222

2323
#include "report.h"
24+
#include "resultstree.h"
2425
#include "showtypes.h"
2526

2627
#include <cstdint>
@@ -197,8 +198,6 @@ class ResultsView : public QWidget {
197198
*/
198199
bool isSuccess() const;
199200

200-
void disableProgressbar();
201-
202201
/**
203202
* @brief Read errors from report XML file.
204203
* @param filename Report file to read.
@@ -222,6 +221,13 @@ class ResultsView : public QWidget {
222221

223222
void setReportType(ReportType reportType);
224223

224+
/**
225+
* @brief Set the results source type for the results tree.
226+
*
227+
* @param source The results source type.
228+
*/
229+
void setResultsSource(ResultsTree::ResultsSource source);
230+
225231
signals:
226232

227233
/**

0 commit comments

Comments
 (0)