Compare commits

...

6 Commits

Author SHA1 Message Date
Keith Edmunds
b86b7f7f33 Resize row on insertion
Fixes #207
2023-12-08 18:15:47 +00:00
Keith Edmunds
c1dd111453 Fix add note only from track dialog
Fixes #208
2023-12-08 18:10:38 +00:00
Keith Edmunds
7ed54f2bab Fix issues saving/restoring active tab
Fixes #212
2023-12-08 14:00:59 +00:00
Keith Edmunds
06ef175b46 Fix moving rows when played rows are hidden
Fixes #210
2023-12-08 13:35:22 +00:00
Keith Edmunds
e313e84010 Fix move unplayed rows
Fixes #211
2023-12-07 23:07:45 +00:00
Keith Edmunds
6391490f9d Select next track after header
Fixes #209
2023-12-07 23:04:25 +00:00
5 changed files with 60 additions and 16 deletions

View File

@ -54,6 +54,10 @@ class TrackSelectDialog(QDialog):
height = record.f_int or 600
self.resize(width, height)
if add_to_header:
self.ui.lblNote.setVisible(False)
self.ui.txtNote.setVisible(False)
def add_selected(self) -> None:
"""Handle Add button"""
@ -65,18 +69,22 @@ class TrackSelectDialog(QDialog):
track = item.data(Qt.ItemDataRole.UserRole)
note = self.ui.txtNote.text()
track_id = None
if track:
track_id = track.id
if not note and not track:
if not track_id:
if note:
self.model.insert_row(self.new_row_number, track_id, note)
self.ui.txtNote.clear()
return
else:
# No note, no track
return
self.ui.txtNote.clear()
self.select_searchtext()
track_id = None
if track:
track_id = track.id
else:
return
# Check whether track is already in playlist
move_existing = False
existing_prd = self.model.is_track_in_playlist(track_id)
@ -87,14 +95,16 @@ class TrackSelectDialog(QDialog):
default_yes=True,
):
move_existing = True
if self.add_to_header and existing_prd: # "and existing_prd" for mypy's benefit
if move_existing:
if self.add_to_header:
if move_existing and existing_prd: # "and existing_prd" for mypy's benefit
self.model.move_track_to_header(self.new_row_number, existing_prd, note)
else:
self.model.add_track_to_header(self.new_row_number, track_id)
# Close dialog - we can only add one track to a header
self.accept()
else:
# Adding a new track row
if move_existing and existing_prd: # "and existing_prd" for mypy's benefit
self.model.move_track_add_note(self.new_row_number, existing_prd, note)
else:

View File

@ -239,6 +239,20 @@ class Playlists(Base):
session.add(self)
session.flush()
@staticmethod
def clear_tabs(session: scoped_session, playlist_ids: List[int]) -> None:
"""
Make all tab records NULL
"""
session.execute(
update(Playlists)
.where(
(Playlists.id.in_(playlist_ids))
)
.values(tab=None)
)
def close(self) -> None:
"""Mark playlist as unloaded"""

View File

@ -875,15 +875,23 @@ class Window(QMainWindow, Ui_MainWindow):
def load_last_playlists(self) -> None:
"""Load the playlists that were open when the last session closed"""
playlist_ids = []
with Session() as session:
for playlist in Playlists.get_open(session):
if playlist:
_ = self.create_playlist_tab(playlist)
playlist_ids.append(playlist.id)
# Set active tab
record = Settings.get_int_settings(session, "active_tab")
if record.f_int and record.f_int >= 0:
if record.f_int is not None and record.f_int >= 0:
self.tabPlaylist.setCurrentIndex(record.f_int)
# Tabs may move during use. Rather than track where tabs
# are, we record the tab index when we close the main
# window. To avoid possible duplicate tab entries, we null
# them all out now.
Playlists.clear_tabs(session, playlist_ids)
def lookup_row_in_songfacts(self) -> None:
"""
Display songfacts page for title in highlighted row

View File

@ -306,7 +306,13 @@ class PlaylistModel(QAbstractTableModel):
if unplayed_rows:
try:
# Find next row after current track
next_row = min([a for a in unplayed_rows if a > row_number])
next_row = min(
[
a
for a in unplayed_rows
if a > row_number and not self.is_header_row(a)
]
)
except ValueError:
# Find first unplayed track
next_row = min(unplayed_rows)
@ -724,6 +730,7 @@ class PlaylistModel(QAbstractTableModel):
self.refresh_data(session)
super().endInsertRows()
self.signals.resize_rows_signal.emit(self.playlist_id)
self.reset_track_sequence_row_numbers()
self.invalidate_rows(list(range(new_row_number, len(self.playlist_rows))))
@ -1472,6 +1479,9 @@ class PlaylistProxyModel(QSortFilterProxyModel):
def get_row_track_path(self, row_number: int) -> str:
return self.data_model.get_row_track_path(row_number)
def get_unplayed_rows(self) -> List[int]:
return self.data_model.get_unplayed_rows()
def hide_played_tracks(self, hide: bool) -> None:
return self.data_model.hide_played_tracks(hide)

View File

@ -234,13 +234,15 @@ class PlaylistTab(QTableView):
super().dropEvent(event)
from_rows = self.selected_model_row_numbers()
to_row = self.indexAt(event.position().toPoint()).row()
to_index = self.indexAt(event.position().toPoint())
to_model_row = self.proxy_model.mapToSource(to_index).row()
if (
0 <= min(from_rows) <= self.model().rowCount()
and 0 <= max(from_rows) <= self.model().rowCount()
and 0 <= to_row <= self.model().rowCount()
0 <= min(from_rows) <= self.data_model.rowCount()
and 0 <= max(from_rows) <= self.data_model.rowCount()
and 0 <= to_model_row <= self.data_model.rowCount()
):
self.model().move_rows(from_rows, to_row)
self.data_model.move_rows(from_rows, to_model_row)
# Reset drag mode to allow row selection by dragging
self.setDragEnabled(False)