forked from qt-creator/qt-creator
QmlDesigner: Query supported file extensions from Quick3D importer
By querying the extensions instead of hardcoding them, it is easier to keep up to date with importer changes. Change-Id: I394510d62f816ec34d20290223a7b9fbdbf9b93b Fixes: QDS-1151 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -162,15 +162,17 @@ void ItemLibraryAssetImporter::addInfo(const QString &infoMsg, const QString &sr
|
||||
|
||||
bool ItemLibraryAssetImporter::isQuick3DAsset(const QString &fileName) const
|
||||
{
|
||||
#ifdef IMPORT_QUICK3D_ASSETS
|
||||
static QStringList quick3DExt;
|
||||
if (quick3DExt.isEmpty()) {
|
||||
quick3DExt << QString(Constants::FbxExtension)
|
||||
<< QString(Constants::ColladaExtension)
|
||||
<< QString(Constants::ObjExtension)
|
||||
<< QString(Constants::BlenderExtension)
|
||||
<< QString(Constants::GltfExtension);
|
||||
const auto exts = m_quick3DAssetImporter->getSupportedExtensions();
|
||||
for (const auto &ext : exts)
|
||||
quick3DExt << ext;
|
||||
}
|
||||
return quick3DExt.contains(QFileInfo(fileName).suffix());
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
QVariantMap ItemLibraryAssetImporter::supportedOptions(const QString &modelFile) const
|
||||
@@ -182,6 +184,24 @@ QVariantMap ItemLibraryAssetImporter::supportedOptions(const QString &modelFile)
|
||||
#endif
|
||||
}
|
||||
|
||||
QHash<QString, QVariantMap> ItemLibraryAssetImporter::allOptions() const
|
||||
{
|
||||
#ifdef IMPORT_QUICK3D_ASSETS
|
||||
return m_quick3DAssetImporter->getAllOptions();
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
QHash<QString, QStringList> ItemLibraryAssetImporter::supportedExtensions() const
|
||||
{
|
||||
#ifdef IMPORT_QUICK3D_ASSETS
|
||||
return m_quick3DAssetImporter->getSupportedExtensions();
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
void ItemLibraryAssetImporter::notifyFinished()
|
||||
{
|
||||
m_isImporting = false;
|
||||
|
@@ -58,6 +58,8 @@ public:
|
||||
|
||||
bool isQuick3DAsset(const QString &fileName) const;
|
||||
QVariantMap supportedOptions(const QString &modelFile) const;
|
||||
QHash<QString, QVariantMap> allOptions() const;
|
||||
QHash<QString, QStringList> supportedExtensions() const;
|
||||
|
||||
signals:
|
||||
void errorReported(const QString &, const QString &) const;
|
||||
|
@@ -51,6 +51,10 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/messagebox.h>
|
||||
|
||||
#ifdef IMPORT_QUICK3D_ASSETS
|
||||
#include <QtQuick3DAssetImport/private/qssgassetimportmanager_p.h>
|
||||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDrag>
|
||||
#include <QFileDialog>
|
||||
@@ -196,30 +200,28 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
|
||||
return true;
|
||||
};
|
||||
|
||||
const QString category = tr("3D Models");
|
||||
|
||||
auto add3DHandler = [&actionManager, &handle3DModel, &category](const char *ext) {
|
||||
const QString filter = QStringLiteral("*.%1").arg(QString::fromLatin1(ext));
|
||||
auto add3DHandler = [&](const QString &category, const QString &ext) {
|
||||
const QString filter = QStringLiteral("*.%1").arg(ext);
|
||||
actionManager->registerAddResourceHandler(
|
||||
AddResourceHandler(category, filter, handle3DModel, 10));
|
||||
};
|
||||
|
||||
QSSGAssetImportManager importManager;
|
||||
QHash<QString, QStringList> supportedExtensions = importManager.getSupportedExtensions();
|
||||
|
||||
// Skip if 3D model handlers have already been added
|
||||
const QList<AddResourceHandler> handlers = actionManager->addResourceHandler();
|
||||
bool categoryAlreadyAdded = false;
|
||||
for (const auto &handler : handlers) {
|
||||
if (handler.category == category) {
|
||||
categoryAlreadyAdded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QSet<QString> handlerCats;
|
||||
for (const auto &h : handlers)
|
||||
handlerCats.insert(h.category);
|
||||
|
||||
if (!categoryAlreadyAdded) {
|
||||
add3DHandler(Constants::FbxExtension);
|
||||
add3DHandler(Constants::ColladaExtension);
|
||||
add3DHandler(Constants::ObjExtension);
|
||||
add3DHandler(Constants::BlenderExtension);
|
||||
add3DHandler(Constants::GltfExtension);
|
||||
const auto categories = supportedExtensions.keys();
|
||||
for (const auto &category : categories) {
|
||||
if (handlerCats.contains(category))
|
||||
continue;
|
||||
const auto extensions = supportedExtensions[category];
|
||||
for (const auto &ext : extensions)
|
||||
add3DHandler(category, ext);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -54,12 +54,6 @@ const char QUICK_3D_ASSETS_FOLDER[] = "/Quick3DAssets";
|
||||
const char DEFAULT_ASSET_IMPORT_FOLDER[] = "/asset_imports";
|
||||
const char QT_QUICK_3D_MODULE_NAME[] = "QtQuick3D";
|
||||
|
||||
const char FbxExtension[] = "fbx";
|
||||
const char ColladaExtension[] = "dae";
|
||||
const char ObjExtension[] = "obj";
|
||||
const char BlenderExtension[] = "blend";
|
||||
const char GltfExtension[] = "gltf";
|
||||
|
||||
namespace Internal {
|
||||
enum { debug = 0 };
|
||||
}
|
||||
|
Reference in New Issue
Block a user