iOS File Dialog: Support setting name filters
Fixes: QTBUG-93624 Pick-to: 6.5 Change-Id: I2e1b522d572fd36f58a3de90f0a685f5d22dfeeb Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
3ff8629a0f
commit
ce20b81070
@ -14,6 +14,16 @@
|
|||||||
{
|
{
|
||||||
NSMutableArray <UTType *> *docTypes = [[[NSMutableArray alloc] init] autorelease];
|
NSMutableArray <UTType *> *docTypes = [[[NSMutableArray alloc] init] autorelease];
|
||||||
|
|
||||||
|
QStringList nameFilters = fileDialog->options()->nameFilters();
|
||||||
|
if (!nameFilters.isEmpty() && (fileDialog->options()->fileMode() != QFileDialogOptions::Directory
|
||||||
|
|| fileDialog->options()->fileMode() != QFileDialogOptions::DirectoryOnly))
|
||||||
|
{
|
||||||
|
QStringList results;
|
||||||
|
for (const QString &filter : nameFilters)
|
||||||
|
results.append(QPlatformFileDialogHelper::cleanFilterList(filter));
|
||||||
|
|
||||||
|
docTypes = [self computeAllowedFileTypes:results];
|
||||||
|
} else {
|
||||||
switch (fileDialog->options()->fileMode()) {
|
switch (fileDialog->options()->fileMode()) {
|
||||||
case QFileDialogOptions::AnyFile:
|
case QFileDialogOptions::AnyFile:
|
||||||
case QFileDialogOptions::ExistingFile:
|
case QFileDialogOptions::ExistingFile:
|
||||||
@ -28,6 +38,7 @@
|
|||||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeFolder]];
|
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeFolder]];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (self = [super initForOpeningContentTypes:docTypes]) {
|
if (self = [super initForOpeningContentTypes:docTypes]) {
|
||||||
m_fileDialog = fileDialog;
|
m_fileDialog = fileDialog;
|
||||||
@ -75,4 +86,25 @@
|
|||||||
emit m_fileDialog->reject();
|
emit m_fileDialog->reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSMutableArray<UTType*>*)computeAllowedFileTypes:(QStringList)filters
|
||||||
|
{
|
||||||
|
QStringList fileTypes;
|
||||||
|
for (const QString &filter : filters) {
|
||||||
|
if (filter.contains(u'?'))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (filter.count(u'*') != 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto extensions = filter.split('.', Qt::SkipEmptyParts);
|
||||||
|
fileTypes += extensions.last();
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableArray<UTType *> *result = [NSMutableArray<UTType *> arrayWithCapacity:fileTypes.size()];
|
||||||
|
for (const QString &string : fileTypes)
|
||||||
|
[result addObject:[UTType typeWithFilenameExtension:string.toNSString()]];
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user