forked from qt-creator/qt-creator
QmlDesigner: Use wildcard for all files and split image formats
Having a large filter makes the dialog unresponsive, so all files filter is changed to *.* and image formats are split according to mime type. For unsuported suffixes we show an error message. Task-number: QDS-5921 Change-Id: Ia2dc912c7e7004da97da48753562173ed163436f Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Miikka Heikkinen
parent
c1c147a9dc
commit
f9c21253c0
@@ -1550,16 +1550,27 @@ void DesignerActionManager::createDefaultAddResourceHandler()
|
||||
registerAddResourceHandler(AddResourceHandler(category, ext, op));
|
||||
};
|
||||
|
||||
// Having a single image type category creates too large of a filter, so we split images into
|
||||
// categories according to their mime types
|
||||
const QList<QByteArray> mimeTypes = QImageReader::supportedMimeTypes();
|
||||
auto transformer = [](const QByteArray& format) -> QString { return QString("*.") + format; };
|
||||
auto imageFormats = Utils::transform(QImageReader::supportedImageFormats(), transformer);
|
||||
imageFormats.push_back("*.hdr");
|
||||
imageFormats.push_back("*.ktx");
|
||||
QHash<QByteArray, QStringList> imageFormats;
|
||||
for (const auto &mimeType : mimeTypes)
|
||||
imageFormats.insert(mimeType, Utils::transform(QImageReader::imageFormatsForMimeType(mimeType), transformer));
|
||||
imageFormats.insert("image/vnd.radiance", {"*.hdr"});
|
||||
imageFormats.insert("image/ktx", {"*.ktx"});
|
||||
|
||||
// The filters will be displayed in reverse order to these lists in file dialog,
|
||||
// so declare most common types last
|
||||
registerHandlers(imageFormats,
|
||||
ModelNodeOperations::addImageToProject,
|
||||
ComponentCoreConstants::addImagesDisplayString);
|
||||
QHash<QByteArray, QStringList>::const_iterator i = imageFormats.constBegin();
|
||||
while (i != imageFormats.constEnd()) {
|
||||
registerHandlers(i.value(),
|
||||
ModelNodeOperations::addImageToProject,
|
||||
QObject::tr("%1: %2")
|
||||
.arg(ComponentCoreConstants::addImagesDisplayString)
|
||||
.arg(QString::fromLatin1(i.key())));
|
||||
++i;
|
||||
}
|
||||
registerHandlers({"*.otf", "*.ttf"},
|
||||
ModelNodeOperations::addFontToProject,
|
||||
ComponentCoreConstants::addFontsDisplayString);
|
||||
|
@@ -619,7 +619,7 @@ void ItemLibraryWidget::addResources(const QStringList &files)
|
||||
return priorities.value(first) < priorities.value(second);
|
||||
});
|
||||
|
||||
QStringList filters { tr("All Files (%1)").arg(map.values().join(' ')) };
|
||||
QStringList filters { tr("All Files (%1)").arg("*.*") };
|
||||
QString filterTemplate = "%1 (%2)";
|
||||
for (const QString &key : qAsConst(sortedKeys))
|
||||
filters.append(filterTemplate.arg(key, map.values(key).join(' ')));
|
||||
@@ -660,11 +660,17 @@ void ItemLibraryWidget::addResources(const QStringList &files)
|
||||
AddResourceOperation operation = categoryToOperation.value(category);
|
||||
QmlDesignerPlugin::emitUsageStatistics(Constants::EVENT_RESOURCE_IMPORTED + category);
|
||||
if (operation) {
|
||||
AddFilesResult result = operation(fileNames, document->fileName().parentDir().toString());
|
||||
AddFilesResult result = operation(fileNames,
|
||||
document->fileName().parentDir().toString());
|
||||
if (result == AddFilesResult::Failed) {
|
||||
Core::AsynchronousMessageBox::warning(tr("Failed to Add Files"),
|
||||
tr("Could not add %1 to project.").arg(fileNames.join(' ')));
|
||||
tr("Could not add %1 to project.")
|
||||
.arg(fileNames.join(' ')));
|
||||
}
|
||||
} else {
|
||||
Core::AsynchronousMessageBox::warning(tr("Failed to Add Files"),
|
||||
tr("Could not add %1 to project. Unsupported file format.")
|
||||
.arg(fileNames.join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user