mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
Improve filtered model interacting with range changes
This commit is contained in:
parent
e47a5a70d4
commit
a8f6481d2b
1 changed files with 58 additions and 11 deletions
|
@ -443,7 +443,8 @@ class FilteredLogModel (FilteredLogModelBase):
|
||||||
self.reset ()
|
self.reset ()
|
||||||
self.__active_process = None
|
self.__active_process = None
|
||||||
self.__filter_progress = 0.
|
self.__filter_progress = 0.
|
||||||
|
self.__old_super_model_range = super_model.line_index_range
|
||||||
|
|
||||||
def reset (self):
|
def reset (self):
|
||||||
|
|
||||||
del self.line_offsets[:]
|
del self.line_offsets[:]
|
||||||
|
@ -563,26 +564,72 @@ class FilteredLogModel (FilteredLogModelBase):
|
||||||
|
|
||||||
return self.super_index[line_index]
|
return self.super_index[line_index]
|
||||||
|
|
||||||
|
def __filtered_indices_in_range (self, first, last):
|
||||||
|
|
||||||
|
# FIXME: Rewrite using bisection!
|
||||||
|
|
||||||
|
if first < 0:
|
||||||
|
raise ValueError ("first cannot be negative (got %r)" % (first,))
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for i in self.super_index:
|
||||||
|
if i >= first and i <= last:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
def super_model_changed_range (self):
|
def super_model_changed_range (self):
|
||||||
|
|
||||||
range_model = self.super_model
|
range_model = self.super_model
|
||||||
|
old_start, old_end = self.__old_super_model_range
|
||||||
super_start, super_end = range_model.line_index_range
|
super_start, super_end = range_model.line_index_range
|
||||||
|
|
||||||
# FIXME: This is too simple!
|
super_start_offset = super_start - old_start
|
||||||
start_index = self.line_index_from_super (super_start)
|
if super_start_offset < 0:
|
||||||
end_index = self.line_index_from_super (super_end)
|
# TODO:
|
||||||
|
raise NotImplementedError ("Only handling further restriction of the range")
|
||||||
|
|
||||||
last_index = len (self.line_offsets) - 1
|
super_end_offset = super_end - old_end
|
||||||
if end_index < last_index:
|
if super_end_offset > 0:
|
||||||
self.__remove_range (end_index + 1, last_index)
|
# TODO:
|
||||||
|
raise NotImplementedError ("Only handling further restriction of the range")
|
||||||
|
|
||||||
if start_index > 0:
|
if super_end_offset < 0:
|
||||||
self.__remove_range (0, start_index - 1)
|
if not self.super_index:
|
||||||
|
# Identity; there are no filters.
|
||||||
|
end_offset = len (self.line_offsets) + super_end_offset
|
||||||
|
else:
|
||||||
|
n_filtered = self.__filtered_indices_in_range (super_end + 1 - super_start,
|
||||||
|
old_end - super_start)
|
||||||
|
end_offset = len (self.line_offsets) - n_filtered
|
||||||
|
end = len (self.line_offsets) - 1 # FIXME
|
||||||
|
assert end_offset <= end
|
||||||
|
self.__remove_range (end_offset, end)
|
||||||
|
|
||||||
|
if super_start_offset > 0:
|
||||||
|
if not self.super_index:
|
||||||
|
# Identity; there are no filters.
|
||||||
|
start_offset = super_start_offset
|
||||||
|
else:
|
||||||
|
n_filtered = self.__filtered_indices_in_range (old_start, super_start)
|
||||||
|
assert n_filtered > 0
|
||||||
|
start_offset = n_filtered
|
||||||
|
self.__remove_range (0, start_offset - 1)
|
||||||
|
|
||||||
|
self.__old_super_model_range = (super_start, super_end,)
|
||||||
|
|
||||||
def __remove_range (self, start, end):
|
def __remove_range (self, start, end):
|
||||||
|
|
||||||
|
if start < 0:
|
||||||
|
raise ValueError ("start cannot be negative (got %r)" % (start,))
|
||||||
|
if end > len (self.line_offsets) - 1:
|
||||||
|
raise ValueError ("end value out of range (got %r)" % (end,))
|
||||||
|
if start > end:
|
||||||
|
raise ValueError ("start cannot be greater than end")
|
||||||
|
|
||||||
self.logger.debug ("removing line range first = %i, last = %i",
|
self.logger.debug ("removing line range first = %i, last = %i",
|
||||||
start, end)
|
start, end)
|
||||||
|
|
||||||
del self.line_offsets[start:end + 1]
|
del self.line_offsets[start:end + 1]
|
||||||
del self.line_levels[start:end + 1]
|
del self.line_levels[start:end + 1]
|
||||||
for super_index in self.super_index[start:end + 1]:
|
for super_index in self.super_index[start:end + 1]:
|
||||||
|
@ -1249,11 +1296,11 @@ class ViewColumnManager (ColumnManager):
|
||||||
self.size_column (column, view, model)
|
self.size_column (column, view, model)
|
||||||
self.columns_sized = True
|
self.columns_sized = True
|
||||||
|
|
||||||
class LineViewLogModel (FilteredLogModel):
|
class LineViewLogModel (FilteredLogModelBase):
|
||||||
|
|
||||||
def __init__ (self, super_model):
|
def __init__ (self, super_model):
|
||||||
|
|
||||||
FilteredLogModel.__init__ (self, super_model)
|
FilteredLogModelBase.__init__ (self, super_model)
|
||||||
|
|
||||||
self.line_offsets = []
|
self.line_offsets = []
|
||||||
self.line_levels = []
|
self.line_levels = []
|
||||||
|
|
Loading…
Reference in a new issue