kernel-shark: Add method for getting all selected events

A new method is added to the class KsEventsCheckBoxWidget. It returns
a list of strings containing all selected events. If the whole system
is selected (the top level checkbox is checked), only the name of the
system is added to the list.

Link: http://lore.kernel.org/linux-trace-devel/20190709155650.2345-3-y.karadz@gmail.com

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
[ Added space between for and '(' ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
diff --git a/kernel-shark/src/KsWidgetsLib.cpp b/kernel-shark/src/KsWidgetsLib.cpp
index ea02b5e..84afec9 100644
--- a/kernel-shark/src/KsWidgetsLib.cpp
+++ b/kernel-shark/src/KsWidgetsLib.cpp
@@ -706,6 +706,47 @@
 	_adjustSize();
 }
 
+/**
+ * @brief Get a list of all checked events. If the whole system is selected
+ *	  (the top level checkbox is checked), only the name of the system is
+ *	  added to the list.
+ *
+ * @param option: If True, "-e" is added as prefix to each element of the list.
+ *
+ * @returns A list of checked events or systems.
+ */
+QStringList KsEventsCheckBoxWidget::getCheckedEvents(bool option)
+{
+	QTreeWidgetItem *sysItem, *evtItem;
+	QStringList list;
+	QString optStr;
+	int nSys, nEvts;
+
+	if (option)
+		optStr = "-e";
+
+	nSys = _tree.topLevelItemCount();
+	for (int t = 0; t < nSys; ++t) {
+		sysItem = _tree.topLevelItem(t);
+		if (sysItem->checkState(0) == Qt::Checked) {
+			list << optStr + sysItem->text(0);
+		} else {
+			nEvts = sysItem->childCount();
+			for (int c = 0; c < nEvts; ++c) {
+				evtItem = sysItem->child(c);
+				if (evtItem->checkState(0) == Qt::Checked) {
+					list << optStr +
+						sysItem->text(0) +
+						":" +
+						evtItem->text(0);
+				}
+			}
+		}
+	}
+
+	return list;
+}
+
 /** Remove a System from the Checkbox tree. */
 void KsEventsCheckBoxWidget::removeSystem(QString name) {
 	QTreeWidgetItem *item =
diff --git a/kernel-shark/src/KsWidgetsLib.hpp b/kernel-shark/src/KsWidgetsLib.hpp
index 6f22374..0d79250 100644
--- a/kernel-shark/src/KsWidgetsLib.hpp
+++ b/kernel-shark/src/KsWidgetsLib.hpp
@@ -333,6 +333,8 @@
 	KsEventsCheckBoxWidget(struct tep_handle *pe,
 			       QWidget *parent = nullptr);
 
+	QStringList getCheckedEvents(bool option);
+
 	void removeSystem(QString name);
 };