QmlDesigner: More integration cleanup

Instead of a warning we now provide different functions for the project
storage. Should give better errors.

Change-Id: I48cea16482950c2b3c5eea3e72d4e9c40b9e75b2
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2024-09-18 12:45:41 +02:00
parent d0099404ec
commit 6820b89227
30 changed files with 600 additions and 537 deletions

View File

@@ -7,9 +7,10 @@
#include <auxiliarydataproperties.h> #include <auxiliarydataproperties.h>
#include <externaldependenciesinterface.h> #include <externaldependenciesinterface.h>
#include <plaintexteditmodifier.h> #include <plaintexteditmodifier.h>
#include <qmldesignerplugin.h>
#include <qmldesignerprojectmanager.h>
#include <rewriterview.h> #include <rewriterview.h>
#include <signalhandlerproperty.h> #include <signalhandlerproperty.h>
#include <qmldesignerplugin.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectmanager.h> #include <projectexplorer/projectmanager.h>
@@ -192,7 +193,9 @@ Qt::CheckState checkState(const std::vector<std::string> &a, const std::vector<s
struct ModelBuilder struct ModelBuilder
{ {
ModelBuilder(const QString &filePath, ExternalDependenciesInterface &externalDependencies) ModelBuilder(const QString &filePath,
ExternalDependenciesInterface &externalDependencies,
[[maybe_unused]] ProjectStorageDependencies projectStorageDependencies)
{ {
const QString fileContent = fileToString(filePath); const QString fileContent = fileToString(filePath);
if (fileContent.isEmpty()) { if (fileContent.isEmpty()) {
@@ -209,7 +212,14 @@ struct ModelBuilder
rewriter->setCheckLinkErrors(false); rewriter->setCheckLinkErrors(false);
rewriter->setTextModifier(modifier.get()); rewriter->setTextModifier(modifier.get());
#ifdef QDS_USE_PROJECTSTORAGE
model = QmlDesigner::Model::create(projectStorageDependencies,
"Item",
{Import::createLibraryImport("QtQuick")},
filePath);
#else
model = QmlDesigner::Model::create("QtQuick.Item", 2, 1); model = QmlDesigner::Model::create("QtQuick.Item", 2, 1);
#endif
model->setRewriterView(rewriter.get()); model->setRewriterView(rewriter.get());
} }
@@ -221,9 +231,12 @@ struct ModelBuilder
} // namespace } // namespace
InsightModel::InsightModel(InsightView *view, ExternalDependenciesInterface &externalDependencies) InsightModel::InsightModel(InsightView *view,
ExternalDependenciesInterface &externalDependencies,
QmlDesignerProjectManager &projectManager)
: m_insightView(view) : m_insightView(view)
, m_externalDependencies(externalDependencies) , m_externalDependencies(externalDependencies)
, m_projectManager(projectManager)
, m_fileSystemWatcher(new Utils::FileSystemWatcher(this)) , m_fileSystemWatcher(new Utils::FileSystemWatcher(this))
{ {
QObject::connect(ProjectExplorer::ProjectManager::instance(), QObject::connect(ProjectExplorer::ProjectManager::instance(),
@@ -446,7 +459,9 @@ void InsightModel::setEnabled(bool value)
return; return;
} }
ModelBuilder builder(m_mainQmlInfo.absoluteFilePath(), m_externalDependencies); ModelBuilder builder(m_mainQmlInfo.absoluteFilePath(),
m_externalDependencies,
m_projectManager.projectStorageDependencies());
if (!builder.model) { if (!builder.model) {
qWarning() << "Could not create model" << m_mainQmlInfo.absoluteFilePath(); qWarning() << "Could not create model" << m_mainQmlInfo.absoluteFilePath();
@@ -613,7 +628,9 @@ int InsightModel::devicePixelRatio()
void InsightModel::parseMainQml() void InsightModel::parseMainQml()
{ {
ModelBuilder builder(m_mainQmlInfo.absoluteFilePath(), m_externalDependencies); ModelBuilder builder(m_mainQmlInfo.absoluteFilePath(),
m_externalDependencies,
m_projectManager.projectStorageDependencies());
if (!builder.model) if (!builder.model)
return; return;

View File

@@ -39,7 +39,9 @@ class InsightModel : public QAbstractListModel
}; };
public: public:
InsightModel(InsightView *view, class ExternalDependenciesInterface &externalDependencies); InsightModel(InsightView *view,
class ExternalDependenciesInterface &externalDependencies,
class QmlDesignerProjectManager &projectManager);
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
@@ -109,6 +111,7 @@ private:
private: private:
QPointer<InsightView> m_insightView; QPointer<InsightView> m_insightView;
ExternalDependenciesInterface &m_externalDependencies; ExternalDependenciesInterface &m_externalDependencies;
QmlDesignerProjectManager &m_projectManager;
Utils::FileSystemWatcher *m_fileSystemWatcher; Utils::FileSystemWatcher *m_fileSystemWatcher;

View File

@@ -20,7 +20,8 @@ class InsightPlugin final : public ExtensionSystem::IPlugin
auto *designerPlugin = QmlDesignerPlugin::instance(); auto *designerPlugin = QmlDesignerPlugin::instance();
auto &viewManager = designerPlugin->viewManager(); auto &viewManager = designerPlugin->viewManager();
viewManager.registerView(std::make_unique<InsightView>( viewManager.registerView(std::make_unique<InsightView>(
QmlDesignerPlugin::externalDependenciesForPluginInitializationOnly())); QmlDesignerPlugin::externalDependenciesForPluginInitializationOnly(),
QmlDesignerPlugin::projectManagerForPluginInitializationOnly()));
return true; return true;
} }

View File

@@ -14,9 +14,10 @@
namespace QmlDesigner { namespace QmlDesigner {
InsightView::InsightView(ExternalDependenciesInterface &externalDependencies) InsightView::InsightView(ExternalDependenciesInterface &externalDependencies,
QmlDesignerProjectManager &projectManager)
: AbstractView(externalDependencies) : AbstractView(externalDependencies)
, m_insightModel(std::make_unique<InsightModel>(this, externalDependencies)) , m_insightModel(std::make_unique<InsightModel>(this, externalDependencies, projectManager))
{ {
Q_ASSERT(m_insightModel); Q_ASSERT(m_insightModel);
} }

View File

@@ -15,13 +15,15 @@ namespace QmlDesigner {
class InsightModel; class InsightModel;
class InsightWidget; class InsightWidget;
class QmlDesignerProjectManager;
class InsightView : public AbstractView class InsightView : public AbstractView
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit InsightView(ExternalDependenciesInterface &externalDependencies); explicit InsightView(ExternalDependenciesInterface &externalDependencies,
QmlDesignerProjectManager &projectManager);
~InsightView() override; ~InsightView() override;
// AbstractView // AbstractView

View File

@@ -56,9 +56,10 @@ add_qtc_plugin(QmlDesigner
DEFINES DEFINES
IDE_LIBRARY_BASENAME=\"${IDE_LIBRARY_BASE_PATH}\" IDE_LIBRARY_BASENAME=\"${IDE_LIBRARY_BASE_PATH}\"
SHARE_QML_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../../../share/qtcreator/qmldesigner" SHARE_QML_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../../../share/qtcreator/qmldesigner"
$<$<BOOL:${USE_PROJECTSTORAGE}>:QDS_USE_PROJECTSTORAGE>
$<$<BOOL:${QTC_USE_QML_DESIGNER_LITE}>:QTC_USE_QML_DESIGNER_LITE> $<$<BOOL:${QTC_USE_QML_DESIGNER_LITE}>:QTC_USE_QML_DESIGNER_LITE>
$<$<BOOL:${DETACH_DISABLED_VIEWS}>:DETACH_DISABLED_VIEWS> $<$<BOOL:${DETACH_DISABLED_VIEWS}>:DETACH_DISABLED_VIEWS>
PUBLIC_DEFINES
$<$<BOOL:${USE_PROJECTSTORAGE}>:QDS_USE_PROJECTSTORAGE>
INCLUDES INCLUDES
${CMAKE_CURRENT_LIST_DIR}/libs ${CMAKE_CURRENT_LIST_DIR}/libs
${CMAKE_CURRENT_LIST_DIR}/components ${CMAKE_CURRENT_LIST_DIR}/components

View File

@@ -81,13 +81,13 @@ private:
std::atomic<bool> m_quitDumper; std::atomic<bool> m_quitDumper;
}; };
AssetExporter::AssetExporter(AssetExporterView *view,
ProjectExplorer::Project *project,
AssetExporter::AssetExporter(AssetExporterView *view, ProjectExplorer::Project *project, QObject *parent) : ProjectStorageDependencies projectStorageDependencies)
QObject(parent), : m_currentState(*this)
m_currentState(*this), , m_project(project)
m_project(project), , m_view(view)
m_view(view) , m_projectStorageDependencies{projectStorageDependencies}
{ {
connect(m_view, &AssetExporterView::loadingFinished, this, &AssetExporter::onQmlFileLoaded); connect(m_view, &AssetExporterView::loadingFinished, this, &AssetExporter::onQmlFileLoaded);
connect(m_view, &AssetExporterView::loadingError, this, &AssetExporter::notifyLoadError); connect(m_view, &AssetExporterView::loadingError, this, &AssetExporter::notifyLoadError);
@@ -257,7 +257,14 @@ void AssetExporter::preprocessQmlFile(const Utils::FilePath &path)
{ {
// Load the QML file and assign UUIDs to items having none. // Load the QML file and assign UUIDs to items having none.
// Meanwhile cache the Component UUIDs as well // Meanwhile cache the Component UUIDs as well
ModelPointer model(Model::create("Item", 2, 7)); #ifdef QDS_USE_PROJECTSTORAGE
ModelPointer model = Model::create(m_projectStorageDependencies,
"Item",
{Import::createLibraryImport("QtQuick")},
path.path());
#else
ModelPointer model = Model::create("Item", 2, 7);
#endif
Utils::FileReader reader; Utils::FileReader reader;
if (!reader.fetch(path)) { if (!reader.fetch(path)) {
ExportNotification::addError(tr("Cannot preprocess file: %1. Error %2") ExportNotification::addError(tr("Cannot preprocess file: %1. Error %2")

View File

@@ -39,8 +39,9 @@ public:
ExportingDone ExportingDone
}; };
AssetExporter(AssetExporterView *view, ProjectExplorer::Project *project, AssetExporter(AssetExporterView *view,
QObject *parent = nullptr); ProjectExplorer::Project *project,
ProjectStorageDependencies projectStorageDependencies);
~AssetExporter(); ~AssetExporter();
void exportQml(const Utils::FilePaths &qmlFiles, const Utils::FilePath &exportPath, void exportQml(const Utils::FilePaths &qmlFiles, const Utils::FilePath &exportPath,
@@ -96,6 +97,7 @@ private:
QHash<QString, QString> m_componentUuidCache; QHash<QString, QString> m_componentUuidCache;
QSet<QByteArray> m_usedHashes; QSet<QByteArray> m_usedHashes;
QHash<QString, QPixmap> m_assets; QHash<QString, QPixmap> m_assets;
ProjectStorageDependencies m_projectStorageDependencies;
std::unique_ptr<AssetDumper> m_assetDumper; std::unique_ptr<AssetDumper> m_assetDumper;
bool m_cancelled = false; bool m_cancelled = false;
}; };

View File

@@ -3,12 +3,13 @@
#include "assetexporterplugin.h" #include "assetexporterplugin.h"
#include "assetexportpluginconstants.h"
#include "assetexportdialog.h" #include "assetexportdialog.h"
#include "assetexporter.h" #include "assetexporter.h"
#include "assetexporterview.h" #include "assetexporterview.h"
#include "filepathmodel.h" #include "assetexportpluginconstants.h"
#include "componentexporter.h" #include "componentexporter.h"
#include "filepathmodel.h"
#include <qmldesignerprojectmanager.h>
#include "dumpers/itemnodedumper.h" #include "dumpers/itemnodedumper.h"
#include "dumpers/textnodedumper.h" #include "dumpers/textnodedumper.h"
@@ -37,6 +38,7 @@
namespace QmlDesigner { namespace QmlDesigner {
AssetExporterPlugin::AssetExporterPlugin() AssetExporterPlugin::AssetExporterPlugin()
: m_projectManager{QmlDesigner::QmlDesignerPlugin::projectManagerForPluginInitializationOnly()}
{ {
ProjectExplorer::TaskHub::addCategory({Constants::TASK_CATEGORY_ASSET_EXPORT, ProjectExplorer::TaskHub::addCategory({Constants::TASK_CATEGORY_ASSET_EXPORT,
tr("Asset Export"), tr("Asset Export"),
@@ -44,6 +46,7 @@ AssetExporterPlugin::AssetExporterPlugin()
false}); false});
auto *designerPlugin = QmlDesigner::QmlDesignerPlugin::instance(); auto *designerPlugin = QmlDesigner::QmlDesignerPlugin::instance();
auto &viewManager = designerPlugin->viewManager(); auto &viewManager = designerPlugin->viewManager();
m_view = viewManager.registerView(std::make_unique<AssetExporterView>( m_view = viewManager.registerView(std::make_unique<AssetExporterView>(
designerPlugin->externalDependenciesForPluginInitializationOnly())); designerPlugin->externalDependenciesForPluginInitializationOnly()));
@@ -79,7 +82,7 @@ void AssetExporterPlugin::onExport()
if (!exportDir.parentDir().isEmpty()) if (!exportDir.parentDir().isEmpty())
exportDir = exportDir.parentDir(); exportDir = exportDir.parentDir();
exportDir = exportDir.pathAppended(startupProject->displayName() + "_export"); exportDir = exportDir.pathAppended(startupProject->displayName() + "_export");
AssetExporter assetExporter(m_view, startupProject); AssetExporter assetExporter(m_view, startupProject, m_projectManager.projectStorageDependencies());
AssetExportDialog assetExporterDialog(exportDir, assetExporter, model); AssetExportDialog assetExporterDialog(exportDir, assetExporter, model);
assetExporterDialog.exec(); assetExporterDialog.exec();
} }

View File

@@ -29,6 +29,7 @@ private:
void updateActions(); void updateActions();
AssetExporterView *m_view = nullptr; AssetExporterView *m_view = nullptr;
class QmlDesignerProjectManager &m_projectManager;
}; };
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -21,19 +21,6 @@
namespace { namespace {
Q_LOGGING_CATEGORY(loggerInfo, "qtc.designer.assetExportPlugin.modelExporter", QtInfoMsg) Q_LOGGING_CATEGORY(loggerInfo, "qtc.designer.assetExportPlugin.modelExporter", QtInfoMsg)
static QByteArrayList populateLineage(const QmlDesigner::ModelNode &node)
{
QByteArrayList lineage;
if (!node.isValid() || node.type().isEmpty())
return {};
for (auto &info : node.metaInfo().prototypes())
lineage.append(info.typeName());
return lineage;
}
} }
namespace QmlDesigner { namespace QmlDesigner {
@@ -78,10 +65,9 @@ const QString &Component::name() const
NodeDumper *Component::createNodeDumper(const ModelNode &node) const NodeDumper *Component::createNodeDumper(const ModelNode &node) const
{ {
QByteArrayList lineage = populateLineage(node);
std::unique_ptr<NodeDumper> reader; std::unique_ptr<NodeDumper> reader;
for (auto &dumperCreator: m_readers) { for (auto &dumperCreator: m_readers) {
std::unique_ptr<NodeDumper> r(dumperCreator->instance(lineage, node)); std::unique_ptr<NodeDumper> r(dumperCreator->instance(node));
if (r->isExportable()) { if (r->isExportable()) {
if (reader) { if (reader) {
if (reader->priority() < r->priority()) if (reader->priority() < r->priority())

View File

@@ -27,7 +27,7 @@ class NodeDumperCreatorBase
public: public:
virtual ~NodeDumperCreatorBase() {} virtual ~NodeDumperCreatorBase() {}
protected: protected:
virtual NodeDumper *instance(const QByteArrayList &, const ModelNode &) const = 0; virtual NodeDumper *instance(const ModelNode &) const = 0;
friend Component; friend Component;
}; };
@@ -39,9 +39,7 @@ public:
~NodeDumperCreator() = default; ~NodeDumperCreator() = default;
protected: protected:
NodeDumper *instance(const QByteArrayList &lineage, const ModelNode &node) const { NodeDumper *instance(const ModelNode &node) const { return new T(node); }
return new T(lineage, node);
}
}; };
} //Internal } //Internal

View File

@@ -14,18 +14,18 @@
namespace QmlDesigner { namespace QmlDesigner {
using namespace Constants; using namespace Constants;
AssetNodeDumper::AssetNodeDumper(const QByteArrayList &lineage, const ModelNode &node) :
ItemNodeDumper(lineage, node) AssetNodeDumper::AssetNodeDumper(const ModelNode &node)
: ItemNodeDumper(node)
{ {
} }
bool AssetNodeDumper::isExportable() const bool AssetNodeDumper::isExportable() const
{ {
auto hasType = [this](const QByteArray &type) { auto qtQuickImageMetaInfo = model()->qtQuickImageMetaInfo();
return lineage().contains(type); auto qtQuickRectangleMetaInfo = model()->qtQuickRectangleMetaInfo();
}; return metaInfo().isBasedOn(qtQuickImageMetaInfo, qtQuickRectangleMetaInfo);
return hasType("QtQuick.Image") || hasType("QtQuick.Rectangle");
} }
QJsonObject AssetNodeDumper::json(Component &component) const QJsonObject AssetNodeDumper::json(Component &component) const

View File

@@ -10,7 +10,7 @@ class Component;
class AssetNodeDumper : public ItemNodeDumper class AssetNodeDumper : public ItemNodeDumper
{ {
public: public:
AssetNodeDumper(const QByteArrayList &lineage, const ModelNode &node); AssetNodeDumper(const ModelNode &node);
~AssetNodeDumper() override = default; ~AssetNodeDumper() override = default;
bool isExportable() const override; bool isExportable() const override;

View File

@@ -22,16 +22,16 @@ static QString capitalize(const QString &str)
namespace QmlDesigner { namespace QmlDesigner {
using namespace Constants; using namespace Constants;
ItemNodeDumper::ItemNodeDumper(const QByteArrayList &lineage,
const ModelNode &node) : ItemNodeDumper::ItemNodeDumper(const ModelNode &node)
NodeDumper(lineage, node) : NodeDumper(node)
{ {
} }
bool QmlDesigner::ItemNodeDumper::isExportable() const bool QmlDesigner::ItemNodeDumper::isExportable() const
{ {
return lineage().contains("QtQuick.Item"); return metaInfo().isQtQuickItem();
} }
QJsonObject QmlDesigner::ItemNodeDumper::json([[maybe_unused]] QmlDesigner::Component &component) const QJsonObject QmlDesigner::ItemNodeDumper::json([[maybe_unused]] QmlDesigner::Component &component) const

View File

@@ -11,7 +11,7 @@ class Component;
class ItemNodeDumper : public NodeDumper class ItemNodeDumper : public NodeDumper
{ {
public: public:
ItemNodeDumper(const QByteArrayList &lineage, const ModelNode &node); ItemNodeDumper(const ModelNode &node);
~ItemNodeDumper() override = default; ~ItemNodeDumper() override = default;

View File

@@ -6,10 +6,11 @@
#include <auxiliarydataproperties.h> #include <auxiliarydataproperties.h>
namespace QmlDesigner { namespace QmlDesigner {
NodeDumper::NodeDumper(const QByteArrayList &lineage, const ModelNode &node) : NodeDumper::NodeDumper(const ModelNode &node)
m_node(node), : m_node(node)
m_objectNode(node), , m_objectNode(node)
m_lineage(lineage) , m_metaInfo(node.metaInfo())
, m_model{node.model()}
{ {
} }

View File

@@ -14,7 +14,7 @@ class ModelNode;
class NodeDumper class NodeDumper
{ {
public: public:
NodeDumper(const QByteArrayList &lineage, const ModelNode &node); NodeDumper(const ModelNode &node);
virtual ~NodeDumper() = default; virtual ~NodeDumper() = default;
@@ -22,16 +22,19 @@ public:
virtual bool isExportable() const = 0; virtual bool isExportable() const = 0;
virtual QJsonObject json(Component& component) const = 0; virtual QJsonObject json(Component& component) const = 0;
const QByteArrayList& lineage() const { return m_lineage; } const NodeMetaInfo &metaInfo() const { return m_metaInfo; }
const QmlObjectNode& objectNode() const { return m_objectNode; } const QmlObjectNode& objectNode() const { return m_objectNode; }
QVariant propertyValue(const PropertyName &name) const; QVariant propertyValue(const PropertyName &name) const;
QString uuid() const; QString uuid() const;
Model *model() const { return m_model; }
protected: protected:
const ModelNode &m_node; const ModelNode &m_node;
private: private:
QmlObjectNode m_objectNode; QmlObjectNode m_objectNode;
QByteArrayList m_lineage; NodeMetaInfo m_metaInfo;
Model *m_model = nullptr;
}; };
} }

View File

@@ -4,6 +4,8 @@
#include "textnodedumper.h" #include "textnodedumper.h"
#include "assetexportpluginconstants.h" #include "assetexportpluginconstants.h"
#include <model.h>
#include <QColor> #include <QColor>
#include <QFontInfo> #include <QFontInfo>
#include <QFontMetricsF> #include <QFontMetricsF>
@@ -35,18 +37,18 @@ QString toJsonAlignEnum(QString value) {
namespace QmlDesigner { namespace QmlDesigner {
using namespace Constants; using namespace Constants;
TextNodeDumper::TextNodeDumper(const QByteArrayList &lineage, const ModelNode &node) :
ItemNodeDumper(lineage, node) TextNodeDumper::TextNodeDumper(const ModelNode &node)
: ItemNodeDumper(node)
{ {
} }
bool TextNodeDumper::isExportable() const bool TextNodeDumper::isExportable() const
{ {
const QByteArrayList &baseClasses = lineage(); auto qtQuickTextMetaInfo = model()->qtQuickTextMetaInfo();
return std::any_of(baseClasses.cbegin(), baseClasses.cend(), [](const QByteArray &type) { auto qtQuickControlsLabelMetaInfo = model()->qtQuickControlsLabelMetaInfo();
return type == "QtQuick.Text" || type == "QtQuick.Controls.Label"; return metaInfo().isBasedOn(qtQuickTextMetaInfo, qtQuickControlsLabelMetaInfo);
});
} }
QJsonObject TextNodeDumper::json([[maybe_unused]] Component &component) const QJsonObject TextNodeDumper::json([[maybe_unused]] Component &component) const

View File

@@ -10,7 +10,7 @@ class Component;
class TextNodeDumper : public ItemNodeDumper class TextNodeDumper : public ItemNodeDumper
{ {
public: public:
TextNodeDumper(const QByteArrayList &lineage, const ModelNode &node); TextNodeDumper(const ModelNode &node);
~TextNodeDumper() override = default; ~TextNodeDumper() override = default;
bool isExportable() const override; bool isExportable() const override;

View File

@@ -376,10 +376,11 @@ void ItemLibraryModel::update(Model *model)
for (const ItemLibraryEntry &entry : itemLibEntries) { for (const ItemLibraryEntry &entry : itemLibEntries) {
NodeMetaInfo metaInfo; NodeMetaInfo metaInfo;
if constexpr (useProjectStorage()) #ifdef QDS_USE_PROJECTSTORAGE
metaInfo = NodeMetaInfo{entry.typeId(), model->projectStorage()}; metaInfo = NodeMetaInfo{entry.typeId(), model->projectStorage()};
else #else
metaInfo = model->metaInfo(entry.typeName()); metaInfo = model->metaInfo(entry.typeName());
#endif
#ifdef QDS_USE_PROJECTSTORAGE #ifdef QDS_USE_PROJECTSTORAGE
bool valid = metaInfo.isValid(); bool valid = metaInfo.isValid();

View File

@@ -24,13 +24,6 @@
#include <variant> #include <variant>
#ifdef QDS_USE_PROJECTSTORAGE
# define DEPRECATED_OLD_CREATE_MODELNODE \
[[deprecated("Use unqualified type names and no versions!")]]
#else
# define DEPRECATED_OLD_CREATE_MODELNODE
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QPixmap; class QPixmap;
class QUrl; class QUrl;
@@ -91,31 +84,32 @@ public:
Imports imports, Imports imports,
const QUrl &fileUrl, const QUrl &fileUrl,
std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {}); std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {});
#ifndef QDS_USE_PROJECTSTORAGE
Model(const TypeName &typeName, Model(const TypeName &typeName,
int major = 1, int major = 1,
int minor = 1, int minor = 1,
Model *metaInfoProxyModel = nullptr, Model *metaInfoProxyModel = nullptr,
std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {}); std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {});
#endif
~Model(); ~Model();
DEPRECATED_OLD_CREATE_MODELNODE static ModelPointer create( #ifndef QDS_USE_PROJECTSTORAGE
const TypeName &typeName, static ModelPointer create(const TypeName &typeName,
int major = 1, int major = 1,
int minor = 1, int minor = 1,
Model *metaInfoProxyModel = nullptr, Model *metaInfoProxyModel = nullptr,
std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {}) std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {})
{ {
return ModelPointer( return ModelPointer(
new Model(typeName, major, minor, metaInfoProxyModel, std::move(resourceManagement))); new Model(typeName, major, minor, metaInfoProxyModel, std::move(resourceManagement)));
} }
#endif
static ModelPointer create( static ModelPointer create(ProjectStorageDependencies projectStorageDependencies,
ProjectStorageDependencies projectStorageDependencies, Utils::SmallStringView typeName,
Utils::SmallStringView typeName, Imports imports,
Imports imports, const QUrl &fileUrl,
const QUrl &fileUrl, std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {})
std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {})
{ {
return ModelPointer(new Model(projectStorageDependencies, return ModelPointer(new Model(projectStorageDependencies,
typeName, typeName,
@@ -124,12 +118,12 @@ public:
std::move(resourceManagement))); std::move(resourceManagement)));
} }
DEPRECATED_OLD_CREATE_MODELNODE static ModelPointer create( #ifndef QDS_USE_PROJECTSTORAGE
ProjectStorageDependencies projectStorageDependencies, static ModelPointer create(ProjectStorageDependencies projectStorageDependencies,
const TypeName &typeName, const TypeName &typeName,
int major = 1, int major = 1,
int minor = 1, int minor = 1,
std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {}) std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {})
{ {
return ModelPointer(new Model(projectStorageDependencies, return ModelPointer(new Model(projectStorageDependencies,
typeName, typeName,
@@ -138,6 +132,7 @@ public:
nullptr, nullptr,
std::move(resourceManagement))); std::move(resourceManagement)));
} }
#endif
ModelPointer createModel(const TypeName &typeName, ModelPointer createModel(const TypeName &typeName,
std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {}); std::unique_ptr<ModelResourceManagementInterface> resourceManagement = {});
@@ -188,6 +183,7 @@ public:
NodeMetaInfo qtQuick3DTextureMetaInfo() const; NodeMetaInfo qtQuick3DTextureMetaInfo() const;
NodeMetaInfo qtQuick3DTextureInputMetaInfo() const; NodeMetaInfo qtQuick3DTextureInputMetaInfo() const;
NodeMetaInfo qtQuickBorderImageMetaInfo() const; NodeMetaInfo qtQuickBorderImageMetaInfo() const;
NodeMetaInfo qtQuickControlsLabelMetaInfo() const;
NodeMetaInfo qtQuickControlsTextAreaMetaInfo() const; NodeMetaInfo qtQuickControlsTextAreaMetaInfo() const;
NodeMetaInfo qtQuickImageMetaInfo() const; NodeMetaInfo qtQuickImageMetaInfo() const;
NodeMetaInfo qtQuickItemMetaInfo() const; NodeMetaInfo qtQuickItemMetaInfo() const;

View File

@@ -23,22 +23,6 @@ QT_BEGIN_NAMESPACE
class QDeclarativeContext; class QDeclarativeContext;
QT_END_NAMESPACE QT_END_NAMESPACE
#ifdef QDS_USE_PROJECTSTORAGE
# define DEPRECATED_TYPENAME [[deprecated("Don't use string based types anymore!")]]
# define DEPRECATED_VERSION_NUMBER \
[[deprecated( \
"In most cases you don't need them anymore because the import is setting them!")]]
# define DEPRECATED_COMPONENT_FILE_NAME [[deprecated("Use sourceId() instead.")]]
# define DEPRECATED_IMPORT_DIRECTORY_PATH [[deprecated("Use allExportedTypeNames().")]]
# define DEPRECATED_REQUIRED_IMPORT_STRING [[deprecated("Use allExportedTypeNames().")]]
#else
# define DEPRECATED_TYPENAME
# define DEPRECATED_VERSION_NUMBER
# define DEPRECATED_COMPONENT_FILE_NAME
# define DEPRECATED_IMPORT_DIRECTORY_PATH
# define DEPRECATED_REQUIRED_IMPORT_STRING
#endif
namespace QmlDesigner { namespace QmlDesigner {
class MetaInfo; class MetaInfo;
@@ -54,7 +38,9 @@ class QMLDESIGNERCORE_EXPORT NodeMetaInfo
public: public:
NodeMetaInfo(); NodeMetaInfo();
#ifndef QDS_USE_PROJECTSTORAGE
NodeMetaInfo(Model *model, const TypeName &typeName, int majorVersion, int minorVersion); NodeMetaInfo(Model *model, const TypeName &typeName, int majorVersion, int minorVersion);
#else
NodeMetaInfo(TypeId typeId, NotNullPointer<const ProjectStorageType> projectStorage) NodeMetaInfo(TypeId typeId, NotNullPointer<const ProjectStorageType> projectStorage)
: m_typeId{typeId} : m_typeId{typeId}
, m_projectStorage{projectStorage} , m_projectStorage{projectStorage}
@@ -62,6 +48,7 @@ public:
NodeMetaInfo(NotNullPointer<const ProjectStorageType> projectStorage) NodeMetaInfo(NotNullPointer<const ProjectStorageType> projectStorage)
: m_projectStorage{projectStorage} : m_projectStorage{projectStorage}
{} {}
#endif
NodeMetaInfo(const NodeMetaInfo &); NodeMetaInfo(const NodeMetaInfo &);
NodeMetaInfo &operator=(const NodeMetaInfo &); NodeMetaInfo &operator=(const NodeMetaInfo &);
@@ -69,6 +56,7 @@ public:
NodeMetaInfo &operator=(NodeMetaInfo &&); NodeMetaInfo &operator=(NodeMetaInfo &&);
~NodeMetaInfo(); ~NodeMetaInfo();
#ifdef QDS_USE_PROJECTSTORAGE
static NodeMetaInfo create(NotNullPointer<const ProjectStorageType> projectStorage, TypeId typeId) static NodeMetaInfo create(NotNullPointer<const ProjectStorageType> projectStorage, TypeId typeId)
{ {
return {typeId, projectStorage}; return {typeId, projectStorage};
@@ -78,6 +66,7 @@ public:
{ {
return std::bind_front(&NodeMetaInfo::create, projectStorage); return std::bind_front(&NodeMetaInfo::create, projectStorage);
} }
#endif
bool isValid() const; bool isValid() const;
explicit operator bool() const { return isValid(); } explicit operator bool() const { return isValid(); }
@@ -118,11 +107,12 @@ public:
bool defaultPropertyIsComponent() const; bool defaultPropertyIsComponent() const;
QString displayName() const; QString displayName() const;
DEPRECATED_TYPENAME TypeName typeName() const; #ifndef QDS_USE_PROJECTSTORAGE
DEPRECATED_TYPENAME TypeName simplifiedTypeName() const; TypeName typeName() const;
DEPRECATED_VERSION_NUMBER int majorVersion() const; TypeName simplifiedTypeName() const;
DEPRECATED_VERSION_NUMBER int minorVersion() const; int majorVersion() const;
int minorVersion() const;
#endif
Storage::Info::ExportedTypeNames allExportedTypeNames() const; Storage::Info::ExportedTypeNames allExportedTypeNames() const;
Storage::Info::ExportedTypeNames exportedTypeNamesForSourceId(SourceId sourceId) const; Storage::Info::ExportedTypeNames exportedTypeNamesForSourceId(SourceId sourceId) const;
@@ -131,7 +121,9 @@ public:
Storage::Info::ItemLibraryEntries itemLibrariesEntries() const; Storage::Info::ItemLibraryEntries itemLibrariesEntries() const;
SourceId sourceId() const; SourceId sourceId() const;
DEPRECATED_COMPONENT_FILE_NAME QString componentFileName() const; #ifndef QDS_USE_PROJECTSTORAGE
QString componentFileName() const;
#endif
bool isBasedOn(const NodeMetaInfo &metaInfo) const; bool isBasedOn(const NodeMetaInfo &metaInfo) const;
bool isBasedOn(const NodeMetaInfo &metaInfo1, const NodeMetaInfo &metaInfo2) const; bool isBasedOn(const NodeMetaInfo &metaInfo1, const NodeMetaInfo &metaInfo2) const;
@@ -214,6 +206,7 @@ public:
bool isQtQuick3DCubeMapTexture() const; bool isQtQuick3DCubeMapTexture() const;
bool isQtQuick3DView3D() const; bool isQtQuick3DView3D() const;
bool isQtQuickBorderImage() const; bool isQtQuickBorderImage() const;
bool isQtQuickControlsLabel() const;
bool isQtQuickControlsSwipeView() const; bool isQtQuickControlsSwipeView() const;
bool isQtQuickControlsTabBar() const; bool isQtQuickControlsTabBar() const;
bool isQtQuickExtrasPicture() const; bool isQtQuickExtrasPicture() const;
@@ -226,6 +219,7 @@ public:
bool isQtQuickPositioner() const; bool isQtQuickPositioner() const;
bool isQtQuickPropertyAnimation() const; bool isQtQuickPropertyAnimation() const;
bool isQtQuickPropertyChanges() const; bool isQtQuickPropertyChanges() const;
bool isQtQuickRectangle() const;
bool isQtQuickRepeater() const; bool isQtQuickRepeater() const;
bool isQtQuickState() const; bool isQtQuickState() const;
bool isQtQuickStateOperation() const; bool isQtQuickStateOperation() const;
@@ -251,9 +245,10 @@ public:
bool usesCustomParser() const; bool usesCustomParser() const;
bool isEnumeration() const; bool isEnumeration() const;
DEPRECATED_IMPORT_DIRECTORY_PATH QString importDirectoryPath() const; #ifndef QDS_USE_PROJECTSTORAGE
DEPRECATED_REQUIRED_IMPORT_STRING QString requiredImportString() const; QString importDirectoryPath() const;
QString requiredImportString() const;
#endif
friend bool operator==(const NodeMetaInfo &first, const NodeMetaInfo &second) friend bool operator==(const NodeMetaInfo &first, const NodeMetaInfo &second)
{ {
if constexpr (useProjectStorage()) if constexpr (useProjectStorage())

View File

@@ -1788,6 +1788,7 @@ Model::Model(ProjectStorageDependencies projectStorageDependencies,
std::move(resourceManagement))) std::move(resourceManagement)))
{} {}
#ifndef QDS_USE_PROJECTSTORAGE
Model::Model(const TypeName &typeName, Model::Model(const TypeName &typeName,
int major, int major,
int minor, int minor,
@@ -1796,6 +1797,7 @@ Model::Model(const TypeName &typeName,
: d(std::make_unique<Internal::ModelPrivate>( : d(std::make_unique<Internal::ModelPrivate>(
this, typeName, major, minor, metaInfoProxyModel, std::move(resourceManagement))) this, typeName, major, minor, metaInfoProxyModel, std::move(resourceManagement)))
{} {}
#endif
ModelPointer Model::createModel(const TypeName &typeName, ModelPointer Model::createModel(const TypeName &typeName,
std::unique_ptr<ModelResourceManagementInterface> resourceManagement) std::unique_ptr<ModelResourceManagementInterface> resourceManagement)
@@ -2480,6 +2482,16 @@ NodeMetaInfo Model::qtQuickTextEditMetaInfo() const
} }
} }
NodeMetaInfo Model::qtQuickControlsLabelMetaInfo() const
{
#ifdef QDS_USE_PROJECTSTORAGE
using namespace Storage::Info;
return createNodeMetaInfo<QtQuick_Controls, Label>();
#else
return metaInfo("QtQuick.Controls.Label");
#endif
}
NodeMetaInfo Model::qtQuickControlsTextAreaMetaInfo() const NodeMetaInfo Model::qtQuickControlsTextAreaMetaInfo() const
{ {
if constexpr (useProjectStorage()) { if constexpr (useProjectStorage()) {
@@ -2773,24 +2785,26 @@ namespace {
} }
} // namespace } // namespace
NodeMetaInfo Model::metaInfo(const TypeName &typeName, int majorVersion, int minorVersion) const NodeMetaInfo Model::metaInfo(const TypeName &typeName,
[[maybe_unused]] int majorVersion,
[[maybe_unused]] int minorVersion) const
{ {
if constexpr (useProjectStorage()) { #ifdef QDS_USE_PROJECTSTORAGE
return NodeMetaInfo(d->projectStorage->typeId(d->importedTypeNameId(typeName)), return NodeMetaInfo(d->projectStorage->typeId(d->importedTypeNameId(typeName)), d->projectStorage);
d->projectStorage); #else
} else { return NodeMetaInfo(metaInfoProxyModel(), typeName, majorVersion, minorVersion);
return NodeMetaInfo(metaInfoProxyModel(), typeName, majorVersion, minorVersion); #endif
}
} }
NodeMetaInfo Model::metaInfo(Module module, Utils::SmallStringView typeName, Storage::Version version) const NodeMetaInfo Model::metaInfo([[maybe_unused]] Module module,
[[maybe_unused]] Utils::SmallStringView typeName,
[[maybe_unused]] Storage::Version version) const
{ {
if constexpr (useProjectStorage()) { #ifdef QDS_USE_PROJECTSTORAGE
return NodeMetaInfo(d->projectStorage->typeId(module.id(), typeName, version), return NodeMetaInfo(d->projectStorage->typeId(module.id(), typeName, version), d->projectStorage);
d->projectStorage); #else
} else { return {};
return {}; #endif
}
} }
#ifndef QDS_USE_PROJECTSTORAGE #ifndef QDS_USE_PROJECTSTORAGE

View File

@@ -687,14 +687,14 @@ NodeMetaInfo ModelNode::metaInfo() const
if (!isValid()) if (!isValid())
return {}; return {};
if constexpr (useProjectStorage()) { #ifdef QDS_USE_PROJECTSTORAGE
return NodeMetaInfo(m_internalNode->typeId, m_model->projectStorage()); return NodeMetaInfo(m_internalNode->typeId, m_model->projectStorage());
} else { #else
return NodeMetaInfo(m_model->metaInfoProxyModel(), return NodeMetaInfo(m_model->metaInfoProxyModel(),
m_internalNode->typeName, m_internalNode->typeName,
m_internalNode->majorVersion, m_internalNode->majorVersion,
m_internalNode->minorVersion); m_internalNode->minorVersion);
} #endif
} }
bool ModelNode::hasMetaInfo() const bool ModelNode::hasMetaInfo() const

View File

@@ -58,6 +58,7 @@ inline constexpr char Item[] = "Item";
inline constexpr char JsonListModel[] = "JsonListModel"; inline constexpr char JsonListModel[] = "JsonListModel";
inline constexpr char KeyframeGroup[] = "KeyframeGroup"; inline constexpr char KeyframeGroup[] = "KeyframeGroup";
inline constexpr char Keyframe[] = "Keyframe"; inline constexpr char Keyframe[] = "Keyframe";
inline constexpr char Label[] = "Label";
inline constexpr char Layout[] = "Layout"; inline constexpr char Layout[] = "Layout";
inline constexpr char Light[] = "Light"; inline constexpr char Light[] = "Light";
inline constexpr char ListElement[] = "ListElement"; inline constexpr char ListElement[] = "ListElement";
@@ -236,6 +237,7 @@ class CommonTypeCache
CacheType<QtQuick3D_Particles3D, ModuleKind::QmlLibrary, SpriteParticle3D>, CacheType<QtQuick3D_Particles3D, ModuleKind::QmlLibrary, SpriteParticle3D>,
CacheType<QtQuick3D_Particles3D, ModuleKind::CppLibrary, QQuick3DParticleAbstractShape>, CacheType<QtQuick3D_Particles3D, ModuleKind::CppLibrary, QQuick3DParticleAbstractShape>,
CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, Control>, CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, Control>,
CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, Label>,
CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, Popup>, CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, Popup>,
CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, SplitView>, CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, SplitView>,
CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, SwipeView>, CacheType<QtQuick_Controls, ModuleKind::QmlLibrary, SwipeView>,

View File

@@ -705,6 +705,11 @@ Internal::DesignModeWidget *QmlDesignerPlugin::mainWidget() const
return d ? &d->mainWidget : nullptr; return d ? &d->mainWidget : nullptr;
} }
QmlDesignerProjectManager &QmlDesignerPlugin::projectManagerForPluginInitializationOnly()
{
return m_instance->d->projectManager;
}
QWidget *QmlDesignerPlugin::createProjectExplorerWidget(QWidget *parent) const QWidget *QmlDesignerPlugin::createProjectExplorerWidget(QWidget *parent) const
{ {
return Internal::DesignModeWidget::createProjectExplorerWidget(parent); return Internal::DesignModeWidget::createProjectExplorerWidget(parent);

View File

@@ -60,6 +60,8 @@ public:
DesignDocument *currentDesignDocument() const; DesignDocument *currentDesignDocument() const;
Internal::DesignModeWidget *mainWidget() const; Internal::DesignModeWidget *mainWidget() const;
static QmlDesignerProjectManager &projectManagerForPluginInitializationOnly();
QWidget *createProjectExplorerWidget(QWidget *parent) const; QWidget *createProjectExplorerWidget(QWidget *parent) const;
void switchToTextModeDeferred(); void switchToTextModeDeferred();

View File

@@ -5,6 +5,7 @@
#include "modelfwd.h" #include "modelfwd.h"
#include <projectstoragefwd.h> #include <projectstoragefwd.h>
#include <qmldesigner_global.h>
#include <QList> #include <QList>
#include <QObject> #include <QObject>
@@ -28,7 +29,7 @@ namespace QmlDesigner {
class ExternalDependenciesInterface; class ExternalDependenciesInterface;
class QmlDesignerProjectManager class QMLDESIGNER_EXPORT QmlDesignerProjectManager
{ {
class QmlDesignerProjectManagerProjectData; class QmlDesignerProjectManagerProjectData;
class PreviewImageCacheData; class PreviewImageCacheData;