11 #include <ui_PathVariableEditor.h>
12 #include <ui_PythonRuntimeSettings.h>
14 #include <QDialogButtonBox>
15 #include <QFileDialog>
18 #include <QMessageBox>
19 #include <QPushButton>
21 #include <QStringListModel>
33 m_pathEdit(new QLineEdit),
34 m_selectPathBtn(new QPushButton),
35 m_dialogBtnBox(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel))
37 m_selectPathBtn->setText(QStringLiteral(
"..."));
38 connect(m_selectPathBtn,
39 &QPushButton::clicked,
41 &PathVariableInputDialog::handleSelectPath);
43 connect(m_dialogBtnBox, &QDialogButtonBox::accepted,
this, &QDialog::accept);
44 connect(m_dialogBtnBox, &QDialogButtonBox::rejected,
this, &QDialog::reject);
46 auto *layout =
new QHBoxLayout;
47 layout->addWidget(m_pathEdit);
48 layout->addWidget(m_selectPathBtn);
50 auto layout1 =
new QVBoxLayout;
51 layout1->addLayout(layout);
52 layout1->addWidget(m_dialogBtnBox);
59 return m_pathEdit->text();
63 void handleSelectPath()
65 QString selectedDir = QFileDialog::getExistingDirectory(
67 tr(
"Select a path to add"),
69 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
70 m_pathEdit->setText(selectedDir);
74 QLineEdit *m_pathEdit;
75 QPushButton *m_selectPathBtn;
76 QDialogButtonBox *m_dialogBtnBox;
85 : QDialog(parent), m_model(new QStringListModel), m_ui(new Ui_PathVariableEditor)
88 m_model->setStringList(values);
89 m_ui->valuesView->setModel(m_model);
90 connect(m_ui->addButton, &QPushButton::clicked,
this, &PathVariableEditor::handleAdd);
91 connect(m_ui->deleteButton, &QPushButton::clicked,
this, &PathVariableEditor::handleDelete);
96 return m_model->stringList();
105 QString
path = dlg.selectedPath();
109 int rowCount = m_model->rowCount();
110 m_model->insertRows(rowCount, 1);
111 m_model->setData(m_model->index(rowCount),
path);
117 const QModelIndex index = m_ui->valuesView->currentIndex();
118 m_model->removeRow(index.row());
122 QStringListModel *m_model;
123 Ui_PathVariableEditor *m_ui;
128 return std::make_unique<QSettings>(
129 QCoreApplication::organizationName(),
130 QCoreApplication::applicationName().append(
":PythonRuntime.Settings"));
134 : QDialog(parent), m_ui(new Ui_PythonRuntimeSettings)
137 m_ui->localEnvSettingsWidget->hide();
138 m_ui->envTypeComboBox->addItem(
"Bundled");
139 #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
140 m_ui->envTypeComboBox->addItem(
"System");
142 m_ui->envTypeComboBox->addItem(
"Local");
145 connect(
this, &QDialog::accepted,
this, &PythonRuntimeSettings::saveSettings);
146 connect(
this, &QDialog::accepted,
this, [
this]() { m_ui->informationLabel->hide(); });
147 connect(
this, &QDialog::rejected,
this, [
this]() { m_ui->informationLabel->hide(); });
148 connect(m_ui->editButton,
149 &QPushButton::clicked,
151 &PythonRuntimeSettings::handleEditPluginsPaths);
152 connect(m_ui->envTypeComboBox,
153 &QComboBox::currentTextChanged,
155 &PythonRuntimeSettings::handleEnvComboBoxChange);
156 connect(m_ui->localEnvSelectBtn,
157 &QPushButton::clicked,
159 &PythonRuntimeSettings::handleSelectLocalEnv);
161 m_ui->informationLabel->hide();
164 QString PythonRuntimeSettings::selectedEnvType()
const
166 return m_ui->envTypeComboBox->currentText();
169 QString PythonRuntimeSettings::localEnvPath()
const
171 if (selectedEnvType() ==
"Local")
173 return m_ui->localEnvPathLabel->text();
178 void PythonRuntimeSettings::restoreSettings()
181 m_pluginsPaths = settings->value(QStringLiteral(
"PluginPaths")).value<QStringList>();
183 const QString envType = settings->value(QStringLiteral(
"EnvType")).
toString();
184 int index = m_ui->envTypeComboBox->findText(envType);
185 index = (index == -1) ? 0 : index;
186 m_ui->envTypeComboBox->setCurrentIndex(index);
188 if (selectedEnvType() ==
"Local")
190 const QString localEnvPath = settings->value(QStringLiteral(
"EnvPath")).
toString();
191 m_ui->localEnvPathLabel->setText(localEnvPath);
195 void PythonRuntimeSettings::saveSettings()
const
198 settings->setValue(QStringLiteral(
"PluginPaths"),
pluginsPaths());
199 settings->setValue(QStringLiteral(
"EnvType"), selectedEnvType());
200 settings->setValue(QStringLiteral(
"EnvPath"), localEnvPath());
203 void PythonRuntimeSettings::handleEditPluginsPaths()
207 m_pluginsPaths = editor.stringList();
208 m_ui->informationLabel->show();
211 void PythonRuntimeSettings::handleEnvComboBoxChange(
const QString &envTypeName)
213 if (envTypeName ==
"Local")
215 m_ui->localEnvSettingsWidget->show();
219 m_ui->localEnvSettingsWidget->hide();
221 m_ui->informationLabel->show();
224 void PythonRuntimeSettings::handleSelectLocalEnv()
226 QString selectedDir = QFileDialog::getExistingDirectory(
this,
"Python Environment Root");
227 if (!selectedDir.isEmpty())
235 m_ui->envTypeComboBox->setCurrentIndex(0);
239 m_ui->localEnvPathLabel->setText(selectedDir);
246 return m_pluginsPaths;
251 if (selectedEnvType() ==
"System")
257 else if (selectedEnvType() ==
"Bundled")
263 else if (selectedEnvType() ==
"Local")
278 return m_ui->envTypeComboBox->currentIndex() == 0;
static std::unique_ptr< QSettings > LoadOurSettings()
#define SETTINGS_ICON_PATH
PathVariableEditor(const QStringList &values, QWidget *parent=nullptr)
QStringList stringList() const
bool validateAndDisplayErrors(QWidget *parent=nullptr) const
void initFromLocation(const QString &prefix)
bool isDefaultPythonEnv() const
PythonRuntimeSettings(QWidget *parent=nullptr)
QStringList pluginsPaths() const
PythonConfig pythonEnvConfig() const
static const std::string path
std::string toString(T x)