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
|
bool ItemLibraryAssetImporter::isQuick3DAsset(const QString &fileName) const
|
||||||
{
|
{
|
||||||
|
#ifdef IMPORT_QUICK3D_ASSETS
|
||||||
static QStringList quick3DExt;
|
static QStringList quick3DExt;
|
||||||
if (quick3DExt.isEmpty()) {
|
if (quick3DExt.isEmpty()) {
|
||||||
quick3DExt << QString(Constants::FbxExtension)
|
const auto exts = m_quick3DAssetImporter->getSupportedExtensions();
|
||||||
<< QString(Constants::ColladaExtension)
|
for (const auto &ext : exts)
|
||||||
<< QString(Constants::ObjExtension)
|
quick3DExt << ext;
|
||||||
<< QString(Constants::BlenderExtension)
|
|
||||||
<< QString(Constants::GltfExtension);
|
|
||||||
}
|
}
|
||||||
return quick3DExt.contains(QFileInfo(fileName).suffix());
|
return quick3DExt.contains(QFileInfo(fileName).suffix());
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap ItemLibraryAssetImporter::supportedOptions(const QString &modelFile) const
|
QVariantMap ItemLibraryAssetImporter::supportedOptions(const QString &modelFile) const
|
||||||
@@ -182,6 +184,24 @@ QVariantMap ItemLibraryAssetImporter::supportedOptions(const QString &modelFile)
|
|||||||
#endif
|
#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()
|
void ItemLibraryAssetImporter::notifyFinished()
|
||||||
{
|
{
|
||||||
m_isImporting = false;
|
m_isImporting = false;
|
||||||
|
@@ -58,6 +58,8 @@ public:
|
|||||||
|
|
||||||
bool isQuick3DAsset(const QString &fileName) const;
|
bool isQuick3DAsset(const QString &fileName) const;
|
||||||
QVariantMap supportedOptions(const QString &modelFile) const;
|
QVariantMap supportedOptions(const QString &modelFile) const;
|
||||||
|
QHash<QString, QVariantMap> allOptions() const;
|
||||||
|
QHash<QString, QStringList> supportedExtensions() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void errorReported(const QString &, const QString &) const;
|
void errorReported(const QString &, const QString &) const;
|
||||||
|
@@ -51,6 +51,10 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/messagebox.h>
|
#include <coreplugin/messagebox.h>
|
||||||
|
|
||||||
|
#ifdef IMPORT_QUICK3D_ASSETS
|
||||||
|
#include <QtQuick3DAssetImport/private/qssgassetimportmanager_p.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@@ -196,30 +200,28 @@ ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const QString category = tr("3D Models");
|
auto add3DHandler = [&](const QString &category, const QString &ext) {
|
||||||
|
const QString filter = QStringLiteral("*.%1").arg(ext);
|
||||||
auto add3DHandler = [&actionManager, &handle3DModel, &category](const char *ext) {
|
|
||||||
const QString filter = QStringLiteral("*.%1").arg(QString::fromLatin1(ext));
|
|
||||||
actionManager->registerAddResourceHandler(
|
actionManager->registerAddResourceHandler(
|
||||||
AddResourceHandler(category, filter, handle3DModel, 10));
|
AddResourceHandler(category, filter, handle3DModel, 10));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QSSGAssetImportManager importManager;
|
||||||
|
QHash<QString, QStringList> supportedExtensions = importManager.getSupportedExtensions();
|
||||||
|
|
||||||
// Skip if 3D model handlers have already been added
|
// Skip if 3D model handlers have already been added
|
||||||
const QList<AddResourceHandler> handlers = actionManager->addResourceHandler();
|
const QList<AddResourceHandler> handlers = actionManager->addResourceHandler();
|
||||||
bool categoryAlreadyAdded = false;
|
QSet<QString> handlerCats;
|
||||||
for (const auto &handler : handlers) {
|
for (const auto &h : handlers)
|
||||||
if (handler.category == category) {
|
handlerCats.insert(h.category);
|
||||||
categoryAlreadyAdded = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!categoryAlreadyAdded) {
|
const auto categories = supportedExtensions.keys();
|
||||||
add3DHandler(Constants::FbxExtension);
|
for (const auto &category : categories) {
|
||||||
add3DHandler(Constants::ColladaExtension);
|
if (handlerCats.contains(category))
|
||||||
add3DHandler(Constants::ObjExtension);
|
continue;
|
||||||
add3DHandler(Constants::BlenderExtension);
|
const auto extensions = supportedExtensions[category];
|
||||||
add3DHandler(Constants::GltfExtension);
|
for (const auto &ext : extensions)
|
||||||
|
add3DHandler(category, ext);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -54,12 +54,6 @@ const char QUICK_3D_ASSETS_FOLDER[] = "/Quick3DAssets";
|
|||||||
const char DEFAULT_ASSET_IMPORT_FOLDER[] = "/asset_imports";
|
const char DEFAULT_ASSET_IMPORT_FOLDER[] = "/asset_imports";
|
||||||
const char QT_QUICK_3D_MODULE_NAME[] = "QtQuick3D";
|
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 {
|
namespace Internal {
|
||||||
enum { debug = 0 };
|
enum { debug = 0 };
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user