gui: Add validation for Python path
This commit adds to cppcheck-gui validation for the path to the Python interpreter entered by the user.
This commit is contained in:
parent
3880412c46
commit
a3a2e574a5
|
@ -292,6 +292,8 @@
|
|||
<property name="title">
|
||||
<string>Python binary (leave this empty to use python in the PATH)</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_13">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mEditPythonPath"/>
|
||||
|
@ -304,6 +306,15 @@
|
|||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="mPythonPathWarning">
|
||||
<property name="text">
|
||||
<string></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QListWidgetItem>
|
||||
#include <QSettings>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QThread>
|
||||
#include "settingsdialog.h"
|
||||
#include "applicationdialog.h"
|
||||
|
@ -41,6 +42,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
|
|||
mTranslator(translator)
|
||||
{
|
||||
mUI.setupUi(this);
|
||||
mUI.mPythonPathWarning->setStyleSheet("color: red");
|
||||
QSettings settings;
|
||||
mTempApplications->copy(list);
|
||||
|
||||
|
@ -56,6 +58,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
|
|||
mUI.mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool()));
|
||||
mUI.mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool()));
|
||||
mUI.mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString());
|
||||
validateEditPythonPath();
|
||||
mUI.mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString());
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -69,6 +72,9 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
|
|||
mCurrentStyle = new CodeEditorStyle(CodeEditorStyle::loadSettings(&settings));
|
||||
manageStyleControls();
|
||||
|
||||
connect(mUI.mEditPythonPath, SIGNAL(textEdited(const QString &)),
|
||||
this, SLOT(validateEditPythonPath()));
|
||||
|
||||
connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok);
|
||||
connect(mUI.mButtons, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
|
||||
connect(mUI.mBtnAddApplication, SIGNAL(clicked()),
|
||||
|
@ -194,6 +200,28 @@ void SettingsDialog::saveCheckboxValue(QSettings *settings, QCheckBox *box,
|
|||
settings->setValue(name, checkStateToBool(box->checkState()));
|
||||
}
|
||||
|
||||
void SettingsDialog::validateEditPythonPath()
|
||||
{
|
||||
const auto pythonPath = mUI.mEditPythonPath->text();
|
||||
if (pythonPath.isEmpty()) {
|
||||
mUI.mEditPythonPath->setStyleSheet("");
|
||||
mUI.mPythonPathWarning->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
QFileInfo pythonPathInfo(pythonPath);
|
||||
if (!pythonPathInfo.exists() ||
|
||||
!pythonPathInfo.isFile() ||
|
||||
!pythonPathInfo.isExecutable()) {
|
||||
mUI.mEditPythonPath->setStyleSheet("QLineEdit {border: 1px solid red}");
|
||||
mUI.mPythonPathWarning->setText(tr("The executable file \"%1\" is not available").arg(pythonPath));
|
||||
mUI.mPythonPathWarning->show();
|
||||
} else {
|
||||
mUI.mEditPythonPath->setStyleSheet("");
|
||||
mUI.mPythonPathWarning->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::addApplication()
|
||||
{
|
||||
Application app;
|
||||
|
|
|
@ -103,6 +103,9 @@ protected slots:
|
|||
*/
|
||||
void ok();
|
||||
|
||||
/** @brief Slot for validating input value in @c editPythonPath */
|
||||
void validateEditPythonPath();
|
||||
|
||||
/**
|
||||
* @brief Slot for adding a new application to the list
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue