Skip to content

Commit

Permalink
Sort records by time on insertion
Browse files Browse the repository at this point in the history
Closes #34
  • Loading branch information
busimus committed Jan 28, 2023
1 parent 1dabb2f commit 58df3e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions cutelog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Exc_Indication(enum.IntEnum):
('single_tab_mode_default', bool, False),
('new_conn_clears_tab', bool, False),
('extra_mode_default', bool, False),
('sort_by_time', bool, True),
('default_serialization_format', str, 'pickle'),
('use_system_proxy', bool, False),

Expand Down
18 changes: 15 additions & 3 deletions cutelog/logger_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def __init__(self, parent, levels, header, max_capacity=0):
self.table_header = header
self.extra_mode = CONFIG['extra_mode_default']
self.word_wrap = CONFIG['word_wrap_default']
self.sort_by_time = CONFIG['sort_by_time']

def columnCount(self, index):
return self.table_header.column_count
Expand Down Expand Up @@ -313,9 +314,18 @@ def add_record(self, record, internal=False):
self.trim_if_needed()
row = len(self.records)

self.beginInsertRows(INVALID_INDEX, row, row)
self.records.append(record)
self.endInsertRows()
if row == 0 or not self.sort_by_time or record.created > self.records[-1].created:
self.beginInsertRows(INVALID_INDEX, row, row)
self.records.append(record)
self.endInsertRows()
else:
for row in range(len(self.records) - 1, -1, -1):
if record.created >= self.records[row].created:
row += 1
break
self.beginInsertRows(INVALID_INDEX, row, row)
self.records.insert(row, record)
self.endInsertRows()
return row

def trim_except_last_n(self, n):
Expand Down Expand Up @@ -864,6 +874,8 @@ def merge_with_records(self, new_records):
self.loggerTable.scrollToBottom()
# # modelReset invalidates the filter already?
# self.invalidate_filter(resize_rows=False)
if self.extra_mode or self.word_wrap:
self.loggerTable.resizeRowsToContents()

def update_detail(self, sel, desel):
indexes = sel.indexes()
Expand Down

0 comments on commit 58df3e4

Please sign in to comment.