All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yordan Karadzhov <ykaradzhov@vmware.com>
To: "rostedt@goodmis.org" <rostedt@goodmis.org>
Cc: "linux-trace-devel@vger.kernel.org" <linux-trace-devel@vger.kernel.org>
Subject: [PATCH 06/11] kernel-shark-qt: Update search iterator when marker is changed
Date: Wed, 21 Nov 2018 15:14:24 +0000	[thread overview]
Message-ID: <20181121151356.16901-8-ykaradzhov@vmware.com> (raw)
In-Reply-To: <20181121151356.16901-1-ykaradzhov@vmware.com>

When the Dual marker changes it active state (between A and B) or
its selected row, the iterator over the list of search matching entries
has to be updated such that it points to the selected entry. If the
selected entry do not belong to the matching list, the iterator will
point to the first matching entry after the selected one.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark-qt/src/KsTraceViewer.cpp | 114 +++++++++++++++++---------
 kernel-shark-qt/src/KsTraceViewer.hpp |   4 +
 2 files changed, 80 insertions(+), 38 deletions(-)

diff --git a/kernel-shark-qt/src/KsTraceViewer.cpp b/kernel-shark-qt/src/KsTraceViewer.cpp
index 3df4a5d..1f96234 100644
--- a/kernel-shark-qt/src/KsTraceViewer.cpp
+++ b/kernel-shark-qt/src/KsTraceViewer.cpp
@@ -350,10 +350,21 @@ void KsTraceViewer::_next()
 	}
 
 	if (!_matchList.empty()) { // Items have been found.
-		++_it; // Move the iterator.
-		if (_it == _matchList.end() ) {
-			// This is the last item of the list. Go back to the beginning.
-			_it = _matchList.begin();
+		int row = _getSelectedDataRow();
+		/*
+		 * The iterator can only be at the selected row or if the
+		 * selected row is not a match at the first matching row after
+		 * the selected one.
+		 */
+		if (*_it == row) {
+			++_it; // Move the iterator.
+			if (_it == _matchList.end() ) {
+				/*
+				 * This is the last item of the list.
+				 * Go back to the beginning.
+				 */
+				_it = _matchList.begin();
+			}
 		}
 
 		// Select the row of the item.
@@ -407,14 +418,17 @@ void KsTraceViewer::_searchStop()
 
 void KsTraceViewer::_clicked(const QModelIndex& i)
 {
-	if (_graphFollows) {
-		/*
-		 * Use the index of the proxy model to retrieve the value
-		 * of the row number in the base model.
-		 */
-		size_t row = _proxyModel.mapRowFromSource(i.row());
+	/*
+	 * Use the index of the proxy model to retrieve the value
+	 * of the row number in the base model.
+	 */
+	size_t row = _proxyModel.mapRowFromSource(i.row());
+
+	_setSearchIterator(row);
+	_updateSearchCount();
+
+	if (_graphFollows)
 		emit select(row); // Send a signal to the Graph widget.
-	}
 }
 
 /** Make a given row of the table visible. */
@@ -454,6 +468,8 @@ void KsTraceViewer::deselect()
 /** Switch the Dual marker. */
 void KsTraceViewer::markSwitch()
 {
+	int row;
+
 	/* The state of the Dual marker has changed. Get the new active marker. */
 	DualMarkerState state = _mState->getState();
 
@@ -495,6 +511,12 @@ void KsTraceViewer::markSwitch()
 	} else {
 		_view.clearSelection();
 	}
+
+	row = _getSelectedDataRow();
+	if (row >= 0) {
+		_setSearchIterator(row);
+		_updateSearchCount();
+	}
 }
 
 /**
@@ -529,12 +551,9 @@ void KsTraceViewer::resizeEvent(QResizeEvent* event)
 void KsTraceViewer::keyReleaseEvent(QKeyEvent *event)
 {
 	if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) {
-		QItemSelectionModel *sm = _view.selectionModel();
-		if (sm->hasSelection()) {
-			/* Only one row at the time can be selected. */
-			int row = sm->selectedRows()[0].row();
+		int row = _getSelectedDataRow();
+		if (row >= 0)
 			emit select(row); // Send a signal to the Graph widget.
-		}
 
 		return;
 	}
