2022-10-26 19:57:41 +03:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-10-26 19:57:41 +03:00
|
|
|
|
|
|
|
|
#include "contentlibrarymaterialsmodel.h"
|
|
|
|
|
|
|
|
|
|
#include "contentlibrarybundleimporter.h"
|
|
|
|
|
#include "contentlibrarymaterial.h"
|
|
|
|
|
#include "contentlibrarymaterialscategory.h"
|
2022-11-29 16:56:08 +02:00
|
|
|
#include "contentlibrarywidget.h"
|
2023-05-03 15:03:57 +03:00
|
|
|
|
2024-04-09 15:27:42 +03:00
|
|
|
#include "designerpaths.h"
|
2023-03-02 14:50:06 +02:00
|
|
|
#include "filedownloader.h"
|
|
|
|
|
#include "fileextractor.h"
|
|
|
|
|
#include "multifiledownloader.h"
|
2024-04-09 15:27:42 +03:00
|
|
|
|
|
|
|
|
#include <qmldesignerplugin.h>
|
2022-11-29 16:56:08 +02:00
|
|
|
|
2023-03-06 10:46:05 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2022-09-20 16:45:26 +03:00
|
|
|
#include <QCoreApplication>
|
2022-09-01 15:03:01 +03:00
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
2023-03-02 14:50:06 +02:00
|
|
|
#include <QQmlEngine>
|
|
|
|
|
#include <QStandardPaths>
|
2022-09-01 15:03:01 +03:00
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2022-11-29 16:56:08 +02:00
|
|
|
ContentLibraryMaterialsModel::ContentLibraryMaterialsModel(ContentLibraryWidget *parent)
|
2022-09-01 15:03:01 +03:00
|
|
|
: QAbstractListModel(parent)
|
2022-11-29 16:56:08 +02:00
|
|
|
, m_widget(parent)
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
2023-05-03 15:03:57 +03:00
|
|
|
m_downloadPath = Paths::bundlesPathSetting() + "/Materials";
|
2023-03-02 14:50:06 +02:00
|
|
|
|
|
|
|
|
m_baseUrl = QmlDesignerPlugin::settings()
|
|
|
|
|
.value(DesignerSettingsKey::DOWNLOADABLE_BUNDLES_URL)
|
|
|
|
|
.toString() + "/materials/v1";
|
|
|
|
|
|
|
|
|
|
qmlRegisterType<QmlDesigner::FileDownloader>("WebFetcher", 1, 0, "FileDownloader");
|
|
|
|
|
qmlRegisterType<QmlDesigner::MultiFileDownloader>("WebFetcher", 1, 0, "MultiFileDownloader");
|
2024-04-25 18:36:24 +03:00
|
|
|
}
|
2023-03-02 14:50:06 +02:00
|
|
|
|
2024-04-25 18:36:24 +03:00
|
|
|
void ContentLibraryMaterialsModel::loadBundle()
|
|
|
|
|
{
|
2023-03-02 14:50:06 +02:00
|
|
|
QDir bundleDir{m_downloadPath};
|
|
|
|
|
if (fetchBundleMetadata(bundleDir) && fetchBundleIcons(bundleDir))
|
|
|
|
|
loadMaterialBundle(bundleDir);
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
int ContentLibraryMaterialsModel::rowCount(const QModelIndex &) const
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
|
|
|
|
return m_bundleCategories.size();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
QVariant ContentLibraryMaterialsModel::data(const QModelIndex &index, int role) const
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
2023-06-07 13:03:11 +02:00
|
|
|
QTC_ASSERT(index.isValid() && index.row() < m_bundleCategories.size(), return {});
|
2022-09-01 15:03:01 +03:00
|
|
|
QTC_ASSERT(roleNames().contains(role), return {});
|
|
|
|
|
|
2022-10-20 22:44:59 +03:00
|
|
|
return m_bundleCategories.at(index.row())->property(roleNames().value(role));
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
bool ContentLibraryMaterialsModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2022-10-20 22:44:59 +03:00
|
|
|
{
|
|
|
|
|
if (!index.isValid() || !roleNames().contains(role))
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
QByteArray roleName = roleNames().value(role);
|
2022-10-26 19:57:41 +03:00
|
|
|
ContentLibraryMaterialsCategory *bundleCategory = m_bundleCategories.at(index.row());
|
2022-10-20 22:44:59 +03:00
|
|
|
QVariant currValue = bundleCategory->property(roleName);
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2022-10-20 22:44:59 +03:00
|
|
|
if (currValue != value) {
|
|
|
|
|
bundleCategory->setProperty(roleName, value);
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2022-10-20 22:44:59 +03:00
|
|
|
emit dataChanged(index, index, {role});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2022-10-20 22:44:59 +03:00
|
|
|
return false;
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
bool ContentLibraryMaterialsModel::isValidIndex(int idx) const
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
|
|
|
|
return idx > -1 && idx < rowCount();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 16:56:08 +02:00
|
|
|
void ContentLibraryMaterialsModel::updateIsEmpty()
|
|
|
|
|
{
|
|
|
|
|
const bool anyCatVisible = Utils::anyOf(m_bundleCategories,
|
|
|
|
|
[&](ContentLibraryMaterialsCategory *cat) {
|
|
|
|
|
return cat->visible();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const bool newEmpty = !anyCatVisible || m_bundleCategories.isEmpty()
|
|
|
|
|
|| !m_widget->hasMaterialLibrary() || !hasRequiredQuick3DImport();
|
|
|
|
|
|
|
|
|
|
if (newEmpty != m_isEmpty) {
|
|
|
|
|
m_isEmpty = newEmpty;
|
|
|
|
|
emit isEmptyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
QHash<int, QByteArray> ContentLibraryMaterialsModel::roleNames() const
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
|
|
|
|
static const QHash<int, QByteArray> roles {
|
2022-10-20 22:44:59 +03:00
|
|
|
{Qt::UserRole + 1, "bundleCategoryName"},
|
2022-09-01 15:03:01 +03:00
|
|
|
{Qt::UserRole + 2, "bundleCategoryVisible"},
|
2022-10-20 22:44:59 +03:00
|
|
|
{Qt::UserRole + 3, "bundleCategoryExpanded"},
|
|
|
|
|
{Qt::UserRole + 4, "bundleCategoryMaterials"}
|
2022-09-01 15:03:01 +03:00
|
|
|
};
|
|
|
|
|
return roles;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
bool ContentLibraryMaterialsModel::fetchBundleIcons(const QDir &bundleDir)
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
2023-03-02 14:50:06 +02:00
|
|
|
QString iconsPath = bundleDir.filePath("icons");
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
QDir iconsDir(iconsPath);
|
2023-03-28 20:46:31 +03:00
|
|
|
if (iconsDir.exists() && iconsDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot).length() > 0)
|
2023-03-02 14:50:06 +02:00
|
|
|
return true;
|
2023-03-06 10:46:05 +01:00
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
QString zipFileUrl = m_baseUrl + "/icons.zip";
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
FileDownloader *downloader = new FileDownloader(this);
|
|
|
|
|
downloader->setUrl(zipFileUrl);
|
|
|
|
|
downloader->setProbeUrl(false);
|
|
|
|
|
downloader->setDownloadEnabled(true);
|
2022-09-20 16:45:26 +03:00
|
|
|
|
2024-02-06 14:01:07 +01:00
|
|
|
QObject::connect(downloader, &FileDownloader::finishedChanged, this,
|
|
|
|
|
[this, downloader, bundleDir] {
|
2023-03-02 14:50:06 +02:00
|
|
|
FileExtractor *extractor = new FileExtractor(this);
|
|
|
|
|
extractor->setArchiveName(downloader->completeBaseName());
|
|
|
|
|
extractor->setSourceFile(downloader->outputFile());
|
|
|
|
|
extractor->setTargetPath(bundleDir.absolutePath());
|
|
|
|
|
extractor->setAlwaysCreateDir(false);
|
|
|
|
|
extractor->setClearTargetPathContents(false);
|
2022-09-20 16:45:26 +03:00
|
|
|
|
2024-02-06 14:01:07 +01:00
|
|
|
QObject::connect(extractor, &FileExtractor::finishedChanged, this,
|
|
|
|
|
[this, downloader, bundleDir, extractor] {
|
2023-03-02 14:50:06 +02:00
|
|
|
downloader->deleteLater();
|
|
|
|
|
extractor->deleteLater();
|
|
|
|
|
|
|
|
|
|
loadMaterialBundle(bundleDir);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
extractor->extract();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
downloader->start();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ContentLibraryMaterialsModel::fetchBundleMetadata(const QDir &bundleDir)
|
|
|
|
|
{
|
|
|
|
|
QString matBundlePath = bundleDir.filePath("material_bundle.json");
|
|
|
|
|
|
|
|
|
|
QFileInfo fi(matBundlePath);
|
|
|
|
|
if (fi.exists() && fi.size() > 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
QString metaFileUrl = m_baseUrl + "/material_bundle.json";
|
|
|
|
|
FileDownloader *downloader = new FileDownloader(this);
|
|
|
|
|
downloader->setUrl(metaFileUrl);
|
|
|
|
|
downloader->setProbeUrl(false);
|
|
|
|
|
downloader->setDownloadEnabled(true);
|
|
|
|
|
downloader->setTargetFilePath(matBundlePath);
|
|
|
|
|
|
2024-02-06 14:01:07 +01:00
|
|
|
QObject::connect(downloader, &FileDownloader::finishedChanged, this,
|
|
|
|
|
[this, downloader, bundleDir] {
|
2023-03-02 14:50:06 +02:00
|
|
|
if (fetchBundleIcons(bundleDir))
|
|
|
|
|
loadMaterialBundle(bundleDir);
|
|
|
|
|
downloader->deleteLater();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
downloader->start();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 15:36:14 +01:00
|
|
|
void ContentLibraryMaterialsModel::downloadSharedFiles(const QDir &targetDir, const QStringList &)
|
2023-03-02 14:50:06 +02:00
|
|
|
{
|
|
|
|
|
QString metaFileUrl = m_baseUrl + "/shared_files.zip";
|
|
|
|
|
FileDownloader *downloader = new FileDownloader(this);
|
|
|
|
|
downloader->setUrl(metaFileUrl);
|
|
|
|
|
downloader->setProbeUrl(false);
|
|
|
|
|
downloader->setDownloadEnabled(true);
|
|
|
|
|
|
2024-02-06 14:01:07 +01:00
|
|
|
QObject::connect(downloader, &FileDownloader::finishedChanged, this,
|
|
|
|
|
[this, downloader, targetDir] {
|
2023-03-02 14:50:06 +02:00
|
|
|
FileExtractor *extractor = new FileExtractor(this);
|
|
|
|
|
extractor->setArchiveName(downloader->completeBaseName());
|
|
|
|
|
extractor->setSourceFile(downloader->outputFile());
|
|
|
|
|
extractor->setTargetPath(targetDir.absolutePath());
|
|
|
|
|
extractor->setAlwaysCreateDir(false);
|
|
|
|
|
extractor->setClearTargetPathContents(false);
|
|
|
|
|
|
|
|
|
|
QObject::connect(extractor, &FileExtractor::finishedChanged, this, [this, downloader, extractor]() {
|
|
|
|
|
downloader->deleteLater();
|
|
|
|
|
extractor->deleteLater();
|
2024-04-29 11:25:21 +03:00
|
|
|
createImporter();
|
2023-03-02 14:50:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
extractor->extract();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
downloader->start();
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 11:25:21 +03:00
|
|
|
void ContentLibraryMaterialsModel::createImporter()
|
2023-03-02 14:50:06 +02:00
|
|
|
{
|
2024-04-29 15:29:46 +03:00
|
|
|
m_importer = new ContentLibraryBundleImporter();
|
2023-07-13 12:10:14 +02:00
|
|
|
#ifdef QDS_USE_PROJECTSTORAGE
|
|
|
|
|
connect(m_importer,
|
2024-04-29 15:29:46 +03:00
|
|
|
&ContentLibraryBundleImporter::importFinished,
|
2023-07-13 12:10:14 +02:00
|
|
|
this,
|
|
|
|
|
[&](const QmlDesigner::TypeName &typeName) {
|
|
|
|
|
m_importerRunning = false;
|
|
|
|
|
emit importerRunningChanged();
|
|
|
|
|
if (typeName.size())
|
|
|
|
|
emit bundleMaterialImported(typeName);
|
|
|
|
|
});
|
|
|
|
|
#else
|
|
|
|
|
connect(m_importer,
|
2024-04-29 15:29:46 +03:00
|
|
|
&ContentLibraryBundleImporter::importFinished,
|
2023-07-13 12:10:14 +02:00
|
|
|
this,
|
2023-03-02 14:50:06 +02:00
|
|
|
[&](const QmlDesigner::NodeMetaInfo &metaInfo) {
|
|
|
|
|
m_importerRunning = false;
|
|
|
|
|
emit importerRunningChanged();
|
|
|
|
|
if (metaInfo.isValid())
|
|
|
|
|
emit bundleMaterialImported(metaInfo);
|
|
|
|
|
});
|
2023-07-13 12:10:14 +02:00
|
|
|
#endif
|
2023-03-02 14:50:06 +02:00
|
|
|
|
2024-04-29 15:29:46 +03:00
|
|
|
connect(m_importer, &ContentLibraryBundleImporter::unimportFinished, this,
|
2023-03-02 14:50:06 +02:00
|
|
|
[&](const QmlDesigner::NodeMetaInfo &metaInfo) {
|
|
|
|
|
Q_UNUSED(metaInfo)
|
|
|
|
|
m_importerRunning = false;
|
|
|
|
|
emit importerRunningChanged();
|
|
|
|
|
emit bundleMaterialUnimported(metaInfo);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
resetModel();
|
|
|
|
|
updateIsEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentLibraryMaterialsModel::loadMaterialBundle(const QDir &matBundleDir)
|
|
|
|
|
{
|
|
|
|
|
if (m_matBundleExists)
|
|
|
|
|
return;
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2022-09-20 16:45:26 +03:00
|
|
|
QString matBundlePath = matBundleDir.filePath("material_bundle.json");
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
if (m_matBundleObj.isEmpty()) {
|
|
|
|
|
QFile matPropsFile(matBundlePath);
|
|
|
|
|
|
|
|
|
|
if (!matPropsFile.open(QIODevice::ReadOnly)) {
|
|
|
|
|
qWarning("Couldn't open material_bundle.json");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonDocument matBundleJsonDoc = QJsonDocument::fromJson(matPropsFile.readAll());
|
|
|
|
|
if (matBundleJsonDoc.isNull()) {
|
|
|
|
|
qWarning("Invalid material_bundle.json file");
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
m_matBundleObj = matBundleJsonDoc.object();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-12 20:46:17 +03:00
|
|
|
QString bundleId = m_matBundleObj.value("id").toString();
|
2022-09-22 15:04:04 +03:00
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
const QJsonObject catsObj = m_matBundleObj.value("categories").toObject();
|
|
|
|
|
const QStringList categories = catsObj.keys();
|
|
|
|
|
for (const QString &cat : categories) {
|
2022-10-26 19:57:41 +03:00
|
|
|
auto category = new ContentLibraryMaterialsCategory(this, cat);
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
const QJsonObject matsObj = catsObj.value(cat).toObject();
|
2024-04-11 18:27:02 +03:00
|
|
|
const QStringList matsNames = matsObj.keys();
|
|
|
|
|
for (const QString &matName : matsNames) {
|
|
|
|
|
const QJsonObject matObj = matsObj.value(matName).toObject();
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
QStringList files;
|
|
|
|
|
const QJsonArray assetsArr = matObj.value("files").toArray();
|
2024-04-26 14:49:05 +03:00
|
|
|
for (const QJsonValueConstRef &asset : assetsArr)
|
2022-09-01 15:03:01 +03:00
|
|
|
files.append(asset.toString());
|
|
|
|
|
|
2022-09-22 15:04:04 +03:00
|
|
|
QUrl icon = QUrl::fromLocalFile(matBundleDir.filePath(matObj.value("icon").toString()));
|
|
|
|
|
QString qml = matObj.value("qml").toString();
|
2024-04-09 15:27:42 +03:00
|
|
|
TypeName type = QLatin1String("%1.%2.%3")
|
|
|
|
|
.arg(QmlDesignerPlugin::instance()->documentManager()
|
|
|
|
|
.generatedComponentUtils().componentBundlesTypePrefix(),
|
|
|
|
|
bundleId,
|
|
|
|
|
qml.chopped(4)).toLatin1(); // chopped(4): remove .qml
|
2022-09-22 15:04:04 +03:00
|
|
|
|
2024-04-11 18:27:02 +03:00
|
|
|
auto bundleMat = new ContentLibraryMaterial(category, matName, qml, type, icon, files,
|
2023-03-02 14:50:06 +02:00
|
|
|
m_downloadPath, m_baseUrl);
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
category->addBundleMaterial(bundleMat);
|
|
|
|
|
}
|
|
|
|
|
m_bundleCategories.append(category);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-29 11:25:21 +03:00
|
|
|
m_importerSharedFiles.clear();
|
2022-09-01 15:03:01 +03:00
|
|
|
const QJsonArray sharedFilesArr = m_matBundleObj.value("sharedFiles").toArray();
|
2024-04-26 14:49:05 +03:00
|
|
|
for (const QJsonValueConstRef &file : sharedFilesArr)
|
2024-04-29 11:25:21 +03:00
|
|
|
m_importerSharedFiles.append(file.toString());
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
QStringList missingSharedFiles;
|
2024-04-29 11:25:21 +03:00
|
|
|
for (const QString &s : std::as_const(m_importerSharedFiles)) {
|
|
|
|
|
if (!QFileInfo::exists(matBundleDir.filePath(s)))
|
2023-03-02 14:50:06 +02:00
|
|
|
missingSharedFiles.push_back(s);
|
|
|
|
|
}
|
2022-11-30 17:14:22 +02:00
|
|
|
|
2024-04-29 11:25:21 +03:00
|
|
|
if (missingSharedFiles.length() > 0)
|
2023-03-02 14:50:06 +02:00
|
|
|
downloadSharedFiles(matBundleDir, missingSharedFiles);
|
2024-04-29 11:25:21 +03:00
|
|
|
else
|
|
|
|
|
createImporter();
|
2023-03-28 11:54:12 +03:00
|
|
|
|
|
|
|
|
m_matBundleExists = true;
|
|
|
|
|
emit matBundleExistsChanged();
|
2022-10-26 19:57:41 +03:00
|
|
|
}
|
|
|
|
|
|
2022-11-29 16:56:08 +02:00
|
|
|
bool ContentLibraryMaterialsModel::hasRequiredQuick3DImport() const
|
2022-10-26 19:57:41 +03:00
|
|
|
{
|
2022-11-29 16:56:08 +02:00
|
|
|
return m_widget->hasQuick3DImport() && m_quick3dMajorVersion == 6 && m_quick3dMinorVersion >= 3;
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
bool ContentLibraryMaterialsModel::matBundleExists() const
|
2022-10-27 16:40:52 +03:00
|
|
|
{
|
2022-11-29 16:56:08 +02:00
|
|
|
return m_matBundleExists;
|
2022-10-27 16:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
2024-04-29 15:29:46 +03:00
|
|
|
ContentLibraryBundleImporter *ContentLibraryMaterialsModel::bundleImporter() const
|
2022-10-12 20:46:17 +03:00
|
|
|
{
|
|
|
|
|
return m_importer;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
void ContentLibraryMaterialsModel::setSearchText(const QString &searchText)
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
|
|
|
|
QString lowerSearchText = searchText.toLower();
|
|
|
|
|
|
|
|
|
|
if (m_searchText == lowerSearchText)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_searchText = lowerSearchText;
|
|
|
|
|
|
2023-06-22 15:17:04 +03:00
|
|
|
for (int i = 0; i < m_bundleCategories.size(); ++i) {
|
|
|
|
|
ContentLibraryMaterialsCategory *cat = m_bundleCategories.at(i);
|
|
|
|
|
bool catVisibilityChanged = cat->filter(m_searchText);
|
|
|
|
|
if (catVisibilityChanged)
|
|
|
|
|
emit dataChanged(index(i), index(i), {roleNames().keys("bundleCategoryVisible")});
|
|
|
|
|
}
|
2022-09-01 15:03:01 +03:00
|
|
|
|
2022-11-29 16:56:08 +02:00
|
|
|
updateIsEmpty();
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
void ContentLibraryMaterialsModel::updateImportedState(const QStringList &importedMats)
|
2022-10-12 20:46:17 +03:00
|
|
|
{
|
|
|
|
|
bool changed = false;
|
2022-10-26 19:57:41 +03:00
|
|
|
for (ContentLibraryMaterialsCategory *cat : std::as_const(m_bundleCategories))
|
2022-10-12 20:46:17 +03:00
|
|
|
changed |= cat->updateImportedState(importedMats);
|
|
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
|
resetModel();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
void ContentLibraryMaterialsModel::setQuick3DImportVersion(int major, int minor)
|
2022-10-27 16:40:52 +03:00
|
|
|
{
|
2022-11-29 16:56:08 +02:00
|
|
|
bool oldRequiredImport = hasRequiredQuick3DImport();
|
2022-10-27 16:40:52 +03:00
|
|
|
|
|
|
|
|
m_quick3dMajorVersion = major;
|
|
|
|
|
m_quick3dMinorVersion = minor;
|
|
|
|
|
|
2022-11-29 16:56:08 +02:00
|
|
|
bool newRequiredImport = hasRequiredQuick3DImport();
|
|
|
|
|
|
|
|
|
|
if (oldRequiredImport == newRequiredImport)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
emit hasRequiredQuick3DImportChanged();
|
|
|
|
|
|
|
|
|
|
updateIsEmpty();
|
2022-10-27 16:40:52 +03:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
void ContentLibraryMaterialsModel::resetModel()
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
|
|
|
|
beginResetModel();
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
void ContentLibraryMaterialsModel::applyToSelected(ContentLibraryMaterial *mat, bool add)
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
|
|
|
|
emit applyToSelectedTriggered(mat, add);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
void ContentLibraryMaterialsModel::addToProject(ContentLibraryMaterial *mat)
|
2022-09-01 15:03:01 +03:00
|
|
|
{
|
2024-04-29 11:25:21 +03:00
|
|
|
QString err = m_importer->importComponent(mat->dirPath(), mat->type(),
|
|
|
|
|
mat->qml(), mat->files() + m_importerSharedFiles);
|
2022-09-22 15:04:04 +03:00
|
|
|
|
2022-10-12 20:46:17 +03:00
|
|
|
if (err.isEmpty()) {
|
|
|
|
|
m_importerRunning = true;
|
|
|
|
|
emit importerRunningChanged();
|
|
|
|
|
} else {
|
2022-09-22 15:04:04 +03:00
|
|
|
qWarning() << __FUNCTION__ << err;
|
2022-10-12 20:46:17 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
void ContentLibraryMaterialsModel::removeFromProject(ContentLibraryMaterial *mat)
|
2022-10-12 20:46:17 +03:00
|
|
|
{
|
|
|
|
|
emit bundleMaterialAboutToUnimport(mat->type());
|
|
|
|
|
|
2024-04-29 11:25:21 +03:00
|
|
|
QString err = m_importer->unimportComponent(mat->type(), mat->qml());
|
2022-10-12 20:46:17 +03:00
|
|
|
|
|
|
|
|
if (err.isEmpty()) {
|
|
|
|
|
m_importerRunning = true;
|
|
|
|
|
emit importerRunningChanged();
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << __FUNCTION__ << err;
|
|
|
|
|
}
|
2022-09-01 15:03:01 +03:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
bool ContentLibraryMaterialsModel::hasModelSelection() const
|
|
|
|
|
{
|
|
|
|
|
return m_hasModelSelection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentLibraryMaterialsModel::setHasModelSelection(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (b == m_hasModelSelection)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_hasModelSelection = b;
|
|
|
|
|
emit hasModelSelectionChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 15:03:01 +03:00
|
|
|
} // namespace QmlDesigner
|