[education/rkward] rkward/settings: Add support for QLineEdit to RKConfigValue

Thomas Friedrichsmeier null at kde.org
Mon Jul 22 22:34:28 BST 2024


Git commit 8d245fda5b950d283d43351c8ae326717a6aa784 by Thomas Friedrichsmeier.
Committed on 22/07/2024 at 21:34.
Pushed by tfry into branch 'master'.

Add support for QLineEdit to RKConfigValue

M  +10   -0    rkward/settings/rksettingsmodule.cpp
M  +3    -0    rkward/settings/rksettingsmodule.h
M  +2    -7    rkward/settings/rksettingsmodulecommandeditor.cpp
M  +10   -10   rkward/settings/rksettingsmodulegraphics.cpp
M  +0    -7    rkward/settings/rksettingsmodulegraphics.h
M  +4    -10   rkward/settings/rksettingsmoduler.cpp
M  +0    -6    rkward/settings/rksettingsmoduler.h

https://invent.kde.org/education/rkward/-/commit/8d245fda5b950d283d43351c8ae326717a6aa784

diff --git a/rkward/settings/rksettingsmodule.cpp b/rkward/settings/rksettingsmodule.cpp
index f7fdd6f92..648f692c5 100644
--- a/rkward/settings/rksettingsmodule.cpp
+++ b/rkward/settings/rksettingsmodule.cpp
@@ -14,6 +14,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <QCheckBox>
 #include <QGroupBox>
 #include <QComboBox>
+#include <QLineEdit>
 
 #include <functional>
 
@@ -102,6 +103,15 @@ RKSpinBox* RKConfigValue<uint, uint>::makeSpinBox(uint min, uint max, RKSettings
 	return ret;
 }
 
+template<>
+QLineEdit* RKConfigValue<QString, QString>::makeLineEdit(RKSettingsModuleWidget* module) {
+	QLineEdit* ret = new QLineEdit();
+	ret->setText(value);
+	QObject::connect(ret, &QLineEdit::textChanged, module, &RKSettingsModuleWidget::change);
+	QObject::connect(module, &RKSettingsModuleWidget::apply, module, [ret, this]() { this->value = ret->text(); });
+	return ret;
+}
+
 QComboBox* RKConfigBase::makeDropDownHelper(const LabelList &entries, RKSettingsModuleWidget* module, int initial, std::function<void(int)> setter) {
 	RK_TRACE(SETTINGS);
 
diff --git a/rkward/settings/rksettingsmodule.h b/rkward/settings/rksettingsmodule.h
index 2228c57a9..d56f15a87 100644
--- a/rkward/settings/rksettingsmodule.h
+++ b/rkward/settings/rksettingsmodule.h
@@ -24,6 +24,7 @@ class RKSettingsModuleWidget;
 class RKSetupWizardItem;
 class RKSpinBox;
 class QAction;
+class QLineEdit;
 
 /** Base class for RKWard config settings.
  *
@@ -89,6 +90,8 @@ public:
 			return makeDropDownHelper(entries, _module, (std::is_same<STORAGE_T, bool>::value && value) ? 1 : (int) value, [this](int val){this->value = (T) val;});
 		}
 	}
+/** Only for QString values: Create a fully connected QLineEdit for this option */
+	QLineEdit* makeLineEdit(RKSettingsModuleWidget* module);
 	RKSpinBox* makeSpinBox(T min, T max, RKSettingsModuleWidget* _module);
 /** For settings to be used outside the settings dialog: Create an appropriate action connected to this value. Call @param handler with the new value, whenever the action is triggered,
  *  and - for convenience - once while creating the action (for intialization) */
diff --git a/rkward/settings/rksettingsmodulecommandeditor.cpp b/rkward/settings/rksettingsmodulecommandeditor.cpp
index 0740b54b6..aec4fb9e5 100644
--- a/rkward/settings/rksettingsmodulecommandeditor.cpp
+++ b/rkward/settings/rksettingsmodulecommandeditor.cpp
@@ -158,23 +158,18 @@ public:
 
 		main_vbox->addSpacing(2 * RKStyle::spacingHint ());
 
-		script_file_filter_box = new QLineEdit();
-		script_file_filter_box->setText(RKSettingsModuleCommandEditor::script_file_filter);
+		auto script_file_filter_box = RKSettingsModuleCommandEditor::script_file_filter.makeLineEdit(this);
 		RKCommonFunctions::setTips(i18n("<p>A list of filters (file name extensions) that should be treated as R script files. Most importantly, files matching one of these filters will always be opened with R syntax highlighting.</p><p>Filters are case insensitive.</p>"), script_file_filter_box);
-		connect(script_file_filter_box, &QLineEdit::textChanged, this, &RKSettingsPageCommandEditor::change);
 		main_vbox->addWidget(new QLabel(i18n("R script file filters (separated by spaces)")));
 		main_vbox->addWidget(script_file_filter_box);
 
 		main_vbox->addStretch();
 	}
 	void applyChanges() override {
-		RK_TRACE(SETTINGS);
-
-		RKSettingsModuleCommandEditor::script_file_filter = script_file_filter_box->text();
+		// All settings based on RKConfigValue
 	}
 private:
 	RKCodeCompletionSettingsWidget *completion_settings_widget;
