[education/rkward] rkward: Also do away with RCommand-flags.

Thomas Friedrichsmeier null at kde.org
Thu Jun 9 15:30:34 BST 2022


Git commit 8008b834bf7dbaf4fbe920d5c50e78c4a6909265 by Thomas Friedrichsmeier.
Committed on 09/06/2022 at 14:29.
Pushed by tfry into branch 'master'.

Also do away with RCommand-flags.

M  +1    -2    rkward/rbackend/rcommand.cpp
M  +1    -5    rkward/rbackend/rcommand.h
M  +3    -3    rkward/rbackend/rkrinterface.cpp
M  +6    -5    rkward/rbackend/rkrinterface.h
M  +1    -1    rkward/settings/rksettingsmodulegraphics.cpp
M  +1    -1    rkward/settings/rksettingsmoduleoutput.cpp
M  +3    -3    rkward/settings/rksettingsmoduler.cpp
M  +2    -2    rkward/windows/rkworkplace.cpp

https://invent.kde.org/education/rkward/commit/8008b834bf7dbaf4fbe920d5c50e78c4a6909265

diff --git a/rkward/rbackend/rcommand.cpp b/rkward/rbackend/rcommand.cpp
index bbae32f2..edeff212 100644
--- a/rkward/rbackend/rcommand.cpp
+++ b/rkward/rbackend/rcommand.cpp
@@ -29,7 +29,7 @@ RCommandNotifier::~RCommandNotifier () {
 
 int RCommand::next_id = 0;
 
-RCommand::RCommand(const QString &command, int type, const QString &rk_equiv, int flags) : RData (), RCommandChain (false) {
+RCommand::RCommand(const QString &command, int type, const QString &rk_equiv) : RData (), RCommandChain (false) {
 	RK_TRACE (RBACKEND);
 	_id = next_id++;
 // if we ever submit enough commands to get a buffer overflow, use only positive numbers.
@@ -37,7 +37,6 @@ RCommand::RCommand(const QString &command, int type, const QString &rk_equiv, in
 		next_id = 0;
 	}
 	_type = type;
-	_flags = flags;
 	if (type & Plugin) _command = command.trimmed ();
 	else _command = command;
 	if (_command.isEmpty ()) _type |= EmptyCommand;
diff --git a/rkward/rbackend/rcommand.h b/rkward/rbackend/rcommand.h
index 0b413ba9..08c5a653 100644
--- a/rkward/rbackend/rcommand.h
+++ b/rkward/rbackend/rcommand.h
@@ -101,9 +101,8 @@ public:
 @param command The command (string) to be run in the backend. This may include newlines and ";". The command should be a complete statement. If it is an incomplete statement, the backend will not wait for the rest of the command to come in, but rather the command will fail with RCommand::errorIncomplete.
 @param type An integer being the result of a bit-wise OR combination of the values in RCommand::CommandTypes. The type-parameter is used to indicate the type of command, and also how the command should retrieve information (as a usual string, or as a data vector). See \ref RCommand::CommandTypes
 @param rk_equiv Not yet used: a short descriptive string attached to the RCommand, that allows the user to make some sense of what this command is all about.
- at param flags A freely assignable integer, that you can use to identify what the command was all about. Only the RCommandReceiver handling the results will have to know what exactly the flags mean.
 */
-	explicit RCommand (const QString &command, int type, const QString &rk_equiv = QString (), int flags=0);
+	explicit RCommand (const QString &command, int type, const QString &rk_equiv = QString ());
 /** destructor. Note: you should not delete RCommands manually. This is done in RInterface. TODO: make protected */
 	~RCommand();
 /** @returns the type as specified in RCommand::RCommand */
@@ -180,8 +179,6 @@ public:
 	bool errorIncomplete () const { return (status & ErrorIncomplete); };
 /** backend rejected command as having a syntax error */
 	bool errorSyntax () const { return (status & ErrorSyntax); };
-/** return the flags associated with the command. Those are the same that you specified in the constructor, RKWard does not touch them. @see RCommand::RCommand */
-	int getFlags () const { return (_flags); };
 	void addTypeFlag (int flag) { _type |= flag; };
 	ROutputList &getOutput () { return output_list; };
 /** modify the command string. DO NOT CALL THIS after the command has been submitted! */
@@ -213,7 +210,6 @@ friend class RCommandStackModel;
 	ROutputList output_list;
 	QString _command;
 	int _type;
-	int _flags;
 	int status;
 	int has_been_run_up_to;
 	QString _rk_equiv;
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index fa535e58..22d5cb9a 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -116,9 +116,9 @@ RInterface::RInterface () {
 	whenAllFinished(this, []() { RKSettings::validateSettingsInteractive (); });
 }
 
-void RInterface::issueCommand (const QString &command, int type, const QString &rk_equiv, int flags, RCommandChain *chain) {
-	RK_TRACE (RBACKEND);
-	issueCommand (new RCommand (command, type, rk_equiv, flags), chain);
+void RInterface::issueCommand(const QString &command, int type, const QString &rk_equiv, RCommandChain *chain) {
+	RK_TRACE(RBACKEND);
+	issueCommand(new RCommand(command, type, rk_equiv), chain);
 }
 
 RInterface::~RInterface(){
diff --git a/rkward/rbackend/rkrinterface.h b/rkward/rbackend/rkrinterface.h
index dc2ce570..2bd5e00f 100644
--- a/rkward/rbackend/rkrinterface.h
+++ b/rkward/rbackend/rkrinterface.h
@@ -40,9 +40,9 @@ public:
 	static RInterface* instance() { return _instance; };
 
 /** issues the given command in the given chain */
-	static void issueCommand(RCommand *command, RCommandChain *chain=0);
+	static void issueCommand(RCommand *command, RCommandChain *chain=nullptr);
 /** convenience function to create a new command and issue it. See documentation on RCommand::RCommand() and RInterface::issueCommand() */
-	static void issueCommand(const QString &command, int type = 0, const QString &rk_equiv = QString(), int flags=0, RCommandChain *chain=0);
+	static void issueCommand(const QString &command, int type = 0, const QString &rk_equiv = QString(), RCommandChain *chain=nullptr);
 
 /** convenience function to call a function / lambda, once all commands issued in the given chain have finished (successfully or not). Internally, this works by queing an empty command. */
 	template<typename T> static void whenAllFinished(QObject *receiver, T func, RCommandChain *chain=nullptr) {
@@ -228,7 +228,6 @@ In some cases you don't just want to deal with a single RCommand in a callback,
 There are several ways to deal with this:
 
 	- storing the RCommand::id () (each command is automatically assigned a unique id)
-	- passing appropriate flags to know how to handle the command (Note that you can freely assign whatever flags you like. Only your own class will need to know how to interpret the flags.)
 	- keeping the pointer (CAUTION: don't use that pointer except to compare it with the pointer of an incoming command. Commands get deleted when they are finished, and maybe (in the future) if they become obsolete etc. Hence the pointers you keep may be invalid!)
 
 
@@ -341,13 +340,15 @@ There are a few special type-modifiers you can specify when creating an RCommand
 This one tells the backend, that the command does not really need to be executed, and does not contain anything. You'll rarely need this flag, but sometimes it is useful to submit an empty command simply to find out when it is finished. @note: RInterface::whenAllFinished() is a more readable alternative to this.
 
 - RCommand::DirectToOutput
-This is typically used in plugins: When you specify this modifier, the plain text result of this command (i.e. whatever R prints out when evaluating the command) will be added to the HTML output file. Remember to call RKWardMainWindow::newOutput in order to refresh the output-window once the command has finished.
+This is typically used in plugins: When you specify this modifier, the plain text result of this command (i.e. whatever R prints out when evaluating the command) will be added to the HTML output file.
 
 - RCommand::GetIntVector, RCommand::GetStringVector, RCommand::GetRealVector
 These are special modifiers helpful when transferring data from R to RKWard (used primarily in the editor classes and in conjunction with RCommand::Sync): They tell the backend to try to fetch the result as an array of int, char*, or double, respectively. For instance, if you know object "myobject" is an integer vector, you may get the data using
 
 \code
-RInterface::issueCommand ("myobject", RCommand::Sync | RCommand::GetIntVector, QString (), this);
+auto command = new RCommand("myobject", RCommand::Sync | RCommand::GetIntVector);
+command->whenFinished(this, [this](RCommand *command) { this->syncDataFromR(command->getIntVector(); });
+RInterface::issueCommand(command);
 \endcode
 
 Assuming the data can in fact be converted to a vector of integers, you can then access the data using these members in RCommand:
diff --git a/rkward/settings/rksettingsmodulegraphics.cpp b/rkward/settings/rksettingsmodulegraphics.cpp
index 12e67b36..d979c129 100644
--- a/rkward/settings/rksettingsmodulegraphics.cpp
+++ b/rkward/settings/rksettingsmodulegraphics.cpp
@@ -171,7 +171,7 @@ void RKSettingsModuleGraphics::applyChanges () {
 
 	QStringList commands = makeRRunTimeOptionCommands ();
 	for (QStringList::const_iterator it = commands.cbegin (); it != commands.cend (); ++it) {
-		RInterface::issueCommand (*it, RCommand::App, QString (), 0, commandChain ());
+		RInterface::issueCommand(new RCommand(*it, RCommand::App), commandChain ());
 	}
 }
 
diff --git a/rkward/settings/rksettingsmoduleoutput.cpp b/rkward/settings/rksettingsmoduleoutput.cpp
index 8c80d204..b951e462 100644
--- a/rkward/settings/rksettingsmoduleoutput.cpp
+++ b/rkward/settings/rksettingsmoduleoutput.cpp
@@ -199,7 +199,7 @@ void RKSettingsModuleOutput::applyChanges () {
 
 	QStringList commands = makeRRunTimeOptionCommands ();
 	for (QStringList::const_iterator it = commands.cbegin (); it != commands.cend (); ++it) {
-		RInterface::issueCommand (*it, RCommand::App, QString (), 0, commandChain ());
+		RInterface::issueCommand(new RCommand(*it, RCommand::App), commandChain());
 	}
 
 	cc_settings->applyChanges ();
diff --git a/rkward/settings/rksettingsmoduler.cpp b/rkward/settings/rksettingsmoduler.cpp
index 8cbc7e02..3a587393 100755
--- a/rkward/settings/rksettingsmoduler.cpp
+++ b/rkward/settings/rksettingsmoduler.cpp
@@ -197,7 +197,7 @@ void RKSettingsModuleR::applyChanges () {
 // apply run time options in R
 	QStringList commands = makeRRunTimeOptionCommands ();
 	for (QStringList::const_iterator it = commands.cbegin (); it != commands.cend (); ++it) {
-		RInterface::issueCommand (*it, RCommand::App, QString (), 0, commandChain ());
+		RInterface::issueCommand(new RCommand(*it, RCommand::App), commandChain ());
 	}
 }
 
@@ -377,7 +377,7 @@ void RKSettingsModuleRPackages::addLibraryLocation (const QString& new_loc, RCom
 	if (!libraryLocations ().contains (new_loc)) liblocs.get().prepend (new_loc);
 
 	// update the backend in any case. User might have changed liblocs, there.
-	RInterface::issueCommand (".libPaths (unique (c (" + RObject::rQuote (new_loc) + ", .libPaths ())))", RCommand::App | RCommand::Sync, QString (), 0, chain);
+	RInterface::issueCommand(new RCommand(".libPaths (unique (c (" + RObject::rQuote (new_loc) + ", .libPaths ())))", RCommand::App | RCommand::Sync), chain);
 }
 
 QStringList expandLibLocs (const QStringList &in) {
@@ -547,7 +547,7 @@ void RKSettingsModuleRPackages::applyChanges () {
 // apply options in R
 	QStringList commands = makeRRunTimeOptionCommands ();
 	for (QStringList::const_iterator it = commands.cbegin (); it != commands.cend (); ++it) {
-		RInterface::issueCommand (*it, RCommand::App, QString (), 0, commandChain ());
+		RInterface::issueCommand(new RCommand(*it, RCommand::App), commandChain());
 	}
 }
 
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index 20a531b7..3990b65c 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -974,7 +974,7 @@ void RKWorkplace::saveWorkplace(const QUrl& for_url, RCommandChain *chain) {
 
 	QString file_param;
 	if (!for_url.isEmpty()) file_param = QString("file=") + RObject::rQuote(for_url.toLocalFile() + QStringLiteral(".rkworkplace")) + QStringLiteral(", ");
-	RInterface::issueCommand("rk.save.workplace(" + file_param + "description=" + RObject::rQuote (makeWorkplaceDescription().join ("\n")) + ')', RCommand::App, i18n ("Save Workplace layout"), 0, chain);
+	RInterface::issueCommand(new RCommand("rk.save.workplace(" + file_param + "description=" + RObject::rQuote(makeWorkplaceDescription().join("\n")) + ')', RCommand::App, i18n("Save Workplace layout")), chain);
 }
 
 void RKWorkplace::restoreWorkplace (RCommandChain *chain, bool merge) {
@@ -983,7 +983,7 @@ void RKWorkplace::restoreWorkplace (RCommandChain *chain, bool merge) {
 
 	QString no_close_windows;
 	if (merge) no_close_windows = "close.windows = FALSE";
-	RInterface::issueCommand ("rk.restore.workplace(" + no_close_windows + ')', RCommand::App, i18n ("Restore Workplace layout"), 0, chain);
+	RInterface::issueCommand(new RCommand("rk.restore.workplace(" + no_close_windows + ')', RCommand::App, i18n ("Restore Workplace layout")), chain);
 }
 
 void RKWorkplace::restoreWorkplace (const QStringList &description) {



More information about the rkward-tracker mailing list