Fixes to allow an empty value in an enum

This commit is contained in:
Charles Haley 2010-12-02 16:19:09 +00:00
parent da750b1410
commit 46614c19e0
5 changed files with 18 additions and 9 deletions

View File

@ -269,10 +269,11 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{
def setModelData(self, editor, model, index):
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 ...
m = index.model()
col = m.column_map[index.column()]
print 'shouldnt happen'
val = m.custom_columns[col]['display']['enum_values'][0]
model.setData(index, QVariant(val), Qt.EditRole)

View File

@ -719,10 +719,12 @@ class BooksModel(QAbstractTableModel): # {{{
typ = cc['datatype']
label=self.db.field_metadata.key_to_label(colhead)
s_index = None
if typ in ('text', 'comments', 'enumeration'):
if typ in ('text', 'comments'):
val = unicode(value.toString()).strip()
val = val if val else None
if typ == 'bool':
elif typ == 'enumeration':
val = unicode(value.toString()).strip()
elif typ == 'bool':
val = value.toPyObject()
elif typ == 'rating':
val = value.toInt()[0]

View File

@ -166,8 +166,12 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
if not self.enum_box.text():
return self.simple_error('', _('You must enter at least one'
' value for enumeration columns'))
display_dict = {'enum_values':
[v.strip() for v in unicode(self.enum_box.text()).split(',')]}
l = [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
key = db.field_metadata.custom_field_prefix+col

View File

@ -212,7 +212,10 @@
<item>
<widget class="QLineEdit" name="enum_box">
<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 name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">

View File

@ -580,7 +580,6 @@ def command_add_custom_column(args, dbpath):
print
print >>sys.stderr, _('You must specify label, name and datatype')
return 1
print opts.display
do_add_custom_column(get_db(dbpath, opts), args[0], args[1], args[2],
opts.is_multiple, json.loads(opts.display))
# Re-open the DB so that field_metadata is reflects the column changes