Merge branch 'copilot/fix-duplicate-column-names' of https://github.com/kovidgoyal/calibre

Fixes #2146097 [Bug: Duplicate column names  - only one shown in menus](https://bugs.launchpad.net/calibre/+bug/2146097)
This commit is contained in:
Kovid Goyal 2026-04-01 11:08:57 +05:30
commit 9eba5b16fe
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 2 deletions

View File

@ -5,6 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from contextlib import suppress
from collections import Counter
from functools import partial
from qt.core import (
@ -37,6 +38,8 @@ def hidden_fields(db):
def get_sorted_fields(db):
fm = db.field_metadata
name_map = [(v,k) for k, v in fm.ui_sortable_field_keys().items()]
counts = Counter(name for name, _ in name_map)
name_map = [(f'{name} [{key}]' if counts[name] > 1 else name, key) for name, key in name_map]
return sorted(name_map, key=lambda x: primary_sort_key(x[0]))

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
import itertools
import operator
from collections import OrderedDict
from collections import Counter, OrderedDict
from functools import partial
from qt.core import (
@ -661,9 +661,11 @@ class BooksView(TableView): # {{{
m.setIcon(QIcon.ic('plus.png'))
hcols = [(hcol, str(self.model().headerData(hidx, Qt.Orientation.Horizontal, Qt.ItemDataRole.DisplayRole) or ''))
for hcol, hidx in hidden_cols.items()]
name_counts = Counter(hname for _, hname in hcols)
hcols.sort(key=lambda x: primary_sort_key(x[1]))
for hcol, hname in hcols:
m.addAction(hname.replace('&', '&&'), partial(handler, action='show', column=hcol))
display = f'{hname} [{hcol}]' if name_counts[hname] > 1 else hname
m.addAction(display.replace('&', '&&'), partial(handler, action='show', column=hcol))
ans.addSeparator()
if col == 'ondevice':
ans.addAction(_('Remember On Device column width'),