diff mbox series

[v2,2/3] kernel-shark: give more space to the command field of the Record dialog

Message ID 20190918142319.11821-3-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series Support "shell quoting" in the Record dialog | expand

Commit Message

Yordan Karadzhov Sept. 18, 2019, 2:23 p.m. UTC
Since the Record dialog not support parsing of complex multi-line
commands the corresponding field of the widget has to be able to
accommodate such multi-line user input.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/src/KsCaptureDialog.cpp | 29 +++++++++++++++++++++++++---
 kernel-shark/src/KsCaptureDialog.hpp | 18 ++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark/src/KsCaptureDialog.cpp b/kernel-shark/src/KsCaptureDialog.cpp
index 7c2ef46..fff42aa 100644
--- a/kernel-shark/src/KsCaptureDialog.cpp
+++ b/kernel-shark/src/KsCaptureDialog.cpp
@@ -29,6 +29,25 @@  static inline tep_handle *local_events()
 	return tracecmd_local_events(tracecmd_get_tracing_dir());
 }
 
+/**
+ * @brief Create KsCommandLineEdit.
+ *
+ * @param text: Defaulst text to be shown.
+ * @param parent: The parent of this widget.
+ */
+KsCommandLineEdit::KsCommandLineEdit(QString text, QWidget *parent)
+: QPlainTextEdit(text, parent) {}
+
+QSize KsCommandLineEdit::minimumSizeHint() const
+{
+	return {FONT_WIDTH * 30, FONT_HEIGHT * 2};
+}
+
+QSize KsCommandLineEdit::sizeHint() const
+{
+	return {FONT_WIDTH * 30, FONT_HEIGHT * 3};
+}
+
 /** @brief Create KsCaptureControl widget. */
 KsCaptureControl::KsCaptureControl(QWidget *parent)
 : QWidget(parent),
@@ -117,7 +136,11 @@  KsCaptureControl::KsCaptureControl(QWidget *parent)
 	_commandLabel.adjustSize();
 	_commandLabel.setFixedWidth(_outputLabel.width());
 	_execLayout.addWidget(&_commandLabel, row, 0);
+
 	_commandLineEdit.setFixedWidth(FONT_WIDTH * 30);
+	_commandLineEdit.setMinimumHeight(FONT_HEIGHT * 2);
+	_commandLineEdit.setMaximumHeight(FONT_HEIGHT * 9);
+
 	_execLayout.addWidget(&_commandLineEdit, row, 1);
 	_commandCheckBox.setCheckState(Qt::Unchecked);
 	_commandCheckBox.adjustSize();
@@ -171,7 +194,7 @@  QStringList KsCaptureControl::getArgs()
 
 	argv << "-o" << outputFileName();
 
-	argv << KsUtils::splitArguments(_commandLineEdit.text());
+	argv << KsUtils::splitArguments(_commandLineEdit.toPlainText());
 
 	return argv;
 }
@@ -282,7 +305,7 @@  void KsCaptureControl::_importSettings()
 		_outputLineEdit.setText(KS_C_STR_CAST(temp->conf_doc));
 
 	if (kshark_config_doc_get(conf, "Command", temp))
-		_commandLineEdit.setText(KS_C_STR_CAST(temp->conf_doc));
+		_commandLineEdit.setPlainText(KS_C_STR_CAST(temp->conf_doc));
 }
 
 void KsCaptureControl::_exportSettings()
@@ -330,7 +353,7 @@  void KsCaptureControl::_exportSettings()
 	kshark_config_doc_add(conf, "Output", kshark_json_to_conf(jout));
 
 	/* Save the command. */
-	comm = _commandLineEdit.text();
+	comm = _commandLineEdit.toPlainText();
 	json_object *jcomm = json_object_new_string(comm.toStdString().c_str());
 	kshark_config_doc_add(conf, "Command", kshark_json_to_conf(jcomm));
 
diff --git a/kernel-shark/src/KsCaptureDialog.hpp b/kernel-shark/src/KsCaptureDialog.hpp
index f8ddf4a..612080c 100644
--- a/kernel-shark/src/KsCaptureDialog.hpp
+++ b/kernel-shark/src/KsCaptureDialog.hpp
@@ -18,6 +18,20 @@ 
 // KernelShark
 #include "KsWidgetsLib.hpp"
 
+/**
+ * The KsCommandLineEdit class is used to override the default size hints of
+ * the QPlainTextEdit class.
+ */
+struct KsCommandLineEdit : public QPlainTextEdit
+{
+	KsCommandLineEdit(QString text, QWidget *parent = 0);
+
+private:
+	QSize sizeHint() const override;
+
+	QSize minimumSizeHint() const override;
+};
+
 /**
  * The KsCaptureControl class provides a control panel for the KernelShark
  * Capture dialog.
@@ -57,7 +71,9 @@  private:
 
 	QLabel		_pluginsLabel, _outputLabel, _commandLabel;
 
-	QLineEdit	_outputLineEdit, _commandLineEdit;
+	QLineEdit	_outputLineEdit;
+
+	KsCommandLineEdit	_commandLineEdit;
 
 	QToolBar	_settingsToolBar, _controlToolBar;