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();
|
ret.symbolName = mUI->mTextSymbolName->text().toStdString();
|
||||||
return ret;
|
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();
|
||||||
NewSuppressionDialog &operator=(const NewSuppressionDialog &) = delete;
|
NewSuppressionDialog &operator=(const NewSuppressionDialog &) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Translate the user input in the GUI into a suppression
|
||||||
|
* @return Cppcheck suppression
|
||||||
|
*/
|
||||||
Suppressions::Suppression getSuppression() const;
|
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:
|
private:
|
||||||
Ui::NewSuppressionDialog *mUI;
|
Ui::NewSuppressionDialog *mUI;
|
||||||
};
|
};
|
||||||
|
|
|
@ -151,6 +151,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
|
||||||
connect(mUI.mBtnIncludeDown, &QPushButton::clicked, this, &ProjectFileDialog::moveIncludePathDown);
|
connect(mUI.mBtnIncludeDown, &QPushButton::clicked, this, &ProjectFileDialog::moveIncludePathDown);
|
||||||
connect(mUI.mBtnAddSuppression, &QPushButton::clicked, this, &ProjectFileDialog::addSuppression);
|
connect(mUI.mBtnAddSuppression, &QPushButton::clicked, this, &ProjectFileDialog::addSuppression);
|
||||||
connect(mUI.mBtnRemoveSuppression, &QPushButton::clicked, this, &ProjectFileDialog::removeSuppression);
|
connect(mUI.mBtnRemoveSuppression, &QPushButton::clicked, this, &ProjectFileDialog::removeSuppression);
|
||||||
|
connect(mUI.mListSuppressions, &QListWidget::doubleClicked, this, &ProjectFileDialog::editSuppression);
|
||||||
connect(mUI.mBtnBrowseMisraFile, &QPushButton::clicked, this, &ProjectFileDialog::browseMisraFile);
|
connect(mUI.mBtnBrowseMisraFile, &QPushButton::clicked, this, &ProjectFileDialog::browseMisraFile);
|
||||||
|
|
||||||
loadFromProjectFile(projectFile);
|
loadFromProjectFile(projectFile);
|
||||||
|
@ -650,16 +651,37 @@ void ProjectFileDialog::removeSuppression()
|
||||||
{
|
{
|
||||||
const int row = mUI.mListSuppressions->currentRow();
|
const int row = mUI.mListSuppressions->currentRow();
|
||||||
QListWidgetItem *item = mUI.mListSuppressions->takeItem(row);
|
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;
|
delete item;
|
||||||
for (int i = 0; i < mSuppressions.size(); ++i) {
|
}
|
||||||
if (mSuppressions[i].getText() == s) {
|
|
||||||
mSuppressions.removeAt(i);
|
void ProjectFileDialog::editSuppression(const QModelIndex &)
|
||||||
break;
|
{
|
||||||
|
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()
|
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"));
|
const QString fileName = QFileDialog::getOpenFileName(this, tr("Select MISRA rule texts file"), QDir::homePath(), tr("Misra rule texts file (%1)").arg("*.txt"));
|
||||||
|
|
|
@ -234,6 +234,11 @@ protected slots:
|
||||||
*/
|
*/
|
||||||
void removeSuppression();
|
void removeSuppression();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Edit suppression (double clicking on suppression)
|
||||||
|
*/
|
||||||
|
void editSuppression(const QModelIndex &index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Browse for misra file
|
* @brief Browse for misra file
|
||||||
*/
|
*/
|
||||||
|
@ -269,6 +274,14 @@ protected:
|
||||||
*/
|
*/
|
||||||
void addExcludePath(const QString &path);
|
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:
|
private:
|
||||||
Ui::ProjectFile mUI;
|
Ui::ProjectFile mUI;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue