forked from qt-creator/qt-creator
QmlDesigner: Lazy initialization of node hints
Very often they are not need, so they can be lazy initialized. Change-Id: I65f758c70f25517a29da87e3c42dec02c84049d2 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -54,7 +54,6 @@ public:
|
|||||||
QPair<QString, QVariant> setParentProperty() const;
|
QPair<QString, QVariant> setParentProperty() const;
|
||||||
QString bindParentToProperty() const;
|
QString bindParentToProperty() const;
|
||||||
|
|
||||||
QHash<QString, QString> hints() const;
|
|
||||||
static NodeHints fromModelNode(const ModelNode &modelNode);
|
static NodeHints fromModelNode(const ModelNode &modelNode);
|
||||||
static NodeHints fromItemLibraryEntry(const ItemLibraryEntry &entry, Model *model);
|
static NodeHints fromItemLibraryEntry(const ItemLibraryEntry &entry, Model *model);
|
||||||
|
|
||||||
@@ -62,6 +61,7 @@ private:
|
|||||||
explicit NodeHints(const ModelNode &modelNode);
|
explicit NodeHints(const ModelNode &modelNode);
|
||||||
explicit NodeHints(const NodeMetaInfo &metaInfo);
|
explicit NodeHints(const NodeMetaInfo &metaInfo);
|
||||||
explicit NodeHints(const ItemLibraryEntry &entry, Model *model);
|
explicit NodeHints(const ItemLibraryEntry &entry, Model *model);
|
||||||
|
QHash<QString, QString> hints() const;
|
||||||
const ModelNode &modelNode() const;
|
const ModelNode &modelNode() const;
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
Model *model() const;
|
Model *model() const;
|
||||||
@@ -69,7 +69,7 @@ private:
|
|||||||
|
|
||||||
ModelNode m_modelNode;
|
ModelNode m_modelNode;
|
||||||
NodeMetaInfo m_metaInfo;
|
NodeMetaInfo m_metaInfo;
|
||||||
QHash<QString, QString> m_hints;
|
mutable QHash<QString, QString> m_hints;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
@@ -107,8 +107,6 @@ QmlDesigner::NodeHints::NodeHints(const ModelNode &node)
|
|||||||
NodeHints::NodeHints(const NodeMetaInfo &metaInfo)
|
NodeHints::NodeHints(const NodeMetaInfo &metaInfo)
|
||||||
: m_metaInfo{metaInfo}
|
: m_metaInfo{metaInfo}
|
||||||
{
|
{
|
||||||
for (const auto &[name, expression] : metaInfo.typeHints())
|
|
||||||
m_hints.insert(name.toQString(), expression.toQString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeHints::NodeHints(const ItemLibraryEntry &entry, [[maybe_unused]] Model *model)
|
NodeHints::NodeHints(const ItemLibraryEntry &entry, [[maybe_unused]] Model *model)
|
||||||
@@ -273,7 +271,7 @@ QString NodeHints::indexPropertyForStackedContainer() const
|
|||||||
if (!isValid())
|
if (!isValid())
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
const QString expression = m_hints.value("indexPropertyForStackedContainer");
|
const QString expression = hints().value("indexPropertyForStackedContainer");
|
||||||
|
|
||||||
if (expression.isEmpty())
|
if (expression.isEmpty())
|
||||||
return QString();
|
return QString();
|
||||||
@@ -286,7 +284,7 @@ QStringList NodeHints::visibleNonDefaultProperties() const
|
|||||||
if (!isValid())
|
if (!isValid())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const QString expression = m_hints.value("visibleNonDefaultProperties");
|
const QString expression = hints().value("visibleNonDefaultProperties");
|
||||||
|
|
||||||
if (expression.isEmpty())
|
if (expression.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
@@ -345,7 +343,7 @@ bool NodeHints::visibleInLibrary() const
|
|||||||
|
|
||||||
QString NodeHints::forceNonDefaultProperty() const
|
QString NodeHints::forceNonDefaultProperty() const
|
||||||
{
|
{
|
||||||
const QString expression = m_hints.value("forceNonDefaultProperty");
|
const QString expression = hints().value("forceNonDefaultProperty");
|
||||||
|
|
||||||
if (expression.isEmpty())
|
if (expression.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
@@ -369,7 +367,7 @@ QVariant parseValue(const QString &string)
|
|||||||
|
|
||||||
QPair<QString, QVariant> NodeHints::setParentProperty() const
|
QPair<QString, QVariant> NodeHints::setParentProperty() const
|
||||||
{
|
{
|
||||||
const QString expression = m_hints.value("setParentProperty");
|
const QString expression = hints().value("setParentProperty");
|
||||||
|
|
||||||
if (expression.isEmpty())
|
if (expression.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
@@ -386,7 +384,7 @@ QPair<QString, QVariant> NodeHints::setParentProperty() const
|
|||||||
|
|
||||||
QString NodeHints::bindParentToProperty() const
|
QString NodeHints::bindParentToProperty() const
|
||||||
{
|
{
|
||||||
const QString expression = m_hints.value("bindParentToProperty");
|
const QString expression = hints().value("bindParentToProperty");
|
||||||
|
|
||||||
if (expression.isEmpty())
|
if (expression.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
@@ -396,6 +394,13 @@ QString NodeHints::bindParentToProperty() const
|
|||||||
|
|
||||||
QHash<QString, QString> NodeHints::hints() const
|
QHash<QString, QString> NodeHints::hints() const
|
||||||
{
|
{
|
||||||
|
#ifdef QDS_USE_PROJECTSTORAGE
|
||||||
|
if (m_hints.empty()) {
|
||||||
|
for (const auto &[name, expression] : m_metaInfo.typeHints())
|
||||||
|
m_hints.insert(name.toQString(), expression.toQString());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return m_hints;
|
return m_hints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +431,7 @@ Model *NodeHints::model() const
|
|||||||
|
|
||||||
bool NodeHints::evaluateBooleanExpression(const QString &hintName, bool defaultValue, const ModelNode otherNode) const
|
bool NodeHints::evaluateBooleanExpression(const QString &hintName, bool defaultValue, const ModelNode otherNode) const
|
||||||
{
|
{
|
||||||
const QString expression = m_hints.value(hintName);
|
const QString expression = hints().value(hintName);
|
||||||
|
|
||||||
if (expression.isEmpty())
|
if (expression.isEmpty())
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
Reference in New Issue
Block a user