From 93a1da46c9149a3c4be46d8df6420d4918b985b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ren=C3=A9=20Stadler?= Date: Mon, 21 Jan 2008 11:15:42 +0200 Subject: [PATCH] Fix filtered range transformation (finally!) --- debug-viewer/GstDebugViewer/GUI.py | 9 ++--- debug-viewer/tests/test_models.py | 69 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/debug-viewer/GstDebugViewer/GUI.py b/debug-viewer/GstDebugViewer/GUI.py index 28309b4..90bc258 100644 --- a/debug-viewer/GstDebugViewer/GUI.py +++ b/debug-viewer/GstDebugViewer/GUI.py @@ -612,13 +612,14 @@ class FilteredLogModel (FilteredLogModelBase): if super_start_offset > 0: if not self.super_index: # Identity; there are no filters. - start_offset = super_start_offset + n_filtered = super_start_offset + start_offset = n_filtered else: - n_filtered = self.__filtered_indices_in_range (old_start, super_start - 1) - assert n_filtered > 0 + n_filtered = self.__filtered_indices_in_range (0, super_start_offset - 1) start_offset = n_filtered - self.__remove_range (0, start_offset - 1) + if n_filtered > 0: + self.__remove_range (0, start_offset - 1) from_super = self.from_super_index for i in self.super_index: diff --git a/debug-viewer/tests/test_models.py b/debug-viewer/tests/test_models.py index b9e5bed..9a23f77 100755 --- a/debug-viewer/tests/test_models.py +++ b/debug-viewer/tests/test_models.py @@ -146,6 +146,71 @@ class TestDynamicFilter (TestCase): for i in range (11)], range (5, 16)) + def test_filtered_range_refilter_skip (self): + + full_model = Model () + ranged_model = GUI.RangeFilteredLogModel (full_model) + # FIXME: Call to .reset should not be needed. + ranged_model.reset () + filtered_model = GUI.FilteredLogModel (ranged_model) + + row_list = self.__row_list + + filtered_model.add_filter (GUI.CategoryFilter ("EVEN"), + Common.Data.DefaultDispatcher ()) + self.__dump_model (filtered_model, "filtered") + + self.assertEquals (row_list (filtered_model), range (1, 20, 2)) + self.assertEquals ([filtered_model.line_index_from_super (i) + for i in range (1, 20, 2)], + range (10)) + self.assertEquals ([filtered_model.line_index_to_super (i) + for i in range (10)], + range (1, 20, 2)) + self.assertEquals ([filtered_model.line_index_from_top (i) + for i in range (1, 20, 2)], + range (10)) + self.assertEquals ([filtered_model.line_index_to_top (i) + for i in range (10)], + range (1, 20, 2)) + + ranged_model.set_range (1, 19) + self.__dump_model (ranged_model, "ranged (1, 19)") + filtered_model.super_model_changed_range () + self.__dump_model (filtered_model, "filtered range") + + self.assertEquals ([filtered_model.line_index_from_super (i) + for i in range (0, 19, 2)], + range (10)) + self.assertEquals ([filtered_model.line_index_to_super (i) + for i in range (10)], + range (0, 19, 2)) + self.assertEquals ([filtered_model.line_index_from_top (i) + for i in range (1, 20, 2)], + range (10)) + self.assertEquals ([filtered_model.line_index_to_top (i) + for i in range (10)], + range (1, 20, 2)) + + ranged_model.set_range (2, 19) + self.__dump_model (ranged_model, "ranged (2, 19)") + filtered_model.super_model_changed_range () + self.__dump_model (filtered_model, "filtered range") + + self.assertEquals (row_list (filtered_model), range (3, 20, 2)) + self.assertEquals ([filtered_model.line_index_from_super (i) + for i in range (1, 18, 2)], + range (9)) + self.assertEquals ([filtered_model.line_index_to_super (i) + for i in range (9)], + range (1, 18, 2)) + self.assertEquals ([filtered_model.line_index_from_top (i) + for i in range (3, 20, 2)], + range (9)) + self.assertEquals ([filtered_model.line_index_to_top (i) + for i in range (9)], + range (3, 20, 2)) + def test_filtered_range_refilter (self): full_model = Model () @@ -335,7 +400,7 @@ class TestDynamicFilter (TestCase): if not hasattr (model, "super_model"): # Top model. - print "\t|%s|" % ("|".join ([str (i).rjust (2) for i in self.__row_list (model)]),), + print "\t(%s)" % ("|".join ([str (i).rjust (2) for i in self.__row_list (model)]),), else: top_model = model.super_model if hasattr (top_model, "super_model"): @@ -345,7 +410,7 @@ class TestDynamicFilter (TestCase): output = [" "] * len (top_indices) for i, position in enumerate (positions): output[position] = str (i).rjust (2) - print "\t|%s|" % ("|".join (output),), + print "\t(%s)" % ("|".join (output),), if comment is None: print -- 2.7.4