Improve types of history model values.

- HistoryItem.atime now always should be an int/float.
- The data for the sort role should also be an int, not a string.
  A float would also work, but maybe be slower for no real benefit.
This commit is contained in:
Florian Bruhin 2015-03-12 15:27:31 +01:00
parent 8023b1456d
commit 97dd86735a

View File

@ -50,9 +50,8 @@ class UrlCompletionModel(base.BaseCompletionModel):
self.new_item(self._quickmark_cat, qm_url, qm_name) self.new_item(self._quickmark_cat, qm_url, qm_name)
for entry in self._history: for entry in self._history:
atime = int(entry.atime)
self.new_item(self._history_cat, entry.url, "", self.new_item(self._history_cat, entry.url, "",
self._fmt_atime(atime), sort=atime) self._fmt_atime(entry.atime), sort=int(entry.atime))
self._history.item_added.connect(self.on_history_item_added) self._history.item_added.connect(self.on_history_item_added)
objreg.get('config').changed.connect(self.reformat_timestamps) objreg.get('config').changed.connect(self.reformat_timestamps)
@ -70,14 +69,13 @@ class UrlCompletionModel(base.BaseCompletionModel):
for i in range(self._history_cat.rowCount()): for i in range(self._history_cat.rowCount()):
name_item = self._history_cat.child(i, 0) name_item = self._history_cat.child(i, 0)
atime_item = self._history_cat.child(i, 2) atime_item = self._history_cat.child(i, 2)
atime = int(name_item.data(base.Role.sort)) atime = name_item.data(base.Role.sort)
atime_item.setText(self._fmt_atime(atime)) atime_item.setText(self._fmt_atime(atime))
@pyqtSlot(object) @pyqtSlot(object)
def on_history_item_added(self, item): def on_history_item_added(self, item):
"""Slot called when a new history item was added.""" """Slot called when a new history item was added."""
if item.url: if item.url:
atime = int(item.atime)
if self._history.historyContains(item.url): if self._history.historyContains(item.url):
for i in range(self._history_cat.rowCount()): for i in range(self._history_cat.rowCount()):
name = self._history_cat.child(i, 0) name = self._history_cat.child(i, 0)
@ -85,9 +83,10 @@ class UrlCompletionModel(base.BaseCompletionModel):
continue continue
if name.text() == item.url: if name.text() == item.url:
self._history_cat.setChild( self._history_cat.setChild(
i, 2, QStandardItem(self._fmt_atime(atime))) i, 2, QStandardItem(self._fmt_atime(item.atime)))
name.setData(str(atime), base.Role.sort) name.setData(int(item.atime), base.Role.sort)
break break
else: else:
self.new_item(self._history_cat, item.url, "", self.new_item(self._history_cat, item.url, "",
self._fmt_atime(atime), sort=atime) self._fmt_atime(item.atime),
sort=int(item.atime))