diff mbox series

[2/8] kernel-shark: Add method for getting all selected events

Message ID 20190709155650.2345-3-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series Fixes needed befor KS 1.0 | expand

Commit Message

Yordan Karadzhov July 9, 2019, 3:56 p.m. UTC
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.

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

Patch

diff --git a/kernel-shark/src/KsWidgetsLib.cpp b/kernel-shark/src/KsWidgetsLib.cpp
index ea02b5e..1c55c79 100644
--- a/kernel-shark/src/KsWidgetsLib.cpp
+++ b/kernel-shark/src/KsWidgetsLib.cpp
@@ -706,6 +706,47 @@  KsEventsCheckBoxWidget::KsEventsCheckBoxWidget(struct tep_handle *tep,
 	_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 @@  struct KsEventsCheckBoxWidget : public KsCheckBoxTreeWidget
 	KsEventsCheckBoxWidget(struct tep_handle *pe,
 			       QWidget *parent = nullptr);
 
+	QStringList getCheckedEvents(bool option);
+
 	void removeSystem(QString name);
 };