diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-04-06 16:44:55 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-04-07 12:32:23 +0000 |
commit | c2b19aa11d890a6cb2c8e3b30fb60d61e11a0cf6 (patch) | |
tree | 619c39923170ee66ef3e05b7a1d34b5b7cbe6600 | |
parent | d8bf785558cd4e9d71c4a5468acee538ca6e2d1d (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
Change-Id: Iee3db4e6c5adfdbdd7f0094b4efd65aa2ecc0f57
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit e702b64b34aff68122224f091d3b94e616771555)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm | 4 |
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]; |