Cppcheck
newsuppressiondialog.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "newsuppressiondialog.h"
20 
21 #include "cppcheck.h"
22 #include "errorlogger.h"
23 #include "suppressions.h"
24 
25 #include "ui_newsuppressiondialog.h"
26 
27 #include <string>
28 
29 #include <QComboBox>
30 #include <QLineEdit>
31 #include <QStringList>
32 
33 class QWidget;
34 enum class Color;
35 
37  QDialog(parent),
38  mUI(new Ui::NewSuppressionDialog)
39 {
40  mUI->setupUi(this);
41 
42  class QErrorLogger : public ErrorLogger {
43  public:
44  void reportOut(const std::string & /*outmsg*/, Color /*c*/) override {}
45  void reportErr(const ErrorMessage &msg) override {
46  errorIds << QString::fromStdString(msg.id);
47  }
48  QStringList errorIds;
49  };
50 
51  QErrorLogger errorLogger;
52  CppCheck::getErrorMessages(errorLogger);
53  errorLogger.errorIds.sort();
54 
55  mUI->mComboErrorId->addItems(errorLogger.errorIds);
56  mUI->mComboErrorId->setCurrentIndex(-1);
57  mUI->mComboErrorId->setCurrentText("");
58 }
59 
61 {
62  delete mUI;
63 }
64 
66 {
68  ret.errorId = mUI->mComboErrorId->currentText().toStdString();
69  if (ret.errorId.empty())
70  ret.errorId = "*";
71  ret.fileName = mUI->mTextFileName->text().toStdString();
72  if (!mUI->mTextLineNumber->text().isEmpty())
73  ret.lineNumber = mUI->mTextLineNumber->text().toInt();
74  ret.symbolName = mUI->mTextSymbolName->text().toStdString();
75  return ret;
76 }
77 
79 {
80  setWindowTitle(tr("Edit suppression"));
81  mUI->mComboErrorId->setCurrentText(QString::fromStdString(suppression.errorId));
82  mUI->mTextFileName->setText(QString::fromStdString(suppression.fileName));
83  mUI->mTextLineNumber->setText(suppression.lineNumber > 0 ? QString::number(suppression.lineNumber) : QString());
84  mUI->mTextSymbolName->setText(QString::fromStdString(suppression.symbolName));
85 }
static void getErrorMessages(ErrorLogger &errorlogger)
Call all "getErrorMessages" in all registered Check classes.
Definition: cppcheck.cpp:1633
This is an interface, which the class responsible of error logging should implement.
Definition: errorlogger.h:214
Wrapper for error messages, provided by reportErr()
Definition: errorlogger.h:48
std::string id
Definition: errorlogger.h:165
SuppressionList::Suppression getSuppression() const
Translate the user input in the GUI into a suppression.
void setSuppression(const SuppressionList::Suppression &suppression)
Update the GUI so it corresponds with the given Cppcheck suppression.
Ui::NewSuppressionDialog * mUI
NewSuppressionDialog(QWidget *parent=nullptr)
Color
Definition: color.h:27
Definition: aboutdialog.h:27