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>
(cherry picked from commit 0b9eb65d97
)
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
41905051de
commit
4bf2b843c8
@@ -120,7 +120,7 @@ StudioControls.Menu {
|
||||
id: addTexturesItem
|
||||
text: qsTr("Add Texture")
|
||||
enabled: rootView.hasMaterialLibrary
|
||||
visible: root.__fileIndex && assetsModel.allFilePathsAreImages(root.__selectedAssetPathsList)
|
||||
visible: root.__fileIndex && assetsModel.allFilePathsAreTextures(root.__selectedAssetPathsList)
|
||||
height: addTexturesItem.visible ? addTexturesItem.implicitHeight : 0
|
||||
onTriggered: rootView.addTextures(root.__selectedAssetPathsList)
|
||||
}
|
||||
@@ -130,7 +130,7 @@ StudioControls.Menu {
|
||||
text: qsTr("Add Light Probe")
|
||||
enabled: rootView.hasMaterialLibrary
|
||||
visible: root.__fileIndex && root.__selectedAssetPathsList.length === 1
|
||||
&& assetsModel.allFilePathsAreImages(root.__selectedAssetPathsList)
|
||||
&& assetsModel.allFilePathsAreTextures(root.__selectedAssetPathsList)
|
||||
height: addLightProbes.visible ? addLightProbes.implicitHeight : 0
|
||||
onTriggered: rootView.addLightProbe(root.__selectedAssetPathsList[0])
|
||||
}
|
||||
|
@@ -160,10 +160,11 @@ bool AssetsLibraryModel::deleteFolderRecursively(const QModelIndex &folderIndex)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool AssetsLibraryModel::allFilePathsAreImages(const QStringList &filePaths) const
|
||||
bool AssetsLibraryModel::allFilePathsAreTextures(const QStringList &filePaths) const
|
||||
{
|
||||
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 addNewFolder(const QString &folderPath);
|
||||
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
|
||||
{
|
||||
|
@@ -320,7 +320,7 @@ QSet<QString> AssetsLibraryWidget::supportedAssetSuffixes(bool complex)
|
||||
|
||||
QSet<QString> suffixes;
|
||||
for (const AddResourceHandler &handler : handlers) {
|
||||
if (Asset(handler.filter).isSupported() != complex)
|
||||
if (Asset::isSupported(handler.filter) != complex)
|
||||
suffixes.insert(handler.filter);
|
||||
}
|
||||
|
||||
|
@@ -18,12 +18,10 @@ namespace QmlDesigner {
|
||||
QQuickImageResponse *AssetImageProvider::requestImageResponse(const QString &id,
|
||||
const QSize &requestedSize)
|
||||
{
|
||||
Asset asset(id);
|
||||
|
||||
if (asset.suffix() == "*.mesh")
|
||||
if (id.endsWith(".mesh"))
|
||||
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, requestedSize);
|
||||
|
@@ -13,6 +13,8 @@ Asset::Asset(const QString &filePath)
|
||||
const QStringList split = filePath.split('.');
|
||||
if (split.size() > 1)
|
||||
m_suffix = "*." + split.last().toLower();
|
||||
|
||||
resolveType();
|
||||
}
|
||||
|
||||
|
||||
@@ -92,68 +94,49 @@ const QSet<QString> &Asset::supportedSuffixes()
|
||||
return allSuffixes;
|
||||
}
|
||||
|
||||
bool Asset::isSupported(const QString &path)
|
||||
{
|
||||
return supportedSuffixes().contains(path);
|
||||
}
|
||||
|
||||
Asset::Type Asset::type() const
|
||||
{
|
||||
if (supportedImageSuffixes().contains(m_suffix))
|
||||
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;
|
||||
return m_type;
|
||||
}
|
||||
|
||||
bool Asset::isImage() const
|
||||
{
|
||||
return type() == Asset::Type::Image;
|
||||
return m_type == Asset::Type::Image;
|
||||
}
|
||||
|
||||
bool Asset::isFragmentShader() const
|
||||
{
|
||||
return type() == Asset::Type::FragmentShader;
|
||||
return m_type == Asset::Type::FragmentShader;
|
||||
}
|
||||
|
||||
bool Asset::isShader() const
|
||||
{
|
||||
return type() == Asset::Type::Shader;
|
||||
return m_type == Asset::Type::Shader;
|
||||
}
|
||||
|
||||
bool Asset::isFont() const
|
||||
{
|
||||
return type() == Asset::Type::Font;
|
||||
return m_type == Asset::Type::Font;
|
||||
}
|
||||
|
||||
bool Asset::isAudio() const
|
||||
{
|
||||
return type() == Asset::Type::Audio;
|
||||
return m_type == Asset::Type::Audio;
|
||||
}
|
||||
|
||||
bool Asset::isVideo() const
|
||||
{
|
||||
return type() == Asset::Type::Video;
|
||||
return m_type == Asset::Type::Video;
|
||||
}
|
||||
|
||||
bool Asset::isTexture3D() const
|
||||
{
|
||||
return type() == Asset::Type::Texture3D;
|
||||
return m_type == Asset::Type::Texture3D;
|
||||
}
|
||||
|
||||
bool Asset::isHdrFile() const
|
||||
@@ -168,7 +151,7 @@ bool Asset::isKtxFile() const
|
||||
|
||||
bool Asset::isEffect() const
|
||||
{
|
||||
return type() == Asset::Type::Effect;
|
||||
return m_type == Asset::Type::Effect;
|
||||
}
|
||||
|
||||
const QString Asset::suffix() const
|
||||
@@ -183,7 +166,30 @@ const QString Asset::id() 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
|
||||
|
@@ -3,12 +3,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class Asset
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -21,6 +32,7 @@ public:
|
||||
static const QStringList &supportedTexture3DSuffixes();
|
||||
static const QStringList &supportedEffectMakerSuffixes();
|
||||
static const QSet<QString> &supportedSuffixes();
|
||||
static bool isSupported(const QString &path);
|
||||
|
||||
const QString suffix() const;
|
||||
const QString id() const;
|
||||
@@ -40,8 +52,11 @@ public:
|
||||
bool isSupported() const;
|
||||
|
||||
private:
|
||||
void resolveType();
|
||||
|
||||
QString m_filePath;
|
||||
QString m_suffix;
|
||||
Type m_type = Unknown;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
Reference in New Issue
Block a user