Fix filtered model index translation and improve tests

This commit is contained in:
René Stadler 2008-01-10 16:15:53 +02:00 committed by Stefan Sauer
parent 48ee98eb5c
commit 73e9b22838
2 changed files with 100 additions and 9 deletions

View file

@ -587,12 +587,14 @@ class FilteredLogModel (FilteredLogModelBase):
super_start_offset = super_start - old_start super_start_offset = super_start - old_start
if super_start_offset < 0: if super_start_offset < 0:
# TODO: # TODO:
raise NotImplementedError ("Only handling further restriction of the range") raise NotImplementedError ("Only handling further restriction of the range"
" (start offset = %i)" % (super_start_offset,))
super_end_offset = super_end - old_end super_end_offset = super_end - old_end
if super_end_offset > 0: if super_end_offset > 0:
# TODO: # TODO:
raise NotImplementedError ("Only handling further restriction of the range") raise NotImplementedError ("Only handling further restriction of the range"
" (end offset = %i)" % (super_end_offset,))
if super_end_offset < 0: if super_end_offset < 0:
if not self.super_index: if not self.super_index:
@ -604,6 +606,7 @@ class FilteredLogModel (FilteredLogModelBase):
end_offset = len (self.line_offsets) - n_filtered end_offset = len (self.line_offsets) - n_filtered
end = len (self.line_offsets) - 1 # FIXME end = len (self.line_offsets) - 1 # FIXME
assert end_offset <= end assert end_offset <= end
self.__remove_range (end_offset, end) self.__remove_range (end_offset, end)
if super_start_offset > 0: if super_start_offset > 0:
@ -614,8 +617,18 @@ class FilteredLogModel (FilteredLogModelBase):
n_filtered = self.__filtered_indices_in_range (old_start, super_start - 1) n_filtered = self.__filtered_indices_in_range (old_start, super_start - 1)
assert n_filtered > 0 assert n_filtered > 0
start_offset = n_filtered start_offset = n_filtered
self.__remove_range (0, start_offset - 1) self.__remove_range (0, start_offset - 1)
from_super = self.from_super_index
for i in self.super_index:
old_index = from_super[i]
del from_super[i]
from_super[i - super_start_offset] = old_index - start_offset
for i in range (len (self.super_index)):
self.super_index[i] -= super_start_offset
self.__old_super_model_range = (super_start, super_end,) self.__old_super_model_range = (super_start, super_end,)
def __remove_range (self, start, end): def __remove_range (self, start, end):
@ -635,9 +648,6 @@ class FilteredLogModel (FilteredLogModelBase):
for super_index in self.super_index[start:end + 1]: for super_index in self.super_index[start:end + 1]:
del self.from_super_index[super_index] del self.from_super_index[super_index]
del self.super_index[start:end + 1] del self.super_index[start:end + 1]
if start == 0:
for super_index in self.super_index:
self.from_super_index[super_index] -= end
class Filter (object): class Filter (object):

View file

@ -92,6 +92,32 @@ class TestDynamicFilter (TestCase):
self.assertEquals (rows, rows_ranged) self.assertEquals (rows, rows_ranged)
self.assertEquals (rows, rows_filtered) self.assertEquals (rows, rows_filtered)
self.assertEquals ([ranged_model.line_index_from_super (i)
for i in range (20)],
range (20))
self.assertEquals ([ranged_model.line_index_to_super (i)
for i in range (20)],
range (20))
self.assertEquals ([ranged_model.line_index_from_top (i)
for i in range (20)],
range (20))
self.assertEquals ([ranged_model.line_index_to_top (i)
for i in range (20)],
range (20))
self.assertEquals ([filtered_model.line_index_from_super (i)
for i in range (20)],
range (20))
self.assertEquals ([filtered_model.line_index_to_super (i)
for i in range (20)],
range (20))
self.assertEquals ([filtered_model.line_index_from_top (i)
for i in range (20)],
range (20))
self.assertEquals ([filtered_model.line_index_to_top (i)
for i in range (20)],
range (20))
ranged_model.set_range (5, 15) ranged_model.set_range (5, 15)
self.__dump_model (ranged_model, "ranged model (5, 15)") self.__dump_model (ranged_model, "ranged model (5, 15)")
filtered_model.super_model_changed_range () filtered_model.super_model_changed_range ()
@ -104,6 +130,32 @@ class TestDynamicFilter (TestCase):
rows_filtered = row_list (filtered_model) rows_filtered = row_list (filtered_model)
self.assertEquals (rows_ranged, rows_filtered) self.assertEquals (rows_ranged, rows_filtered)
self.assertEquals ([ranged_model.line_index_from_super (i)
for i in range (5, 16)],
range (11))
self.assertEquals ([ranged_model.line_index_to_super (i)
for i in range (11)],
range (5, 16))
self.assertEquals ([ranged_model.line_index_from_top (i)
for i in range (5, 16)],
range (11))
self.assertEquals ([ranged_model.line_index_to_top (i)
for i in range (11)],
range (5, 16))
self.assertEquals ([filtered_model.line_index_from_super (i)
for i in range (11)],
range (11))
self.assertEquals ([filtered_model.line_index_to_super (i)
for i in range (11)],
range (11))
self.assertEquals ([filtered_model.line_index_from_top (i)
for i in range (5, 16)],
range (11))
self.assertEquals ([filtered_model.line_index_to_top (i)
for i in range (11)],
range (5, 16))
filtered_model.add_filter (GUI.CategoryFilter ("EVEN"), filtered_model.add_filter (GUI.CategoryFilter ("EVEN"),
Common.Data.DefaultDispatcher ()) Common.Data.DefaultDispatcher ())
rows_filtered = row_list (filtered_model) rows_filtered = row_list (filtered_model)
@ -111,15 +163,44 @@ class TestDynamicFilter (TestCase):
self.__dump_model (filtered_model, "filtered model") self.__dump_model (filtered_model, "filtered model")
self.assertEquals ([filtered_model.line_index_from_super (i)
for i in range (0, 11, 2)],
range (6))
self.assertEquals ([filtered_model.line_index_from_top (i)
for i in range (5, 16, 2)],
range (6))
ranged_model.set_range (7, 12) ranged_model.set_range (7, 12)
self.__dump_model (ranged_model, "ranged model (7, 12)")
filtered_model.super_model_changed_range () filtered_model.super_model_changed_range ()
self.__dump_model (ranged_model, "ranged model (7, 12)") self.assertEquals (row_list (ranged_model), range (7, 13))
self.assertEquals ([ranged_model.line_index_from_super (i)
rows_ranged = row_list (ranged_model) for i in range (7, 13)],
self.assertEquals (rows_ranged, range (7, 13)) range (6))
self.assertEquals ([ranged_model.line_index_to_super (i)
for i in range (6)],
range (7, 13))
self.assertEquals ([ranged_model.line_index_from_top (i)
for i in range (7, 13)],
range (6))
self.assertEquals ([ranged_model.line_index_to_top (i)
for i in range (6)],
range (7, 13))
self.__dump_model (filtered_model, "filtered model (ranged 7, 12)") self.__dump_model (filtered_model, "filtered model (ranged 7, 12)")
self.assertEquals ([filtered_model.line_index_from_super (i)
for i in range (0, 6, 2)],
range (3))
self.assertEquals ([filtered_model.line_index_to_super (i)
for i in range (3)],
range (0, 6, 2))
self.assertEquals ([filtered_model.line_index_from_top (i)
for i in range (7, 12, 2)],
range (3))
self.assertEquals ([filtered_model.line_index_to_top (i)
for i in range (3)],
range (7, 12, 2))
rows_filtered = row_list (filtered_model) rows_filtered = row_list (filtered_model)
self.assertEquals (rows_filtered, range (7, 13, 2)) self.assertEquals (rows_filtered, range (7, 13, 2))