diff mbox series

[3/5] kernel-shark: Define KS_NO_ROW_SELECTED as a negative row index (-1)

Message ID 20190212170402.10104-4-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Commit 3d38628097c57d199935c86dd06ceb9b830c4f4d
Headers show
Series The right click of the button deselects the marker | expand

Commit Message

Yordan Karadzhov Feb. 12, 2019, 5:04 p.m. UTC
Currently the model of the table treats any negative value of the Passive
Marker index as "No Row is Selected". In multiple places in the code the
value of "-1" is used in order to deselecting the marker. Defining a
dedicated constant (KS_NO_ROW_SELECTED), to be used for deselecting the
Passive Marker will make the code more readable and robust.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=202327
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/KsModels.cpp      | 8 ++++----
 kernel-shark/src/KsModels.hpp      | 3 +++
 kernel-shark/src/KsTraceViewer.cpp | 6 +++---
 3 files changed, 10 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark/src/KsModels.cpp b/kernel-shark/src/KsModels.cpp
index 1b68143..b89fee8 100644
--- a/kernel-shark/src/KsModels.cpp
+++ b/kernel-shark/src/KsModels.cpp
@@ -199,8 +199,8 @@  KsViewModel::KsViewModel(QObject *parent)
   _nRows(0),
   _header({"#", "CPU", "Time Stamp", "Task", "PID",
 	   "Latency", "Event", "Info"}),
-  _markA(-1),
-  _markB(-1)
+  _markA(KS_NO_ROW_SELECTED),
+  _markB(KS_NO_ROW_SELECTED)
 {}
 
 /**
@@ -311,10 +311,10 @@  void KsViewModel::selectRow(DualMarkerState state, int row)
 {
 	if (state == DualMarkerState::A) {
 		_markA = row;
-		_markB = -1;
+		_markB = KS_NO_ROW_SELECTED;
 	} else {
 		_markB = row;
-		_markA = -1;
+		_markA = KS_NO_ROW_SELECTED;
 	}
 }
 
diff --git a/kernel-shark/src/KsModels.hpp b/kernel-shark/src/KsModels.hpp
index 808c574..3faaf4a 100644
--- a/kernel-shark/src/KsModels.hpp
+++ b/kernel-shark/src/KsModels.hpp
@@ -28,6 +28,9 @@ 
 #include "libkshark-model.h"
 #include "KsSearchFSM.hpp"
 
+/** A negative row index, to be used for deselecting the Passive Marker. */
+#define KS_NO_ROW_SELECTED -1
+
 enum class DualMarkerState;
 
 class KsDataStore;
diff --git a/kernel-shark/src/KsTraceViewer.cpp b/kernel-shark/src/KsTraceViewer.cpp
index 61d7386..2881bd0 100644
--- a/kernel-shark/src/KsTraceViewer.cpp
+++ b/kernel-shark/src/KsTraceViewer.cpp
@@ -474,7 +474,7 @@  void KsTraceViewer::markSwitch()
 		 * The passive marker is not set.
 		 * Make sure that the model colors nothing.
 		 */
-		_model.selectRow(!state, -1);
+		_model.selectRow(!state, KS_NO_ROW_SELECTED);
 	}
 
 	/*
@@ -722,12 +722,12 @@  void KsTraceViewer::passiveMarkerSelectRow(int row)
 
 /**
  * Get the currently selected row. If no row is selected the function
- * returns -1.
+ * returns KS_NO_ROW_SELECTED (-1).
  */
 int KsTraceViewer::selectedRow()
 {
 	QItemSelectionModel *sm = _view.selectionModel();
-	int dataRow = -1;
+	int dataRow = KS_NO_ROW_SELECTED;
 
 	if (sm->hasSelection()) {
 		/* Only one row at the time can be selected. */