Skip to content

Commit cbb4b1b

Browse files
committed
htmlreport: Add checkboxes to toggle error visibility by id
1 parent e4f81ba commit cbb4b1b

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

htmlreport/cppcheck-htmlreport

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ HTML_HEAD = """
215215
clickable.onclick = toggle;
216216
}
217217
}
218+
function set_class_display(c, st) {
219+
var elements = document.querySelectorAll('.' + c),
220+
len = elements.length;
221+
for (i = 0; i < len; i++) {
222+
elements[i].style.display = st;
223+
}
224+
}
225+
function toggle_class_visibility(id) {
226+
var box = document.getElementById(id);
227+
set_class_display(id, box.checked ? '' : 'none');
228+
}
218229
</script>
219230
</head>
220231
<body onload="init_expandables()">
@@ -547,12 +558,18 @@ if __name__ == '__main__':
547558
except IndexError:
548559
cnt_min = 0
549560

561+
stat_fmt = " <tr><td><input type='checkbox' onclick='toggle_class_visibility(this.id)' id='{}' name='{}' checked></td><td>{}</td><td>{}</td></tr>"
550562
for occurrences in reversed(range(cnt_min, cnt_max + 1)):
551563
for _id in [k for k, v in sorted(counter.items()) if v == occurrences]:
552-
stat_html.append(" " + str(dict(counter.most_common())[_id]) + " " + str(_id) + "<br/>\n")
564+
stat_html.append(stat_fmt.format(_id, _id, dict(counter.most_common())[_id], _id))
553565

554566
output_file.write(HTML_HEAD.replace('id="menu" dir="rtl"', 'id="menu_index"', 1).replace("Defects:", "Defect summary;", 1) % (options.title, '', options.title, '', ''))
555-
output_file.write(' <p>\n' + ' ' + str(stats_count) + ' total<br/><br/>\n' + ''.join(stat_html) + '<br/><br/><a href="stats.html">Statistics</a></p>')
567+
output_file.write(' <table>')
568+
output_file.write(' <tr><th>Show</th><th>#</th><th>Defect ID</th></tr>')
569+
output_file.write(''.join(stat_html))
570+
output_file.write(' <tr><td></td><td>' + str(stats_count) + '</td><td>total</td></tr>')
571+
output_file.write(' </table>')
572+
output_file.write(' <a href="stats.html">Statistics</a></p>')
556573
output_file.write(HTML_HEAD_END.replace("content", "content_index", 1))
557574
output_file.write(' <table>\n')
558575

@@ -591,17 +608,17 @@ if __name__ == '__main__':
591608
error_class = 'class="error"'
592609
if error['id'] == 'missingInclude':
593610
output_file.write(
594-
'\n <tr><td></td><td>%s</td><td></td><td>%s</td><td>%s</td></tr>' %
595-
(error['id'], error['severity'], error['msg']))
611+
'\n <tr class="%s"><td></td><td>%s</td><td></td><td>%s</td><td>%s</td></tr>' %
612+
(error['id'], error['id'], error['severity'], error['msg']))
596613
elif (error['id'] == 'unmatchedSuppression') and filename.endswith('*'):
597614
output_file.write(
598-
'\n <tr><td></td><td>%s</td><td></td><td>%s</td><td %s>%s</td></tr>' %
599-
(error['id'], error['severity'], error_class,
615+
'\n <tr class="%s"><td></td><td>%s</td><td></td><td>%s</td><td %s>%s</td></tr>' %
616+
(error['id'], error['id'], error['severity'], error_class,
600617
error['msg']))
601618
else:
602619
output_file.write(
603-
'\n <tr><td><a href="%s#line-%d">%d</a></td><td>%s</td><td>%s</td><td>%s</td><td %s>%s</td></tr>' %
604-
(data['htmlfile'], error['line'], error['line'],
620+
'\n <tr class="%s"><td><a href="%s#line-%d">%d</a></td><td>%s</td><td>%s</td><td>%s</td><td %s>%s</td></tr>' %
621+
(error['id'], data['htmlfile'], error['line'], error['line'],
605622
error['id'], cwe_url, error['severity'], error_class,
606623
error['msg']))
607624

0 commit comments

Comments
 (0)