Fix merge_metadata to not overwrite non-text fields ('bool', 'int', 'float', 'rating', 'datetime') that have a value of zero/false instead of none.

Change the delegate for custom numeric columns to permit setting a value to undefined when editing on the library view.
This commit is contained in:
Charles Haley 2011-08-06 10:21:55 +01:00
parent 6ee00a041e
commit e4e5eb36e7
2 changed files with 7 additions and 1 deletions

View File

@ -418,7 +418,7 @@ class EditMetadataAction(InterfaceAction):
db.set_custom(dest_id, dest_value, num=colnum) db.set_custom(dest_id, dest_value, num=colnum)
if db.field_metadata[key]['datatype'] in \ if db.field_metadata[key]['datatype'] in \
('bool', 'int', 'float', 'rating', 'datetime') \ ('bool', 'int', 'float', 'rating', 'datetime') \
and not dest_value: and dest_value is None:
db.set_custom(dest_id, src_value, num=colnum) db.set_custom(dest_id, src_value, num=colnum)
if db.field_metadata[key]['datatype'] == 'series' \ if db.field_metadata[key]['datatype'] == 'series' \
and not dest_value: and not dest_value:

View File

@ -310,6 +310,12 @@ class CcNumberDelegate(QStyledItemDelegate): # {{{
editor.setDecimals(2) editor.setDecimals(2)
return editor return editor
def setModelData(self, editor, model, index):
val = editor.value()
if val == editor.minimum():
val = None
model.setData(index, QVariant(val), Qt.EditRole)
def setEditorData(self, editor, index): def setEditorData(self, editor, index):
m = index.model() m = index.model()
val = m.db.data[index.row()][m.custom_columns[m.column_map[index.column()]]['rec_index']] val = m.db.data[index.row()][m.custom_columns[m.column_map[index.column()]]['rec_index']]