GUI: Edit existing suppression in the project file dialog
This commit is contained in:
parent
f2e7071922
commit
9e3b392ec6
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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,14 +651,35 @@ 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;
|
||||
}
|
||||
|
||||
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) {
|
||||
mSuppressions.removeAt(i);
|
||||
break;
|
||||
}
|
||||
if (mSuppressions[i].getText() == s)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ProjectFileDialog::browseMisraFile()
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue