summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-04-06 16:44:55 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-04-07 14:05:04 +0200
commite702b64b34aff68122224f091d3b94e616771555 (patch)
tree1d7f24a0701bee390040e35eefd73ec03ae89276 /src/plugins/platforms/cocoa
parent07098034162d0f345662c549269ca2d4c6f36f25 (diff)
macOS: Allow duplicate entries in file dialog name filter
Using QFileDialog::setMimeTypeFilters() with a list of mime types may in some cases result in the same name for two different mime types, for example both "image/heic" and "image/heif" will result in the name "HEIF image (*.heic *.heif)". When the resulting name filter is propagated to the platform layer, we add entries to a NSPopUpButton, but the convenience API we used, addItemWithTitle:, does not allow duplicates. As a result, the entries in the menu didn't match the list of name filters we then looked up and applied to the actual file name filtering, causing off by one errors. Ideally we'd make sure the name filters are unique and well formed all the way from the QFileDialog to the platform and back, but for now we work around issue by using the NSMenu API directly, which does allow for duplicate entires. Fixes: QTBUG-101361 Pick-to: 6.2 6.3 Change-Id: Iee3db4e6c5adfdbdd7f0094b4efd65aa2ecc0f57 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index 51925feb5b..367164d740 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -303,7 +303,7 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
if (filters.size() > 0){
for (int i = 0; i < filters.size(); ++i) {
QString filter = hideDetails ? [self removeExtensions:filters.at(i)] : filters.at(i);
- [m_popupButton addItemWithTitle:filter.toNSString()];
+ [m_popupButton.menu addItemWithTitle:filter.toNSString() action:nil keyEquivalent:@""];
}
[m_popupButton selectItemAtIndex:0];
m_panel.accessoryView = m_accessoryView;
@@ -497,7 +497,7 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
(filterToUse == -1 && currentFilter.startsWith(selectedFilter)))
filterToUse = i;
QString filter = hideDetails ? [self removeExtensions:currentFilter] : currentFilter;
- [m_popupButton addItemWithTitle:filter.toNSString()];
+ [m_popupButton.menu addItemWithTitle:filter.toNSString() action:nil keyEquivalent:@""];
}
if (filterToUse != -1)
[m_popupButton selectItemAtIndex:filterToUse];