GUI: Re-enable misra interface in open source GUI

This commit is contained in:
Daniel Marjamäki 2022-12-31 16:08:23 +01:00
parent 0c95971c54
commit e70afda95a
8 changed files with 123 additions and 6 deletions

View File

@ -80,6 +80,7 @@
#define SETTINGS_LANGUAGE "Application language"
#define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths"
#define SETTINGS_PYTHON_PATH "Python path"
#define SETTINGS_MISRA_FILE "MISRA C 2012 file"
#define SETTINGS_CLANG_PATH "Clang path"
#define SETTINGS_VS_INCLUDE_PATHS "VS include paths"
#define SETTINGS_INLINE_SUPPRESSIONS "Inline suppressions"

View File

@ -971,6 +971,15 @@ Settings MainWindow::getCppcheckSettings()
json += "{ \"script\":\"" + addonFilePath + "\"";
if (!pythonCmd.isEmpty())
json += ", \"python\":\"" + pythonCmd + "\"";
const QString misraFile = fromNativePath(mSettings->value(SETTINGS_MISRA_FILE).toString());
if (addon == "misra" && !misraFile.isEmpty()) {
QString arg;
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
arg = "--misra-pdf=" + misraFile;
else
arg = "--rule-texts=" + misraFile;
json += ", \"args\":[\"" + arg + "\"]";
}
json += " }";
result.addons.emplace(json.toStdString());
}

View File

@ -779,7 +779,7 @@
<item>
<widget class="QGroupBox" name="groupBox_12">
<property name="title">
<string>Coding standards (Premium)</string>
<string>Coding standards</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
<item>
@ -789,6 +789,31 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="mLayoutMisraRuleTexts">
<item>
<widget class="QLabel" name="mLabelMisraFile">
<property name="text">
<string>MISRA rule texts</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditMisraFile">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copy/paste the text from Appendix A &amp;quot;Summary of guidelines&amp;quot; from the MISRA C 2012 pdf to a text file.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnBrowseMisraFile">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="mMisraCpp2008">
<property name="text">

View File

@ -225,6 +225,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
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);
connect(mUI->mChkAllVsConfigs, &QCheckBox::clicked, this, &ProjectFileDialog::checkAllVSConfigs);
loadFromProjectFile(projectFile);
}
@ -349,11 +350,19 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
const QString dataDir = getDataDir();
updateAddonCheckBox(mUI->mAddonThreadSafety, projectFile, dataDir, "threadsafety");
updateAddonCheckBox(mUI->mAddonY2038, projectFile, dataDir, "y2038");
updateAddonCheckBox(mUI->mMisraC2012, projectFile, dataDir, ADDON_MISRA);
const QString &misraFile = settings.value(SETTINGS_MISRA_FILE, QString()).toString();
mUI->mEditMisraFile->setText(misraFile);
if (mPremium) {
mUI->mLabelMisraFile->setVisible(false);
mUI->mEditMisraFile->setVisible(false);
mUI->mBtnBrowseMisraFile->setVisible(false);
} else if (!mUI->mMisraC2012->isEnabled()) {
mUI->mEditMisraFile->setEnabled(false);
mUI->mBtnBrowseMisraFile->setEnabled(false);
}
if (mPremium)
updateAddonCheckBox(mUI->mMisraC2012, projectFile, dataDir, ADDON_MISRA);
else
mUI->mMisraC2012->setChecked(false);
mUI->mCertC2016->setChecked(mPremium && projectFile->getCodingStandards().contains(CODING_STANDARD_CERT_C));
mUI->mCertCpp2016->setChecked(mPremium && projectFile->getCodingStandards().contains(CODING_STANDARD_CERT_CPP));
mUI->mMisraCpp2008->setChecked(mPremium && projectFile->getCodingStandards().contains(CODING_STANDARD_MISRA_CPP_2008));
@ -364,7 +373,6 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
else
mUI->mEditCertIntPrecision->setText(QString::number(projectFile->getCertIntPrecision()));
mUI->mMisraC2012->setEnabled(mPremium);
mUI->mMisraCpp2008->setEnabled(mPremium);
mUI->mCertC2016->setEnabled(mPremium);
mUI->mCertCpp2016->setEnabled(mPremium);
@ -899,3 +907,20 @@ int ProjectFileDialog::getSuppressionIndex(const QString &shortText) const
}
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"));
if (!fileName.isEmpty()) {
QSettings settings;
mUI->mEditMisraFile->setText(fileName);
settings.setValue(SETTINGS_MISRA_FILE, fileName);
mUI->mMisraC2012->setText("MISRA C 2012");
mUI->mMisraC2012->setEnabled(true);
updateAddonCheckBox(mUI->mMisraC2012, nullptr, getDataDir(), ADDON_MISRA);
}
}

