Resove active/proxy model coding
This commit is contained in:
parent
e5dc3dbf03
commit
839467a5e3
@ -324,12 +324,12 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
QMessageBox.StandardButton.Ok,
|
||||
)
|
||||
|
||||
def active_base_model(self) -> PlaylistModel:
|
||||
return self.playlists[self.selection.playlist_id].base_model
|
||||
|
||||
def active_tab(self) -> PlaylistTab:
|
||||
return self.tabPlaylist.currentWidget()
|
||||
|
||||
def active_proxy_model(self) -> PlaylistProxyModel:
|
||||
return self.tabPlaylist.currentWidget().model()
|
||||
|
||||
def clear_next(self) -> None:
|
||||
"""
|
||||
Clear next track
|
||||
@ -724,23 +724,16 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
if track_sequence.current:
|
||||
track_sequence.current.fade()
|
||||
|
||||
def get_active_base_model(self) -> PlaylistModel:
|
||||
"""
|
||||
Return the model for the current tab
|
||||
"""
|
||||
|
||||
return self.playlists[self.selection.playlist_id].base_model
|
||||
|
||||
def hide_played(self):
|
||||
"""Toggle hide played tracks"""
|
||||
|
||||
if self.hide_played_tracks:
|
||||
self.hide_played_tracks = False
|
||||
self.active_proxy_model().hide_played_tracks(False)
|
||||
self.active_base_model().hide_played_tracks(False)
|
||||
self.btnHidePlayed.setText("Hide played")
|
||||
else:
|
||||
self.hide_played_tracks = True
|
||||
self.active_proxy_model().hide_played_tracks(True)
|
||||
self.active_base_model().hide_played_tracks(True)
|
||||
self.btnHidePlayed.setText("Show played")
|
||||
if Config.HIDE_PLAYED_MODE == Config.HIDE_PLAYED_MODE_SECTIONS:
|
||||
self.active_tab().hide_played_sections()
|
||||
@ -756,7 +749,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# We need to keep a referent to the FileImporter else it will be
|
||||
# garbage collected while import threads are still running
|
||||
self.importer = FileImporter(
|
||||
self.get_active_base_model(),
|
||||
self.active_base_model(),
|
||||
self.active_tab().source_model_selected_row_number(),
|
||||
)
|
||||
self.importer.do_import()
|
||||
@ -771,7 +764,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
dlg.resize(500, 100)
|
||||
ok = dlg.exec()
|
||||
if ok:
|
||||
self.get_active_base_model().insert_row(
|
||||
self.active_base_model().insert_row(
|
||||
proposed_row_number=self.active_tab().source_model_selected_row_number(),
|
||||
note=dlg.textValue(),
|
||||
)
|
||||
@ -781,14 +774,14 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
new_row_number = (
|
||||
self.active_tab().source_model_selected_row_number()
|
||||
or self.active_proxy_model().rowCount()
|
||||
or self.active_base_model().rowCount()
|
||||
)
|
||||
with db.Session() as session:
|
||||
dlg = TrackSelectDialog(
|
||||
parent=self,
|
||||
session=session,
|
||||
new_row_number=new_row_number,
|
||||
base_model=self.get_active_base_model(),
|
||||
base_model=self.active_base_model(),
|
||||
)
|
||||
dlg.exec()
|
||||
session.commit()
|
||||
@ -846,7 +839,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# Save the selected PlaylistRows items ready for a later
|
||||
# paste
|
||||
self.move_source_rows = self.active_tab().get_selected_rows()
|
||||
self.move_source_model = self.get_active_base_model()
|
||||
self.move_source_model = self.active_base_model()
|
||||
|
||||
log.debug(
|
||||
f"mark_rows_for_moving(): {self.move_source_rows=} {self.move_source_model=}"
|
||||
@ -883,7 +876,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
to_row = 0
|
||||
|
||||
# Move rows
|
||||
self.get_active_base_model().move_rows_between_playlists(
|
||||
self.active_base_model().move_rows_between_playlists(
|
||||
row_numbers, to_row, to_playlist_id
|
||||
)
|
||||
|
||||
@ -913,7 +906,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
Move unplayed rows to another playlist
|
||||
"""
|
||||
|
||||
unplayed_rows = self.get_active_base_model().get_unplayed_rows()
|
||||
unplayed_rows = self.active_base_model().get_unplayed_rows()
|
||||
if not unplayed_rows:
|
||||
return
|
||||
# We can get a race condition as selected rows change while
|
||||
@ -996,12 +989,12 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
if not self.move_source_rows or not self.move_source_model:
|
||||
return
|
||||
|
||||
to_playlist_model = self.get_active_base_model()
|
||||
to_playlist_model = self.active_base_model()
|
||||
selected_rows = self.active_tab().get_selected_rows()
|
||||
if selected_rows:
|
||||
destination_row = selected_rows[0]
|
||||
else:
|
||||
destination_row = self.active_proxy_model().rowCount()
|
||||
destination_row = self.active_base_model().rowCount()
|
||||
|
||||
# If we move a row to immediately under the current track, make
|
||||
# that moved row the next track
|
||||
@ -1186,8 +1179,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
track.intro = intro
|
||||
session.commit()
|
||||
self.preview_manager.set_intro(intro)
|
||||
self.get_active_base_model().refresh_row(session, row_number)
|
||||
self.get_active_base_model().invalidate_row(row_number)
|
||||
self.active_base_model().refresh_row(session, row_number)
|
||||
self.active_base_model().invalidate_row(row_number)
|
||||
|
||||
def preview_start(self) -> None:
|
||||
"""Restart preview"""
|
||||
@ -1358,7 +1351,9 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
Incremental search of playlist
|
||||
"""
|
||||
|
||||
self.active_proxy_model().set_incremental_search(self.txtSearch.text())
|
||||
active_proxy_model = self.playlists[self.selection.playlist_id].proxy_model
|
||||
|
||||
active_proxy_model.set_incremental_search(self.txtSearch.text())
|
||||
|
||||
def selected_or_next_track_info(self) -> Optional[RowAndTrack]:
|
||||
"""
|
||||
@ -1374,7 +1369,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
if row_number is None:
|
||||
return None
|
||||
|
||||
track_info = self.get_active_base_model().get_row_info(row_number)
|
||||
track_info = self.active_base_model().get_row_info(row_number)
|
||||
if track_info is None:
|
||||
return None
|
||||
|
||||
@ -1456,20 +1451,14 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# No playlist
|
||||
return
|
||||
|
||||
# Switch to correct tab
|
||||
if playlist_id != self.active_tab().playlist_id:
|
||||
for idx in range(self.tabPlaylist.count()):
|
||||
if self.tabPlaylist.widget(idx).playlist_id == playlist_id:
|
||||
self.tabPlaylist.setCurrentIndex(idx)
|
||||
break
|
||||
|
||||
display_row = (
|
||||
self.active_proxy_model()
|
||||
.mapFromSource(
|
||||
self.get_active_base_model().index(playlist_track.row_number, 0)
|
||||
)
|
||||
.row()
|
||||
)
|
||||
self.tabPlaylist.currentWidget().scroll_to_top(display_row)
|
||||
self.active_tab().scroll_to_top(playlist_track.row_number)
|
||||
|
||||
def solicit_playlist_name(
|
||||
self, session: Session, default: str = ""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user