Merge pull request #2799 from jubnzv/gui-add-python-path-validation

gui: Add validation for Python path
This commit is contained in:
Daniel Marjamäki 2020-09-13 12:43:34 +02:00 committed by GitHub
commit ebb5ff0e19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 11 deletions

View File

@ -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>

View File

@ -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;

View File

@ -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
*