View File

@ -267,6 +267,11 @@ protected slots:
*/
void editSuppression(const QModelIndex &index);
/**
* @brief Browse for misra file
*/
void browseMisraFile();
/**
* @brief Check for all VS configurations
*/

View File

@ -324,6 +324,40 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="mGroupBoxMisra">
<property name="title">
<string>MISRA addon</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>MISRA rule texts file</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditMisraFile">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copy/paste the text from Appendix A &amp;quot;Summary of guidelines&amp;quot; from the MISRA C 2012 pdf to a text file.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnBrowseMisraFile">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">

View File

@ -65,6 +65,9 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
mUI->mCheckForUpdates->setCheckState(boolToCheckState(settings.value(SETTINGS_CHECK_FOR_UPDATES, false).toBool()));
mUI->mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString());
validateEditPythonPath();
if (premium)
mUI->mGroupBoxMisra->setVisible(false);
mUI->mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString());
#ifdef Q_OS_WIN
//mUI->mTabClang->setVisible(true);
@ -94,6 +97,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
this, SLOT(editApplication()));
connect(mUI->mBtnBrowsePythonPath, &QPushButton::clicked, this, &SettingsDialog::browsePythonPath);
connect(mUI->mBtnBrowseMisraFile, &QPushButton::clicked, this, &SettingsDialog::browseMisraFile);
connect(mUI->mBtnEditTheme, SIGNAL(clicked()), this, SLOT(editCodeEditorStyle()));
connect(mUI->mThemeSystem, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
connect(mUI->mThemeDark, SIGNAL(released()), this, SLOT(setCodeEditorStyleDefault()));
@ -185,6 +189,8 @@ void SettingsDialog::saveSettingValues() const
saveCheckboxValue(&settings, mUI->mShowErrorId, SETTINGS_SHOW_ERROR_ID);
saveCheckboxValue(&settings, mUI->mCheckForUpdates, SETTINGS_CHECK_FOR_UPDATES);
settings.setValue(SETTINGS_PYTHON_PATH, mUI->mEditPythonPath->text());
if (!mPremium)
settings.setValue(SETTINGS_MISRA_FILE, mUI->mEditMisraFile->text());
#ifdef Q_OS_WIN
settings.setValue(SETTINGS_CLANG_PATH, mUI->mEditClangPath->text());
@ -350,6 +356,13 @@ void SettingsDialog::browsePythonPath()
mUI->mEditPythonPath->setText(fileName);
}
void SettingsDialog::browseMisraFile()
{
const QString fileName = QFileDialog::getOpenFileName(this, tr("Select MISRA File"), QDir::homePath(), "Misra File (*.pdf *.txt)");
if (!fileName.isEmpty())
mUI->mEditMisraFile->setText(fileName);
}
// Slot to set default light style
void SettingsDialog::setCodeEditorStyleDefault()
{

View File

@ -141,6 +141,11 @@ protected slots:
/** @brief Slot for browsing for the clang binary */
void browseClangPath();
/**
* @brief Browse for MISRA file
*/
void browseMisraFile();
/**
* @brief Set Code Editor Style to Default
*/