From 6607e4e2d73ffc0abe1ce1cc2e76a613b96eb9e9 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 14:49:35 +0800 Subject: [PATCH] Ensure on removal of share that display string is updated for last (now non-)duplicate share Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index 23f03edf2da5b..2a314c3faec65 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -647,10 +647,26 @@ void ShareModel::slotRemoveShareWithId(const QString &shareId) const auto sharee = share->getShareWith(); slotRemoveSharee(sharee); - beginRemoveRows({}, shareIndex.row(), shareIndex.row()); - _shares.removeAt(shareIndex.row()); + const auto shareRow = shareIndex.row(); + beginRemoveRows({}, shareRow, shareRow); + _shares.removeAt(shareRow); endRemoveRows(); + // Handle display name duplicates now. First remove the index from the bucket it was in; then, + // check if this removal means the remaining index in the bucket is no longer a duplicate. + // If this is the case then handle the update for this item too. + const auto duplicateShares = _duplicateDisplayNameShareIndices.value(shareRow); + if (duplicateShares) { + duplicateShares->remove(shareRow); + if (duplicateShares->count() == 1) { + const auto noLongerDuplicateIndex = *(duplicateShares->begin()); + _duplicateDisplayNameShareIndices.remove(noLongerDuplicateIndex); + const auto noLongerDuplicateModelIndex = index(noLongerDuplicateIndex); + Q_EMIT dataChanged(noLongerDuplicateModelIndex, noLongerDuplicateModelIndex, {Qt::DisplayRole}); + } + _duplicateDisplayNameShareIndices.remove(shareRow); + } + handleLinkShare(); Q_EMIT sharesChanged();