-	QLineEdit* script_file_filter_box;
 };
 
 RKTextEditorConfigPageWrapper::RKTextEditorConfigPageWrapper(QWidget* parent, RKSettingsModule *parent_module, RKSettingsModule::PageId superpage, KTextEditor::ConfigPage* wrapped) :
diff --git a/rkward/settings/rksettingsmodulegraphics.cpp b/rkward/settings/rksettingsmodulegraphics.cpp
index 1da409ca2..a9027c920 100644
--- a/rkward/settings/rksettingsmodulegraphics.cpp
+++ b/rkward/settings/rksettingsmodulegraphics.cpp
@@ -62,21 +62,24 @@ public:
 		button = new QRadioButton(i18n("Platform default device"), group);
 		default_device_group->addButton(button, (int) RKSettingsModuleGraphics::PlatformDevice);
 		group_layout->addWidget(button);
-		button = new QRadioButton(i18n("Other device:"), group);
-		default_device_group->addButton(button, (int) RKSettingsModuleGraphics::OtherDevice);
+		auto other_device_button = new QRadioButton(i18n("Other device:"), group);
+		default_device_group->addButton(other_device_button, (int) RKSettingsModuleGraphics::OtherDevice);
 		QHBoxLayout *h_layout = new QHBoxLayout();
 		group_layout->addLayout(h_layout);
-		h_layout->addWidget(button);
-		default_device_other_edit = new QLineEdit(RKSettingsModuleGraphics::default_device_other, group);
+		h_layout->addWidget(other_device_button);
+		auto default_device_other_edit = RKSettingsModuleGraphics::default_device_other.makeLineEdit(this);
 		h_layout->addWidget(default_device_other_edit);
-		button = static_cast<QRadioButton*>(default_device_group->button((int) RKSettingsModuleGraphics::default_device));
-		if (button) button->setChecked(true);
 		RKCommonFunctions::setTips(i18n("<p>The default device to be used for plotting, i.e. when new plot is created, while no graphics device is active (see <i>options(\"device\")</i>).</p>"
 		                                "<p>The RKWard native device is the recommended choice for most users. This corresponds to the R command <i>RK()</i>.</p>"
 		                                "<p>The 'Platform default device' corresponds to one of <i>X11()</i>, <i>windows()</i>, or <i>quartz()</i>, depending on the platform.</p>"
 		                                "<p>You can also specify the name of a function such as <i>Cairo</i>.</p>"), group);
 		connect(default_device_group, &QButtonGroup::idClicked, this, &RKSettingsPageGraphics::boxChanged);
-		connect(default_device_other_edit, &QLineEdit::textChanged, this, &RKSettingsPageGraphics::boxChanged);
+		connect(default_device_group, &QButtonGroup::idToggled, default_device_other_edit, [default_device_other_edit](int id) {
+			default_device_other_edit->setEnabled(id == (int) RKSettingsModuleGraphics::OtherDevice);
+		});
+		default_device_other_edit->setEnabled(false);
+		auto dbutton = default_device_group->button((int) RKSettingsModuleGraphics::default_device);
+		if (dbutton) dbutton->setChecked(true);
 		h_layout1->addWidget(group);
 
 		group = new QGroupBox(i18n("Integration of R standard devices"), this);
@@ -139,7 +142,6 @@ public:
 	}
 	void updateControls() {
 		RK_TRACE(SETTINGS);
-		default_device_other_edit->setEnabled(default_device_group->checkedId () == (int) RKSettingsModuleGraphics::OtherDevice);
 		QRadioButton *button = static_cast<QRadioButton*>(replace_standard_devices_group->button((int) RKSettingsModuleGraphics::ReplaceDevice));
 		if (button) button->setEnabled(default_device_group->checkedId() != RKSettingsModuleGraphics::PlatformDevice);
 	}
@@ -155,7 +157,6 @@ public:
 		RK_TRACE(SETTINGS);
 
 		RKSettingsModuleGraphics::default_device = (RKSettingsModuleGraphics::DefaultDevice) default_device_group->checkedId();
-		RKSettingsModuleGraphics::default_device_other = default_device_other_edit->text();
 		RKSettingsModuleGraphics::replace_standard_devices = (RKSettingsModuleGraphics::StandardDevicesMode) replace_standard_devices_group->checkedId();
 
 		QStringList commands = RKSettingsModuleGraphics::makeRRunTimeOptionCommands();
@@ -165,7 +166,6 @@ public:
 	}
 private:
 	QButtonGroup *default_device_group;
-	QLineEdit *default_device_other_edit;
 	QButtonGroup *replace_standard_devices_group;
 };
 
