Clean up editing
This commit is contained in:
parent
669125794f
commit
b9fd7a5d21
@ -295,11 +295,9 @@ class PlaylistTab(QTableWidget):
|
||||
# Call sequences:
|
||||
# Start editing:
|
||||
# edit()
|
||||
# _cell_edit_started()
|
||||
# End editing:
|
||||
# _cell_changed() (only if changes made)
|
||||
# closeEditor()
|
||||
# _cell_edit_ended()
|
||||
|
||||
def _cell_changed(self, row: int, column: int) -> None:
|
||||
"""Called when cell content has changed"""
|
||||
@ -386,18 +384,17 @@ class PlaylistTab(QTableWidget):
|
||||
event: QEvent) -> bool:
|
||||
"""
|
||||
Override PySide2.QAbstractItemView.edit to catch when editing starts
|
||||
|
||||
Editing only ever starts with a double click on a cell
|
||||
"""
|
||||
|
||||
# 'result' will only be true on double-click
|
||||
result = super(PlaylistTab, self).edit(index, trigger, event)
|
||||
if result: # will only be true on double-clicke
|
||||
if result:
|
||||
row = index.row()
|
||||
column = index.column()
|
||||
|
||||
# Is this a track row?
|
||||
track_row = self._get_row_track_id(row)
|
||||
|
||||
note_column = 0
|
||||
if track_row:
|
||||
if self._get_row_track_id(row):
|
||||
# If a track row, we only allow editing of title, artist and
|
||||
# note. Check that this column is one of those.
|
||||
if column in [TITLE, ARTIST, ROW_NOTES]:
|
||||
@ -423,19 +420,14 @@ class PlaylistTab(QTableWidget):
|
||||
|
||||
# If this is a note cell, we need to remove any existing section
|
||||
# timing so user can't edit that. Keep it simple: refresh text
|
||||
# from database. Note column will only be non-zero if we are
|
||||
# from database. note_column will only be non-zero if we are
|
||||
# editing a note.
|
||||
if note_column:
|
||||
with Session() as session:
|
||||
plr_item = self._get_row_plr(session, row)
|
||||
item = self.item(row, note_column)
|
||||
if not item:
|
||||
return False
|
||||
if not plr_item:
|
||||
return False
|
||||
if not plr_item.note:
|
||||
plr_item.note = ''
|
||||
item.setText(plr_item.note)
|
||||
self._set_row_note_text(session, row, plr_item.note)
|
||||
|
||||
# Connect signal so we know when cell has changed.
|
||||
self.cellChanged.connect(self._cell_changed)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user