mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fixes to allow an empty value in an enum
This commit is contained in:
parent
da750b1410
commit
46614c19e0
@ -269,10 +269,11 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{
|
|||||||
|
|
||||||
def setModelData(self, editor, model, index):
|
def setModelData(self, editor, model, index):
|
||||||
val = unicode(editor.currentText())
|
val = unicode(editor.currentText())
|
||||||
if val == '':
|
m = index.model()
|
||||||
|
col = m.column_map[index.column()]
|
||||||
|
if val not in m.custom_columns[col]['display']['enum_values']:
|
||||||
# This shouldn't happen ...
|
# This shouldn't happen ...
|
||||||
m = index.model()
|
print 'shouldnt happen'
|
||||||
col = m.column_map[index.column()]
|
|
||||||
val = m.custom_columns[col]['display']['enum_values'][0]
|
val = m.custom_columns[col]['display']['enum_values'][0]
|
||||||
model.setData(index, QVariant(val), Qt.EditRole)
|
model.setData(index, QVariant(val), Qt.EditRole)
|
||||||
|
|
||||||
|
@ -719,10 +719,12 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
typ = cc['datatype']
|
typ = cc['datatype']
|
||||||
label=self.db.field_metadata.key_to_label(colhead)
|
label=self.db.field_metadata.key_to_label(colhead)
|
||||||
s_index = None
|
s_index = None
|
||||||
if typ in ('text', 'comments', 'enumeration'):
|
if typ in ('text', 'comments'):
|
||||||
val = unicode(value.toString()).strip()
|
val = unicode(value.toString()).strip()
|
||||||
val = val if val else None
|
val = val if val else None
|
||||||
if typ == 'bool':
|
elif typ == 'enumeration':
|
||||||
|
val = unicode(value.toString()).strip()
|
||||||
|
elif typ == 'bool':
|
||||||
val = value.toPyObject()
|
val = value.toPyObject()
|
||||||
elif typ == 'rating':
|
elif typ == 'rating':
|
||||||
val = value.toInt()[0]
|
val = value.toInt()[0]
|
||||||
|
@ -166,8 +166,12 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
|
|||||||
if not self.enum_box.text():
|
if not self.enum_box.text():
|
||||||
return self.simple_error('', _('You must enter at least one'
|
return self.simple_error('', _('You must enter at least one'
|
||||||
' value for enumeration columns'))
|
' value for enumeration columns'))
|
||||||
display_dict = {'enum_values':
|
l = [v.strip() for v in unicode(self.enum_box.text()).split(',')]
|
||||||
[v.strip() for v in unicode(self.enum_box.text()).split(',')]}
|
for i in range(0, len(l)-1):
|
||||||
|
if l[i] in l[i+1:]:
|
||||||
|
return self.simple_error('', _('The value "{0}" is in the '
|
||||||
|
'list more than once').format(l[i]))
|
||||||
|
display_dict = {'enum_values': l}
|
||||||
|
|
||||||
db = self.parent.gui.library_view.model().db
|
db = self.parent.gui.library_view.model().db
|
||||||
key = db.field_metadata.custom_field_prefix+col
|
key = db.field_metadata.custom_field_prefix+col
|
||||||
|
@ -212,7 +212,10 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="enum_box">
|
<widget class="QLineEdit" name="enum_box">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>A comma-separated list of permitted values. The first value is the default</string>
|
<string>A comma-separated list of permitted values. You can specify
|
||||||
|
empty values by entering only the comma. For example, the list
|
||||||
|
',one,two,three' has 4 valid values, one of them empty. The first
|
||||||
|
value in the list is the default.</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
@ -580,7 +580,6 @@ def command_add_custom_column(args, dbpath):
|
|||||||
print
|
print
|
||||||
print >>sys.stderr, _('You must specify label, name and datatype')
|
print >>sys.stderr, _('You must specify label, name and datatype')
|
||||||
return 1
|
return 1
|
||||||
print opts.display
|
|
||||||
do_add_custom_column(get_db(dbpath, opts), args[0], args[1], args[2],
|
do_add_custom_column(get_db(dbpath, opts), args[0], args[1], args[2],
|
||||||
opts.is_multiple, json.loads(opts.display))
|
opts.is_multiple, json.loads(opts.display))
|
||||||
# Re-open the DB so that field_metadata is reflects the column changes
|
# Re-open the DB so that field_metadata is reflects the column changes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user