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-03-02 14:50:06 +02:00
|
|
|
#include "filedownloader.h"
|
|
|
|
|
#include "fileextractor.h"
|
|
|
|
|
#include "multifiledownloader.h"
|
2022-09-22 15:04:04 +03:00
|
|
|
#include "qmldesignerconstants.h"
|
2023-03-02 14:50:06 +02: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-03-02 14:50:06 +02:00
|
|
|
m_downloadPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)
|
|
|
|
|
+ "/QtDesignStudio/bundles/Materials";
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
QTC_ASSERT(index.isValid() && index.row() < m_bundleCategories.count(), return {});
|
|
|
|
|
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-23 20:50:12 +02:00
|
|
|
if (iconsDir.exists() && iconsDir.entryList(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
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
QObject::connect(downloader, &FileDownloader::finishedChanged, this, [=]() {
|
|
|
|
|
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
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
QObject::connect(extractor, &FileExtractor::finishedChanged, this, [=]() {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
QObject::connect(downloader, &FileDownloader::finishedChanged, this, [=]() {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
QObject::connect(downloader, &FileDownloader::finishedChanged, this, [=]() {
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
createImporter(m_importerBundlePath, m_importerBundleId, m_importerSharedFiles);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
extractor->extract();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
downloader->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContentLibraryMaterialsModel::createImporter(const QString &bundlePath, const QString &bundleId,
|
|
|
|
|
const QStringList &sharedFiles)
|
|
|
|
|
{
|
|
|
|
|
m_importer = new Internal::ContentLibraryBundleImporter(bundlePath, bundleId, sharedFiles);
|
|
|
|
|
connect(m_importer, &Internal::ContentLibraryBundleImporter::importFinished, this,
|
|
|
|
|
[&](const QmlDesigner::NodeMetaInfo &metaInfo) {
|
|
|
|
|
m_importerRunning = false;
|
|
|
|
|
emit importerRunningChanged();
|
|
|
|
|
if (metaInfo.isValid())
|
|
|
|
|
emit bundleMaterialImported(metaInfo);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_importer, &Internal::ContentLibraryBundleImporter::unimportFinished, this,
|
|
|
|
|
[&](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-11-29 16:56:08 +02:00
|
|
|
m_matBundleExists = true;
|
2022-09-01 15:03:01 +03:00
|
|
|
|
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();
|
|
|
|
|
const QStringList mats = matsObj.keys();
|
|
|
|
|
for (const QString &mat : mats) {
|
|
|
|
|
const QJsonObject matObj = matsObj.value(mat).toObject();
|
|
|
|
|
|
|
|
|
|
QStringList files;
|
|
|
|
|
const QJsonArray assetsArr = matObj.value("files").toArray();
|
2022-09-21 14:44:23 +02:00
|
|
|
for (const auto /*QJson{Const,}ValueRef*/ &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();
|
|
|
|
|
TypeName type = QLatin1String("%1.%2.%3").arg(
|
|
|
|
|
QLatin1String(Constants::COMPONENT_BUNDLES_FOLDER).mid(1),
|
|
|
|
|
bundleId,
|
|
|
|
|
qml.chopped(4)).toLatin1(); // chopped(4): remove .qml
|
|
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
auto bundleMat = new ContentLibraryMaterial(category, mat, qml, type, icon, files,
|
|
|
|
|
m_downloadPath, m_baseUrl);
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
category->addBundleMaterial(bundleMat);
|
|
|
|
|
}
|
|
|
|
|
m_bundleCategories.append(category);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList sharedFiles;
|
|
|
|
|
const QJsonArray sharedFilesArr = m_matBundleObj.value("sharedFiles").toArray();
|
2022-09-21 14:44:23 +02:00
|
|
|
for (const auto /*QJson{Const,}ValueRef*/ &file : sharedFilesArr)
|
2022-09-01 15:03:01 +03:00
|
|
|
sharedFiles.append(file.toString());
|
|
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
QStringList missingSharedFiles;
|
|
|
|
|
for (const QString &s : std::as_const(sharedFiles)) {
|
|
|
|
|
const QString fullSharedFilePath = matBundleDir.filePath(s);
|
2022-10-12 20:46:17 +03:00
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
if (!QFile::exists(fullSharedFilePath))
|
|
|
|
|
missingSharedFiles.push_back(s);
|
|
|
|
|
}
|
2022-11-30 17:14:22 +02:00
|
|
|
|
2023-03-02 14:50:06 +02:00
|
|
|
if (missingSharedFiles.length() > 0) {
|
|
|
|
|
m_importerBundlePath = matBundleDir.path();
|
|
|
|
|
m_importerBundleId = bundleId;
|
|
|
|
|
m_importerSharedFiles = sharedFiles;
|
|
|
|
|
downloadSharedFiles(matBundleDir, missingSharedFiles);
|
|
|
|
|
} else {
|
|
|
|
|
createImporter(matBundleDir.path(), bundleId, sharedFiles);
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2022-10-26 19:57:41 +03:00
|
|
|
Internal::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;
|
|
|
|
|
|
|
|
|
|
bool catVisibilityChanged = false;
|
2022-11-29 16:56:08 +02:00
|
|
|
for (ContentLibraryMaterialsCategory *cat : std::as_const(m_bundleCategories))
|
2022-09-01 15:03:01 +03:00
|
|
|
catVisibilityChanged |= cat->filter(m_searchText);
|
|
|
|
|
|
2022-11-29 16:56:08 +02:00
|
|
|
updateIsEmpty();
|
2022-09-01 15:03:01 +03:00
|
|
|
|
|
|
|
|
if (catVisibilityChanged)
|
|
|
|
|
resetModel();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2022-09-22 15:04:04 +03:00
|
|
|
QString err = m_importer->importComponent(mat->qml(), mat->files());
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
QString err = m_importer->unimportComponent(mat->qml());
|
|
|
|
|
|
|
|
|
|
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
|