From bc66638e5c9900b114bec5eb6aa8193a5d99bc7e Mon Sep 17 00:00:00 2001 From: Hailin Gan Date: Mon, 17 Nov 2025 11:06:13 +0800 Subject: [PATCH 1/2] Fix crash on drag and drop file to Playlist --- YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp b/YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp index 4a0612c70..8daecf3da 100644 --- a/YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp +++ b/YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp @@ -194,6 +194,10 @@ void PlaylistTreeWidget::dragMoveEvent(QDragMoveEvent *event) if (dropTarget) { auto draggedItems = selectedItems(); + if (draggedItems.size() <= 0){ + event->ignore(); + return; + } auto draggedItem = dynamic_cast(draggedItems[0]); // handle video items as target From 44d1d86c3dbca733ee6313c14bfe240f3d1018db Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Thu, 20 Nov 2025 15:27:45 +0100 Subject: [PATCH 2/2] Refactor function --- .../src/ui/widgets/PlaylistTreeWidget.cpp | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp b/YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp index 8daecf3da..447a9e6da 100644 --- a/YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp +++ b/YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp @@ -187,26 +187,30 @@ playlistItem *PlaylistTreeWidget::getDropTarget(const QPoint &pos) const void PlaylistTreeWidget::dragMoveEvent(QDragMoveEvent *event) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - auto dropTarget = this->getDropTarget(event->position().toPoint()); + const auto dropTarget = this->getDropTarget(event->position().toPoint()); #else - auto dropTarget = getDropTarget(event->pos()); + const auto dropTarget = getDropTarget(event->pos()); #endif - if (dropTarget) + + if (!dropTarget) { - auto draggedItems = selectedItems(); - if (draggedItems.size() <= 0){ - event->ignore(); - return; - } - auto draggedItem = dynamic_cast(draggedItems[0]); + event->ignore(); + return; + } - // handle video items as target - if (!dropTarget->acceptDrops(draggedItem)) - { - // no valid drop - event->ignore(); - return; - } + const auto draggedItems = this->selectedItems(); + if (draggedItems.empty()) + { + event->ignore(); + return; + } + + const auto draggedItem = dynamic_cast(draggedItems[0]); + + if (!dropTarget->acceptDrops(draggedItem)) + { + event->ignore(); + return; } QTreeWidget::dragMoveEvent(event); @@ -279,7 +283,7 @@ void PlaylistTreeWidget::updateAllContainterItems() { for (int i = 0; i < topLevelItemCount(); i++) { - QTreeWidgetItem * item = topLevelItem(i); + QTreeWidgetItem *item = topLevelItem(i); playlistItemContainer *containerItem = dynamic_cast(item); if (containerItem != nullptr) containerItem->updateChildItems(); @@ -806,7 +810,7 @@ QString PlaylistTreeWidget::getPlaylistString(QDir dirName) // Create the XML document structure QDomDocument document; document.appendChild(document.createProcessingInstruction( - QStringLiteral("xml"), QStringLiteral("version=\"1.0\" encoding=\"UTF-8\""))); + QStringLiteral("xml"), QStringLiteral("version=\"1.0\" encoding=\"UTF-8\""))); QDomElement plist = document.createElement(QStringLiteral("playlistItems")); plist.setAttribute(QStringLiteral("version"), QStringLiteral("2.0")); document.appendChild(plist); @@ -815,7 +819,7 @@ QString PlaylistTreeWidget::getPlaylistString(QDir dirName) for (int i = 0; i < topLevelItemCount(); ++i) { QTreeWidgetItem *item = topLevelItem(i); - playlistItem * plItem = dynamic_cast(item); + playlistItem *plItem = dynamic_cast(item); plItem->savePlaylist(plist, dirName); } @@ -908,7 +912,7 @@ bool PlaylistTreeWidget::loadPlaylistFromByteArray(QByteArray data, QString file QMessageBox::critical(this, "Error loading playlist.", errorMessage + - QString(" in line/column %1/%2").arg(errorLine).arg(errorColumn)); + QString(" in line/column %1/%2").arg(errorLine).arg(errorColumn)); return false; } @@ -920,16 +924,16 @@ bool PlaylistTreeWidget::loadPlaylistFromByteArray(QByteArray data, QString file { // This is a playlist file in the old format. This is not supported anymore. QMessageBox::critical( - this, - "Error loading playlist.", - "The given playlist file seems to be in the old XML format. The playlist format was " - "changed a while back and the old format is no longer supported."); + this, + "Error loading playlist.", + "The given playlist file seems to be in the old XML format. The playlist format was " + "changed a while back and the old format is no longer supported."); return false; } if (root.tagName() != "playlistItems" || root.attribute("version") != "2.0") { QMessageBox::critical( - this, "Error loading playlist.", "The playlist file format could not be recognized."); + this, "Error loading playlist.", "The playlist file format could not be recognized."); return false; } @@ -982,19 +986,19 @@ void PlaylistTreeWidget::checkAndUpdateItems() if (!changedItems.empty()) { auto ret = - QMessageBox::question(parentWidget(), - "Item changed", - "The source of one or more currently loaded items has changed. " - "Do you want to reload the item(s)?"); + QMessageBox::question(parentWidget(), + "Item changed", + "The source of one or more currently loaded items has changed. " + "Do you want to reload the item(s)?"); if (ret != QMessageBox::Yes) { ret = QMessageBox::question( - parentWidget(), - "Item changed", - "It is really recommended to reload the changed items. YUView does not always buffer all " - "data from the items. We can not guarantee that the data you are shown is correct " - "anymore. For the shown values, there is no indication if they are old or new. Parsing " - "of statistics files may fail. So again: Do you want to reload the item(s)?"); + parentWidget(), + "Item changed", + "It is really recommended to reload the changed items. YUView does not always buffer all " + "data from the items. We can not guarantee that the data you are shown is correct " + "anymore. For the shown values, there is no indication if they are old or new. Parsing " + "of statistics files may fail. So again: Do you want to reload the item(s)?"); if (ret != QMessageBox::Yes) return; // Really no } @@ -1126,7 +1130,7 @@ QList PlaylistTreeWidget::getAllPlaylistItems(const bool topLeve for (int i = 0; i < topLevelItemCount(); i++) { QTreeWidgetItem *item = topLevelItem(i); - playlistItem * plItem = dynamic_cast(item); + playlistItem *plItem = dynamic_cast(item); if (plItem != nullptr) { returnList.append(plItem);