@@ -564,7 +583,7 @@ size_t KsTraceViewer::_searchItems(int column,
 				   const QString &searchText,
 				   condition_func cond)
 {
-	int count;
+	int count, dataRow;
 
 	_searchProgBar.show();
 	_pbAction->setVisible(true);
@@ -588,28 +607,10 @@ size_t KsTraceViewer::_searchItems(int column,
 	if (count == 0) // No items have been found. Do nothing.
 		return 0;
 
-	QItemSelectionModel *sm = _view.selectionModel();
-	if (sm->hasSelection()) {
-		/* Only one row at the time can be selected. */
-		int row = sm->selectedRows()[0].row();
-
+	dataRow = _getSelectedDataRow();
+	if (dataRow >= 0) {
 		_view.clearSelection();
-		_it = _matchList.begin();
-		/*
-		 * Move the iterator to the first element of the match list
-		 * after the selected one.
-		 */
-		while (*_it <= row) {
-			++_it;  // Move the iterator.
-			if (_it == _matchList.end()) {
-				/*
-				 * This is the last item of the list. Go back
-				 * to the beginning.
-				 */
-				_it = _matchList.begin();
-				break;
-			}
-		}
+		_setSearchIterator(dataRow);
 	} else {
 		/* Move the iterator to the beginning of the match list. */
 		_view.clearSelection();
@@ -621,6 +622,29 @@ size_t KsTraceViewer::_searchItems(int column,
 	return count;
 }
 
+void KsTraceViewer::_setSearchIterator(int row)
+{
+	if (_matchList.isEmpty())
+		return;
+
+	/*
+	 * Move the iterator to the first element of the match list
+	 * after the selected one.
+	 */
+	_it = _matchList.begin();
+	while (*_it < row) {
+		++_it;  // Move the iterator.
+		if (_it == _matchList.end()) {
+			/*
+			 * This is the last item of the list. Go back
+			 * to the beginning.
+			 */
+			_it = _matchList.begin();
+			break;
+		}
+	}
+}
+
 void KsTraceViewer::_searchItemsMapReduce(int column,
 					  const QString &searchText,
 					  condition_func cond)
@@ -668,3 +692,17 @@ void KsTraceViewer::_searchItemsMapReduce(int column,
 	for (auto &m: maps)
 		lamSearchReduce(_matchList, m.get());
 }
+
+int KsTraceViewer::_getSelectedDataRow()
+{
+	QItemSelectionModel *sm = _view.selectionModel();
+	int dataRow = -1;
+
+	if (sm->hasSelection()) {
+		/* Only one row at the time can be selected. */
+		QModelIndex  i = sm->selectedRows()[0];
+		dataRow = _proxyModel.mapRowFromSource(i.row());
+	}
+
+	return dataRow;
+}
diff --git a/kernel-shark-qt/src/KsTraceViewer.hpp b/kernel-shark-qt/src/KsTraceViewer.hpp
index 19371de..50c9115 100644
--- a/kernel-shark-qt/src/KsTraceViewer.hpp
+++ b/kernel-shark-qt/src/KsTraceViewer.hpp
@@ -140,6 +140,10 @@ private:
 
 	void _onCustomContextMenu(const QPoint &);
 
+	void _setSearchIterator(int row);
+
+	int _getSelectedDataRow();
+
 private slots:
 
 	void _searchEdit(int);
-- 
2.17.1

  parent reply	other threads:[~2018-11-22  1:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-21 15:14 [PATCH 00/11] Small modifications and bug fixes toward KS 1.0 Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 01/11] kernel-shark-qt: protect all calls of tep_read_number_field() Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 01/11] kernel-shark-qt: Protect " Yordan Karadzhov
2018-11-27 20:34   ` Steven Rostedt
2018-11-21 15:14 ` [PATCH 02/11] kernel-shark-qt: Fix the returned error value of kshark_get_event_id_easy() Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 03/11] kernel-shark-qt: Avoid race condition in kshark_get_event_name_easy() Yordan Karadzhov
2018-11-27 20:37   ` Steven Rostedt
2018-11-21 15:14 ` [PATCH 04/11] kernel-shark-qt: Optimize the search in the text data Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 05/11] kernel-shark-qt: Add iterator index to the search panel Yordan Karadzhov
2018-11-21 15:14 ` Yordan Karadzhov [this message]
2018-11-21 15:14 ` [PATCH 07/11] kernel-shark-qt: Optimize the search in a case of a small data-set Yordan Karadzhov
2018-11-21 15:14 ` [PATCH 08/11] kernel-shark qt: No error when Record authentication dialog is closed Yordan Karadzhov
2018-11-27 20:45   ` Steven Rostedt
2018-11-21 15:14 ` [PATCH 09/11] kernel-shark-qt: Remove all system=ftrace events from Record dialog Yordan Karadzhov
2018-11-27 23:02 ` [PATCH 00/11] Small modifications and bug fixes toward KS 1.0 Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181121151356.16901-8-ykaradzhov@vmware.com \
    --to=ykaradzhov@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.