forked from qt-creator/qt-creator
QmlDesigner: Extend nanotracer to binding property
Change-Id: Idf3631299e8dd246b56878f322da9adf81d39788 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -14,32 +14,34 @@ class QMLDESIGNERCORE_EXPORT BindingProperty final : public QmlDesigner::Abstrac
|
|||||||
friend Internal::ModelPrivate;
|
friend Internal::ModelPrivate;
|
||||||
friend AbstractProperty;
|
friend AbstractProperty;
|
||||||
|
|
||||||
|
using SL = ModelTracing::SourceLocation;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setExpression(const QString &expression);
|
void setExpression(const QString &expression, SL sl = {});
|
||||||
const QString &expression() const;
|
const QString &expression(SL sl = {}) const;
|
||||||
|
|
||||||
BindingProperty();
|
BindingProperty();
|
||||||
BindingProperty(const BindingProperty &property, AbstractView *view);
|
BindingProperty(const BindingProperty &property, AbstractView *view);
|
||||||
|
|
||||||
void setDynamicTypeNameAndExpression(const TypeName &type, const QString &expression);
|
void setDynamicTypeNameAndExpression(const TypeName &type, const QString &expression, SL sl = {});
|
||||||
|
|
||||||
ModelNode resolveToModelNode() const;
|
ModelNode resolveToModelNode(SL sl = {}) const;
|
||||||
AbstractProperty resolveToProperty() const;
|
AbstractProperty resolveToProperty(SL sl = {}) const;
|
||||||
bool isList() const;
|
bool isList(SL sl = {}) const;
|
||||||
QList<ModelNode> resolveListToModelNodes() const;
|
QList<ModelNode> resolveListToModelNodes(SL sl = {}) const;
|
||||||
QList<ModelNode> resolveToModelNodes() const;
|
QList<ModelNode> resolveToModelNodes(SL sl = {}) const;
|
||||||
void addModelNodeToArray(const ModelNode &modelNode);
|
void addModelNodeToArray(const ModelNode &modelNode, SL sl = {});
|
||||||
void removeModelNodeFromArray(const ModelNode &modelNode);
|
void removeModelNodeFromArray(const ModelNode &modelNode, SL sl = {});
|
||||||
|
|
||||||
static QList<BindingProperty> findAllReferencesTo(const ModelNode &modelNode);
|
static QList<BindingProperty> findAllReferencesTo(const ModelNode &modelNode, SL sl = {});
|
||||||
static void deleteAllReferencesTo(const ModelNode &modelNode);
|
static void deleteAllReferencesTo(const ModelNode &modelNode, SL sl = {});
|
||||||
|
|
||||||
bool canBeReference() const;
|
bool canBeReference(SL sl = {}) const;
|
||||||
|
|
||||||
bool isAlias() const;
|
bool isAlias(SL sl = {}) const;
|
||||||
bool isAliasExport() const;
|
bool isAliasExport(SL sl = {}) const;
|
||||||
|
|
||||||
static QVariant convertToLiteral(const TypeName &typeName, const QString &expression);
|
static QVariant convertToLiteral(const TypeName &typeName, const QString &expression, SL sl = {});
|
||||||
|
|
||||||
BindingProperty(Utils::SmallStringView propertyName,
|
BindingProperty(Utils::SmallStringView propertyName,
|
||||||
const Internal::InternalNodePointer &internalNode,
|
const Internal::InternalNodePointer &internalNode,
|
||||||
@@ -54,9 +56,10 @@ private:
|
|||||||
|
|
||||||
using BindingProperties = QList<BindingProperty>;
|
using BindingProperties = QList<BindingProperty>;
|
||||||
|
|
||||||
bool compareBindingProperties(const QmlDesigner::BindingProperty &bindingProperty01, const QmlDesigner::BindingProperty &bindingProperty02);
|
bool compareBindingProperties(const QmlDesigner::BindingProperty &bindingProperty01,
|
||||||
|
const QmlDesigner::BindingProperty &bindingProperty02);
|
||||||
|
|
||||||
QMLDESIGNERCORE_EXPORT QTextStream& operator<<(QTextStream &stream, const BindingProperty &property);
|
QMLDESIGNERCORE_EXPORT QTextStream &operator<<(QTextStream &stream, const BindingProperty &property);
|
||||||
QMLDESIGNERCORE_EXPORT QDebug operator<<(QDebug debug, const BindingProperty &AbstractProperty);
|
QMLDESIGNERCORE_EXPORT QDebug operator<<(QDebug debug, const BindingProperty &AbstractProperty);
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -3,9 +3,8 @@
|
|||||||
|
|
||||||
#include "bindingproperty.h"
|
#include "bindingproperty.h"
|
||||||
#include "nodeproperty.h"
|
#include "nodeproperty.h"
|
||||||
#include "internalproperty.h"
|
|
||||||
#include "internalnode_p.h"
|
#include "internalnode_p.h"
|
||||||
#include "model.h"
|
|
||||||
#include "model_p.h"
|
#include "model_p.h"
|
||||||
|
|
||||||
#include <qmldesignerutils/stringutils.h>
|
#include <qmldesignerutils/stringutils.h>
|
||||||
@@ -29,8 +28,12 @@ BindingProperty::BindingProperty(const BindingProperty &property, AbstractView *
|
|||||||
: AbstractProperty(property.name(), property.internalNodeSharedPointer(), property.model(), view)
|
: AbstractProperty(property.name(), property.internalNodeSharedPointer(), property.model(), view)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void BindingProperty::setExpression(const QString &expression)
|
void BindingProperty::setExpression(const QString &expression, SL sl)
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property set expression",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -60,8 +63,12 @@ void BindingProperty::setExpression(const QString &expression)
|
|||||||
|
|
||||||
const constinit QString null;
|
const constinit QString null;
|
||||||
|
|
||||||
const QString &BindingProperty::expression() const
|
const QString &BindingProperty::expression(SL sl) const
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property expression",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (isValid()) {
|
if (isValid()) {
|
||||||
if (auto property = internalNode()->bindingProperty(name()))
|
if (auto property = internalNode()->bindingProperty(name()))
|
||||||
return property->expression();
|
return property->expression();
|
||||||
@@ -104,8 +111,12 @@ ModelNode BindingProperty::resolveBinding(QStringView binding, ModelNode current
|
|||||||
return currentNode;
|
return currentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelNode BindingProperty::resolveToModelNode() const
|
ModelNode BindingProperty::resolveToModelNode(SL sl) const
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property resolve to model node",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
QString binding = expression();
|
QString binding = expression();
|
||||||
|
|
||||||
if (binding.isEmpty())
|
if (binding.isEmpty())
|
||||||
@@ -123,9 +134,12 @@ inline static QStringList commaSeparatedSimplifiedStringList(const QString &stri
|
|||||||
return simpleList;
|
return simpleList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractProperty BindingProperty::resolveToProperty(SL sl) const
|
||||||
AbstractProperty BindingProperty::resolveToProperty() const
|
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property resolve to proprety",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
@@ -146,8 +160,12 @@ AbstractProperty BindingProperty::resolveToProperty() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BindingProperty::isList() const
|
bool BindingProperty::isList(SL sl) const
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property is list",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -156,8 +174,12 @@ bool BindingProperty::isList() const
|
|||||||
return expression.startsWith('[') && expression.endsWith(']');
|
return expression.startsWith('[') && expression.endsWith(']');
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ModelNode> BindingProperty::resolveListToModelNodes() const
|
QList<ModelNode> BindingProperty::resolveListToModelNodes(SL sl) const
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property reolve list to model nodes",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
QString binding = expression();
|
QString binding = expression();
|
||||||
|
|
||||||
if (binding.isEmpty())
|
if (binding.isEmpty())
|
||||||
@@ -176,8 +198,12 @@ QList<ModelNode> BindingProperty::resolveListToModelNodes() const
|
|||||||
return returnList;
|
return returnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ModelNode> BindingProperty::resolveToModelNodes() const
|
QList<ModelNode> BindingProperty::resolveToModelNodes(SL sl) const
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property resolve to model nodes",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
QString binding = expression();
|
QString binding = expression();
|
||||||
|
|
||||||
if (binding.isEmpty())
|
if (binding.isEmpty())
|
||||||
@@ -200,8 +226,12 @@ QList<ModelNode> BindingProperty::resolveToModelNodes() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void BindingProperty::addModelNodeToArray(const ModelNode &modelNode)
|
void BindingProperty::addModelNodeToArray(const ModelNode &modelNode, SL sl)
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property add model node to array",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -228,8 +258,12 @@ void BindingProperty::addModelNodeToArray(const ModelNode &modelNode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BindingProperty::removeModelNodeFromArray(const ModelNode &modelNode)
|
void BindingProperty::removeModelNodeFromArray(const ModelNode &modelNode, SL sl)
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property remove model node from array",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (!isBindingProperty())
|
if (!isBindingProperty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -248,8 +282,12 @@ void BindingProperty::removeModelNodeFromArray(const ModelNode &modelNode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<BindingProperty> BindingProperty::findAllReferencesTo(const ModelNode &modelNode)
|
QList<BindingProperty> BindingProperty::findAllReferencesTo(const ModelNode &modelNode, SL sl)
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property find all references to",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (!modelNode.isValid())
|
if (!modelNode.isValid())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
@@ -263,8 +301,12 @@ QList<BindingProperty> BindingProperty::findAllReferencesTo(const ModelNode &mod
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BindingProperty::deleteAllReferencesTo(const ModelNode &modelNode)
|
void BindingProperty::deleteAllReferencesTo(const ModelNode &modelNode, SL sl)
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property delete all references to",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
for (BindingProperty &bindingProperty : findAllReferencesTo(modelNode)) {
|
for (BindingProperty &bindingProperty : findAllReferencesTo(modelNode)) {
|
||||||
if (bindingProperty.isList())
|
if (bindingProperty.isList())
|
||||||
bindingProperty.removeModelNodeFromArray(modelNode);
|
bindingProperty.removeModelNodeFromArray(modelNode);
|
||||||
@@ -273,13 +315,21 @@ void BindingProperty::deleteAllReferencesTo(const ModelNode &modelNode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BindingProperty::canBeReference() const
|
bool BindingProperty::canBeReference(SL sl) const
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property can be reference",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
return !name().startsWith("anchors.");
|
return !name().startsWith("anchors.");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BindingProperty::isAlias() const
|
bool BindingProperty::isAlias(SL sl) const
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property is alias",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -288,8 +338,12 @@ bool BindingProperty::isAlias() const
|
|||||||
&& parentModelNode().view()->modelNodeForId(expression()).isValid();
|
&& parentModelNode().view()->modelNodeForId(expression()).isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BindingProperty::isAliasExport() const
|
bool BindingProperty::isAliasExport(SL sl) const
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property is alias export",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return false;
|
return false;
|
||||||
return parentModelNode() == parentModelNode().model()->rootModelNode() && isDynamic()
|
return parentModelNode() == parentModelNode().model()->rootModelNode() && isDynamic()
|
||||||
@@ -303,8 +357,12 @@ static bool isTrueFalseLiteral(const QString &expression)
|
|||||||
|| (expression.compare("true", Qt::CaseInsensitive) == 0);
|
|| (expression.compare("true", Qt::CaseInsensitive) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant BindingProperty::convertToLiteral(const TypeName &typeName, const QString &testExpression)
|
QVariant BindingProperty::convertToLiteral(const TypeName &typeName, const QString &testExpression, SL sl)
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property convert to literal",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
if ("QColor" == typeName || "color" == typeName) {
|
if ("QColor" == typeName || "color" == typeName) {
|
||||||
QString unquoted = testExpression;
|
QString unquoted = testExpression;
|
||||||
unquoted.remove('"');
|
unquoted.remove('"');
|
||||||
@@ -343,8 +401,14 @@ QVariant BindingProperty::convertToLiteral(const TypeName &typeName, const QStri
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void BindingProperty::setDynamicTypeNameAndExpression(const TypeName &typeName, const QString &expression)
|
void BindingProperty::setDynamicTypeNameAndExpression(const TypeName &typeName,
|
||||||
|
const QString &expression,
|
||||||
|
SL sl)
|
||||||
{
|
{
|
||||||
|
NanotraceHR::Tracer tracer{"binding property set dynamic type name and expression",
|
||||||
|
ModelTracing::category(),
|
||||||
|
keyValue("caller location", sl)};
|
||||||
|
|
||||||
Internal::WriteLocker locker(model());
|
Internal::WriteLocker locker(model());
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user