Changeset View
Changeset View
Standalone View
Standalone View
shell/settings/environmentwidget.cpp
Show All 19 Lines | |||||
20 | Boston, MA 02110-1301, USA. | 20 | Boston, MA 02110-1301, USA. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "environmentwidget.h" | 23 | #include "environmentwidget.h" | ||
24 | 24 | | |||
25 | #include <QDialog> | 25 | #include <QDialog> | ||
26 | #include <QDialogButtonBox> | 26 | #include <QDialogButtonBox> | ||
27 | #include <QHeaderView> | 27 | #include <QHeaderView> | ||
28 | #include <QPointer> | ||||
28 | #include <QPushButton> | 29 | #include <QPushButton> | ||
29 | #include <QSortFilterProxyModel> | 30 | #include <QSortFilterProxyModel> | ||
30 | #include <QLineEdit> | 31 | #include <QLineEdit> | ||
31 | #include <QPlainTextEdit> | 32 | #include <QPlainTextEdit> | ||
32 | #include <QVBoxLayout> | 33 | #include <QVBoxLayout> | ||
33 | #include <QHBoxLayout> | 34 | #include <QHBoxLayout> | ||
34 | #include <QValidator> | 35 | #include <QValidator> | ||
35 | 36 | | |||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | |||||
171 | 172 | | |||
172 | void EnvironmentWidget::defaults( KConfig* config ) | 173 | void EnvironmentWidget::defaults( KConfig* config ) | ||
173 | { | 174 | { | ||
174 | loadSettings( config ); | 175 | loadSettings( config ); | ||
175 | } | 176 | } | ||
176 | 177 | | |||
177 | QString EnvironmentWidget::askNewProfileName(const QString& defaultName) | 178 | QString EnvironmentWidget::askNewProfileName(const QString& defaultName) | ||
178 | { | 179 | { | ||
179 | QDialog dialog(this); | 180 | QPointer<QDialog> dialog = new QDialog(this); | ||
180 | dialog.setWindowTitle(i18n("Enter Name of New Environment Profile")); | 181 | dialog->setWindowTitle(i18n("Enter Name of New Environment Profile")); | ||
181 | 182 | | |||
182 | QVBoxLayout *layout = new QVBoxLayout(&dialog); | 183 | QVBoxLayout *layout = new QVBoxLayout(dialog); | ||
183 | 184 | | |||
184 | auto editLayout = new QHBoxLayout; | 185 | auto editLayout = new QHBoxLayout; | ||
185 | 186 | | |||
186 | auto label = new QLabel(i18n("Name:")); | 187 | auto label = new QLabel(i18n("Name:")); | ||
187 | editLayout->addWidget(label); | 188 | editLayout->addWidget(label); | ||
188 | auto edit = new QLineEdit; | 189 | auto edit = new QLineEdit; | ||
189 | editLayout->addWidget(edit); | 190 | editLayout->addWidget(edit); | ||
190 | layout->addLayout(editLayout); | 191 | layout->addLayout(editLayout); | ||
191 | 192 | | |||
192 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | 193 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||
193 | auto okButton = buttonBox->button(QDialogButtonBox::Ok); | 194 | auto okButton = buttonBox->button(QDialogButtonBox::Ok); | ||
194 | okButton->setEnabled(false); | 195 | okButton->setEnabled(false); | ||
195 | okButton->setDefault(true); | 196 | okButton->setDefault(true); | ||
196 | dialog.connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); | 197 | dialog->connect(buttonBox, &QDialogButtonBox::accepted, dialog, &QDialog::accept); | ||
197 | dialog.connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); | 198 | dialog->connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject); | ||
198 | layout->addWidget(buttonBox); | 199 | layout->addWidget(buttonBox); | ||
199 | 200 | | |||
200 | auto validator = new ProfileNameValidator(m_environmentProfileListModel, &dialog); | 201 | auto validator = new ProfileNameValidator(m_environmentProfileListModel, dialog); | ||
201 | connect(edit, &QLineEdit::textChanged, validator, [validator, okButton](const QString& text) { | 202 | connect(edit, &QLineEdit::textChanged, validator, [validator, okButton](const QString& text) { | ||
202 | int pos; | 203 | int pos; | ||
203 | QString t(text); | 204 | QString t(text); | ||
204 | const bool isValidProfileName = (validator->validate(t, pos) == QValidator::Acceptable); | 205 | const bool isValidProfileName = (validator->validate(t, pos) == QValidator::Acceptable); | ||
205 | okButton->setEnabled(isValidProfileName); | 206 | okButton->setEnabled(isValidProfileName); | ||
206 | }); | 207 | }); | ||
207 | 208 | | |||
208 | edit->setText(defaultName); | 209 | edit->setText(defaultName); | ||
209 | edit->selectAll(); | 210 | edit->selectAll(); | ||
210 | 211 | | |||
211 | if (dialog.exec() != QDialog::Accepted) { | 212 | if (dialog->exec() != QDialog::Accepted) { | ||
213 | delete dialog; | ||||
212 | return {}; | 214 | return {}; | ||
213 | } | 215 | } | ||
216 | delete dialog; | ||||
214 | 217 | | |||
215 | return edit->text(); | 218 | return edit->text(); | ||
216 | } | 219 | } | ||
217 | 220 | | |||
218 | void EnvironmentWidget::removeSelectedVariables() | 221 | void EnvironmentWidget::removeSelectedVariables() | ||
219 | { | 222 | { | ||
220 | const auto selectedRows = ui.variableTable->selectionModel()->selectedRows(); | 223 | const auto selectedRows = ui.variableTable->selectionModel()->selectedRows(); | ||
221 | if (selectedRows.isEmpty()) { | 224 | if (selectedRows.isEmpty()) { | ||
Show All 12 Lines | |||||
234 | void EnvironmentWidget::onVariableInserted(int column, const QVariant& value) | 237 | void EnvironmentWidget::onVariableInserted(int column, const QVariant& value) | ||
235 | { | 238 | { | ||
236 | Q_UNUSED(column); | 239 | Q_UNUSED(column); | ||
237 | m_environmentProfileModel->addVariable(value.toString(), QString()); | 240 | m_environmentProfileModel->addVariable(value.toString(), QString()); | ||
238 | } | 241 | } | ||
239 | 242 | | |||
240 | void EnvironmentWidget::batchModeEditButtonClicked() | 243 | void EnvironmentWidget::batchModeEditButtonClicked() | ||
241 | { | 244 | { | ||
242 | QDialog dialog(this); | 245 | QPointer<QDialog> dialog = new QDialog(this); | ||
243 | dialog.setWindowTitle( i18n( "Batch Edit Mode" ) ); | 246 | dialog->setWindowTitle( i18n( "Batch Edit Mode" ) ); | ||
244 | 247 | | |||
245 | QVBoxLayout *layout = new QVBoxLayout(&dialog); | 248 | QVBoxLayout *layout = new QVBoxLayout(dialog); | ||
246 | 249 | | |||
247 | auto edit = new QPlainTextEdit; | 250 | auto edit = new QPlainTextEdit; | ||
248 | edit->setPlaceholderText(QStringLiteral("VARIABLE1=VALUE1\nVARIABLE2=VALUE2")); | 251 | edit->setPlaceholderText(QStringLiteral("VARIABLE1=VALUE1\nVARIABLE2=VALUE2")); | ||
249 | QString text; | 252 | QString text; | ||
250 | for (int i = 0; i < m_proxyModel->rowCount(); ++i) { | 253 | for (int i = 0; i < m_proxyModel->rowCount(); ++i) { | ||
251 | const auto variable = m_proxyModel->index(i, EnvironmentProfileModel::VariableColumn).data().toString(); | 254 | const auto variable = m_proxyModel->index(i, EnvironmentProfileModel::VariableColumn).data().toString(); | ||
252 | const auto value = m_proxyModel->index(i, EnvironmentProfileModel::ValueColumn).data().toString(); | 255 | const auto value = m_proxyModel->index(i, EnvironmentProfileModel::ValueColumn).data().toString(); | ||
253 | text.append(QStringLiteral("%1=%2\n").arg(variable, value)); | 256 | text.append(QStringLiteral("%1=%2\n").arg(variable, value)); | ||
254 | } | 257 | } | ||
255 | edit->setPlainText(text); | 258 | edit->setPlainText(text); | ||
256 | layout->addWidget( edit ); | 259 | layout->addWidget( edit ); | ||
257 | 260 | | |||
258 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | 261 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); | ||
259 | auto okButton = buttonBox->button(QDialogButtonBox::Ok); | 262 | auto okButton = buttonBox->button(QDialogButtonBox::Ok); | ||
260 | okButton->setDefault(true); | 263 | okButton->setDefault(true); | ||
261 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | 264 | okButton->setShortcut(Qt::CTRL | Qt::Key_Return); | ||
262 | dialog.connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); | 265 | dialog->connect(buttonBox, &QDialogButtonBox::accepted, dialog, &QDialog::accept); | ||
263 | dialog.connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); | 266 | dialog->connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject); | ||
264 | layout->addWidget(buttonBox); | 267 | layout->addWidget(buttonBox); | ||
265 | 268 | | |||
266 | dialog.resize(600, 400); | 269 | dialog->resize(600, 400); | ||
267 | 270 | | |||
268 | if ( dialog.exec() != QDialog::Accepted ) { | 271 | if ( dialog->exec() != QDialog::Accepted ) { | ||
272 | delete dialog; | ||||
269 | return; | 273 | return; | ||
270 | } | 274 | } | ||
275 | delete dialog; | ||||
271 | 276 | | |||
272 | m_environmentProfileModel->setVariablesFromString(edit->toPlainText()); | 277 | m_environmentProfileModel->setVariablesFromString(edit->toPlainText()); | ||
273 | } | 278 | } | ||
274 | 279 | | |||
275 | void EnvironmentWidget::addProfile() | 280 | void EnvironmentWidget::addProfile() | ||
276 | { | 281 | { | ||
277 | const auto profileName = askNewProfileName(QString()); | 282 | const auto profileName = askNewProfileName(QString()); | ||
278 | if (profileName.isEmpty()) { | 283 | if (profileName.isEmpty()) { | ||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |