InsetParams refactoring

Yuriy Skalko yuriy.skalko at gmail.com
Mon Dec 28 14:13:06 UTC 2020


Here is an update to my previous patch. I've separated it into several 
patches. The next step will be moving `string2params` into InsetParams.

Please review these patches.


Yuriy
-------------- next part --------------
From f8a2c8a143bd54cec1da51b611e0a66c4af3305e Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Sun, 6 Dec 2020 11:24:01 +0200
Subject: [PATCH 1/7] Extract InsetParams superclass

---
 src/Makefile.am                    |  1 +
 src/insets/Inset.h                 |  1 +
 src/insets/InsetBox.h              |  6 ++---
 src/insets/InsetBranch.h           |  6 ++---
 src/insets/InsetCommandParams.h    |  7 +++---
 src/insets/InsetFloat.h            |  6 ++---
 src/insets/InsetIPAMacro.h         |  6 ++---
 src/insets/InsetIndex.h            |  6 ++---
 src/insets/InsetListings.h         |  2 +-
 src/insets/InsetListingsParams.cpp |  4 ++--
 src/insets/InsetListingsParams.h   |  8 +++----
 src/insets/InsetNewline.h          |  6 ++---
 src/insets/InsetNewpage.h          |  6 ++---
 src/insets/InsetNote.h             |  6 ++---
 src/insets/InsetParams.h           | 36 ++++++++++++++++++++++++++++++
 src/insets/InsetPhantom.h          |  6 ++---
 src/insets/InsetScript.h           |  6 ++---
 src/insets/InsetSeparator.h        |  6 ++---
 src/insets/InsetSpace.h            |  6 ++---
 src/insets/InsetWrap.h             |  6 ++---
 20 files changed, 88 insertions(+), 49 deletions(-)
 create mode 100644 src/insets/InsetParams.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 31701f2fb1..7dec8a1a6d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -639,6 +639,7 @@ HEADERFILESINSETS = \
 	insets/InsetNewpage.h \
 	insets/InsetNomencl.h \
 	insets/InsetNote.h \
+	insets/InsetParams.h \
 	insets/InsetPhantom.h \
 	insets/InsetQuotes.h \
 	insets/InsetRef.h \
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index ab2c535e46..4c637d19aa 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -17,6 +17,7 @@
 
 #include "ColorCode.h"
 #include "InsetCode.h"
+#include "InsetParams.h"
 #include "LayoutEnums.h"
 #include "OutputEnums.h"
 #include "OutputParams.h"
diff --git a/src/insets/InsetBox.h b/src/insets/InsetBox.h
index cc80da3ecd..a0a2334df9 100644
--- a/src/insets/InsetBox.h
+++ b/src/insets/InsetBox.h
@@ -21,15 +21,15 @@
 
 namespace lyx {
 
-class InsetBoxParams
+class InsetBoxParams : public InsetParams
 {
 public:
 	///
 	explicit InsetBoxParams(std::string const &);
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 
 	///
 	std::string type;
diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h
index 6106ce5a5c..fdde0a1816 100644
--- a/src/insets/InsetBranch.h
+++ b/src/insets/InsetBranch.h
@@ -16,7 +16,7 @@
 
 namespace lyx {
 
-class InsetBranchParams {
+class InsetBranchParams : public InsetParams {
 public:
 	///
 	explicit InsetBranchParams(docstring const & b = docstring())
@@ -24,9 +24,9 @@ public:
 	InsetBranchParams(docstring const & b, bool i)
 		: branch(b), inverted(i) {}
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	docstring branch;
 	///
diff --git a/src/insets/InsetCommandParams.h b/src/insets/InsetCommandParams.h
index 1800fb599d..4e417ad94d 100644
--- a/src/insets/InsetCommandParams.h
+++ b/src/insets/InsetCommandParams.h
@@ -15,6 +15,7 @@
 #define INSETCOMMANDPARAMS_H
 
 #include "InsetCode.h"
+#include "InsetParams.h"
 
 #include "support/docstring.h"
 
@@ -115,7 +116,7 @@ private:
 };
 
 
-class InsetCommandParams {
+class InsetCommandParams : public InsetParams {
 public:
 	/// Construct parameters for inset of type \p code.
 	explicit InsetCommandParams(InsetCode code);
@@ -128,11 +129,11 @@ public:
 	///
 	InsetCode code() const { return insetCode_; }
 	/// Parse the command
-	void read(Lexer &);
+	void read(Lexer &) override;
 	///
 	void Read(Lexer &, Buffer const *);
 	///
-	void write(std::ostream &) const;
+	void write(std::ostream &) const override;
 	///
 	void Write(std::ostream & os, Buffer const * buf) const;
 	/// Build the complete LaTeX command
diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h
index 0fc0fba398..daa5b3181d 100644
--- a/src/insets/InsetFloat.h
+++ b/src/insets/InsetFloat.h
@@ -21,16 +21,16 @@ namespace lyx {
 struct TexString;
 
 
-class InsetFloatParams
+class InsetFloatParams : public InsetParams
 {
 public:
 	///
 	InsetFloatParams() : type("senseless"), placement("document"), alignment("document"),
 		wide(false), sideways(false), subfloat(false) {}
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	std::string type;
 	///
diff --git a/src/insets/InsetIPAMacro.h b/src/insets/InsetIPAMacro.h
index 3305e6bf6e..432bb5a897 100644
--- a/src/insets/InsetIPAMacro.h
+++ b/src/insets/InsetIPAMacro.h
@@ -21,7 +21,7 @@ namespace lyx {
 
 class LaTeXFeatures;
 
-class InsetIPADecoParams
+class InsetIPADecoParams : public InsetParams
 {
 public:
 	enum Type {
@@ -31,9 +31,9 @@ public:
 	///
 	InsetIPADecoParams();
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	Type type;
 };
diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h
index bddb8ba380..b2038536f2 100644
--- a/src/insets/InsetIndex.h
+++ b/src/insets/InsetIndex.h
@@ -19,15 +19,15 @@
 
 namespace lyx {
 
-class InsetIndexParams {
+class InsetIndexParams : public InsetParams {
 public:
 	///
 	explicit InsetIndexParams(docstring const & b = docstring())
 		: index(b) {}
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	docstring index;
 };
diff --git a/src/insets/InsetListings.h b/src/insets/InsetListings.h
index 41be4394ce..1a80078645 100644
--- a/src/insets/InsetListings.h
+++ b/src/insets/InsetListings.h
@@ -12,9 +12,9 @@
 #ifndef INSET_LISTINGS_H
 #define INSET_LISTINGS_H
 
+#include "InsetCaptionable.h"
 #include "InsetListingsParams.h"
 
-
 namespace lyx {
 
 class LaTeXFeatures;
diff --git a/src/insets/InsetListingsParams.cpp b/src/insets/InsetListingsParams.cpp
index 9390d6bbe4..8ffb438797 100644
--- a/src/insets/InsetListingsParams.cpp
+++ b/src/insets/InsetListingsParams.cpp
@@ -9,18 +9,18 @@
  */
 
 #include <config.h>
-#include <algorithm>
 
 #include "InsetListingsParams.h"
 
-#include "support/Length.h"
 #include "Lexer.h"
 
 #include "support/convert.h"
 #include "support/gettext.h"
+#include "support/Length.h"
 #include "support/lstrings.h"
 #include "support/textutils.h"
 
+#include <algorithm>
 #include <sstream>
 
 using namespace std;
diff --git a/src/insets/InsetListingsParams.h b/src/insets/InsetListingsParams.h
index 90c5adb763..7497110738 100644
--- a/src/insets/InsetListingsParams.h
+++ b/src/insets/InsetListingsParams.h
@@ -12,13 +12,13 @@
 #ifndef INSETLISTINGSPARAMS_H
 #define INSETLISTINGSPARAMS_H
 
-#include "InsetCaptionable.h"
+#include "InsetCollapsible.h"
 
 #include <map>
 
 namespace lyx {
 
-class InsetListingsParams {
+class InsetListingsParams : public InsetParams {
 public:
 	///
 	InsetListingsParams();
@@ -28,10 +28,10 @@ public:
 		InsetCollapsible::CollapseStatus s = InsetCollapsible::Open);
 
 	/// write parameters to an ostream
-	void write(std::ostream &) const;
+	void write(std::ostream &) const override;
 
 	/// read parameters from an ostream
-	void read(Lexer &);
+	void read(Lexer &) override;
 
 	/// valid parameter string
 	std::string params(std::string const & sep=",") const;
diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h
index 3d540a8618..10f894d1e6 100644
--- a/src/insets/InsetNewline.h
+++ b/src/insets/InsetNewline.h
@@ -17,7 +17,7 @@
 
 namespace lyx {
 
-class InsetNewlineParams
+class InsetNewlineParams : public InsetParams
 {
 public:
 	/// The different kinds of spaces we support
@@ -30,9 +30,9 @@ public:
 	///
 	InsetNewlineParams() : kind(NEWLINE) {}
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	Kind kind;
 };
diff --git a/src/insets/InsetNewpage.h b/src/insets/InsetNewpage.h
index f02048804d..633b81ffd7 100644
--- a/src/insets/InsetNewpage.h
+++ b/src/insets/InsetNewpage.h
@@ -17,7 +17,7 @@
 
 namespace lyx {
 
-class InsetNewpageParams
+class InsetNewpageParams : public InsetParams
 {
 public:
 	/// The different kinds of spaces we support
@@ -36,9 +36,9 @@ public:
 	///
 	InsetNewpageParams() : kind(NEWPAGE) {}
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	Kind kind;
 };
diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h
index aeab8f038b..bf14e14758 100644
--- a/src/insets/InsetNote.h
+++ b/src/insets/InsetNote.h
@@ -17,7 +17,7 @@
 
 namespace lyx {
 
-class InsetNoteParams
+class InsetNoteParams : public InsetParams
 {
 public:
 	enum Type {
@@ -28,9 +28,9 @@ public:
 	/// \c type defaults to Note
 	InsetNoteParams();
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	Type type;
 };
diff --git a/src/insets/InsetParams.h b/src/insets/InsetParams.h
new file mode 100644
index 0000000000..0d7060317a
--- /dev/null
+++ b/src/insets/InsetParams.h
@@ -0,0 +1,36 @@
+// -*- C++ -*-
+/**
+ * \file InsetParams.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Yuriy Skalko
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef INSETPARAMS_H
+#define INSETPARAMS_H
+
+#include <ostream>
+
+namespace lyx {
+
+class Lexer;
+
+
+class InsetParams
+{
+public:
+	///
+	virtual ~InsetParams() = default;
+	///
+	virtual void write(std::ostream & os) const = 0;
+	///
+	virtual void read(Lexer & lex) = 0;
+};
+
+
+} // namespace lyx
+
+#endif // INSETPARAMS_H
diff --git a/src/insets/InsetPhantom.h b/src/insets/InsetPhantom.h
index 72281df2ae..2ca9b05622 100644
--- a/src/insets/InsetPhantom.h
+++ b/src/insets/InsetPhantom.h
@@ -17,7 +17,7 @@
 
 namespace lyx {
 
-class InsetPhantomParams
+class InsetPhantomParams : public InsetParams
 {
 public:
 	enum Type {
@@ -28,9 +28,9 @@ public:
 	/// \c type defaults to Phantom
 	InsetPhantomParams();
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	Type type;
 };
diff --git a/src/insets/InsetScript.h b/src/insets/InsetScript.h
index 9eb80dbbd5..e4a9da7621 100644
--- a/src/insets/InsetScript.h
+++ b/src/insets/InsetScript.h
@@ -18,7 +18,7 @@
 
 namespace lyx {
 
-class InsetScriptParams
+class InsetScriptParams : public InsetParams
 {
 public:
 	enum Type {
@@ -28,9 +28,9 @@ public:
 	/// \c type defaults to Subscript
 	InsetScriptParams();
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	int shift(FontInfo const & font) const;
 	///
diff --git a/src/insets/InsetSeparator.h b/src/insets/InsetSeparator.h
index f7e0ab9059..212d3894b4 100644
--- a/src/insets/InsetSeparator.h
+++ b/src/insets/InsetSeparator.h
@@ -17,7 +17,7 @@
 
 namespace lyx {
 
-class InsetSeparatorParams
+class InsetSeparatorParams : public InsetParams
 {
 public:
 	/// The different kinds of separators we support
@@ -29,9 +29,9 @@ public:
 	///
 	InsetSeparatorParams() : kind(PLAIN) {}
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	Kind kind;
 };
diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h
index 5cf7aa7303..a4fb63357f 100644
--- a/src/insets/InsetSpace.h
+++ b/src/insets/InsetSpace.h
@@ -24,7 +24,7 @@ namespace lyx {
 
 class LaTeXFeatures;
 
-struct InsetSpaceParams {
+struct InsetSpaceParams : public InsetParams {
 	/// The different kinds of spaces we support
 	enum Kind {
 		/// Normal space ('\ ')
@@ -77,9 +77,9 @@ struct InsetSpaceParams {
 	///
 	explicit InsetSpaceParams(bool m = false) : kind(NORMAL), math(m) {}
 	///
-	void write(std::ostream & os) const;
+	void write(std::ostream & os) const override;
 	///
-	void read(Lexer & lex);
+	void read(Lexer & lex) override;
 	///
 	Kind kind;
 	///
diff --git a/src/insets/InsetWrap.h b/src/insets/InsetWrap.h
index 02e0a202b6..bbf4000820 100644
--- a/src/insets/InsetWrap.h
+++ b/src/insets/InsetWrap.h
@@ -20,12 +20,12 @@
 namespace lyx {
 
 
-class InsetWrapParams {
+class InsetWrapParams : public InsetParams {
 public:
 	///
-	void write(std::ostream &) const;
+	void write(std::ostream &) const override;
 	///
-	void read(Lexer &);
+	void read(Lexer &) override;
 
 	///
 	std::string type;
-- 
2.28.0.windows.1

-------------- next part --------------
From 82e9f4c8a33e0883237c9df9947f2593a981de81 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Mon, 21 Dec 2020 13:38:34 +0200
Subject: [PATCH 2/7] Move Buffer argument from methods to constructor to unify
 interfaces

Add Buffer member in InsetExternalParams and InsetGraphicsParams.
Remove Buffer argument from string2params and params2string.
---
 src/BufferView.cpp                 |  4 +-
 src/CutAndPaste.cpp                |  2 +-
 src/Text3.cpp                      |  4 +-
 src/factory.cpp                    |  8 ++--
 src/frontends/qt/GuiExternal.cpp   |  9 +++--
 src/frontends/qt/GuiGraphics.cpp   | 14 ++++---
 src/insets/InsetCommand.cpp        |  8 ++--
 src/insets/InsetExternal.cpp       | 65 +++++++++++++++++-------------
 src/insets/InsetExternal.h         | 19 +++++----
 src/insets/InsetGraphics.cpp       | 52 +++++++++++++-----------
 src/insets/InsetGraphics.h         |  4 +-
 src/insets/InsetGraphicsParams.cpp | 20 ++++-----
 src/insets/InsetGraphicsParams.h   | 16 +++++---
 src/insets/InsetInfo.cpp           |  2 +-
 14 files changed, 128 insertions(+), 99 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 758a9928f1..01af7505d8 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1744,9 +1744,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		string const newId = cmd.getArg(0);
 		bool fetchId = newId.empty(); //if we wait for groupId from first graphics inset
 
-		InsetGraphicsParams grp_par;
+		InsetGraphicsParams grp_par(&buffer_);
 		if (!fetchId)
-			InsetGraphics::string2params(graphics::getGroupParams(buffer_, newId), buffer_, grp_par);
+			InsetGraphics::string2params(graphics::getGroupParams(buffer_, newId), grp_par);
 
 		if (!from.nextInset())	//move to closest inset
 			from.forwardInset();
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index fc555c1375..598413e369 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -1351,7 +1351,7 @@ void pasteClipboardGraphics(Cursor & cur, ErrorList & /* errorList */,
 
 	// create inset for graphic
 	InsetGraphics * inset = new InsetGraphics(cur.buffer());
-	InsetGraphicsParams params;
+	InsetGraphicsParams params(cur.buffer());
 	params.filename = support::DocFileName(filename.absFileName(), false);
 	inset->setParams(params);
 	cur.recordUndo();
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 61b64efc87..cd72b26953 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1387,12 +1387,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
 		string id = to_utf8(cmd.argument());
 		string grp = graphics::getGroupParams(bv->buffer(), id);
-		InsetGraphicsParams tmp, inspar = ins->getParams();
+		InsetGraphicsParams tmp(&bv->buffer()), inspar = ins->getParams();
 
 		if (id.empty())
 			inspar.groupId = to_utf8(cmd.argument());
 		else {
-			InsetGraphics::string2params(grp, bv->buffer(), tmp);
+			InsetGraphics::string2params(grp, tmp);
 			tmp.filename = inspar.filename;
 			inspar = tmp;
 		}
diff --git a/src/factory.cpp b/src/factory.cpp
index 6f17797ada..0fb4f1b8a3 100644
--- a/src/factory.cpp
+++ b/src/factory.cpp
@@ -312,8 +312,8 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
 			}
 
 			case EXTERNAL_CODE: {
-				InsetExternalParams iep;
-				InsetExternal::string2params(to_utf8(cmd.argument()), *buf, iep);
+				InsetExternalParams iep(buf);
+				InsetExternal::string2params(to_utf8(cmd.argument()), iep);
 				auto inset = make_unique<InsetExternal>(buf);
 				inset->setBuffer(*buf);
 				inset->setParams(iep);
@@ -321,8 +321,8 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
 			}
 
 			case GRAPHICS_CODE: {
-				InsetGraphicsParams igp;
-				InsetGraphics::string2params(to_utf8(cmd.argument()), *buf, igp);
+				InsetGraphicsParams igp(buf);
+				InsetGraphics::string2params(to_utf8(cmd.argument()), igp);
 				auto inset = make_unique<InsetGraphics>(buf);
 				inset->setParams(igp);
 				return inset.release();
diff --git a/src/frontends/qt/GuiExternal.cpp b/src/frontends/qt/GuiExternal.cpp
index 55688c54e4..968f4b43ea 100644
--- a/src/frontends/qt/GuiExternal.cpp
+++ b/src/frontends/qt/GuiExternal.cpp
@@ -83,7 +83,8 @@ char const * const origin_gui_strs[] = {
 
 
 GuiExternal::GuiExternal(GuiView & lv)
-	: GuiDialog(lv, "external", qt_("External Material")), bbChanged_(false)
+	: GuiDialog(lv, "external", qt_("External Material")),
+	  params_(&buffer()), bbChanged_(false)
 {
 	setupUi(this);
 
@@ -629,20 +630,20 @@ void GuiExternal::applyView()
 
 bool GuiExternal::initialiseParams(string const & sdata)
 {
-	InsetExternal::string2params(sdata, buffer(), params_);
+	InsetExternal::string2params(sdata, params_);
 	return true;
 }
 
 
 void GuiExternal::clearParams()
 {
-	params_ = InsetExternalParams();
+	params_ = InsetExternalParams(&buffer());
 }
 
 
 void GuiExternal::dispatchParams()
 {
-	string const lfun = InsetExternal::params2string(params_, buffer());
+	string const lfun = InsetExternal::params2string(params_);
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiGraphics.cpp b/src/frontends/qt/GuiGraphics.cpp
index b8a5af95f6..1501edf18e 100644
--- a/src/frontends/qt/GuiGraphics.cpp
+++ b/src/frontends/qt/GuiGraphics.cpp
@@ -110,7 +110,8 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
 
 
 GuiGraphics::GuiGraphics(GuiView & lv)
-	: GuiDialog(lv, "graphics", qt_("Graphics")), bbChanged(false)
+	: GuiDialog(lv, "graphics", qt_("Graphics")),
+	  bbChanged(false), params_(&buffer())
 {
 	setupUi(this);
 
@@ -309,7 +310,8 @@ void GuiGraphics::changeGroup(int /* index */)
 
 	// group exists: load params into the dialog
 	groupCO->blockSignals(true);
-	InsetGraphics::string2params(grp, buffer(), params_);
+	params_.setBuffer(&buffer());
+	InsetGraphics::string2params(grp, params_);
 	paramsToDialog(params_);
 	groupCO->blockSignals(false);
 
@@ -752,7 +754,8 @@ bool GuiGraphics::isValid()
 
 bool GuiGraphics::initialiseParams(string const & sdata)
 {
-	InsetGraphics::string2params(sdata, buffer(), params_);
+	params_.setBuffer(&buffer());
+	InsetGraphics::string2params(sdata, params_);
 	paramsToDialog(params_);
 	current_group_ = params_.groupId;
 	return true;
@@ -761,14 +764,15 @@ bool GuiGraphics::initialiseParams(string const & sdata)
 
 void GuiGraphics::clearParams()
 {
-	params_ = InsetGraphicsParams();
+	params_ = InsetGraphicsParams(&buffer());
 }
 
 
 void GuiGraphics::dispatchParams()
 {
 	InsetGraphicsParams tmp_params(params_);
-	string const lfun = InsetGraphics::params2string(tmp_params, buffer());
+	tmp_params.setBuffer(&buffer());
+	string const lfun = InsetGraphics::params2string(tmp_params);
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp
index 67ff5fc6b6..c4b5f1d9bf 100644
--- a/src/insets/InsetCommand.cpp
+++ b/src/insets/InsetCommand.cpp
@@ -378,8 +378,8 @@ bool decodeInsetParam(string const & name, string & data,
 		break;
 	}
 	case EXTERNAL_CODE: {
-		InsetExternalParams p;
-		data = InsetExternal::params2string(p, buffer);
+		InsetExternalParams p(&buffer);
+		data = InsetExternal::params2string(p);
 		break;
 	}
 	case FLOAT_CODE:  {
@@ -398,8 +398,8 @@ bool decodeInsetParam(string const & name, string & data,
 		break;
 	}
 	case GRAPHICS_CODE: {
-		InsetGraphicsParams p;
-		data = InsetGraphics::params2string(p, buffer);
+		InsetGraphicsParams p(&buffer);
+		data = InsetGraphics::params2string(p);
 		break;
 	}
 	case MATH_SPACE_CODE: {
diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp
index 7575702cfc..1b9f8bc942 100644
--- a/src/insets/InsetExternal.cpp
+++ b/src/insets/InsetExternal.cpp
@@ -117,11 +117,12 @@ support::FileName TempName::operator()() const
 } // namespace external
 
 
-InsetExternalParams::InsetExternalParams()
+InsetExternalParams::InsetExternalParams(Buffer const * b)
 	: display(true),
 	  preview_mode(PREVIEW_OFF),
 	  lyxscale(defaultLyxScale),
-	  draft(false)
+	  draft(false),
+	  buffer_(b)
 {
 	if (defaultTemplateName.empty()) {
 		external::TemplateManager const & etm =
@@ -176,13 +177,13 @@ void InsetExternalParams::settemplate(string const & name)
 }
 
 
-void InsetExternalParams::write(Buffer const & buf, ostream & os) const
+void InsetExternalParams::write(ostream & os) const
 {
 	os << "External\n"
 	   << "\ttemplate " << templatename() << '\n';
 
 	if (!filename.empty())
-		os << "\tfilename " << filename.outputFileName(buf.filePath()) << '\n';
+		os << "\tfilename " << filename.outputFileName(buffer_->filePath()) << '\n';
 
 	if (!display)
 		os << "\tdisplay false\n";
@@ -233,7 +234,7 @@ void InsetExternalParams::write(Buffer const & buf, ostream & os) const
 }
 
 
-bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
+void InsetExternalParams::read(Lexer & lex)
 {
 	enum {
 		EX_TEMPLATE = 1,
@@ -286,7 +287,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
 		case EX_FILENAME: {
 			lex.eatLine();
 			string const name = lex.getString();
-			filename = buffer.getReferencedFileName(name);
+			filename = buffer_->getReferencedFileName(name);
 			break;
 		}
 
@@ -385,10 +386,12 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
 
 	if (lyxerr.debugging(Debug::EXTERNAL)) {
 		lyxerr	<< "InsetExternalParams::read:\n";
-		write(buffer, lyxerr);
+		write(lyxerr);
 	}
 
-	return !read_error;
+	if (read_error)
+		throw ExceptionMessage(WarningException, from_ascii("Read Error: "),
+							   from_ascii("Wrong tag in External inset"));
 }
 
 
@@ -419,7 +422,7 @@ docstring screenLabel(InsetExternalParams const & params,
 
 
 InsetExternal::InsetExternal(Buffer * buf)
-	: Inset(buf), renderer_(new RenderButton)
+	: Inset(buf), params_(buf), renderer_(new RenderButton)
 {
 }
 
@@ -456,25 +459,29 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
 	switch (cmd.action()) {
 
 	case LFUN_INSET_EDIT: {
-		InsetExternalParams p =  params();
+		InsetExternalParams p(params());
+		p.setBuffer(&buffer());
 		if (!cmd.argument().empty())
-			string2params(to_utf8(cmd.argument()), buffer(), p);
+			string2params(to_utf8(cmd.argument()), p);
 		external::editExternal(p, buffer());
 		break;
 	}
 
 	case LFUN_INSET_MODIFY: {
-		InsetExternalParams p;
-		string2params(to_utf8(cmd.argument()), buffer(), p);
+		InsetExternalParams p(&buffer());
+		string2params(to_utf8(cmd.argument()), p);
 		cur.recordUndo();
 		setParams(p);
 		break;
 	}
 
-	case LFUN_INSET_DIALOG_UPDATE:
+	case LFUN_INSET_DIALOG_UPDATE: {
+		InsetExternalParams p(params());
+		p.setBuffer(&cur.bv().buffer());
 		cur.bv().updateDialog("external",
-			params2string(params(), cur.bv().buffer()));
+			params2string(p));
 		break;
+	}
 
 	default:
 		Inset::doDispatch(cur, cmd);
@@ -511,7 +518,9 @@ void InsetExternal::addToToc(DocIterator const & cpit, bool output_active,
 
 bool InsetExternal::showInsetDialog(BufferView * bv) const
 {
-	bv->showDialog("external", params2string(params(), bv->buffer()),
+	InsetExternalParams p(params());
+	p.setBuffer(&bv->buffer());
+	bv->showDialog("external", params2string(p),
 		const_cast<InsetExternal *>(this));
 	return true;
 }
@@ -681,15 +690,19 @@ void InsetExternal::fileChanged() const
 
 void InsetExternal::write(ostream & os) const
 {
-	params_.write(buffer(), os);
+	params_.write(os);
 }
 
 
 void InsetExternal::read(Lexer & lex)
 {
-	InsetExternalParams params;
-	if (params.read(buffer(), lex))
-		setParams(params);
+	InsetExternalParams params(&buffer());
+	try {
+		params.read(lex);
+	} catch (ExceptionMessage &) {
+		return;
+	}
+	setParams(params);
 }
 
 
@@ -890,10 +903,9 @@ string InsetExternal::contextMenuName() const
 }
 
 
-void InsetExternal::string2params(string const & in, Buffer const & buffer,
-	InsetExternalParams & params)
+void InsetExternal::string2params(string const & in, InsetExternalParams & params)
 {
-	params = InsetExternalParams();
+	params = InsetExternalParams(params.buffer());
 	if (in.empty())
 		return;
 
@@ -919,16 +931,15 @@ void InsetExternal::string2params(string const & in, Buffer const & buffer,
 		return;
 	}
 
-	params.read(buffer, lex);
+	params.read(lex);
 }
 
 
-string InsetExternal::params2string(InsetExternalParams const & params,
-	Buffer const & buffer)
+string InsetExternal::params2string(InsetExternalParams const & params)
 {
 	ostringstream data;
 	data << "external" << ' ';
-	params.write(buffer, data);
+	params.write(data);
 	data << "\\end_inset\n";
 	return data.str();
 }
diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h
index f124445f5e..1649802d07 100644
--- a/src/insets/InsetExternal.h
+++ b/src/insets/InsetExternal.h
@@ -46,12 +46,16 @@ private:
 
 
 /// hold parameters settable from the GUI
-class InsetExternalParams {
+class InsetExternalParams : public InsetParams {
 public:
-	InsetExternalParams();
+	explicit InsetExternalParams(Buffer const * b);
+	InsetExternalParams(InsetExternalParams const &) = default;
 
-	void write(Buffer const &, std::ostream &) const;
-	bool read(Buffer const &, Lexer &);
+	void write(std::ostream &) const override;
+	void read(Lexer &) override;
+
+	Buffer const * buffer() { return buffer_; }
+	void setBuffer(Buffer const * b) { buffer_ = b; }
 
 	/// The name of the tempfile used for manipulations.
 	support::FileName tempname() const { return tempname_(); }
@@ -82,6 +86,7 @@ public:
 private:
 	external::TempName tempname_;
 	std::string templatename_;
+	Buffer const * buffer_;
 };
 
 
@@ -98,11 +103,9 @@ public:
 	///
 	~InsetExternal();
 	///
-	static void string2params(std::string const &, Buffer const &,
-				  InsetExternalParams &);
+	static void string2params(std::string const &, InsetExternalParams &);
 	///
-	static std::string params2string(InsetExternalParams const &,
-					       Buffer const &);
+	static std::string params2string(InsetExternalParams const &);
 	///
 	InsetExternalParams const & params() const;
 	///
diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp
index 7daa40d9aa..8d56fc9f1c 100644
--- a/src/insets/InsetGraphics.cpp
+++ b/src/insets/InsetGraphics.cpp
@@ -148,8 +148,7 @@ string findTargetFormat(string const & format, OutputParams const & runparams)
 }
 
 
-void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
-	InsetGraphicsParams & params)
+void readInsetGraphics(Lexer & lex, bool allowOrigin, InsetGraphicsParams & params)
 {
 	bool finished = false;
 
@@ -165,7 +164,7 @@ void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
 		if (token == "\\end_inset") {
 			finished = true;
 		} else {
-			if (!params.Read(lex, token, buf, allowOrigin))
+			if (!params.read(lex, token, allowOrigin))
 				lyxerr << "Unknown token, "
 				       << token
 				       << ", skipping."
@@ -178,14 +177,14 @@ void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
 
 
 InsetGraphics::InsetGraphics(Buffer * buf)
-	: Inset(buf), graphic_label(xml::uniqueID(from_ascii("graph"))),
+	: Inset(buf), params_(buf), graphic_label(xml::uniqueID(from_ascii("graph"))),
 	  graphic_(new RenderGraphic(this))
 {
 }
 
 
 InsetGraphics::InsetGraphics(InsetGraphics const & ig)
-	: Inset(ig),
+	: Inset(ig), params_(nullptr),
 	  graphic_label(xml::uniqueID(from_ascii("graph"))),
 	  graphic_(new RenderGraphic(*ig.graphic_, this))
 {
@@ -210,9 +209,10 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
 	switch (cmd.action()) {
 	case LFUN_INSET_EDIT: {
-		InsetGraphicsParams p = params();
+		InsetGraphicsParams p(params());
+		p.setBuffer(&buffer());
 		if (!cmd.argument().empty())
-			string2params(to_utf8(cmd.argument()), buffer(), p);
+			string2params(to_utf8(cmd.argument()), p);
 		editGraphics(p);
 		break;
 	}
@@ -223,8 +223,8 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
 			break;
 		}
 
-		InsetGraphicsParams p;
-		string2params(to_utf8(cmd.argument()), buffer(), p);
+		InsetGraphicsParams p(&buffer());
+		string2params(to_utf8(cmd.argument()), p);
 		if (p.filename.empty()) {
 			cur.noScreenUpdate();
 			break;
@@ -240,9 +240,12 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
 		break;
 	}
 
-	case LFUN_INSET_DIALOG_UPDATE:
-		cur.bv().updateDialog("graphics", params2string(params(), buffer()));
+	case LFUN_INSET_DIALOG_UPDATE: {
+		InsetGraphicsParams p(params());
+		p.setBuffer(&buffer());
+		cur.bv().updateDialog("graphics", params2string(p));
 		break;
+	}
 
 	case LFUN_GRAPHICS_RELOAD:
 		params_.filename.refresh();
@@ -278,7 +281,9 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 bool InsetGraphics::showInsetDialog(BufferView * bv) const
 {
-	bv->showDialog("graphics", params2string(params(), bv->buffer()),
+	InsetGraphicsParams p(params());
+	p.setBuffer(&bv->buffer());
+	bv->showDialog("graphics", params2string(p),
 		const_cast<InsetGraphics *>(this));
 	return true;
 }
@@ -300,7 +305,7 @@ void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 void InsetGraphics::write(ostream & os) const
 {
 	os << "Graphics\n";
-	params().Write(os, buffer());
+	params().write(os);
 }
 
 
@@ -308,7 +313,7 @@ void InsetGraphics::read(Lexer & lex)
 {
 	lex.setContext("InsetGraphics::read");
 	//lex >> "Graphics";
-	readInsetGraphics(lex, buffer(), true, params_);
+	readInsetGraphics(lex, true, params_);
 	graphic_->update(params().as_grfxParams());
 }
 
@@ -1158,8 +1163,7 @@ string InsetGraphics::contextMenuName() const
 }
 
 
-void InsetGraphics::string2params(string const & in, Buffer const & buffer,
-	InsetGraphicsParams & params)
+void InsetGraphics::string2params(string const & in, InsetGraphicsParams & params)
 {
 	if (in.empty())
 		return;
@@ -1169,17 +1173,16 @@ void InsetGraphics::string2params(string const & in, Buffer const & buffer,
 	lex.setStream(data);
 	lex.setContext("InsetGraphics::string2params");
 	lex >> "graphics";
-	params = InsetGraphicsParams();
-	readInsetGraphics(lex, buffer, false, params);
+	params = InsetGraphicsParams(params.buffer());
+	readInsetGraphics(lex, false, params);
 }
 
 
-string InsetGraphics::params2string(InsetGraphicsParams const & params,
-	Buffer const & buffer)
+string InsetGraphics::params2string(InsetGraphicsParams const & params)
 {
 	ostringstream data;
 	data << "graphics" << ' ';
-	params.Write(data, buffer);
+	params.write(data);
 	data << "\\end_inset\n";
 	return data.str();
 }
@@ -1232,8 +1235,9 @@ string getGroupParams(Buffer const & b, string const & groupId)
 		InsetGraphicsParams const & inspar = ins->getParams();
 		if (inspar.groupId == groupId) {
 			InsetGraphicsParams tmp = inspar;
+			tmp.setBuffer(&b);
 			tmp.filename.erase();
-			return InsetGraphics::params2string(tmp, b);
+			return InsetGraphics::params2string(tmp);
 		}
 	}
 	return string();
@@ -1242,8 +1246,8 @@ string getGroupParams(Buffer const & b, string const & groupId)
 
 void unifyGraphicsGroups(Buffer & b, string const & argument)
 {
-	InsetGraphicsParams params;
-	InsetGraphics::string2params(argument, b, params);
+	InsetGraphicsParams params(&b);
+	InsetGraphics::string2params(argument, params);
 
 	// This handles undo groups automagically
 	UndoGroupHelper ugh(&b);
diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h
index 2f0156dfc9..151e4313f2 100644
--- a/src/insets/InsetGraphics.h
+++ b/src/insets/InsetGraphics.h
@@ -40,11 +40,9 @@ public:
 
 	///
 	static void string2params(std::string const & data,
-				  Buffer const & buffer,
 				  InsetGraphicsParams &);
 	///
-	static std::string params2string(InsetGraphicsParams const &,
-					  Buffer const &);
+	static std::string params2string(InsetGraphicsParams const &);
 
 	/** Set the inset parameters, used by the GUIndependent dialog.
 	    Return true of new params are different from what was so far.
diff --git a/src/insets/InsetGraphicsParams.cpp b/src/insets/InsetGraphicsParams.cpp
index 13b57c0775..a33ef66103 100644
--- a/src/insets/InsetGraphicsParams.cpp
+++ b/src/insets/InsetGraphicsParams.cpp
@@ -35,9 +35,9 @@ using namespace lyx::support;
 namespace lyx {
 
 
-InsetGraphicsParams::InsetGraphicsParams()
+InsetGraphicsParams::InsetGraphicsParams(Buffer const * b)
 {
-	init();
+	init(b);
 }
 
 
@@ -60,7 +60,7 @@ InsetGraphicsParams & InsetGraphicsParams::operator=(InsetGraphicsParams const &
 }
 
 
-void InsetGraphicsParams::init()
+void InsetGraphicsParams::init(Buffer const * b)
 {
 	filename.erase();
 	lyxscale = 100;			// lyx scaling in percentage
@@ -80,6 +80,7 @@ void InsetGraphicsParams::init()
 	rotateOrigin.erase();		// Origin of rotation
 	special.erase();		// additional userdefined stuff
 	groupId.clear();
+	buffer_ = b;
 }
 
 
@@ -103,6 +104,8 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & params)
 	rotateOrigin = params.rotateOrigin;
 	special = params.special;
 	groupId = params.groupId;
+
+	buffer_ = params.buffer_;
 }
 
 
@@ -137,11 +140,11 @@ bool operator!=(InsetGraphicsParams const & left,
 }
 
 
-void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
+void InsetGraphicsParams::write(ostream & os) const
 {
 	// Do not write the default values
 	if (!filename.empty())
-		os << "\tfilename " << filename.outputFileName(buffer.filePath()) << '\n';
+		os << "\tfilename " << filename.outputFileName(buffer_->filePath()) << '\n';
 	if (lyxscale != 100)
 		os << "\tlyxscale " << lyxscale << '\n';
 	if (!display)
@@ -180,15 +183,14 @@ void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
 }
 
 
-bool InsetGraphicsParams::Read(Lexer & lex, string const & token,
-                               Buffer const & buf, bool allowOrigin)
+bool InsetGraphicsParams::read(Lexer & lex, string const & token, bool allowOrigin)
 {
 	if (token == "filename") {
 		lex.eatLine();
 		if (allowOrigin)
-			filename = buf.getReferencedFileName(lex.getString());
+			filename = buffer_->getReferencedFileName(lex.getString());
 		else
-			filename.set(lex.getString(), buf.filePath());
+			filename.set(lex.getString(), buffer_->filePath());
 	} else if (token == "lyxscale") {
 		lex.next();
 		lyxscale = lex.getInteger();
diff --git a/src/insets/InsetGraphicsParams.h b/src/insets/InsetGraphicsParams.h
index 1aa0b23d5b..bae4d35982 100644
--- a/src/insets/InsetGraphicsParams.h
+++ b/src/insets/InsetGraphicsParams.h
@@ -13,6 +13,7 @@
 #ifndef INSETGRAPHICSPARAMS_H
 #define INSETGRAPHICSPARAMS_H
 
+#include "insets/InsetParams.h"
 
 #include "graphics/GraphicsParams.h"
 
@@ -62,35 +63,40 @@ public:
 	std::string rotateOrigin;
 	/// any userdefined special command
 	std::string special;
+	///
+	Buffer const * buffer_;
 
 	/// Does this need to be handled specifically
 	/// in dark mode? (use by InsetInfo)
 	bool darkModeSensitive;
 
 	///
-	InsetGraphicsParams();
+	InsetGraphicsParams(Buffer const * b);
 	///
 	InsetGraphicsParams(InsetGraphicsParams const &);
 	///
 	InsetGraphicsParams & operator=(InsetGraphicsParams const &);
 	/// Save the parameters in the LyX format stream.
 	/// Buffer is needed to figure out if a figure is embedded.
-	void Write(std::ostream & os, Buffer const & buf) const;
+	void write(std::ostream & os) const;
 	/// If the token belongs to our parameters, read it.
-	bool Read(Lexer & lex, std::string const & token, Buffer const & buf,
-	          bool allowOrigin);
+	bool read(Lexer & lex, std::string const & token, bool allowOrigin);
 	/// convert
 	// Only a subset of InsetGraphicsParams is needed for display purposes.
 	// This function also interrogates lyxrc to ascertain whether
 	// to display or not.
 	graphics::Params as_grfxParams() const;
+	///
+	Buffer const * buffer() { return buffer_; }
+	///
+	void setBuffer(Buffer const * b) { buffer_ = b; }
 
 	// FIXME UNICODE. Write functions need to use odostream instead of ostream firstly.
 	/// Identification of the graphics template. No template equals empty string.
 	std::string groupId;
 private:
 	/// Initialize the object to a default status.
-	void init();
+	void init(Buffer const * b);
 	/// Copy the other objects content to us, used in copy c-tor and assignment
 	void copy(InsetGraphicsParams const & params);
 };
diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp
index 819d8ff62e..dc321d6e4b 100644
--- a/src/insets/InsetInfo.cpp
+++ b/src/insets/InsetInfo.cpp
@@ -1073,7 +1073,7 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype, bool cons
 			}
 		}
 		InsetGraphics * inset = new InsetGraphics(buffer_);
-		InsetGraphicsParams igp;
+		InsetGraphicsParams igp(buffer_);
 		igp.filename = file;
 		igp.lyxscale = percent_scale;
 		igp.scale = string();
-- 
2.28.0.windows.1

-------------- next part --------------
From 9d0aaf5b2ca4c821243234fa684a996ece564d16 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Mon, 21 Dec 2020 17:30:34 +0200
Subject: [PATCH 3/7] Refactor `params2string` -> `toString`

Move `params2string` static methods of Insets into `toString`
methods of InsetParams.
---
 src/BufferView.cpp                   |  2 +-
 src/Text3.cpp                        |  8 ++--
 src/frontends/qt/FloatPlacement.cpp  |  2 +-
 src/frontends/qt/GuiBibitem.cpp      |  2 +-
 src/frontends/qt/GuiBibtex.cpp       |  2 +-
 src/frontends/qt/GuiBox.cpp          |  2 +-
 src/frontends/qt/GuiBranch.cpp       |  2 +-
 src/frontends/qt/GuiCitation.cpp     |  2 +-
 src/frontends/qt/GuiCounter.cpp      |  2 +-
 src/frontends/qt/GuiExternal.cpp     |  2 +-
 src/frontends/qt/GuiGraphics.cpp     |  2 +-
 src/frontends/qt/GuiHSpace.cpp       |  2 +-
 src/frontends/qt/GuiHyperlink.cpp    |  2 +-
 src/frontends/qt/GuiInclude.cpp      |  2 +-
 src/frontends/qt/GuiIndex.cpp        |  2 +-
 src/frontends/qt/GuiLabel.cpp        |  2 +-
 src/frontends/qt/GuiLine.cpp         |  2 +-
 src/frontends/qt/GuiListings.cpp     |  2 +-
 src/frontends/qt/GuiNomenclature.cpp |  2 +-
 src/frontends/qt/GuiNote.cpp         |  2 +-
 src/frontends/qt/GuiPhantom.cpp      |  2 +-
 src/frontends/qt/GuiPrintNomencl.cpp |  2 +-
 src/frontends/qt/GuiPrintindex.cpp   |  2 +-
 src/frontends/qt/GuiRef.cpp          |  2 +-
 src/frontends/qt/GuiWrap.cpp         |  2 +-
 src/frontends/qt/Menus.cpp           |  2 +-
 src/insets/InsetBox.cpp              |  4 +-
 src/insets/InsetBox.h                |  4 +-
 src/insets/InsetBranch.cpp           |  4 +-
 src/insets/InsetBranch.h             |  4 +-
 src/insets/InsetCommand.cpp          | 63 +++++++++-------------------
 src/insets/InsetCommand.h            |  2 -
 src/insets/InsetCommandParams.cpp    | 10 +++++
 src/insets/InsetCommandParams.h      |  2 +
 src/insets/InsetExternal.cpp         |  9 ++--
 src/insets/InsetExternal.h           |  3 +-
 src/insets/InsetFloat.cpp            |  8 ++--
 src/insets/InsetFloat.h              |  4 +-
 src/insets/InsetFloatList.cpp        |  2 +-
 src/insets/InsetGraphics.cpp         | 16 ++-----
 src/insets/InsetGraphics.h           |  2 -
 src/insets/InsetGraphicsParams.cpp   | 11 +++++
 src/insets/InsetGraphicsParams.h     |  2 +
 src/insets/InsetIPAMacro.cpp         |  4 +-
 src/insets/InsetIPAMacro.h           |  4 +-
 src/insets/InsetIndex.cpp            |  8 ++--
 src/insets/InsetIndex.h              |  4 +-
 src/insets/InsetLabel.cpp            |  4 +-
 src/insets/InsetListings.cpp         | 13 +-----
 src/insets/InsetListings.h           |  2 -
 src/insets/InsetListingsParams.cpp   |  9 ++++
 src/insets/InsetListingsParams.h     |  3 ++
 src/insets/InsetNewline.cpp          |  4 +-
 src/insets/InsetNewline.h            |  4 +-
 src/insets/InsetNewpage.cpp          |  4 +-
 src/insets/InsetNewpage.h            |  4 +-
 src/insets/InsetNote.cpp             |  8 ++--
 src/insets/InsetNote.h               |  4 +-
 src/insets/InsetParams.h             |  3 ++
 src/insets/InsetPhantom.cpp          |  8 ++--
 src/insets/InsetPhantom.h            |  3 +-
 src/insets/InsetRef.cpp              |  2 +-
 src/insets/InsetScript.cpp           |  4 +-
 src/insets/InsetScript.h             |  4 +-
 src/insets/InsetSeparator.cpp        |  4 +-
 src/insets/InsetSeparator.h          |  4 +-
 src/insets/InsetSpace.cpp            |  8 ++--
 src/insets/InsetSpace.h              |  4 +-
 src/insets/InsetTOC.cpp              |  2 +-
 src/insets/InsetWrap.cpp             |  8 ++--
 src/insets/InsetWrap.h               |  5 +--
 src/mathed/InsetMathHull.cpp         |  2 +-
 src/mathed/InsetMathRef.cpp          |  4 +-
 73 files changed, 169 insertions(+), 183 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 01af7505d8..0091f13ba3 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -2122,7 +2122,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 			icp["before"] = from_utf8(opt1);
 		icp["literal"] = 
 			from_ascii(InsetCitation::last_literal ? "true" : "false");
-		string icstr = InsetCommand::params2string(icp);
+		string icstr = icp.toString();
 		FuncRequest fr(LFUN_INSET_INSERT, icstr);
 		lyx::dispatch(fr);
 		break;
diff --git a/src/Text3.cpp b/src/Text3.cpp
index cd72b26953..04272d158b 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -2009,7 +2009,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 			} else
 				p["name"] = content;
 		}
-		string const data = InsetCommand::params2string(p);
+		string const data = p.toString();
 
 		// we need to have a target. if we already have one, then
 		// that gets used at the default for the name, too, which
@@ -2029,7 +2029,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 		p["name"] = (cmd.argument().empty()) ?
 			cur.getPossibleLabel() :
 			cmd.argument();
-		string const data = InsetCommand::params2string(p);
+		string const data = p.toString();
 
 		if (cmd.argument().empty()) {
 			bv->showDialog("label", data);
@@ -2266,7 +2266,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 			cur.clearSelection();
 		} else
 			p["symbol"] = cmd.argument();
-		string const data = InsetCommand::params2string(p);
+		string const data = p.toString();
 		bv->showDialog("nomenclature", data);
 		break;
 	}
@@ -2277,7 +2277,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 			p["type"] = from_ascii("idx");
 		else
 			p["type"] = cmd.argument();
-		string const data = InsetCommand::params2string(p);
+		string const data = p.toString();
 		FuncRequest fr(LFUN_INSET_INSERT, data);
 		dispatch(cur, fr);
 		break;
diff --git a/src/frontends/qt/FloatPlacement.cpp b/src/frontends/qt/FloatPlacement.cpp
index 21d13e9c3b..4141608e4e 100644
--- a/src/frontends/qt/FloatPlacement.cpp
+++ b/src/frontends/qt/FloatPlacement.cpp
@@ -73,7 +73,7 @@ docstring FloatPlacement::dialogToParams() const
 	params.sideways = sidewaysCB->isChecked();
 	params.alignment = getAlignment();
 	params.placement = getPlacement();
-	return from_ascii(InsetFloat::params2string(params));
+	return from_ascii(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiBibitem.cpp b/src/frontends/qt/GuiBibitem.cpp
index ccbbf95b20..a0321f18c9 100644
--- a/src/frontends/qt/GuiBibitem.cpp
+++ b/src/frontends/qt/GuiBibitem.cpp
@@ -106,7 +106,7 @@ docstring GuiBibitem::dialogToParams() const
 	params["label"] = qstring_to_ucs4(label);
 	params["literal"] = literalCB->isChecked()
 			? from_ascii("true") : from_ascii("false");
-	return from_utf8(InsetCommand::params2string(params));
+	return from_utf8(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiBibtex.cpp b/src/frontends/qt/GuiBibtex.cpp
index 66cff69bda..a9e0e45c55 100644
--- a/src/frontends/qt/GuiBibtex.cpp
+++ b/src/frontends/qt/GuiBibtex.cpp
@@ -637,7 +637,7 @@ bool GuiBibtex::initialiseParams(std::string const & sdata)
 
 void GuiBibtex::dispatchParams()
 {
-	std::string const lfun = InsetCommand::params2string(params_);
+	std::string const lfun = params_.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiBox.cpp b/src/frontends/qt/GuiBox.cpp
index 0d22aa7963..14cbaf7f5b 100644
--- a/src/frontends/qt/GuiBox.cpp
+++ b/src/frontends/qt/GuiBox.cpp
@@ -493,7 +493,7 @@ docstring GuiBox::dialogToParams() const
 	else
 		params.backgroundcolor = "none";
 
-	return from_ascii(InsetBox::params2string(params));
+	return from_ascii(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiBranch.cpp b/src/frontends/qt/GuiBranch.cpp
index 24b6977390..e66cff2e42 100644
--- a/src/frontends/qt/GuiBranch.cpp
+++ b/src/frontends/qt/GuiBranch.cpp
@@ -63,7 +63,7 @@ void GuiBranch::paramsToDialog(Inset const * inset)
 docstring GuiBranch::dialogToParams() const
 {
 	InsetBranchParams params(qstring_to_ucs4(branchCO->currentText()), invertedCB->isChecked());
-	return from_utf8(InsetBranch::params2string(params));
+	return from_utf8(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiCitation.cpp b/src/frontends/qt/GuiCitation.cpp
index 20b4c34dc0..b2656b132a 100644
--- a/src/frontends/qt/GuiCitation.cpp
+++ b/src/frontends/qt/GuiCitation.cpp
@@ -1058,7 +1058,7 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
 
 void GuiCitation::dispatchParams()
 {
-	std::string const lfun = InsetCommand::params2string(params_);
+	std::string const lfun = params_.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiCounter.cpp b/src/frontends/qt/GuiCounter.cpp
index 1c79725a87..6c5e9bf6e3 100644
--- a/src/frontends/qt/GuiCounter.cpp
+++ b/src/frontends/qt/GuiCounter.cpp
@@ -132,7 +132,7 @@ docstring GuiCounter::dialogToParams() const
 	params["value"] = convert<docstring>(valueSB->value());
 	params.setCmdName(fromqstr(actionCB->itemData(actionCB->currentIndex()).toString()));
 	params["lyxonly"] = from_ascii(lyxonlyXB->isChecked() ? "true" : "false");
-	return from_utf8(InsetCounter::params2string(params));
+	return from_utf8(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiExternal.cpp b/src/frontends/qt/GuiExternal.cpp
index 968f4b43ea..79531dc632 100644
--- a/src/frontends/qt/GuiExternal.cpp
+++ b/src/frontends/qt/GuiExternal.cpp
@@ -643,7 +643,7 @@ void GuiExternal::clearParams()
 
 void GuiExternal::dispatchParams()
 {
-	string const lfun = InsetExternal::params2string(params_);
+	string const lfun = params_.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiGraphics.cpp b/src/frontends/qt/GuiGraphics.cpp
index 1501edf18e..22aef69f9a 100644
--- a/src/frontends/qt/GuiGraphics.cpp
+++ b/src/frontends/qt/GuiGraphics.cpp
@@ -772,7 +772,7 @@ void GuiGraphics::dispatchParams()
 {
 	InsetGraphicsParams tmp_params(params_);
 	tmp_params.setBuffer(&buffer());
-	string const lfun = InsetGraphics::params2string(tmp_params);
+	string const lfun = tmp_params.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiHSpace.cpp b/src/frontends/qt/GuiHSpace.cpp
index 64c5b3809f..a02cfa517c 100644
--- a/src/frontends/qt/GuiHSpace.cpp
+++ b/src/frontends/qt/GuiHSpace.cpp
@@ -286,7 +286,7 @@ docstring GuiHSpace::dialogToParams() const
 	} else if (item == "visible")
 		params.kind = InsetSpaceParams::VISIBLE;
 
-	return from_ascii(InsetSpace::params2string(params));
+	return from_ascii(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiHyperlink.cpp b/src/frontends/qt/GuiHyperlink.cpp
index c063ca2362..468d3dbf3c 100644
--- a/src/frontends/qt/GuiHyperlink.cpp
+++ b/src/frontends/qt/GuiHyperlink.cpp
@@ -104,7 +104,7 @@ docstring GuiHyperlink::dialogToParams() const
 	params["literal"] = literalCB->isChecked()
 			? from_ascii("true") : from_ascii("false");
 	params.setCmdName("href");
-	return from_utf8(InsetHyperlink::params2string(params));
+	return from_utf8(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiInclude.cpp b/src/frontends/qt/GuiInclude.cpp
index 3d4f3dde1b..555db0eeef 100644
--- a/src/frontends/qt/GuiInclude.cpp
+++ b/src/frontends/qt/GuiInclude.cpp
@@ -391,7 +391,7 @@ bool GuiInclude::initialiseParams(std::string const & sdata)
 
 void GuiInclude::dispatchParams()
 {
-	std::string const lfun = InsetCommand::params2string(params_);
+	std::string const lfun = params_.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiIndex.cpp b/src/frontends/qt/GuiIndex.cpp
index 6264d6a101..e23f5793b5 100644
--- a/src/frontends/qt/GuiIndex.cpp
+++ b/src/frontends/qt/GuiIndex.cpp
@@ -92,7 +92,7 @@ void GuiIndex::clearParams()
 
 void GuiIndex::dispatchParams()
 {
-	dispatch(FuncRequest(getLfun(), InsetIndex::params2string(params_)));
+	dispatch(FuncRequest(getLfun(), params_.toString()));
 }
 
 
diff --git a/src/frontends/qt/GuiLabel.cpp b/src/frontends/qt/GuiLabel.cpp
index 78d1e3fc43..102a89f1eb 100644
--- a/src/frontends/qt/GuiLabel.cpp
+++ b/src/frontends/qt/GuiLabel.cpp
@@ -54,7 +54,7 @@ docstring GuiLabel::dialogToParams() const
 {
 	InsetCommandParams params(insetCode());
 	params["name"] = qstring_to_ucs4(keywordED->text());
-	return from_utf8(InsetLabel::params2string(params));
+	return from_utf8(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiLine.cpp b/src/frontends/qt/GuiLine.cpp
index 2a8b9de2bc..139d12cc45 100644
--- a/src/frontends/qt/GuiLine.cpp
+++ b/src/frontends/qt/GuiLine.cpp
@@ -77,7 +77,7 @@ docstring GuiLine::dialogToParams() const
 	params["width"] = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
 	params["height"] = from_utf8(widgetsToLength(HeightLE, HeightUnitCO));
 	params.setCmdName("rule");
-	return from_ascii(InsetLine::params2string(params));
+	return from_ascii(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiListings.cpp b/src/frontends/qt/GuiListings.cpp
index 0b3cb24b3b..76483de160 100644
--- a/src/frontends/qt/GuiListings.cpp
+++ b/src/frontends/qt/GuiListings.cpp
@@ -690,7 +690,7 @@ void GuiListings::clearParams()
 
 void GuiListings::dispatchParams()
 {
-	string const lfun = InsetListings::params2string(params_);
+	string const lfun = params_.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiNomenclature.cpp b/src/frontends/qt/GuiNomenclature.cpp
index 92e7760abe..0d63f55b1a 100644
--- a/src/frontends/qt/GuiNomenclature.cpp
+++ b/src/frontends/qt/GuiNomenclature.cpp
@@ -61,7 +61,7 @@ docstring GuiNomenclature::dialogToParams() const
 	params["description"] = qstring_to_ucs4(description);
 	params["literal"] = literalCB->isChecked()
 			? from_ascii("true") : from_ascii("false");
-	return from_utf8(InsetNomencl::params2string(params));
+	return from_utf8(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiNote.cpp b/src/frontends/qt/GuiNote.cpp
index 59c771d55c..480f7b3f12 100644
--- a/src/frontends/qt/GuiNote.cpp
+++ b/src/frontends/qt/GuiNote.cpp
@@ -86,7 +86,7 @@ void GuiNote::clearParams()
 
 void GuiNote::dispatchParams()
 {
-	dispatch(FuncRequest(getLfun(), InsetNote::params2string(params_)));
+	dispatch(FuncRequest(getLfun(), params_.toString()));
 }
 
 
diff --git a/src/frontends/qt/GuiPhantom.cpp b/src/frontends/qt/GuiPhantom.cpp
index 62fc99036c..bcc8ee6d4f 100644
--- a/src/frontends/qt/GuiPhantom.cpp
+++ b/src/frontends/qt/GuiPhantom.cpp
@@ -85,7 +85,7 @@ void GuiPhantom::clearParams()
 
 void GuiPhantom::dispatchParams()
 {
-	dispatch(FuncRequest(getLfun(), InsetPhantom::params2string(params_)));
+	dispatch(FuncRequest(getLfun(), params_.toString()));
 }
 
 
diff --git a/src/frontends/qt/GuiPrintNomencl.cpp b/src/frontends/qt/GuiPrintNomencl.cpp
index a70a9e091c..8ea61cfdcc 100644
--- a/src/frontends/qt/GuiPrintNomencl.cpp
+++ b/src/frontends/qt/GuiPrintNomencl.cpp
@@ -86,7 +86,7 @@ docstring GuiPrintNomencl::dialogToParams() const
 	if (set_width == from_ascii("custom"))
 		width = from_utf8(widgetsToLength(valueLE, unitLC));
 	params["width"] = width;
-	return from_ascii(InsetNomencl::params2string(params));
+	return from_ascii(params.toString());
 }
 
 
diff --git a/src/frontends/qt/GuiPrintindex.cpp b/src/frontends/qt/GuiPrintindex.cpp
index b618287ae1..0607182335 100644
--- a/src/frontends/qt/GuiPrintindex.cpp
+++ b/src/frontends/qt/GuiPrintindex.cpp
@@ -126,7 +126,7 @@ bool GuiPrintindex::initialiseParams(string const & sdata)
 
 void GuiPrintindex::dispatchParams()
 {
-	std::string const lfun = InsetCommand::params2string(params_);
+	std::string const lfun = params_.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiRef.cpp b/src/frontends/qt/GuiRef.cpp
index f16c6565a6..39f97eab27 100644
--- a/src/frontends/qt/GuiRef.cpp
+++ b/src/frontends/qt/GuiRef.cpp
@@ -613,7 +613,7 @@ bool GuiRef::initialiseParams(std::string const & sdata)
 
 void GuiRef::dispatchParams()
 {
-	std::string const lfun = InsetCommand::params2string(params_);
+	std::string const lfun = params_.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/GuiWrap.cpp b/src/frontends/qt/GuiWrap.cpp
index 0f66cf0758..8ecacbbe5a 100644
--- a/src/frontends/qt/GuiWrap.cpp
+++ b/src/frontends/qt/GuiWrap.cpp
@@ -201,7 +201,7 @@ void GuiWrap::clearParams()
 
 void GuiWrap::dispatchParams()
 {
-	string const lfun = InsetWrap::params2string(params_);
+	string const lfun = params_.toString();
 	dispatch(FuncRequest(getLfun(), lfun));
 }
 
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index 266fb68d30..584f22f5a1 100644
--- a/src/frontends/qt/Menus.cpp
+++ b/src/frontends/qt/Menus.cpp
@@ -1563,7 +1563,7 @@ void MenuDefinition::expandIndicesContext(Buffer const * buf, bool listof)
 		if (listof) {
 			InsetCommandParams p(INDEX_PRINT_CODE);
 			p["type"] = cit->shortcut();
-			string const data = InsetCommand::params2string(p);
+			string const data = p.toString();
 			addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cit->index()),
 					   FuncRequest(LFUN_INSET_MODIFY, data)));
 		} else {
diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp
index 9cf0169422..60291bf62b 100644
--- a/src/insets/InsetBox.cpp
+++ b/src/insets/InsetBox.cpp
@@ -834,11 +834,11 @@ string InsetBox::contextMenuName() const
 }
 
 
-string InsetBox::params2string(InsetBoxParams const & params)
+string InsetBoxParams::toString() const
 {
 	ostringstream data;
 	data << "box" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetBox.h b/src/insets/InsetBox.h
index a0a2334df9..6cc0db6bf3 100644
--- a/src/insets/InsetBox.h
+++ b/src/insets/InsetBox.h
@@ -30,6 +30,8 @@ public:
 	void write(std::ostream & os) const override;
 	///
 	void read(Lexer & lex) override;
+	///
+	std::string toString() const override;
 
 	///
 	std::string type;
@@ -92,8 +94,6 @@ public:
 	///
 	InsetBox(Buffer *, std::string const &);
 
-	///
-	static std::string params2string(InsetBoxParams const &);
 	///
 	static void string2params(std::string const &, InsetBoxParams &);
 	///
diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index c0d6bd31e2..baa6c58768 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -387,10 +387,10 @@ bool InsetBranch::isMacroScope() const
 }
 
 
-string InsetBranch::params2string(InsetBranchParams const & params)
+string InsetBranchParams::toString() const
 {
 	ostringstream data;
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h
index fdde0a1816..87eb71ff91 100644
--- a/src/insets/InsetBranch.h
+++ b/src/insets/InsetBranch.h
@@ -28,6 +28,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+	///
 	docstring branch;
 	///
 	bool inverted;
@@ -48,8 +50,6 @@ public:
 	///
 	InsetBranch(Buffer *, InsetBranchParams const &);
 
-	///
-	static std::string params2string(InsetBranchParams const &);
 	///
 	static void string2params(std::string const &, InsetBranchParams &);
 	///
diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp
index c4b5f1d9bf..755e06fd7c 100644
--- a/src/insets/InsetCommand.cpp
+++ b/src/insets/InsetCommand.cpp
@@ -195,7 +195,7 @@ void InsetCommand::changeCmdName(string const & new_name)
 		InsetCommandParams p(p_.code());
 		p = p_;
 		p.setCmdName(new_name);
-		string const data = InsetCommand::params2string(p);
+		string const data = p.toString();
 		lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
 		lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD));
 	} else
@@ -223,7 +223,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
 			if (buffer().masterParams().track_changes) {
 				// With change tracking, we insert a new inset and
 				// delete the old one
-				string const data = InsetCommand::params2string(p);
+				string const data = p.toString();
 				lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
 				lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD));
 			} else
@@ -238,7 +238,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
 
 	case LFUN_INSET_DIALOG_UPDATE: {
 		string const name = to_utf8(cmd.argument());
-		cur.bv().updateDialog(name, params2string(params()));
+		cur.bv().updateDialog(name, params().toString());
 		break;
 	}
 
@@ -288,7 +288,7 @@ string InsetCommand::contextMenuName() const
 bool InsetCommand::showInsetDialog(BufferView * bv) const
 {
 	if (p_.code() != NO_CODE)
-		bv->showDialog(insetName(p_.code()), params2string(p_),
+		bv->showDialog(insetName(p_.code()), p_.toString(),
 			const_cast<InsetCommand *>(this));
 	return true;
 }
@@ -317,16 +317,6 @@ bool InsetCommand::string2params(string const & data,
 }
 
 
-string InsetCommand::params2string(InsetCommandParams const & params)
-{
-	ostringstream data;
-	data << insetName(params.code()) << ' ';
-	params.write(data);
-	data << "\\end_inset\n";
-	return data.str();
-}
-
-
 bool decodeInsetParam(string const & name, string & data,
 	Buffer const & buffer)
 {
@@ -343,8 +333,7 @@ bool decodeInsetParam(string const & name, string & data,
 	case TOC_CODE:
 	case HYPERLINK_CODE:
 	case COUNTER_CODE: {
-		InsetCommandParams p(code);
-		data = InsetCommand::params2string(p);
+		data = InsetCommandParams(code).toString();
 		break;
 	}
 	case INCLUDE_CODE: {
@@ -353,24 +342,20 @@ bool decodeInsetParam(string const & name, string & data,
 		if (data.empty())
 			// default type is requested
 			data = "include";
-		InsetCommandParams p(INCLUDE_CODE, data);
-		data = InsetCommand::params2string(p);
+		data = InsetCommandParams(INCLUDE_CODE, data).toString();
 		break;
 	}
 	case BOX_CODE: {
 		// \c data == "Boxed" || "Frameless" etc
-		InsetBoxParams p(data);
-		data = InsetBox::params2string(p);
+		data = InsetBoxParams(data).toString();
 		break;
 	}
 	case BRANCH_CODE: {
-		InsetBranchParams p;
-		data = InsetBranch::params2string(p);
+		data = InsetBranchParams().toString();
 		break;
 	}
 	case CITE_CODE: {
-		InsetCommandParams p(CITE_CODE);
-		data = InsetCommand::params2string(p);
+		data = InsetCommandParams(CITE_CODE).toString();
 		break;
 	}
 	case ERT_CODE: {
@@ -378,48 +363,39 @@ bool decodeInsetParam(string const & name, string & data,
 		break;
 	}
 	case EXTERNAL_CODE: {
-		InsetExternalParams p(&buffer);
-		data = InsetExternal::params2string(p);
+		data = InsetExternalParams(&buffer).toString();
 		break;
 	}
 	case FLOAT_CODE:  {
-		InsetFloatParams p;
-		data = InsetFloat::params2string(p);
+		data = InsetFloatParams().toString();
 		break;
 	}
 	case INDEX_CODE: {
-		InsetIndexParams p;
-		data = InsetIndex::params2string(p);
+		data = InsetIndexParams().toString();
 		break;
 	}
 	case LISTINGS_CODE: {
-		InsetListingsParams p;
-		data = InsetListings::params2string(p);
+		data = InsetListingsParams().toString();
 		break;
 	}
 	case GRAPHICS_CODE: {
-		InsetGraphicsParams p(&buffer);
-		data = InsetGraphics::params2string(p);
+		data = InsetGraphicsParams(&buffer).toString();
 		break;
 	}
 	case MATH_SPACE_CODE: {
-		InsetSpaceParams p(true);
-		data = InsetSpace::params2string(p);
+		data = InsetSpaceParams(true).toString();
 		break;
 	}
 	case NOTE_CODE: {
-		InsetNoteParams p;
-		data = InsetNote::params2string(p);
+		data = InsetNoteParams().toString();
 		break;
 	}
 	case PHANTOM_CODE: {
-		InsetPhantomParams p;
-		data = InsetPhantom::params2string(p);
+		data = InsetPhantomParams().toString();
 		break;
 	}
 	case SPACE_CODE: {
-		InsetSpaceParams p;
-		data = InsetSpace::params2string(p);
+		data = InsetSpaceParams().toString();
 		break;
 	}
 	case VSPACE_CODE: {
@@ -428,8 +404,7 @@ bool decodeInsetParam(string const & name, string & data,
 		break;
 	}
 	case WRAP_CODE: {
-		InsetWrapParams p;
-		data = InsetWrap::params2string(p);
+		data = InsetWrapParams().toString();
 		break;
 	}
 	default:
diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h
index 7b2b5bde08..a4c66b3d1f 100644
--- a/src/insets/InsetCommand.h
+++ b/src/insets/InsetCommand.h
@@ -51,8 +51,6 @@ public:
 	static bool string2params(std::string const & data,
 				  InsetCommandParams &);
 	///
-	static std::string params2string(InsetCommandParams const &);
-	///
 	InsetCommandParams const & params() const { return p_; }
 	///
 	void setParams(InsetCommandParams const &);
diff --git a/src/insets/InsetCommandParams.cpp b/src/insets/InsetCommandParams.cpp
index 09c9ee85a0..4ea716f9c4 100644
--- a/src/insets/InsetCommandParams.cpp
+++ b/src/insets/InsetCommandParams.cpp
@@ -604,6 +604,16 @@ docstring InsetCommandParams::getFirstNonOptParam() const
 }
 
 
+string InsetCommandParams::toString() const
+{
+	ostringstream data;
+	data << insetName(code()) << ' ';
+	write(data);
+	data << "\\end_inset\n";
+	return data.str();
+}
+
+
 docstring const & InsetCommandParams::operator[](string const & name) const
 {
 	static const docstring dummy;
diff --git a/src/insets/InsetCommandParams.h b/src/insets/InsetCommandParams.h
index 4e417ad94d..a7656dc4fc 100644
--- a/src/insets/InsetCommandParams.h
+++ b/src/insets/InsetCommandParams.h
@@ -136,6 +136,8 @@ public:
 	void write(std::ostream &) const override;
 	///
 	void Write(std::ostream & os, Buffer const * buf) const;
+	///
+	std::string toString() const override;
 	/// Build the complete LaTeX command
 	docstring getCommand(OutputParams const &) const;
 	/// Return the command name
diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp
index 1b9f8bc942..655371ee9d 100644
--- a/src/insets/InsetExternal.cpp
+++ b/src/insets/InsetExternal.cpp
@@ -478,8 +478,7 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
 	case LFUN_INSET_DIALOG_UPDATE: {
 		InsetExternalParams p(params());
 		p.setBuffer(&cur.bv().buffer());
-		cur.bv().updateDialog("external",
-			params2string(p));
+		cur.bv().updateDialog("external", p.toString());
 		break;
 	}
 
@@ -520,7 +519,7 @@ bool InsetExternal::showInsetDialog(BufferView * bv) const
 {
 	InsetExternalParams p(params());
 	p.setBuffer(&bv->buffer());
-	bv->showDialog("external", params2string(p),
+	bv->showDialog("external", p.toString(),
 		const_cast<InsetExternal *>(this));
 	return true;
 }
@@ -935,11 +934,11 @@ void InsetExternal::string2params(string const & in, InsetExternalParams & param
 }
 
 
-string InsetExternal::params2string(InsetExternalParams const & params)
+string InsetExternalParams::toString() const
 {
 	ostringstream data;
 	data << "external" << ' ';
-	params.write(data);
+	write(data);
 	data << "\\end_inset\n";
 	return data.str();
 }
diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h
index 1649802d07..8d233c80b7 100644
--- a/src/insets/InsetExternal.h
+++ b/src/insets/InsetExternal.h
@@ -53,6 +53,7 @@ public:
 
 	void write(std::ostream &) const override;
 	void read(Lexer &) override;
+	std::string toString() const override;
 
 	Buffer const * buffer() { return buffer_; }
 	void setBuffer(Buffer const * b) { buffer_ = b; }
@@ -105,8 +106,6 @@ public:
 	///
 	static void string2params(std::string const &, InsetExternalParams &);
 	///
-	static std::string params2string(InsetExternalParams const &);
-	///
 	InsetExternalParams const & params() const;
 	///
 	void setParams(InsetExternalParams const &);
diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp
index 7068b0ab07..c15c63ce22 100644
--- a/src/insets/InsetFloat.cpp
+++ b/src/insets/InsetFloat.cpp
@@ -189,7 +189,7 @@ void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
 	}
 
 	case LFUN_INSET_DIALOG_UPDATE: {
-		cur.bv().updateDialog("float", params2string(params()));
+		cur.bv().updateDialog("float", params().toString());
 		break;
 	}
 
@@ -281,7 +281,7 @@ void InsetFloatParams::write(ostream & os) const
 {
 	if (type.empty()) {
 		// Better this than creating a parse error. This in fact happens in the
-		// parameters dialog via InsetFloatParams::params2string.
+		// parameters dialog via InsetFloatParams::toString.
 		os << "senseless" << '\n';
 	} else
 		os << type << '\n';
@@ -967,10 +967,10 @@ void InsetFloat::string2params(string const & in, InsetFloatParams & params)
 }
 
 
-string InsetFloat::params2string(InsetFloatParams const & params)
+string InsetFloatParams::toString() const
 {
 	ostringstream data;
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h
index daa5b3181d..9a043b5bab 100644
--- a/src/insets/InsetFloat.h
+++ b/src/insets/InsetFloat.h
@@ -32,6 +32,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+	///
 	std::string type;
 	///
 	std::string placement;
@@ -61,8 +63,6 @@ public:
 	///
 	static void string2params(std::string const &, InsetFloatParams &);
 	///
-	static std::string params2string(InsetFloatParams const &);
-	///
 	void setWide(bool w, bool update_label = true);
 	///
 	void setSideways(bool s, bool update_label = true);
diff --git a/src/insets/InsetFloatList.cpp b/src/insets/InsetFloatList.cpp
index e711feebf4..d5ff6cd604 100644
--- a/src/insets/InsetFloatList.cpp
+++ b/src/insets/InsetFloatList.cpp
@@ -87,7 +87,7 @@ void InsetFloatList::doDispatch(Cursor & cur, FuncRequest & cmd) {
 	switch (cmd.action()) {
 	case LFUN_MOUSE_RELEASE:
 		if (!cur.selection() && cmd.button() == mouse_button::button1) {
-			cur.bv().showDialog("toc", params2string(params()));
+			cur.bv().showDialog("toc", params().toString());
 			cur.dispatched();
 		}
 		break;
diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp
index 8d56fc9f1c..14f303c1a5 100644
--- a/src/insets/InsetGraphics.cpp
+++ b/src/insets/InsetGraphics.cpp
@@ -243,7 +243,7 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
 	case LFUN_INSET_DIALOG_UPDATE: {
 		InsetGraphicsParams p(params());
 		p.setBuffer(&buffer());
-		cur.bv().updateDialog("graphics", params2string(p));
+		cur.bv().updateDialog("graphics", p.toString());
 		break;
 	}
 
@@ -283,7 +283,7 @@ bool InsetGraphics::showInsetDialog(BufferView * bv) const
 {
 	InsetGraphicsParams p(params());
 	p.setBuffer(&bv->buffer());
-	bv->showDialog("graphics", params2string(p),
+	bv->showDialog("graphics", p.toString(),
 		const_cast<InsetGraphics *>(this));
 	return true;
 }
@@ -1178,16 +1178,6 @@ void InsetGraphics::string2params(string const & in, InsetGraphicsParams & param
 }
 
 
-string InsetGraphics::params2string(InsetGraphicsParams const & params)
-{
-	ostringstream data;
-	data << "graphics" << ' ';
-	params.write(data);
-	data << "\\end_inset\n";
-	return data.str();
-}
-
-
 docstring InsetGraphics::toolTip(BufferView const &, int, int) const
 {
 	return from_utf8(params().filename.onlyFileName());
@@ -1237,7 +1227,7 @@ string getGroupParams(Buffer const & b, string const & groupId)
 			InsetGraphicsParams tmp = inspar;
 			tmp.setBuffer(&b);
 			tmp.filename.erase();
-			return InsetGraphics::params2string(tmp);
+			return tmp.toString();
 		}
 	}
 	return string();
diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h
index 151e4313f2..a597ca31e9 100644
--- a/src/insets/InsetGraphics.h
+++ b/src/insets/InsetGraphics.h
@@ -41,8 +41,6 @@ public:
 	///
 	static void string2params(std::string const & data,
 				  InsetGraphicsParams &);
-	///
-	static std::string params2string(InsetGraphicsParams const &);
 
 	/** Set the inset parameters, used by the GUIndependent dialog.
 	    Return true of new params are different from what was so far.
diff --git a/src/insets/InsetGraphicsParams.cpp b/src/insets/InsetGraphicsParams.cpp
index a33ef66103..c4de633552 100644
--- a/src/insets/InsetGraphicsParams.cpp
+++ b/src/insets/InsetGraphicsParams.cpp
@@ -28,6 +28,7 @@
 #include "support/Translator.h"
 
 #include <ostream>
+#include <sstream>
 
 using namespace std;
 using namespace lyx::support;
@@ -253,6 +254,16 @@ bool InsetGraphicsParams::read(Lexer & lex, string const & token, bool allowOrig
 }
 
 
+string InsetGraphicsParams::toString() const
+{
+	ostringstream data;
+	data << "graphics" << ' ';
+	write(data);
+	data << "\\end_inset\n";
+	return data.str();
+}
+
+
 graphics::Params InsetGraphicsParams::as_grfxParams() const
 {
 	graphics::Params pars;
diff --git a/src/insets/InsetGraphicsParams.h b/src/insets/InsetGraphicsParams.h
index bae4d35982..be3fae8a14 100644
--- a/src/insets/InsetGraphicsParams.h
+++ b/src/insets/InsetGraphicsParams.h
@@ -81,6 +81,8 @@ public:
 	void write(std::ostream & os) const;
 	/// If the token belongs to our parameters, read it.
 	bool read(Lexer & lex, std::string const & token, bool allowOrigin);
+	///
+	std::string toString() const;
 	/// convert
 	// Only a subset of InsetGraphicsParams is needed for display purposes.
 	// This function also interrogates lyxrc to ascertain whether
diff --git a/src/insets/InsetIPAMacro.cpp b/src/insets/InsetIPAMacro.cpp
index 5d2035b559..1da5e29599 100644
--- a/src/insets/InsetIPAMacro.cpp
+++ b/src/insets/InsetIPAMacro.cpp
@@ -340,11 +340,11 @@ docstring InsetIPADeco::toolTip(BufferView const &, int, int) const
 }
 
 
-string InsetIPADeco::params2string(InsetIPADecoParams const & params)
+string InsetIPADecoParams::toString() const
 {
 	ostringstream data;
 	data << "IPADeco" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetIPAMacro.h b/src/insets/InsetIPAMacro.h
index 432bb5a897..41dd3bf405 100644
--- a/src/insets/InsetIPAMacro.h
+++ b/src/insets/InsetIPAMacro.h
@@ -35,6 +35,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+	///
 	Type type;
 };
 
@@ -53,8 +55,6 @@ public:
 	///
 	~InsetIPADeco();
 	///
-	static std::string params2string(InsetIPADecoParams const &);
-	///
 	static void string2params(std::string const &, InsetIPADecoParams &);
 	///
 	InsetIPADecoParams const & params() const { return params_; }
diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp
index 149ef6506a..4deae0eba3 100644
--- a/src/insets/InsetIndex.cpp
+++ b/src/insets/InsetIndex.cpp
@@ -384,7 +384,7 @@ docstring InsetIndex::xhtml(XMLStream & xs, OutputParams const &) const
 
 bool InsetIndex::showInsetDialog(BufferView * bv) const
 {
-	bv->showDialog("index", params2string(params_),
+	bv->showDialog("index", params_.toString(),
 			const_cast<InsetIndex *>(this));
 	return true;
 }
@@ -411,7 +411,7 @@ void InsetIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 	}
 
 	case LFUN_INSET_DIALOG_UPDATE:
-		cur.bv().updateDialog("index", params2string(params_));
+		cur.bv().updateDialog("index", params_.toString());
 		break;
 
 	default:
@@ -520,11 +520,11 @@ void InsetIndex::read(Lexer & lex)
 }
 
 
-string InsetIndex::params2string(InsetIndexParams const & params)
+string InsetIndexParams::toString() const
 {
 	ostringstream data;
 	data << "index";
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h
index b2038536f2..c2f23a610c 100644
--- a/src/insets/InsetIndex.h
+++ b/src/insets/InsetIndex.h
@@ -29,6 +29,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+
 	docstring index;
 };
 
@@ -40,8 +42,6 @@ public:
 	///
 	InsetIndex(Buffer *, InsetIndexParams const &);
 	///
-	static std::string params2string(InsetIndexParams const &);
-	///
 	static void string2params(std::string const &, InsetIndexParams &);
 private:
 	///
diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp
index 2c0c1e5194..910c08682c 100644
--- a/src/insets/InsetLabel.cpp
+++ b/src/insets/InsetLabel.cpp
@@ -104,7 +104,7 @@ void InsetLabel::updateLabelAndRefs(docstring const & new_label,
 		// delete the old one
 		InsetCommandParams p(LABEL_CODE, "label");
 		p["name"] = label;
-		string const data = InsetCommand::params2string(p);
+		string const data = p.toString();
 		lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
 		lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD));
 	} else
@@ -294,7 +294,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
 	case LFUN_LABEL_INSERT_AS_REFERENCE: {
 		InsetCommandParams p(REF_CODE, "ref");
 		p["reference"] = getParam("name");
-		string const data = InsetCommand::params2string(p);
+		string const data = p.toString();
 		lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
 		break;
 	}
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
index 51763d40af..c99e4c512d 100644
--- a/src/insets/InsetListings.cpp
+++ b/src/insets/InsetListings.cpp
@@ -569,7 +569,7 @@ void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd)
 	}
 
 	case LFUN_INSET_DIALOG_UPDATE:
-		cur.bv().updateDialog("listings", params2string(params()));
+		cur.bv().updateDialog("listings", params().toString());
 		break;
 
 	default:
@@ -635,7 +635,7 @@ void InsetListings::validate(LaTeXFeatures & features) const
 
 bool InsetListings::showInsetDialog(BufferView * bv) const
 {
-	bv->showDialog("listings", params2string(params()),
+	bv->showDialog("listings", params().toString(),
 		const_cast<InsetListings *>(this));
 	return true;
 }
@@ -700,13 +700,4 @@ void InsetListings::string2params(string const & in,
 }
 
 
-string InsetListings::params2string(InsetListingsParams const & params)
-{
-	ostringstream data;
-	data << "listings" << ' ';
-	params.write(data);
-	return data.str();
-}
-
-
 } // namespace lyx
diff --git a/src/insets/InsetListings.h b/src/insets/InsetListings.h
index 1a80078645..cc65ef14a6 100644
--- a/src/insets/InsetListings.h
+++ b/src/insets/InsetListings.h
@@ -36,8 +36,6 @@ public:
 	~InsetListings();
 	///
 	static void string2params(std::string const &, InsetListingsParams &);
-	///
-	static std::string params2string(InsetListingsParams const &);
 private:
 	///
 	bool isLabeled() const override { return true; }
diff --git a/src/insets/InsetListingsParams.cpp b/src/insets/InsetListingsParams.cpp
index 8ffb438797..ab8a0573c3 100644
--- a/src/insets/InsetListingsParams.cpp
+++ b/src/insets/InsetListingsParams.cpp
@@ -1006,6 +1006,15 @@ void InsetListingsParams::read(Lexer & lex)
 }
 
 
+string InsetListingsParams::toString() const
+{
+	ostringstream data;
+	data << "listings" << ' ';
+	write(data);
+	return data.str();
+}
+
+
 string InsetListingsParams::params(string const & sep) const
 {
 	string par;
diff --git a/src/insets/InsetListingsParams.h b/src/insets/InsetListingsParams.h
index 7497110738..6f008b8865 100644
--- a/src/insets/InsetListingsParams.h
+++ b/src/insets/InsetListingsParams.h
@@ -33,6 +33,9 @@ public:
 	/// read parameters from an ostream
 	void read(Lexer &) override;
 
+	///
+	std::string toString() const override;
+
 	/// valid parameter string
 	std::string params(std::string const & sep=",") const;
 
diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp
index f5fcd42ac6..983457dd53 100644
--- a/src/insets/InsetNewline.cpp
+++ b/src/insets/InsetNewline.cpp
@@ -281,11 +281,11 @@ void InsetNewline::string2params(string const & in, InsetNewlineParams & params)
 }
 
 
-string InsetNewline::params2string(InsetNewlineParams const & params)
+string InsetNewlineParams::toString() const
 {
 	ostringstream data;
 	data << "newline" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h
index 10f894d1e6..82667f5240 100644
--- a/src/insets/InsetNewline.h
+++ b/src/insets/InsetNewline.h
@@ -34,6 +34,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+	///
 	Kind kind;
 };
 
@@ -50,8 +52,6 @@ public:
 	RowFlags rowFlags() const override { return BreakAfter | RowAfter; }
 	///
 	static void string2params(std::string const &, InsetNewlineParams &);
-	///
-	static std::string params2string(InsetNewlineParams const &);
 private:
 	///
 	InsetCode lyxCode() const override { return NEWLINE_CODE; }
diff --git a/src/insets/InsetNewpage.cpp b/src/insets/InsetNewpage.cpp
index da94452632..6ab41fa3ce 100644
--- a/src/insets/InsetNewpage.cpp
+++ b/src/insets/InsetNewpage.cpp
@@ -351,11 +351,11 @@ void InsetNewpage::string2params(string const & in, InsetNewpageParams & params)
 }
 
 
-string InsetNewpage::params2string(InsetNewpageParams const & params)
+string InsetNewpageParams::toString() const
 {
 	ostringstream data;
 	data << "newpage" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetNewpage.h b/src/insets/InsetNewpage.h
index 633b81ffd7..55df6b8b96 100644
--- a/src/insets/InsetNewpage.h
+++ b/src/insets/InsetNewpage.h
@@ -40,6 +40,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+	///
 	Kind kind;
 };
 
@@ -53,8 +55,6 @@ public:
 	explicit InsetNewpage(InsetNewpageParams const & par);
 	///
 	static void string2params(std::string const &, InsetNewpageParams &);
-	///
-	static std::string params2string(InsetNewpageParams const &);
 private:
 	///
 	InsetCode lyxCode() const override { return NEWPAGE_CODE; }
diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp
index 28d8db18e5..c2ab7e003f 100644
--- a/src/insets/InsetNote.cpp
+++ b/src/insets/InsetNote.cpp
@@ -129,7 +129,7 @@ void InsetNote::read(Lexer & lex)
 
 bool InsetNote::showInsetDialog(BufferView * bv) const
 {
-	bv->showDialog("note", params2string(params()),
+	bv->showDialog("note", params().toString(),
 		const_cast<InsetNote *>(this));
 	return true;
 }
@@ -161,7 +161,7 @@ void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
 	}
 
 	case LFUN_INSET_DIALOG_UPDATE:
-		cur.bv().updateDialog("note", params2string(params()));
+		cur.bv().updateDialog("note", params().toString());
 		break;
 
 	default:
@@ -338,11 +338,11 @@ FontInfo InsetNote::getFont() const
 }
 
 
-string InsetNote::params2string(InsetNoteParams const & params)
+string InsetNoteParams::toString() const
 {
 	ostringstream data;
 	data << "note" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h
index bf14e14758..eb99a139e0 100644
--- a/src/insets/InsetNote.h
+++ b/src/insets/InsetNote.h
@@ -32,6 +32,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+
 	Type type;
 };
 
@@ -51,8 +53,6 @@ public:
 	///
 	~InsetNote();
 	///
-	static std::string params2string(InsetNoteParams const &);
-	///
 	static void string2params(std::string const &, InsetNoteParams &);
 	///
 	InsetNoteParams const & params() const { return params_; }
diff --git a/src/insets/InsetParams.h b/src/insets/InsetParams.h
index 0d7060317a..81866cb33a 100644
--- a/src/insets/InsetParams.h
+++ b/src/insets/InsetParams.h
@@ -13,6 +13,7 @@
 #define INSETPARAMS_H
 
 #include <ostream>
+#include <string>
 
 namespace lyx {
 
@@ -28,6 +29,8 @@ public:
 	virtual void write(std::ostream & os) const = 0;
 	///
 	virtual void read(Lexer & lex) = 0;
+	///
+	virtual std::string toString() const = 0;
 };
 
 
diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp
index d1a25f6a70..61d41ca2b2 100644
--- a/src/insets/InsetPhantom.cpp
+++ b/src/insets/InsetPhantom.cpp
@@ -238,7 +238,7 @@ void InsetPhantom::setButtonLabel()
 
 bool InsetPhantom::showInsetDialog(BufferView * bv) const
 {
-	bv->showDialog("phantom", params2string(params()),
+	bv->showDialog("phantom", params().toString(),
 		const_cast<InsetPhantom *>(this));
 	return true;
 }
@@ -256,7 +256,7 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
 		break;
 
 	case LFUN_INSET_DIALOG_UPDATE:
-		cur.bv().updateDialog("phantom", params2string(params()));
+		cur.bv().updateDialog("phantom", params().toString());
 		break;
 
 	default:
@@ -362,11 +362,11 @@ string InsetPhantom::contextMenuName() const
 }
 
 
-string InsetPhantom::params2string(InsetPhantomParams const & params)
+string InsetPhantomParams::toString() const
 {
 	ostringstream data;
 	data << "phantom" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetPhantom.h b/src/insets/InsetPhantom.h
index 2ca9b05622..4d31099b03 100644
--- a/src/insets/InsetPhantom.h
+++ b/src/insets/InsetPhantom.h
@@ -32,6 +32,7 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
 	Type type;
 };
 
@@ -51,8 +52,6 @@ public:
 	///
 	~InsetPhantom();
 	///
-	static std::string params2string(InsetPhantomParams const &);
-	///
 	static void string2params(std::string const &, InsetPhantomParams &);
 	///
 	InsetPhantomParams const & params() const { return params_; }
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index 200f5e5b72..9c76a64d2f 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -92,7 +92,7 @@ void InsetRef::changeTarget(docstring const & new_label)
 	if (buffer().masterParams().track_changes) {
 		InsetCommandParams icp(REF_CODE, "ref");
 		icp["reference"] = new_label;
-		string const data = InsetCommand::params2string(icp);
+		string const data = icp.toString();
 		lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
 		lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD));
 	} else
diff --git a/src/insets/InsetScript.cpp b/src/insets/InsetScript.cpp
index c1f8da1e82..4a9ed85ee8 100644
--- a/src/insets/InsetScript.cpp
+++ b/src/insets/InsetScript.cpp
@@ -378,11 +378,11 @@ string InsetScript::contextMenuName() const
 }
 
 
-string InsetScript::params2string(InsetScriptParams const & params)
+string InsetScriptParams::toString() const
 {
 	ostringstream data;
 	data << "script ";
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetScript.h b/src/insets/InsetScript.h
index e4a9da7621..516f40fc14 100644
--- a/src/insets/InsetScript.h
+++ b/src/insets/InsetScript.h
@@ -32,6 +32,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+	///
 	int shift(FontInfo const & font) const;
 	///
 	Type type;
@@ -55,8 +57,6 @@ public:
 	///
 	~InsetScript();
 	///
-	static std::string params2string(InsetScriptParams const &);
-	///
 	static void string2params(std::string const &, InsetScriptParams &);
 	///
 	InsetScriptParams const & params() const { return params_; }
diff --git a/src/insets/InsetSeparator.cpp b/src/insets/InsetSeparator.cpp
index 218172c87a..5d6b71f734 100644
--- a/src/insets/InsetSeparator.cpp
+++ b/src/insets/InsetSeparator.cpp
@@ -302,11 +302,11 @@ void InsetSeparator::string2params(string const & in, InsetSeparatorParams & par
 }
 
 
-string InsetSeparator::params2string(InsetSeparatorParams const & params)
+string InsetSeparatorParams::toString() const
 {
 	ostringstream data;
 	data << "separator" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetSeparator.h b/src/insets/InsetSeparator.h
index 212d3894b4..b930a2ada2 100644
--- a/src/insets/InsetSeparator.h
+++ b/src/insets/InsetSeparator.h
@@ -33,6 +33,8 @@ public:
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+
 	Kind kind;
 };
 
@@ -46,8 +48,6 @@ public:
 	explicit InsetSeparator(InsetSeparatorParams const & params);
 	///
 	static void string2params(std::string const &, InsetSeparatorParams &);
-	///
-	static std::string params2string(InsetSeparatorParams const &);
 	/// To be used in combination with inset-forall
 	/// Here's a command that removes every latexpar separator:
 	///   inset-forall Separator:latexpar char-delete-forward
diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp
index 2deea3097e..4f9ba96e59 100644
--- a/src/insets/InsetSpace.cpp
+++ b/src/insets/InsetSpace.cpp
@@ -158,7 +158,7 @@ void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
 	}
 
 	case LFUN_INSET_DIALOG_UPDATE:
-		cur.bv().updateDialog("space", params2string(params()));
+		cur.bv().updateDialog("space", params().toString());
 		break;
 
 	default:
@@ -946,13 +946,13 @@ void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
 }
 
 
-string InsetSpace::params2string(InsetSpaceParams const & params)
+string InsetSpaceParams::toString() const
 {
 	ostringstream data;
-	if (params.math)
+	if (math)
 		data << "math";
 	data << "space" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h
index a4fb63357f..44f6a5e61e 100644
--- a/src/insets/InsetSpace.h
+++ b/src/insets/InsetSpace.h
@@ -81,6 +81,8 @@ struct InsetSpaceParams : public InsetParams {
 	///
 	void read(Lexer & lex) override;
 	///
+	std::string toString() const override;
+	///
 	Kind kind;
 	///
 	GlueLength length;
@@ -108,8 +110,6 @@ public:
 	///
 	static void string2params(std::string const &, InsetSpaceParams &);
 	///
-	static std::string params2string(InsetSpaceParams const &);
-	///
 	GlueLength length() const;
 
 	///
diff --git a/src/insets/InsetTOC.cpp b/src/insets/InsetTOC.cpp
index a429d2d5bc..6302f819ad 100644
--- a/src/insets/InsetTOC.cpp
+++ b/src/insets/InsetTOC.cpp
@@ -83,7 +83,7 @@ void InsetTOC::doDispatch(Cursor & cur, FuncRequest & cmd) {
 	switch (cmd.action()) {
 	case LFUN_MOUSE_RELEASE:
 		if (!cur.selection() && cmd.button() == mouse_button::button1) {
-			cur.bv().showDialog("toc", params2string(params()));
+			cur.bv().showDialog("toc", params().toString());
 			cur.dispatched();
 		}
 		break;
diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp
index b05d5dba47..bb3c044304 100644
--- a/src/insets/InsetWrap.cpp
+++ b/src/insets/InsetWrap.cpp
@@ -102,7 +102,7 @@ void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd)
 	}
 
 	case LFUN_INSET_DIALOG_UPDATE:
-		cur.bv().updateDialog("wrap", params2string(params()));
+		cur.bv().updateDialog("wrap", params().toString());
 		break;
 
 	default:
@@ -248,7 +248,7 @@ bool InsetWrap::insetAllowed(InsetCode code) const
 bool InsetWrap::showInsetDialog(BufferView * bv) const
 {
 	if (!InsetText::showInsetDialog(bv))
-		bv->showDialog("wrap", params2string(params()),
+		bv->showDialog("wrap", params().toString(),
 			const_cast<InsetWrap *>(this));
 	return true;
 }
@@ -268,11 +268,11 @@ void InsetWrap::string2params(string const & in, InsetWrapParams & params)
 }
 
 
-string InsetWrap::params2string(InsetWrapParams const & params)
+string InsetWrapParams::toString() const
 {
 	ostringstream data;
 	data << "wrap" << ' ';
-	params.write(data);
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetWrap.h b/src/insets/InsetWrap.h
index bbf4000820..bf65db4e58 100644
--- a/src/insets/InsetWrap.h
+++ b/src/insets/InsetWrap.h
@@ -26,7 +26,8 @@ public:
 	void write(std::ostream &) const override;
 	///
 	void read(Lexer &) override;
-
+	///
+	std::string toString() const override;
 	///
 	std::string type;
 	///
@@ -52,8 +53,6 @@ public:
 	InsetWrapParams const & params() const { return params_; }
 	///
 	static void string2params(std::string const &, InsetWrapParams &);
-	///
-	static std::string params2string(InsetWrapParams const &);
 private:
 	///
 	void setCaptionType(std::string const & type) override;
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index f0df1d90fd..9cac0f9f53 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -1881,7 +1881,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
 
 		InsetCommandParams p(LABEL_CODE);
 		p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
-		string const data = InsetCommand::params2string(p);
+		string const data = p.toString();
 
 		if (cmd.argument().empty())
 			cur.bv().showDialog("label", data);
diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp
index 9efd865ea7..0ba4a07081 100644
--- a/src/mathed/InsetMathRef.cpp
+++ b/src/mathed/InsetMathRef.cpp
@@ -213,7 +213,7 @@ string const InsetMathRef::createDialogStr() const
 	icp["reference"] = asString(cell(0));
 	if (!cell(1).empty())
 		icp["name"] = asString(cell(1));
-	return InsetCommand::params2string(icp);
+	return icp.toString();
 }
 
 
@@ -232,7 +232,7 @@ void InsetMathRef::changeTarget(docstring const & target)
 	MathData ar;
 	Buffer & buf = buffer();
 	if (createInsetMath_fromDialogStr(
-	    from_utf8(InsetCommand::params2string(icp)), ar)) {
+	    from_utf8(icp.toString()), ar)) {
 		*this = *ar[0].nucleus()->asRefInset();
 		// FIXME audit setBuffer calls
 		setBuffer(buf);
-- 
2.28.0.windows.1

-------------- next part --------------
From f11b819283d3a8ab9df2985b7a026124663fc517 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Mon, 21 Dec 2020 18:03:45 +0200
Subject: [PATCH 4/7] Implement `InsetERTParams`

---
 src/frontends/qt/GuiERT.cpp |  3 ++-
 src/insets/InsetCommand.cpp |  2 +-
 src/insets/InsetERT.cpp     | 20 ++++++++++++++++++--
 src/insets/InsetERT.h       | 19 +++++++++++++++++--
 4 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/src/frontends/qt/GuiERT.cpp b/src/frontends/qt/GuiERT.cpp
index fece83ea76..e3d792c884 100644
--- a/src/frontends/qt/GuiERT.cpp
+++ b/src/frontends/qt/GuiERT.cpp
@@ -42,7 +42,8 @@ docstring GuiERT::dialogToParams() const
 {
 	InsetCollapsible::CollapseStatus const status = openRB->isChecked()
 		? InsetCollapsible::Open : InsetCollapsible::Collapsed;
-	return from_ascii(InsetERT::params2string(status));
+	InsetERTParams params(status);
+	return from_ascii(params.toString());
 }
 
 
diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp
index 755e06fd7c..e5a789e322 100644
--- a/src/insets/InsetCommand.cpp
+++ b/src/insets/InsetCommand.cpp
@@ -359,7 +359,7 @@ bool decodeInsetParam(string const & name, string & data,
 		break;
 	}
 	case ERT_CODE: {
-		data = InsetERT::params2string(InsetCollapsible::Open);
+		data = InsetERTParams().toString();
 		break;
 	}
 	case EXTERNAL_CODE: {
diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp
index 559fef2b09..00eb1d0405 100644
--- a/src/insets/InsetERT.cpp
+++ b/src/insets/InsetERT.cpp
@@ -192,10 +192,26 @@ InsetCollapsible::CollapseStatus InsetERT::string2params(string const & in)
 }
 
 
-string InsetERT::params2string(CollapseStatus status)
+void InsetERTParams::write(ostream & os) const
+{
+	os << status_;
+}
+
+
+void InsetERTParams::read(Lexer & lex)
+{
+	lex.setContext("InsetERTParams::read");
+	int s;
+	lex >> s;
+	status_ = static_cast<CollapseStatus>(s);
+}
+
+
+string InsetERTParams::toString() const
 {
 	ostringstream data;
-	data << "ert" << ' ' << status;
+	data << "ert" << ' ';
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetERT.h b/src/insets/InsetERT.h
index 72220d07d0..57a8c4ed0e 100644
--- a/src/insets/InsetERT.h
+++ b/src/insets/InsetERT.h
@@ -17,6 +17,23 @@
 
 namespace lyx {
 
+struct InsetERTParams : public InsetParams {
+
+	typedef InsetCollapsible::CollapseStatus CollapseStatus;
+
+	explicit InsetERTParams(CollapseStatus status = CollapseStatus::Open)
+		: status_(status) {}
+	///
+	void write(std::ostream & os) const override;
+	///
+	void read(Lexer & lex) override;
+	///
+	std::string toString() const override;
+	///
+	CollapseStatus status_;
+};
+
+
 /** A collapsible text inset for LaTeX insertions.
 
   To write full ert (including styles and other insets) in a given
@@ -34,8 +51,6 @@ public:
 	InsetERT(InsetERT const & old);
 	///
 	static CollapseStatus string2params(std::string const &);
-	///
-	static std::string params2string(CollapseStatus);
 
 	std::string contextMenuName() const override
 		{ return "context-ert"; }
-- 
2.28.0.windows.1

-------------- next part --------------
From b1f2a4cbd9b97fe152532f8dbbf19a96b82a425a Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Mon, 21 Dec 2020 23:57:13 +0200
Subject: [PATCH 5/7] Implement `InsetVSpaceParams`

---
 src/frontends/qt/GuiVSpace.cpp |  5 +++--
 src/insets/InsetCommand.cpp    |  3 +--
 src/insets/InsetVSpace.cpp     | 18 ++++++++++++++++--
 src/insets/InsetVSpace.h       | 17 +++++++++++++++--
 4 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/src/frontends/qt/GuiVSpace.cpp b/src/frontends/qt/GuiVSpace.cpp
index 7163634441..49e49893a1 100644
--- a/src/frontends/qt/GuiVSpace.cpp
+++ b/src/frontends/qt/GuiVSpace.cpp
@@ -171,9 +171,10 @@ docstring GuiVSpace::dialogToParams() const
 	if (spacingCO->currentIndex() == 7 && valueLE->text().isEmpty())
 		return docstring();
 
-	VSpace const params = setVSpaceFromWidgets(spacingCO->currentIndex(),
+	VSpace const space = setVSpaceFromWidgets(spacingCO->currentIndex(),
 			valueLE, unitCO, keepCB->isChecked());
-	return from_ascii(InsetVSpace::params2string(params));
+	InsetVSpaceParams params(space);
+	return from_ascii(params.toString());
 }
 
 
diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp
index e5a789e322..a1557f35ad 100644
--- a/src/insets/InsetCommand.cpp
+++ b/src/insets/InsetCommand.cpp
@@ -399,8 +399,7 @@ bool decodeInsetParam(string const & name, string & data,
 		break;
 	}
 	case VSPACE_CODE: {
-		VSpace space;
-		data = InsetVSpace::params2string(space);
+		data = InsetVSpaceParams().toString();
 		break;
 	}
 	case WRAP_CODE: {
diff --git a/src/insets/InsetVSpace.cpp b/src/insets/InsetVSpace.cpp
index c774e98b85..a96a83c501 100644
--- a/src/insets/InsetVSpace.cpp
+++ b/src/insets/InsetVSpace.cpp
@@ -258,10 +258,24 @@ void InsetVSpace::string2params(string const & in, VSpace & vspace)
 }
 
 
-string InsetVSpace::params2string(VSpace const & vspace)
+void InsetVSpaceParams::write(ostream & os) const
+{
+	os << space_.asLyXCommand();
+}
+
+
+void InsetVSpaceParams::read(Lexer & lex)
+{
+	lex.setContext("InsetVSpaceParams::read");
+	lex >> space_;
+}
+
+
+string InsetVSpaceParams::toString() const
 {
 	ostringstream data;
-	data << "vspace" << ' ' << vspace.asLyXCommand();
+	data << "vspace" << ' ';
+	write(data);
 	return data.str();
 }
 
diff --git a/src/insets/InsetVSpace.h b/src/insets/InsetVSpace.h
index 9b95f00ff0..0022d224d8 100644
--- a/src/insets/InsetVSpace.h
+++ b/src/insets/InsetVSpace.h
@@ -18,6 +18,21 @@
 
 namespace lyx {
 
+struct InsetVSpaceParams : public InsetParams {
+
+	explicit InsetVSpaceParams(VSpace const & space = VSpace())
+		: space_(space) {}
+	///
+	void write(std::ostream & os) const override;
+	///
+	void read(Lexer & lex) override;
+	///
+	std::string toString() const override;
+	///
+	VSpace space_;
+};
+
+
 class InsetVSpace : public Inset
 {
 public:
@@ -37,8 +52,6 @@ public:
 	std::string contextMenuName() const override;
 	///
 	static void string2params(std::string const &, VSpace &);
-	///
-	static std::string params2string(VSpace const &);
 private:
 	///
 	void metrics(MetricsInfo & mi, Dimension & dim) const override;
-- 
2.28.0.windows.1



More information about the lyx-devel mailing list