diff --git a/rkward/settings/rksettingsmodulegraphics.h b/rkward/settings/rksettingsmodulegraphics.h
index 1530a08c9..940e891fb 100644
--- a/rkward/settings/rksettingsmodulegraphics.h
+++ b/rkward/settings/rksettingsmodulegraphics.h
@@ -11,13 +11,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include <QStringList>
 
-class QLineEdit;
-class QGroupBox;
-class RKSpinBox;
-class QSpinBox;
-class QButtonGroup;
-class QRadioButton;
-
 /**
 @author Thomas Friedrichsmeier
 */
diff --git a/rkward/settings/rksettingsmoduler.cpp b/rkward/settings/rksettingsmoduler.cpp
index 6623aa160..2d8d7c60b 100755
--- a/rkward/settings/rksettingsmoduler.cpp
+++ b/rkward/settings/rksettingsmoduler.cpp
@@ -88,9 +88,8 @@ public:
 
 		// options (OutDec)
 		grid->addWidget(new QLabel(i18n("Decimal character (only for printing)"), this), ++row, 0);
-		outdec_input = new QLineEdit(RKSettingsModuleR::options_outdec, this);
+		auto outdec_input = RKSettingsModuleR::options_outdec.makeLineEdit(this);
 		outdec_input->setMaxLength(1);
-		connect(outdec_input, &QLineEdit::textChanged, this, &RKSettingsPageR::change);
 		grid->addWidget(outdec_input, row, 1);
 
 		// options (width)
@@ -188,7 +187,6 @@ public:
 	void applyChanges() override {
 		RK_TRACE(SETTINGS);
 
-		RKSettingsModuleR::options_outdec = outdec_input->text();
 		RKSettingsModuleR::options_editor = editor_input->currentText();
 		RKSettingsModuleR::options_pager = pager_input->currentText();
 		RKSettingsModuleR::options_further = further_input->toPlainText();
@@ -208,7 +206,6 @@ public:
 		}
 	}
 private:
-	QLineEdit *outdec_input;
 	QComboBox *editor_input;
 	QComboBox *pager_input;
 	QTextEdit *further_input;
@@ -329,15 +326,14 @@ public:
 		main_vbox->addWidget(new QLabel(i18n("CRAN download mirror (leave empty to be prompted once each session):"), this));
 		QHBoxLayout* hbox = new QHBoxLayout();
 		main_vbox->addLayout(hbox);
-		cran_mirror_input = new QLineEdit(RKSettingsModuleRPackages::cran_mirror_url, this);
+		auto cran_mirror_input = RKSettingsModuleRPackages::cran_mirror_url.makeLineEdit(this);
 		if (RKSettingsModuleRPackages::cran_mirror_url == "@CRAN@") cran_mirror_input->clear();
-		connect(cran_mirror_input, &QLineEdit::textChanged, this, &RKSettingsPageRPackages::change);
 		hbox->addWidget(cran_mirror_input);
 		QPushButton* cran_mirror_button = new QPushButton(i18n("Select mirror"), this);
-		connect(cran_mirror_button, &QPushButton::clicked, this, [this]() {
+		connect(cran_mirror_button, &QPushButton::clicked, this, [this, cran_mirror_input]() {
 			QString title = i18n("Select CRAN mirror");
 			RCommand* command = new RCommand("rk.select.CRAN.mirror()\n", RCommand::App | RCommand::GetStringVector, title);
-			connect(command->notifier(), &RCommandNotifier::commandFinished, this, [this](RCommand *command) {
+			connect(command->notifier(), &RCommandNotifier::commandFinished, cran_mirror_input, [cran_mirror_input](RCommand *command) {
 				if (command->succeeded()) {
 					RK_ASSERT(command->getDataLength() >= 1);
 					cran_mirror_input->setText(command->stringVector().value(0));
@@ -418,7 +414,6 @@ public:
 	void applyChanges() override {
 		RK_TRACE(SETTINGS);
 
-		RKSettingsModuleRPackages::cran_mirror_url = cran_mirror_input->text();
 		if (RKSettingsModuleRPackages::cran_mirror_url.get().isEmpty ()) RKSettingsModuleRPackages::cran_mirror_url = "@CRAN@";
 
 		RKSettingsModuleRPackages::package_repositories = repository_selector->getValues();
@@ -433,7 +428,6 @@ public:
 private:
 	MultiStringSelector *libloc_selector;
 	MultiStringSelector *repository_selector;
-	QLineEdit* cran_mirror_input;
 };
 
 RKSettingsModuleRPackages::RKSettingsModuleRPackages(QObject *parent) : RKSettingsModule(parent) {
diff --git a/rkward/settings/rksettingsmoduler.h b/rkward/settings/rksettingsmoduler.h
index f9cdf3d13..8d1d65997 100644
--- a/rkward/settings/rksettingsmoduler.h
+++ b/rkward/settings/rksettingsmoduler.h
@@ -12,12 +12,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include <qstring.h>
 #include <qstringlist.h>
 
-class QComboBox;
-class QLineEdit;
-class MultiStringSelector;
-class QSpinBox;
-class QTextEdit;
-
 /**
 Configure the R-backend
 


More information about the rkward-tracker mailing list