summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2023-02-13 15:17:33 +0200
committerTim Jenssen <tim.jenssen@qt.io>2023-02-23 11:22:53 +0000
commit4bf2b843c86c87ec48d433d623083a232401af34 (patch)
tree20ba09e91dcf4fa8b45689b99a013347149a5ffb
parent41905051de5e155d4b62bd41109db5ecc8ebf50e (diff)
downloadqt-creator-4bf2b843c86c87ec48d433d623083a232401af34.tar.gz
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 0b9eb65d975b499179db32457f1e76009914efe1) Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
-rw-r--r--share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsContextMenu.qml4
-rw-r--r--src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp5
-rw-r--r--src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h2
-rw-r--r--src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp2
-rw-r--r--src/plugins/qmldesigner/components/propertyeditor/assetimageprovider.cpp6
-rw-r--r--src/plugins/qmldesigner/utils/asset.cpp74
-rw-r--r--src/plugins/qmldesigner/utils/asset.h17
7 files changed, 65 insertions, 45 deletions
diff --git a/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsContextMenu.qml b/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsContextMenu.qml
index 2eda6f0773..03051c747d 100644
--- a/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsContextMenu.qml
+++ b/share/qtcreator/qmldesigner/itemLibraryQmlSources/AssetsContextMenu.qml
@@ -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])
}
diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp
index c4f1845368..e7142aa6f7 100644
--- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp
+++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp
@@ -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();
});
}
diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h
index c7ccba3339..625216af8a 100644
--- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h
+++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.h
@@ -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
{
diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp
index bf82e08aae..9f9fde4992 100644
--- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp
+++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp
@@ -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);
}
diff --git a/src/plugins/qmldesigner/components/propertyeditor/assetimageprovider.cpp b/src/plugins/qmldesigner/components/propertyeditor/assetimageprovider.cpp
index a4f5a85108..ad60079c5a 100644
--- a/src/plugins/qmldesigner/components/propertyeditor/assetimageprovider.cpp
+++ b/src/plugins/qmldesigner/components/propertyeditor/assetimageprovider.cpp
@@ -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);
diff --git a/src/plugins/qmldesigner/utils/asset.cpp b/src/plugins/qmldesigner/utils/asset.cpp
index 7e8931d9cb..738d49f334 100644
--- a/src/plugins/qmldesigner/utils/asset.cpp
+++ b/src/plugins/qmldesigner/utils/asset.cpp
@@ -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;
}
-Asset::Type Asset::type() const
+bool Asset::isSupported(const QString &path)
{
- 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 supportedSuffixes().contains(path);
+}
- return Asset::Type::Unknown;
+Asset::Type Asset::type() const
+{
+ 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
diff --git a/src/plugins/qmldesigner/utils/asset.h b/src/plugins/qmldesigner/utils/asset.h
index 9218cac3b8..a9d6d0a135 100644
--- a/src/plugins/qmldesigner/utils/asset.h
+++ b/src/plugins/qmldesigner/utils/asset.h
@@ -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