Commit 908d099c authored by Christoph Reiter's avatar Christoph Reiter 🐍

Make Gtk.List/TreeStore.insert_before/after atomic

Instead of adding a row and then setting the values do it in one
go using insert_with_values().

This gets rid of a row-changed signal and things like cellrenderers
don't have to deal with potentially empty rows. It's also a bit faster.
parent a56ad492
Pipeline #7398 passed with stages
in 7 minutes and 51 seconds
......@@ -986,27 +986,25 @@ class ListStore(Gtk.ListStore, TreeModel, TreeSortable):
def insert(self, position, row=None):
return self._do_insert(position, row)
# FIXME: sends two signals; check if this can use an atomic
# insert_with_valuesv()
def insert_before(self, sibling, row=None):
treeiter = Gtk.ListStore.insert_before(self, sibling)
if row is not None:
self.set_row(treeiter, row)
return treeiter
if sibling is None:
position = -1
else:
position = self.get_path(sibling).get_indices()[-1]
return self._do_insert(position, row)
# FIXME: sends two signals; check if this can use an atomic
# insert_with_valuesv()
return Gtk.ListStore.insert_before(self, sibling)
def insert_after(self, sibling, row=None):
treeiter = Gtk.ListStore.insert_after(self, sibling)
if row is not None:
self.set_row(treeiter, row)
if sibling is None:
position = 0
else:
position = self.get_path(sibling).get_indices()[-1] + 1
return self._do_insert(position, row)
return treeiter
return Gtk.ListStore.insert_after(self, sibling)
def set_value(self, treeiter, column, value):
value = self._convert_value(column, value)
......@@ -1250,27 +1248,25 @@ class TreeStore(Gtk.TreeStore, TreeModel, TreeSortable):
def insert(self, parent, position, row=None):
return self._do_insert(parent, position, row)
# FIXME: sends two signals; check if this can use an atomic
# insert_with_valuesv()
def insert_before(self, parent, sibling, row=None):
treeiter = Gtk.TreeStore.insert_before(self, parent, sibling)
if row is not None:
self.set_row(treeiter, row)
return treeiter
if sibling is None:
position = -1
else:
position = self.get_path(sibling).get_indices()[-1]
return self._do_insert(parent, position, row)
# FIXME: sends two signals; check if this can use an atomic
# insert_with_valuesv()
return Gtk.TreeStore.insert_before(self, parent, sibling)
def insert_after(self, parent, sibling, row=None):
treeiter = Gtk.TreeStore.insert_after(self, parent, sibling)
if row is not None:
self.set_row(treeiter, row)
if sibling is None:
position = 0
else:
position = self.get_path(sibling).get_indices()[-1] + 1
return self._do_insert(parent, position, row)
return treeiter
return Gtk.TreeStore.insert_after(self, parent, sibling)
def set_value(self, treeiter, column, value):
value = self._convert_value(column, value)
......
......@@ -1404,14 +1404,14 @@ class TestTreeModel(unittest.TestCase):
iter_ = store.insert_before(None, [1234])
assert store.get_path(iter_).get_indices() == [3]
assert store.get_value(iter_, 0) == 1234
assert signals == ['row-inserted', 'row-changed']
assert signals == ['row-inserted']
del signals[:]
# insert non-empty
iter_ = store.insert_before(iter_, [4321])
assert store.get_path(iter_).get_indices() == [3]
assert store.get_value(iter_, 0) == 4321
assert signals == ['row-inserted', 'row-changed']
assert signals == ['row-inserted']
del signals[:]
assert [r[0] for r in store] == [0, None, None, 4321, 1234]
......@@ -1452,14 +1452,14 @@ class TestTreeModel(unittest.TestCase):
iter_ = store.insert_after(None, [1234])
assert store.get_path(iter_).get_indices() == [0]
assert store.get_value(iter_, 0) == 1234
assert signals == ['row-inserted', 'row-changed']
assert signals == ['row-inserted']
del signals[:]
# insert non-empty
iter_ = store.insert_after(iter_, [4321])
assert store.get_path(iter_).get_indices() == [1]
assert store.get_value(iter_, 0) == 4321
assert signals == ['row-inserted', 'row-changed']
assert signals == ['row-inserted']
del signals[:]
assert [r[0] for r in store] == [1234, 4321, None, None, 0]
......@@ -1505,14 +1505,14 @@ class TestTreeModel(unittest.TestCase):
iter_ = store.insert_before(parent, None, [1234])
assert store.get_path(iter_).get_indices() == [0, 3]
assert store.get_value(iter_, 0) == 1234
assert signals == ['row-inserted', 'row-changed']
assert signals == ['row-inserted']
del signals[:]
# insert non-empty
iter_ = store.insert_before(parent, iter_, [4321])
assert store.get_path(iter_).get_indices() == [0, 3]
assert store.get_value(iter_, 0) == 4321
assert signals == ['row-inserted', 'row-changed']
assert signals == ['row-inserted']
del signals[:]
def func(model, path, iter_, rows):
......@@ -1565,14 +1565,14 @@ class TestTreeModel(unittest.TestCase):
iter_ = store.insert_after(parent, None, [1234])
assert store.get_path(iter_).get_indices() == [0, 0]
assert store.get_value(iter_, 0) == 1234
assert signals == ['row-inserted', 'row-changed']
assert signals == ['row-inserted']
del signals[:]
# insert non-empty
iter_ = store.insert_after(parent, iter_, [4321])
assert store.get_path(iter_).get_indices() == [0, 1]
assert store.get_value(iter_, 0) == 4321
assert signals == ['row-inserted', 'row-changed']
assert signals == ['row-inserted']
del signals[:]
def func(model, path, iter_, rows):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment