diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 58963a1..80ac900 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -247,7 +247,7 @@ void MainWindow::clearGallery() void MainWindow::loadGalleryBySingleLocalFile(const QString &path) { - m_pm->loadPlaylist({QUrl::fromLocalFile(path)}); + m_pm->loadPlaylist(QUrl::fromLocalFile(path)); } void MainWindow::galleryPrev() @@ -700,7 +700,7 @@ void MainWindow::on_actionPaste_triggered() } else if (clipboardFileUrl.isValid()) { QString localFile(clipboardFileUrl.toLocalFile()); m_graphicsView->showFileFromPath(localFile, true); - m_pm->loadPlaylist({clipboardFileUrl}); + m_pm->loadPlaylist(clipboardFileUrl); } } diff --git a/app/playlistmanager.cpp b/app/playlistmanager.cpp index ac1b9ae..b8c5bdd 100644 --- a/app/playlistmanager.cpp +++ b/app/playlistmanager.cpp @@ -104,6 +104,11 @@ int PlaylistModel::indexOf(const QUrl &url) const return m_playlist.indexOf(url); } +QUrl PlaylistModel::urlByIndex(int index) const +{ + return m_playlist.value(index); +} + QStringList PlaylistModel::autoLoadFilterSuffixes() const { return m_autoLoadSuffixes; @@ -157,7 +162,7 @@ PlaylistManager::~PlaylistManager() } -const PlaylistModel *PlaylistManager::model() const +PlaylistModel *PlaylistManager::model() { return &m_model; } @@ -174,6 +179,13 @@ QModelIndex PlaylistManager::loadPlaylist(const QList &urls) return idx; } +QModelIndex PlaylistManager::loadPlaylist(const QUrl &url) +{ + QModelIndex idx = m_model.loadPlaylist(url); + setProperty("currentIndex", idx.row()); + return idx; +} + int PlaylistManager::totalCount() const { return m_model.rowCount(); @@ -209,7 +221,7 @@ void PlaylistManager::setCurrentIndex(const QModelIndex &index) QUrl PlaylistManager::urlByIndex(const QModelIndex &index) { - return m_model.data(index, PlaylistModel::UrlRole).toUrl(); + return m_model.urlByIndex(index.row()); } QString PlaylistManager::localFileByIndex(const QModelIndex &index) diff --git a/app/playlistmanager.h b/app/playlistmanager.h index 80ea5f3..0abdf6d 100644 --- a/app/playlistmanager.h +++ b/app/playlistmanager.h @@ -25,6 +25,7 @@ public: QModelIndex appendToPlaylist(const QUrl & url); bool removeAt(int index); int indexOf(const QUrl & url) const; + QUrl urlByIndex(int index) const; QStringList autoLoadFilterSuffixes() const; QModelIndex createIndex(int row) const; @@ -52,10 +53,11 @@ public: explicit PlaylistManager(QObject *parent = nullptr); ~PlaylistManager(); - const PlaylistModel * model() const; + PlaylistModel * model(); void setPlaylist(const QList & url); QModelIndex loadPlaylist(const QList & urls); + QModelIndex loadPlaylist(const QUrl & url); int totalCount() const; QModelIndex previousIndex() const;