fix table selection things with proxymodel
This commit is contained in:
parent
d2992215f6
commit
89804aaccb
29
LICENSE
29
LICENSE
@ -1,21 +1,16 @@
|
|||||||
MIT License
|
MusicPom - Qt music library manager and audio player for Linux
|
||||||
|
|
||||||
Copyright (c) 2024 billypom
|
Copyright (C) 2025 billypom
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
This program is free software: you can redistribute it and/or modify
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
it under the terms of the GNU General Public License as published by
|
||||||
in the Software without restriction, including without limitation the rights
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
(at your option) any later version.
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
This program is distributed in the hope that it will be useful,
|
||||||
copies or substantial portions of the Software.
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
You should have received a copy of the GNU General Public License
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|||||||
@ -482,6 +482,10 @@ class MusicTable(QTableView):
|
|||||||
|
|
||||||
def delete_songs(self):
|
def delete_songs(self):
|
||||||
"""Asks to delete the currently selected songs from the db and music table (not the filesystem)"""
|
"""Asks to delete the currently selected songs from the db and music table (not the filesystem)"""
|
||||||
|
# FIXME: determine if we are in a playlist or not
|
||||||
|
# then delete songs from only the playlist
|
||||||
|
# or provide extra questionbox option
|
||||||
|
# | Delete from playlist & lib | Delete from playlist only | Cancel |
|
||||||
selected_filepaths = self.get_selected_songs_filepaths()
|
selected_filepaths = self.get_selected_songs_filepaths()
|
||||||
formatted_selected_filepaths = "\n".join(selected_filepaths)
|
formatted_selected_filepaths = "\n".join(selected_filepaths)
|
||||||
question_dialog = QuestionBoxDetails(
|
question_dialog = QuestionBoxDetails(
|
||||||
@ -708,12 +712,12 @@ class MusicTable(QTableView):
|
|||||||
else:
|
else:
|
||||||
std_item = QStandardItem(str(item) if item else "")
|
std_item = QStandardItem(str(item) if item else "")
|
||||||
items.append(std_item)
|
items.append(std_item)
|
||||||
|
|
||||||
self.model2.appendRow(items)
|
|
||||||
# store database id in the row object using setData
|
# store database id in the row object using setData
|
||||||
# - useful for fast db fetching and other model operations
|
# - useful for fast db fetching and other model operations
|
||||||
for item in items:
|
for item in items:
|
||||||
item.setData(id, Qt.ItemDataRole.UserRole)
|
item.setData(id, Qt.ItemDataRole.UserRole)
|
||||||
|
self.model2.appendRow(items)
|
||||||
|
|
||||||
self.model2.layoutChanged.emit() # emits a signal that the view should be updated
|
self.model2.layoutChanged.emit() # emits a signal that the view should be updated
|
||||||
self.playlistStatsSignal.emit(f"Songs: {row_count} | Total time: {total_time}")
|
self.playlistStatsSignal.emit(f"Songs: {row_count} | Total time: {total_time}")
|
||||||
self.connect_data_changed()
|
self.connect_data_changed()
|
||||||
@ -808,7 +812,7 @@ class MusicTable(QTableView):
|
|||||||
filepaths = []
|
filepaths = []
|
||||||
for row in selected_rows:
|
for row in selected_rows:
|
||||||
idx = self.proxymodel.index(
|
idx = self.proxymodel.index(
|
||||||
row, list(self.headers.gui.values()).index("path")
|
row, self.headers.user_headers.index("filepath")
|
||||||
)
|
)
|
||||||
filepaths.append(idx.data())
|
filepaths.append(idx.data())
|
||||||
return filepaths
|
return filepaths
|
||||||
@ -824,7 +828,7 @@ class MusicTable(QTableView):
|
|||||||
return []
|
return []
|
||||||
selected_rows = set(index.row() for index in indexes)
|
selected_rows = set(index.row() for index in indexes)
|
||||||
id_list = [
|
id_list = [
|
||||||
self.model2.data(self.model2.index(row, 0), Qt.ItemDataRole.UserRole)
|
self.proxymodel.data(self.proxymodel.index(row, 0), Qt.ItemDataRole.UserRole)
|
||||||
for row in selected_rows
|
for row in selected_rows
|
||||||
]
|
]
|
||||||
return id_list
|
return id_list
|
||||||
@ -847,11 +851,16 @@ class MusicTable(QTableView):
|
|||||||
|
|
||||||
def set_selected_song_filepath(self) -> None:
|
def set_selected_song_filepath(self) -> None:
|
||||||
"""Sets the filepath of the currently selected song"""
|
"""Sets the filepath of the currently selected song"""
|
||||||
self.selected_song_filepath = (
|
try:
|
||||||
self.currentIndex()
|
table_index = self.headers.user_headers.index("filepath")
|
||||||
.siblingAtColumn(list(self.headers.gui.values()).index("path"))
|
filepath = self.currentIndex().siblingAtColumn(table_index).data()
|
||||||
.data()
|
except ValueError:
|
||||||
)
|
# if the user doesnt have filepath selected as a header, retrieve the file from db
|
||||||
|
row = self.currentIndex().row()
|
||||||
|
id = self.proxymodel.data(self.proxymodel.index(row, 0), Qt.ItemDataRole.UserRole)
|
||||||
|
with DBA.DBAccess() as db:
|
||||||
|
filepath = db.query('SELECT filepath FROM song WHERE id = ?', (id,))[0][0]
|
||||||
|
self.selected_song_filepath = filepath
|
||||||
|
|
||||||
def set_current_song_filepath(self) -> None:
|
def set_current_song_filepath(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
2
main.py
2
main.py
@ -424,7 +424,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow):
|
|||||||
Start playback of `tableView.current_song_filepath` & moves playback slider
|
Start playback of `tableView.current_song_filepath` & moves playback slider
|
||||||
"""
|
"""
|
||||||
if not filepath:
|
if not filepath:
|
||||||
filepath = self.tableView.get_current_song_filepath()
|
filepath = self.tableView.get_selected_song_filepath()
|
||||||
# get metadata
|
# get metadata
|
||||||
metadata = get_tags(filepath)[0]
|
metadata = get_tags(filepath)[0]
|
||||||
# read the file
|
# read the file
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user