38 #include "ui_resultsview.h" 
   43 #include <QAbstractItemModel> 
   44 #include <QApplication> 
   56 #include <QListWidget> 
   57 #include <QListWidgetItem> 
   59 #include <QMessageBox> 
   61 #include <QPrintDialog> 
   62 #include <QPrintPreviewDialog> 
   64 #include <QProgressBar> 
   67 #include <QStandardItem> 
   68 #include <QStandardItemModel> 
   69 #include <QTextDocument> 
   71 #include <QTextStream> 
   73 #include <QVariantMap> 
   94     mUI->mListLog->setContextMenuPolicy(Qt::CustomContextMenu);
 
   99     mUI->mProgress->setMinimum(0);
 
  100     mUI->mProgress->setVisible(
false);
 
  101     mUI->mLabelCriticalErrors->setVisible(
false);
 
  104     mUI->mCode->setStyle(theStyle);
 
  107     mUI->mVerticalSplitter->restoreState(state);
 
  110     mUI->mTree->initialize(settings, list, checkThreadHandler);
 
  125     mUI->mDetails->setText(QString());
 
  133     mUI->mProgress->setValue(0);
 
  134     mUI->mProgress->setFormat(
"%p%");
 
  136     mUI->mLabelCriticalErrors->setVisible(
false);
 
  143     mUI->mTree->clear(filename);
 
  148     mUI->mTree->clearRecheckFile(filename);
 
  153     return mUI->mTree->mShowSeverities;
 
  158     mUI->mProgress->setValue(value);
 
  159     mUI->mProgress->setFormat(QString(
"%p% (%1)").arg(description));
 
  174     if (
mUI->mTree->addErrorItem(item)) {
 
  182     mUI->mTree->filterResults(filter);
 
  188     if (!f.open(QIODevice::Text | QIODevice::Append))
 
  191     ts <<  
'[' << QDate::currentDate().toString(
"dd.MM.yyyy") << 
"]\n";
 
  192     ts << QDateTime::currentMSecsSinceEpoch() << 
'\n';
 
  204     mUI->mTree->updateFromOldReport(filename);
 
  225             mUI->mTree->saveResults(report);
 
  228             msgBox.setText(tr(
"Failed to save the report."));
 
  229             msgBox.setIcon(QMessageBox::Critical);
 
  236         msgBox.setText(tr(
"Failed to save the report."));
 
  237         msgBox.setIcon(QMessageBox::Critical);
 
  245     QPrintDialog dialog(&printer, 
this);
 
  246     dialog.setWindowTitle(tr(
"Print Report"));
 
  247     if (dialog.exec() != QDialog::Accepted)
 
  256     QPrintPreviewDialog dialog(&printer, 
this);
 
  257     connect(&dialog, SIGNAL(paintRequested(QPrinter*)), SLOT(
print(QPrinter*)));
 
  265         msgBox.setText(tr(
"No errors found, nothing to print."));
 
  266         msgBox.setIcon(QMessageBox::Critical);
 
  272     mUI->mTree->saveResults(&report);
 
  280                                  bool showNoErrorsMessage,
 
  282                                  bool showInconclusive)
 
  284     mUI->mTree->updateSettings(showFullPath, saveFullPath, saveAllErrors, showErrorId, showInconclusive);
 
  291     mUI->mCode->setStyle(theStyle);
 
  296     mUI->mTree->setCheckDirectory(dir);
 
  301     return mUI->mTree->getCheckDirectory();
 
  314     mUI->mProgress->setVisible(
true);
 
  316     mUI->mProgress->setValue(0);
 
  317     mUI->mProgress->setFormat(tr(
"%p% (%1 of %2 files checked)").arg(0).arg(count));
 
  322     mUI->mProgress->setVisible(
false);
 
  323     mUI->mProgress->setFormat(
"%p%");
 
  334     mUI->mTree->refreshTree();
 
  340             QMessageBox msg(QMessageBox::Information,
 
  342                             tr(
"No errors found."),
 
  348         else if (!
mUI->mTree->hasVisibleResults()) {
 
  349             QString text = tr(
"Errors were found, but they are configured to be hidden.\n" \
 
  350                               "To toggle what kind of errors are shown, open view menu.");
 
  351             QMessageBox msg(QMessageBox::Information,
 
  364     return mUI->mTree->hasVisibleResults();
 
  369     return mUI->mTree->hasResults();
 
  374     mUI->mTree->saveSettings();
 
  375     QByteArray state = 
mUI->mVerticalSplitter->saveState();
 
  377     mUI->mVerticalSplitter->restoreState(state);
 
  382     mUI->retranslateUi(
this);
 
  383     mUI->mTree->translate();
 
  388     mUI->mProgress->setEnabled(
false);
 
  398         msgBox.setText(tr(
"Failed to read the report."));
 
  399         msgBox.setIcon(QMessageBox::Critical);
 
  405         msgBox.setText(tr(
"XML format version 1 is no longer supported."));
 
  406         msgBox.setIcon(QMessageBox::Critical);
 
  412     QList<ErrorItem> errors;
 
  414         errors = report.
read();
 
  417         msgBox.setText(tr(
"Failed to read the report."));
 
  418         msgBox.setIcon(QMessageBox::Critical);
 
  424         mUI->mTree->addErrorItem(item);
 
  428     if (!errors.isEmpty() && !errors[0].errorPath.isEmpty()) {
 
  429         QString relativePath = QFileInfo(filename).canonicalPath();
 
  430         if (QFileInfo::exists(relativePath + 
'/' + errors[0].errorPath[0].file))
 
  434     mUI->mTree->setCheckDirectory(dir);
 
  439     const auto *model = qobject_cast<const QStandardItemModel*>(
mUI->mTree->model());
 
  440     QStandardItem *item = model->itemFromIndex(index);
 
  444         mUI->mDetails->setText(QString());
 
  449     if (item->parent() && item->column() != 0)
 
  450         item = item->parent()->child(item->row(), 0);
 
  452     QVariantMap data = item->data().toMap();
 
  455     if (!data.contains(
"severity")) {
 
  457         mUI->mDetails->setText(QString());
 
  461     const QString message = data[
"message"].toString();
 
  462     QString formattedMsg = message;
 
  464     const QString file0 = data[
"file0"].toString();
 
  465     if (!file0.isEmpty() && 
Path::isHeader2(data[
"file"].toString().toStdString()))
 
  466         formattedMsg += QString(
"\n\n%1: %2").arg(tr(
"First included by")).arg(QDir::toNativeSeparators(file0));
 
  468     if (data[
"cwe"].toInt() > 0)
 
  469         formattedMsg.prepend(
"CWE: " + QString::number(data[
"cwe"].toInt()) + 
"\n");
 
  470     if (
mUI->mTree->showIdColumn())
 
  471         formattedMsg.prepend(tr(
"Id") + 
": " + data[
"id"].
toString() + 
"\n");
 
  472     if (data[
"incomplete"].toBool())
 
  473         formattedMsg += 
"\n" + tr(
"Bug hunting analysis is incomplete");
 
  474     mUI->mDetails->setText(formattedMsg);
 
  476     const int lineNumber = data[
"line"].toInt();
 
  478     QString filepath = data[
"file"].toString();
 
  479     if (!QFileInfo::exists(filepath) && QFileInfo::exists(
mUI->mTree->getCheckDirectory() + 
'/' + filepath))
 
  480         filepath = 
mUI->mTree->getCheckDirectory() + 
'/' + filepath;
 
  483     if (data.contains(
"symbolNames"))
 
  484         symbols = data[
"symbolNames"].toString().split(
"\n");
 
  486     if (filepath == 
mUI->mCode->getFileName()) {
 
  487         mUI->mCode->setError(lineNumber, symbols);
 
  491     QFile file(filepath);
 
  492     if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
 
  497     QTextStream in(&file);
 
  498     mUI->mCode->setError(in.readAll(), lineNumber, symbols);
 
  499     mUI->mCode->setFileName(filepath);
 
  504     mUI->mListLog->addItem(str);
 
  514     mUI->mListLog->clear();
 
  519     const QListWidgetItem * item = 
mUI->mListLog->currentItem();
 
  520     if (
nullptr != item) {
 
  521         QClipboard *clipboard = QApplication::clipboard();
 
  522         clipboard->setText(item->text());
 
  529     for (
int i=0; i < 
mUI->mListLog->count(); ++i) {
 
  530         const QListWidgetItem * item = 
mUI->mListLog->item(i);
 
  531         if (
nullptr != item) {
 
  532             logText += item->text();
 
  535     QClipboard *clipboard = QApplication::clipboard();
 
  536     clipboard->setText(logText);
 
  541     if (
mUI->mListLog->count() <= 0)
 
  544     const QPoint globalPos = 
mUI->mListLog->mapToGlobal(pos);
 
  547     contextMenu.addAction(tr(
"Clear Log"), 
this, SLOT(
logClear()));
 
  548     contextMenu.addAction(tr(
"Copy this Log entry"), 
this, SLOT(
logCopyEntry()));
 
  549     contextMenu.addAction(tr(
"Copy complete Log"), 
this, SLOT(
logCopyComplete()));
 
  551     contextMenu.exec(globalPos);
 
  557     mUI->mLabelCriticalErrors->setText(tr(
"Analysis was stopped"));
 
  558     mUI->mLabelCriticalErrors->setVisible(
true);
 
  571         QString msg = tr(
"There was a critical error with id '%1'").arg(item.
errorId);
 
  572         if (!item.
file0.isEmpty())
 
  573             msg += 
", " + tr(
"when checking %1").arg(item.
file0);
 
  575             msg += 
", " + tr(
"when checking a file");
 
  576         msg += 
". " + tr(
"Analysis was aborted.");
 
  577         mUI->mLabelCriticalErrors->setText(msg);
 
  578         mUI->mLabelCriticalErrors->setVisible(
true);
 
List of applications user has specified to open errors with.
 
A class for check statistics.
 
QStringList getTools() const
Get tools with results.
 
void clear()
Clear the statistics.
 
unsigned getCount(const QString &tool, ShowTypes::ShowType type) const
Return statistics for given type.
 
const std::set< std::string > & getActiveCheckers() const
 
void addItem(const QString &tool, ShowTypes::ShowType type)
Add new checked item to statistics.
 
void setCheckersReport(QString report)
 
void addChecker(const QString &checker)
Add checker to statistics.
 
std::string getReport(const std::string &criticalErrors) const
 
static CodeEditorStyle loadSettings(QSettings *settings)
 
A class containing error data for one error.
 
QString toString() const
Convert error item to string.
 
static bool isCriticalErrorId(const std::string &id)
 
static bool isHeader2(const std::string &path)
Is filename a header based on file extension.
 
Printable (in-memory) report.
 
const QString & getFormattedReportText() const
Returns the formatted report.
 
A base class for reports.
 
virtual bool create()
Create the report (file).
 
void treeSelectionChanged(const QModelIndex ¤t)
Signal for selection change in result tree.
 
void showHiddenResults()
Function to show results that were previous hidden with HideResult()
 
void resultsHidden(bool hidden)
Signal that results have been hidden or shown.
 
void showClangResults(bool show)
Show/hide clang-tidy/clang-analyzer errors.
 
void checkSelected(QStringList selectedItems)
Signal to perform selected files recheck.
 
void suppressIds(QStringList ids)
Suppress Ids.
 
void showResults(ShowTypes::ShowType type, bool show)
Function to show/hide certain type of errors Refreshes the tree.
 
void showCppcheckResults(bool show)
Show/hide cppcheck errors.
 
Widget to show cppcheck progressbar and result.
 
void progress(int value, const QString &description)
Slot for updating the checking progress.
 
void logClear()
Clear log messages.
 
bool isSuccess() const
Are there successful results?
 
bool hasResults() const
Do we have results from check?
 
void updateSettings(bool showFullPath, bool saveFullPath, bool saveAllErrors, bool showNoErrorsMessage, bool showErrorId, bool showInconclusive)
Update tree settings.
 
bool hasVisibleResults() const
Do we have visible results to show?
 
void showResults(ShowTypes::ShowType type, bool show)
Show/hide certain type of errors Refreshes the tree.
 
void checkSelected(QStringList selectedFilesList)
Signal to perform recheck of selected files.
 
void setCheckSettings(const Settings &settings)
Set settings used in checking.
 
void suppressIds(QStringList ids)
Suppress Ids.
 
bool mShowNoErrorsMessage
Should we show a "No errors found dialog" every time no errors were found?
 
void save(const QString &filename, Report::Type type, const QString &productName) const
Save results to a file.
 
void updateStyleSetting(QSettings *settings)
Update Code Editor Style.
 
void setCheckDirectory(const QString &dir)
Set the directory we are checking.
 
void showCppcheckResults(bool show)
Show/hide cppcheck errors.
 
QString mCriticalErrors
Critical error ids.
 
void collapseAllResults()
Collapse all results in the result list.
 
void readErrorsXml(const QString &filename)
Read errors from report XML file.
 
ResultsView(QWidget *parent=nullptr)
 
void updateDetails(const QModelIndex &index)
Update detailed message when selected item is changed.
 
void printPreview()
Slot opening a print preview dialog.
 
CheckStatistics * mStatistics
 
void checkingFinished()
Inform the view that checking finished.
 
void print()
Slot opening a print dialog to print the current report.
 
void clear(bool results)
Clear results and statistics and reset progressinfo.
 
void disableProgressbar()
 
void showHiddenResults()
Show hidden results in the result list.
 
void showClangResults(bool show)
Show/hide clang-tidy/clang-analyzer errors.
 
void resultsHidden(bool hidden)
Signal that results have been hidden or shown.
 
void error(const ErrorItem &item)
Slot for new error to be displayed.
 
Settings * mCheckSettings
 
void gotResults()
Signal to be emitted when we have results.
 
void on_mListLog_customContextMenuRequested(const QPoint &pos)
Custom context menu for Analysis Log.
 
void expandAllResults()
Expand all results in the result list.
 
bool mSuccess
Set to true when checking finish successfully.
 
void translate()
Translate this view.
 
void logCopyComplete()
Copy all log messages.
 
void log(const QString &str)
Log message.
 
void clearRecheckFile(const QString &filename)
Remove a recheck file from the results.
 
void checkingStarted(int count)
Inform the view that checking has started.
 
void saveSettings(QSettings *settings)
Save View's settings.
 
void debugError(const ErrorItem &item)
debug message
 
void updateFromOldReport(const QString &filename) const
Update results from old report (tag, sinceDate)
 
const ShowTypes & getShowTypes() const
Return Showtypes.
 
void saveStatistics(const QString &filename) const
Write statistics in file.
 
void logCopyEntry()
Copy selected log message entry.
 
void stopAnalysis()
This function should be called when analysis is stopped.
 
void filterResults(const QString &filter)
Filters the results in the result list.
 
QString getCheckDirectory()
Get the directory we are checking.
 
void handleCriticalError(const ErrorItem &item)
If provided ErrorItem is a critical error then display warning message in the resultsview.
 
void initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler)
 
This is just a container for general settings so that we don't need to pass individual values to func...
 
A class for different show types we have.
 
static ShowTypes::ShowType SeverityToShowType(Severity severity)
Convert severity string to ShowTypes value.
 
This class handles creating threadresult and starting threads.
 
XML file report version 2.
 
QList< ErrorItem > read() override
Read contents of the report file.
 
bool open() override
Open existing report file.
 
static int determineVersion(const QString &filename)
Get the XML report format version from the file.
 
std::string toString(Color c)
 
@ internal
Internal message.
 
#define SETTINGS_SHOW_NO_ERRORS
 
#define SETTINGS_MAINWND_SPLITTER_STATE