Skip to content

Commit a16c0db

Browse files
committed
Fixed cppcheck-opensource#1861 (GUI: Allow hiding error)
1 parent bb745da commit a16c0db

6 files changed

Lines changed: 83 additions & 2 deletions

File tree

‎gui/main.ui‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<x>0</x>
6767
<y>0</y>
6868
<width>640</width>
69-
<height>21</height>
69+
<height>25</height>
7070
</rect>
7171
</property>
7272
<widget class="QMenu" name="mMenuFile">
@@ -106,6 +106,8 @@
106106
<addaction name="mActionCollapseAll"/>
107107
<addaction name="mActionExpandAll"/>
108108
<addaction name="separator"/>
109+
<addaction name="mActionShowHidden"/>
110+
<addaction name="separator"/>
109111
<addaction name="mActionViewLog"/>
110112
<addaction name="mActionViewStats"/>
111113
</widget>
@@ -461,6 +463,11 @@
461463
<string>Show performance warnings</string>
462464
</property>
463465
</action>
466+
<action name="mActionShowHidden">
467+
<property name="text">
468+
<string>Show &amp;hidden</string>
469+
</property>
470+
</action>
464471
</widget>
465472
<customwidgets>
466473
<customwidget>

‎gui/mainwindow.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ MainWindow::MainWindow() :
6969
connect(mUI.mActionUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll()));
7070
connect(mUI.mActionCollapseAll, SIGNAL(triggered()), mUI.mResults, SLOT(CollapseAllResults()));
7171
connect(mUI.mActionExpandAll, SIGNAL(triggered()), mUI.mResults, SLOT(ExpandAllResults()));
72+
connect(mUI.mActionShowHidden, SIGNAL(triggered()), mUI.mResults, SLOT(ShowHiddenResults()));
7273
connect(mUI.mActionViewLog, SIGNAL(triggered()), this, SLOT(ShowLogView()));
7374
connect(mUI.mActionViewStats, SIGNAL(triggered()), this, SLOT(ShowStatistics()));
7475

‎gui/resultstree.cpp‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item)
132132

133133
//Add user data to that item
134134
QMap<QString, QVariant> data;
135+
data["hide"] = false;
135136
data["severity"] = SeverityToShowType(item.severity);
136137
data["summary"] = item.summary;
137138
data["message"] = item.message;
@@ -313,6 +314,35 @@ void ResultsTree::ShowResults(ShowTypes type, bool show)
313314
}
314315
}
315316

317+
void ResultsTree::ShowHiddenResults()
318+
{
319+
//Clear the "hide" flag for each item
320+
int filecount = mModel.rowCount();
321+
for (int i = 0; i < filecount; i++)
322+
{
323+
QStandardItem *file = mModel.item(i, 0);
324+
if (!file)
325+
continue;
326+
327+
QVariantMap data = file->data().toMap();
328+
data["hide"] = false;
329+
file->setData(QVariant(data));
330+
331+
int errorcount = file->rowCount();
332+
for (int j = 0; j < errorcount; j++)
333+
{
334+
QStandardItem *child = file->child(j, 0);
335+
if (child)
336+
{
337+
data = child->data().toMap();
338+
data["hide"] = false;
339+
child->setData(QVariant(data));
340+
}
341+
}
342+
}
343+
RefreshTree();
344+
}
345+
316346

317347
void ResultsTree::RefreshTree()
318348
{
@@ -350,7 +380,7 @@ void ResultsTree::RefreshTree()
350380
QVariantMap data = userdata.toMap();
351381

352382
//Check if this error should be hidden
353-
bool hide = !mShowTypes[VariantToShowType(data["severity"])];
383+
bool hide = (data["hide"].toBool() || !mShowTypes[VariantToShowType(data["severity"])]);
354384

355385
if (!hide)
356386
{
@@ -367,6 +397,12 @@ void ResultsTree::RefreshTree()
367397
}
368398
}
369399

400+
//Hide the file if its "hide" attribute is set
401+
if (file->data().toMap()["hide"].toBool())
402+
{
403+
show = false;
404+
}
405+
370406
//Show the file if any of it's errors are visible
371407
setRowHidden(i, QModelIndex(), !show);
372408
}
@@ -463,14 +499,17 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
463499
QAction *copyfilename = new QAction(tr("Copy filename"), &menu);
464500
QAction *copypath = new QAction(tr("Copy full path"), &menu);
465501
QAction *copymessage = new QAction(tr("Copy message"), &menu);
502+
QAction *hide = new QAction(tr("Hide"), &menu);
466503

467504
menu.addAction(copyfilename);
468505
menu.addAction(copypath);
469506
menu.addAction(copymessage);
507+
menu.addAction(hide);
470508

471509
connect(copyfilename, SIGNAL(triggered()), this, SLOT(CopyFilename()));
472510
connect(copypath, SIGNAL(triggered()), this, SLOT(CopyFullPath()));
473511
connect(copymessage, SIGNAL(triggered()), this, SLOT(CopyMessage()));
512+
connect(hide, SIGNAL(triggered()), this, SLOT(HideResult()));
474513
}
475514

476515
//Start the menu
@@ -621,6 +660,19 @@ void ResultsTree::CopyMessage()
621660
}
622661
}
623662

663+
void ResultsTree::HideResult()
664+
{
665+
if (mContextItem)
666+
{
667+
//Set the "hide" flag for this item
668+
QVariantMap data = mContextItem->data().toMap();
669+
data["hide"] = true;
670+
mContextItem->setData(QVariant(data));
671+
672+
RefreshTree();
673+
}
674+
}
675+
624676
void ResultsTree::Context(int application)
625677
{
626678
StartApplication(mContextItem, application);

‎gui/resultstree.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class ResultsTree : public QTreeView
7171
*/
7272
void ShowResults(ShowTypes type, bool show);
7373

74+
/**
75+
* @brief Function to show results that were previous hidden with HideResult()
76+
*/
77+
void ShowHiddenResults();
78+
7479
/**
7580
* @brief Save results to a text stream
7681
*
@@ -150,6 +155,12 @@ protected slots:
150155
*/
151156
void CopyMessage();
152157

158+
/**
159+
* @brief Slot for context menu item to hide the current error message
160+
*
161+
*/
162+
void HideResult();
163+
153164
protected:
154165

155166
/**

‎gui/resultsview.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ void ResultsView::ExpandAllResults()
8989
mUI.mTree->expandAll();
9090
}
9191

92+
void ResultsView::ShowHiddenResults()
93+
{
94+
mUI.mTree->ShowHiddenResults();
95+
}
96+
9297
void ResultsView::Save(const QString &filename, Report::Type type)
9398
{
9499
if (!mErrorsFound)

‎gui/resultsview.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ public slots:
173173
*/
174174
void ExpandAllResults();
175175

176+
/**
177+
* @brief Show hidden results in the result list.
178+
*/
179+
void ShowHiddenResults();
180+
176181
protected:
177182
/**
178183
* @brief Have any errors been found

0 commit comments

Comments
 (0)