Bug 2023459: Duplicate user-category items after merging in tag category editor

This commit is contained in:
Charles Haley 2023-06-11 12:35:26 +01:00
parent 80702e5a72
commit 332d3aa944

View File

@ -1481,13 +1481,21 @@ class TagsModel(QAbstractItemModel): # {{{
''' '''
user_cats = self.db.new_api.pref('user_categories', {}) user_cats = self.db.new_api.pref('user_categories', {})
for k in user_cats.keys(): for k in user_cats.keys():
new_contents = [] ucat = {n:c for n,c,_ in user_cats[k]}
for tup in user_cats[k]: # Check if the new name with the same category already exists. If
if tup[0] == item_name and tup[1] == item_category: # so, remove the old name because it would be a duplicate. This can
new_contents.append([new_name, item_category, 0]) # happen if two items in the item_category were renamed to the same
else: # name.
new_contents.append(tup) if ucat.get(new_name, None) == item_category:
user_cats[k] = new_contents if ucat.pop(item_name, None) is not None:
# Only update the user_cats when something changes
user_cats[k] = list([(n, c, 0) for n, c in ucat.items()])
elif ucat.get(item_name, None) == item_category:
# If the old name/item_category exists, rename it to the new
# name using del/add
del ucat[item_name]
ucat[new_name] = item_category
user_cats[k] = list([(n, c, 0) for n, c in ucat.items()])
self.db.new_api.set_pref('user_categories', user_cats) self.db.new_api.set_pref('user_categories', user_cats)
def delete_item_from_all_user_categories(self, item_name, item_category): def delete_item_from_all_user_categories(self, item_name, item_category):