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