forked from qt-creator/qt-creator
QmlDesigner: Allow texture/light probe creation for hdr and ktx files
Also refactored Asset class a bit to optimize cases where multiple type checks are done against same asset by resolving type at constructor instead of on demand. Pretty much all cases where Asset instance is needed also require resolving the type, so this makes sense. Refactored the remaining cases to not create Asset instance unnecessarily. Fixes: QDS-9128 Change-Id: If9d518c9dcfcc70962e5d4e9881889c6ac243c97 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -120,7 +120,7 @@ StudioControls.Menu {
|
|||||||
id: addTexturesItem
|
id: addTexturesItem
|
||||||
text: qsTr("Add Texture")
|
text: qsTr("Add Texture")
|
||||||
enabled: rootView.hasMaterialLibrary
|
enabled: rootView.hasMaterialLibrary
|
||||||
visible: root.__fileIndex && assetsModel.allFilePathsAreImages(root.__selectedAssetPathsList)
|
visible: root.__fileIndex && assetsModel.allFilePathsAreTextures(root.__selectedAssetPathsList)
|
||||||
height: addTexturesItem.visible ? addTexturesItem.implicitHeight : 0
|
height: addTexturesItem.visible ? addTexturesItem.implicitHeight : 0
|
||||||
onTriggered: rootView.addTextures(root.__selectedAssetPathsList)
|
onTriggered: rootView.addTextures(root.__selectedAssetPathsList)
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ StudioControls.Menu {
|
|||||||
text: qsTr("Add Light Probe")
|
text: qsTr("Add Light Probe")
|
||||||
enabled: rootView.hasMaterialLibrary
|
enabled: rootView.hasMaterialLibrary
|
||||||
visible: root.__fileIndex && root.__selectedAssetPathsList.length === 1
|
visible: root.__fileIndex && root.__selectedAssetPathsList.length === 1
|
||||||
&& assetsModel.allFilePathsAreImages(root.__selectedAssetPathsList)
|
&& assetsModel.allFilePathsAreTextures(root.__selectedAssetPathsList)
|
||||||
height: addLightProbes.visible ? addLightProbes.implicitHeight : 0
|
height: addLightProbes.visible ? addLightProbes.implicitHeight : 0
|
||||||
onTriggered: rootView.addLightProbe(root.__selectedAssetPathsList[0])
|
onTriggered: rootView.addLightProbe(root.__selectedAssetPathsList[0])
|
||||||
}
|
}
|
||||||
|
@@ -160,10 +160,11 @@ bool AssetsLibraryModel::deleteFolderRecursively(const QModelIndex &folderIndex)
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AssetsLibraryModel::allFilePathsAreImages(const QStringList &filePaths) const
|
bool AssetsLibraryModel::allFilePathsAreTextures(const QStringList &filePaths) const
|
||||||
{
|
{
|
||||||
return Utils::allOf(filePaths, [](const QString &path) {
|
return Utils::allOf(filePaths, [](const QString &path) {
|
||||||
return Asset(path).isImage();
|
Asset asset(path);
|
||||||
|
return asset.isImage() || asset.isTexture3D();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,7 +46,7 @@ public:
|
|||||||
Q_INVOKABLE bool renameFolder(const QString &folderPath, const QString &newName);
|
Q_INVOKABLE bool renameFolder(const QString &folderPath, const QString &newName);
|
||||||
Q_INVOKABLE bool addNewFolder(const QString &folderPath);
|
Q_INVOKABLE bool addNewFolder(const QString &folderPath);
|
||||||
Q_INVOKABLE bool deleteFolderRecursively(const QModelIndex &folderIndex);
|
Q_INVOKABLE bool deleteFolderRecursively(const QModelIndex &folderIndex);
|
||||||
Q_INVOKABLE bool allFilePathsAreImages(const QStringList &filePaths) const;
|
Q_INVOKABLE bool allFilePathsAreTextures(const QStringList &filePaths) const;
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override
|
||||||
{
|
{
|
||||||
|
@@ -320,7 +320,7 @@ QSet<QString> AssetsLibraryWidget::supportedAssetSuffixes(bool complex)
|
|||||||
|
|
||||||
QSet<QString> suffixes;
|
QSet<QString> suffixes;
|
||||||
for (const AddResourceHandler &handler : handlers) {
|
for (const AddResourceHandler &handler : handlers) {
|
||||||
if (Asset(handler.filter).isSupported() != complex)
|
if (Asset::isSupported(handler.filter) != complex)
|
||||||
suffixes.insert(handler.filter);
|
suffixes.insert(handler.filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,12 +18,10 @@ namespace QmlDesigner {
|
|||||||
QQuickImageResponse *AssetImageProvider::requestImageResponse(const QString &id,
|
QQuickImageResponse *AssetImageProvider::requestImageResponse(const QString &id,
|
||||||
const QSize &requestedSize)
|
const QSize &requestedSize)
|
||||||
{
|
{
|
||||||
Asset asset(id);
|
if (id.endsWith(".mesh"))
|
||||||
|
|
||||||
if (asset.suffix() == "*.mesh")
|
|
||||||
return m_imageCacheProvider.requestImageResponse(id, {});
|
return m_imageCacheProvider.requestImageResponse(id, {});
|
||||||
|
|
||||||
if (asset.suffix() == "*.builtin")
|
if (id.endsWith(".builtin"))
|
||||||
return m_imageCacheProvider.requestImageResponse("#" + id.split('.').first(), {});
|
return m_imageCacheProvider.requestImageResponse("#" + id.split('.').first(), {});
|
||||||
|
|
||||||
return m_imageCacheProvider.requestImageResponse(id, requestedSize);
|
return m_imageCacheProvider.requestImageResponse(id, requestedSize);
|
||||||
|
@@ -13,6 +13,8 @@ Asset::Asset(const QString &filePath)
|
|||||||
const QStringList split = filePath.split('.');
|
const QStringList split = filePath.split('.');
|
||||||
if (split.size() > 1)
|
if (split.size() > 1)
|
||||||
m_suffix = "*." + split.last().toLower();
|
m_suffix = "*." + split.last().toLower();
|
||||||
|
|
||||||
|
resolveType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -92,68 +94,49 @@ const QSet<QString> &Asset::supportedSuffixes()
|
|||||||
return allSuffixes;
|
return allSuffixes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Asset::isSupported(const QString &path)
|
||||||
|
{
|
||||||
|
return supportedSuffixes().contains(path);
|
||||||
|
}
|
||||||
|
|
||||||
Asset::Type Asset::type() const
|
Asset::Type Asset::type() const
|
||||||
{
|
{
|
||||||
if (supportedImageSuffixes().contains(m_suffix))
|
return m_type;
|
||||||
return Asset::Type::Image;
|
|
||||||
|
|
||||||
if (supportedFragmentShaderSuffixes().contains(m_suffix))
|
|
||||||
return Asset::Type::FragmentShader;
|
|
||||||
|
|
||||||
if (supportedShaderSuffixes().contains(m_suffix))
|
|
||||||
return Asset::Type::Shader;
|
|
||||||
|
|
||||||
if (supportedFontSuffixes().contains(m_suffix))
|
|
||||||
return Asset::Type::Font;
|
|
||||||
|
|
||||||
if (supportedAudioSuffixes().contains(m_suffix))
|
|
||||||
return Asset::Type::Audio;
|
|
||||||
|
|
||||||
if (supportedVideoSuffixes().contains(m_suffix))
|
|
||||||
return Asset::Type::Video;
|
|
||||||
|
|
||||||
if (supportedTexture3DSuffixes().contains(m_suffix))
|
|
||||||
return Asset::Type::Texture3D;
|
|
||||||
|
|
||||||
if (supportedEffectMakerSuffixes().contains(m_suffix))
|
|
||||||
return Asset::Type::Effect;
|
|
||||||
|
|
||||||
return Asset::Type::Unknown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::isImage() const
|
bool Asset::isImage() const
|
||||||
{
|
{
|
||||||
return type() == Asset::Type::Image;
|
return m_type == Asset::Type::Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::isFragmentShader() const
|
bool Asset::isFragmentShader() const
|
||||||
{
|
{
|
||||||
return type() == Asset::Type::FragmentShader;
|
return m_type == Asset::Type::FragmentShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::isShader() const
|
bool Asset::isShader() const
|
||||||
{
|
{
|
||||||
return type() == Asset::Type::Shader;
|
return m_type == Asset::Type::Shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::isFont() const
|
bool Asset::isFont() const
|
||||||
{
|
{
|
||||||
return type() == Asset::Type::Font;
|
return m_type == Asset::Type::Font;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::isAudio() const
|
bool Asset::isAudio() const
|
||||||
{
|
{
|
||||||
return type() == Asset::Type::Audio;
|
return m_type == Asset::Type::Audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::isVideo() const
|
bool Asset::isVideo() const
|
||||||
{
|
{
|
||||||
return type() == Asset::Type::Video;
|
return m_type == Asset::Type::Video;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::isTexture3D() const
|
bool Asset::isTexture3D() const
|
||||||
{
|
{
|
||||||
return type() == Asset::Type::Texture3D;
|
return m_type == Asset::Type::Texture3D;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::isHdrFile() const
|
bool Asset::isHdrFile() const
|
||||||
@@ -168,7 +151,7 @@ bool Asset::isKtxFile() const
|
|||||||
|
|
||||||
bool Asset::isEffect() const
|
bool Asset::isEffect() const
|
||||||
{
|
{
|
||||||
return type() == Asset::Type::Effect;
|
return m_type == Asset::Type::Effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString Asset::suffix() const
|
const QString Asset::suffix() const
|
||||||
@@ -183,7 +166,30 @@ const QString Asset::id() const
|
|||||||
|
|
||||||
bool Asset::isSupported() const
|
bool Asset::isSupported() const
|
||||||
{
|
{
|
||||||
return supportedSuffixes().contains(m_filePath);
|
return m_type != Asset::Type::Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Asset::resolveType()
|
||||||
|
{
|
||||||
|
if (m_suffix.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (supportedImageSuffixes().contains(m_suffix))
|
||||||
|
m_type = Asset::Type::Image;
|
||||||
|
else if (supportedFragmentShaderSuffixes().contains(m_suffix))
|
||||||
|
m_type = Asset::Type::FragmentShader;
|
||||||
|
else if (supportedShaderSuffixes().contains(m_suffix))
|
||||||
|
m_type = Asset::Type::Shader;
|
||||||
|
else if (supportedFontSuffixes().contains(m_suffix))
|
||||||
|
m_type = Asset::Type::Font;
|
||||||
|
else if (supportedAudioSuffixes().contains(m_suffix))
|
||||||
|
m_type = Asset::Type::Audio;
|
||||||
|
else if (supportedVideoSuffixes().contains(m_suffix))
|
||||||
|
m_type = Asset::Type::Video;
|
||||||
|
else if (supportedTexture3DSuffixes().contains(m_suffix))
|
||||||
|
m_type = Asset::Type::Texture3D;
|
||||||
|
else if (supportedEffectMakerSuffixes().contains(m_suffix))
|
||||||
|
m_type = Asset::Type::Effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Asset::hasSuffix() const
|
bool Asset::hasSuffix() const
|
||||||
|
@@ -3,12 +3,23 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class Asset
|
class Asset
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Type { Unknown, Image, MissingImage, FragmentShader, Font, Audio, Video, Texture3D, Effect, Shader };
|
enum Type { Unknown,
|
||||||
|
Image,
|
||||||
|
MissingImage,
|
||||||
|
FragmentShader,
|
||||||
|
Font,
|
||||||
|
Audio,
|
||||||
|
Video,
|
||||||
|
Texture3D,
|
||||||
|
Effect,
|
||||||
|
Shader };
|
||||||
|
|
||||||
Asset(const QString &filePath);
|
Asset(const QString &filePath);
|
||||||
|
|
||||||
@@ -21,6 +32,7 @@ public:
|
|||||||
static const QStringList &supportedTexture3DSuffixes();
|
static const QStringList &supportedTexture3DSuffixes();
|
||||||
static const QStringList &supportedEffectMakerSuffixes();
|
static const QStringList &supportedEffectMakerSuffixes();
|
||||||
static const QSet<QString> &supportedSuffixes();
|
static const QSet<QString> &supportedSuffixes();
|
||||||
|
static bool isSupported(const QString &path);
|
||||||
|
|
||||||
const QString suffix() const;
|
const QString suffix() const;
|
||||||
const QString id() const;
|
const QString id() const;
|
||||||
@@ -40,8 +52,11 @@ public:
|
|||||||
bool isSupported() const;
|
bool isSupported() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void resolveType();
|
||||||
|
|
||||||
QString m_filePath;
|
QString m_filePath;
|
||||||
QString m_suffix;
|
QString m_suffix;
|
||||||
|
Type m_type = Unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user