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">
|
<property name="title">
|
||||||
<string>Python binary (leave this empty to use python in the PATH)</string>
|
<string>Python binary (leave this empty to use python in the PATH)</string>
|
||||||
</property>
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_13">
|
||||||
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="mEditPythonPath"/>
|
<widget class="QLineEdit" name="mEditPythonPath"/>
|
||||||
|
@ -304,6 +306,15 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="mPythonPathWarning">
|
||||||
|
<property name="text">
|
||||||
|
<string></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include "settingsdialog.h"
|
#include "settingsdialog.h"
|
||||||
#include "applicationdialog.h"
|
#include "applicationdialog.h"
|
||||||
|
@ -41,6 +42,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
|
||||||
mTranslator(translator)
|
mTranslator(translator)
|
||||||
{
|
{
|
||||||
mUI.setupUi(this);
|
mUI.setupUi(this);
|
||||||
|
mUI.mPythonPathWarning->setStyleSheet("color: red");
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
mTempApplications->copy(list);
|
mTempApplications->copy(list);
|
||||||
|
|
||||||
|
@ -56,6 +58,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
|
||||||
mUI.mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool()));
|
mUI.mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool()));
|
||||||
mUI.mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool()));
|
mUI.mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool()));
|
||||||
mUI.mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString());
|
mUI.mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString());
|
||||||
|
validateEditPythonPath();
|
||||||
mUI.mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString());
|
mUI.mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString());
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -69,6 +72,9 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
|
||||||
mCurrentStyle = new CodeEditorStyle(CodeEditorStyle::loadSettings(&settings));
|
mCurrentStyle = new CodeEditorStyle(CodeEditorStyle::loadSettings(&settings));
|
||||||
manageStyleControls();
|
manageStyleControls();
|
||||||
|
|
||||||
|
connect(mUI.mEditPythonPath, SIGNAL(textEdited(const QString &)),
|
||||||
|
this, SLOT(validateEditPythonPath()));
|
||||||
|
|
||||||
connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok);
|
connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok);
|
||||||
connect(mUI.mButtons, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
|
connect(mUI.mButtons, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
|
||||||
connect(mUI.mBtnAddApplication, SIGNAL(clicked()),
|
connect(mUI.mBtnAddApplication, SIGNAL(clicked()),
|
||||||
|
@ -194,6 +200,28 @@ void SettingsDialog::saveCheckboxValue(QSettings *settings, QCheckBox *box,
|
||||||
settings->setValue(name, checkStateToBool(box->checkState()));
|
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()
|
void SettingsDialog::addApplication()
|
||||||
{
|
{
|
||||||
Application app;
|
Application app;
|
||||||
|
|
|
@ -103,6 +103,9 @@ protected slots:
|
||||||
*/
|
*/
|
||||||
void ok();
|
void ok();
|
||||||
|
|
||||||
|
/** @brief Slot for validating input value in @c editPythonPath */
|
||||||
|
void validateEditPythonPath();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Slot for adding a new application to the list
|
* @brief Slot for adding a new application to the list
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue