diff --git a/gui/newsuppressiondialog.cpp b/gui/newsuppressiondialog.cpp index 7a25e9e5e..ccce6bc8b 100644 --- a/gui/newsuppressiondialog.cpp +++ b/gui/newsuppressiondialog.cpp @@ -45,3 +45,12 @@ Suppressions::Suppression NewSuppressionDialog::getSuppression() const ret.symbolName = mUI->mTextSymbolName->text().toStdString(); return ret; } + +void NewSuppressionDialog::setSuppression(const Suppressions::Suppression &suppression) +{ + setWindowTitle(tr("Edit suppression")); + mUI->mComboErrorId->setCurrentText(QString::fromStdString(suppression.errorId)); + mUI->mTextFileName->setText(QString::fromStdString(suppression.fileName)); + mUI->mTextLineNumber->setText(suppression.lineNumber > 0 ? QString::number(suppression.lineNumber) : QString()); + mUI->mTextSymbolName->setText(QString::fromStdString(suppression.symbolName)); +} diff --git a/gui/newsuppressiondialog.h b/gui/newsuppressiondialog.h index a318d9fc5..656cb4122 100644 --- a/gui/newsuppressiondialog.h +++ b/gui/newsuppressiondialog.h @@ -17,8 +17,19 @@ public: ~NewSuppressionDialog(); NewSuppressionDialog &operator=(const NewSuppressionDialog &) = delete; + /** + * @brief Translate the user input in the GUI into a suppression + * @return Cppcheck suppression + */ Suppressions::Suppression getSuppression() const; + /** + * @brief Update the GUI so it corresponds with the given + * Cppcheck suppression + * @param suppression Cppcheck suppression + */ + void setSuppression(const Suppressions::Suppression &suppression); + private: Ui::NewSuppressionDialog *mUI; }; diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index bb6311b82..769023dbe 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -151,6 +151,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent) connect(mUI.mBtnIncludeDown, &QPushButton::clicked, this, &ProjectFileDialog::moveIncludePathDown); connect(mUI.mBtnAddSuppression, &QPushButton::clicked, this, &ProjectFileDialog::addSuppression); connect(mUI.mBtnRemoveSuppression, &QPushButton::clicked, this, &ProjectFileDialog::removeSuppression); + connect(mUI.mListSuppressions, &QListWidget::doubleClicked, this, &ProjectFileDialog::editSuppression); connect(mUI.mBtnBrowseMisraFile, &QPushButton::clicked, this, &ProjectFileDialog::browseMisraFile); loadFromProjectFile(projectFile); @@ -650,16 +651,37 @@ void ProjectFileDialog::removeSuppression() { const int row = mUI.mListSuppressions->currentRow(); QListWidgetItem *item = mUI.mListSuppressions->takeItem(row); - const std::string s = item->text().toStdString(); + int suppressionIndex = getSuppressionIndex(item->text()); + if (suppressionIndex >= 0) + mSuppressions.removeAt(suppressionIndex); delete item; - for (int i = 0; i < mSuppressions.size(); ++i) { - if (mSuppressions[i].getText() == s) { - mSuppressions.removeAt(i); - break; +} + +void ProjectFileDialog::editSuppression(const QModelIndex &) +{ + const int row = mUI.mListSuppressions->currentRow(); + QListWidgetItem *item = mUI.mListSuppressions->item(row); + int suppressionIndex = getSuppressionIndex(item->text()); + if (suppressionIndex >= 0) { // TODO what if suppression is not found? + NewSuppressionDialog dlg; + dlg.setSuppression(mSuppressions[suppressionIndex]); + if (dlg.exec() == QDialog::Accepted) { + mSuppressions[suppressionIndex] = dlg.getSuppression(); + setSuppressions(mSuppressions); } } } +int ProjectFileDialog::getSuppressionIndex(const QString shortText) const +{ + const std::string s = shortText.toStdString(); + for (int i = 0; i < mSuppressions.size(); ++i) { + if (mSuppressions[i].getText() == s) + return i; + } + return -1; +} + void ProjectFileDialog::browseMisraFile() { const QString fileName = QFileDialog::getOpenFileName(this, tr("Select MISRA rule texts file"), QDir::homePath(), tr("Misra rule texts file (%1)").arg("*.txt")); diff --git a/gui/projectfiledialog.h b/gui/projectfiledialog.h index 0cdf76bdd..d717ec39d 100644 --- a/gui/projectfiledialog.h +++ b/gui/projectfiledialog.h @@ -234,6 +234,11 @@ protected slots: */ void removeSuppression(); + /** + * @brief Edit suppression (double clicking on suppression) + */ + void editSuppression(const QModelIndex &index); + /** * @brief Browse for misra file */ @@ -269,6 +274,14 @@ protected: */ void addExcludePath(const QString &path); + /** + * @brief Get mSuppressions index that match the + * given short text + * @param shortText text as generated by Suppression::getText + * @return index of matching suppression, -1 if not found + */ + int getSuppressionIndex(const QString shortText) const; + private: Ui::ProjectFile mUI;