QmlDesigner: Extend the tracer to the properties

Task-number: QDS-15148
Change-Id: Ib87b5db1d17e76a9c18a618b9980210d37937f8d
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Burak Hancerli
2025-05-23 10:41:01 +02:00
parent a3701c5c31
commit de7cacac4d
10 changed files with 243 additions and 74 deletions

View File

@@ -18,20 +18,22 @@ class QMLDESIGNERCORE_EXPORT NodeAbstractProperty : public AbstractProperty
friend Internal::ModelPrivate;
friend AbstractProperty;
using SL = ModelTracing::SourceLocation;
friend QMLDESIGNERCORE_EXPORT bool operator ==(const NodeAbstractProperty &property1, const NodeAbstractProperty &property2);
friend QMLDESIGNERCORE_EXPORT bool operator !=(const NodeAbstractProperty &property1, const NodeAbstractProperty &property2);
public:
NodeAbstractProperty();
NodeAbstractProperty(const NodeAbstractProperty &property, AbstractView *view);
void reparentHere(const ModelNode &modelNode);
bool isEmpty() const;
int count() const;
int indexOf(const ModelNode &node) const;
NodeAbstractProperty parentProperty() const;
void reparentHere(const ModelNode &modelNode, SL sl = {});
bool isEmpty(SL sl = {}) const;
int count(SL sl = {}) const;
int indexOf(const ModelNode &node, SL sl = {}) const;
NodeAbstractProperty parentProperty(SL sl = {}) const;
QList<ModelNode> allSubNodes();
QList<ModelNode> directSubNodes() const;
QList<ModelNode> allSubNodes(SL sl = {});
QList<ModelNode> directSubNodes(SL sl = {}) const;
friend auto qHash(const NodeAbstractProperty &property) { qHash(AbstractProperty(property)); }

View File

@@ -157,6 +157,8 @@ class QMLDESIGNERCORE_EXPORT NodeListProperty final : public NodeAbstractPropert
friend AbstractProperty;
friend Internal::ModelPrivate;
using SL = ModelTracing::SourceLocation;
public:
using value_type = ModelNode;
using iterator = Internal::NodeListPropertyIterator;
@@ -173,26 +175,28 @@ public:
AbstractView *view)
: NodeAbstractProperty(propertyName, internalNode, model, view)
{}
QList<ModelNode> toModelNodeList() const;
void slide(int, int) const;
void swap(int, int) const;
void reparentHere(const ModelNode &modelNode);
ModelNode at(int index) const;
void iterSwap(iterator &first, iterator &second);
iterator rotate(iterator first, iterator newFirst, iterator last);
QList<ModelNode> toModelNodeList(SL sl = {}) const;
void slide(int, int, SL sl = {}) const;
void swap(int, int, SL sl = {}) const;
void reparentHere(const ModelNode &modelNode, SL sl = {});
ModelNode at(int index, SL sl = {}) const;
void iterSwap(iterator &first, iterator &second, SL sl = {});
iterator rotate(iterator first, iterator newFirst, iterator last, SL sl = {});
template<typename Range>
iterator rotate(Range &range, iterator newFirst)
{
return rotate(range.begin(), newFirst, range.end());
}
void reverse(iterator first, iterator last);
void reverse(iterator first, iterator last, SL sl = {});
template<typename Range>
void reverse(Range &range)
{
reverse(range.begin(), range.end());
}
static void reverseModelNodes(const QList<ModelNode> &nodes);
static void reverseModelNodes(const QList<ModelNode> &nodes, SL sl = {});
iterator begin();
iterator end();

View File

@@ -16,12 +16,16 @@ class QMLDESIGNERCORE_EXPORT NodeProperty final : public NodeAbstractProperty
friend Internal::ModelPrivate;
friend AbstractProperty;
public:
void setModelNode(const ModelNode &modelNode);
ModelNode modelNode() const;
using SL = ModelTracing::SourceLocation;
void reparentHere(const ModelNode &modelNode);
void setDynamicTypeNameAndsetModelNode(const TypeName &typeName, const ModelNode &modelNode);
public:
void setModelNode(const ModelNode &modelNode, SL sl = {});
ModelNode modelNode(SL sl = {}) const;
void reparentHere(const ModelNode &modelNode, SL sl = {});
void setDynamicTypeNameAndsetModelNode(const TypeName &typeName,
const ModelNode &modelNode,
SL sl = {});
NodeProperty();

View File

@@ -14,18 +14,20 @@ class QMLDESIGNERCORE_EXPORT SignalHandlerProperty final : public AbstractProper
friend Internal::ModelPrivate;
friend AbstractProperty;
public:
void setSource(const QString &source);
QString source() const;
QString sourceNormalizedWithBraces() const;
using SL = ModelTracing::SourceLocation;
bool useNewFunctionSyntax();
public:
void setSource(const QString &source, SL sl = {});
QString source(SL sl = {}) const;
QString sourceNormalizedWithBraces(SL sl = {}) const;
bool useNewFunctionSyntax(SL sl = {});
SignalHandlerProperty();
SignalHandlerProperty(const SignalHandlerProperty &property, AbstractView *view);
static PropertyName prefixAdded(PropertyNameView propertyName);
static PropertyName prefixRemoved(PropertyNameView propertyName);
static PropertyName prefixAdded(PropertyNameView propertyName, SL sl = {});
static PropertyName prefixRemoved(PropertyNameView propertyName, SL sl = {});
SignalHandlerProperty(PropertyNameView propertyName,
const Internal::InternalNodePointer &internalNode,
@@ -34,7 +36,7 @@ public:
: AbstractProperty(propertyName, internalNode, model, view)
{}
static QString normalizedSourceWithBraces(const QString &source);
static QString normalizedSourceWithBraces(const QString &source, SL sl = {});
};
class QMLDESIGNERCORE_EXPORT SignalDeclarationProperty final : public AbstractProperty
@@ -43,9 +45,11 @@ class QMLDESIGNERCORE_EXPORT SignalDeclarationProperty final : public AbstractPr
friend Internal::ModelPrivate;
friend AbstractProperty;
using SL = ModelTracing::SourceLocation;
public:
void setSignature(const QString &source);
QString signature() const;
void setSignature(const QString &source, SL sl = {});
QString signature(SL sl = {}) const;
SignalDeclarationProperty();
SignalDeclarationProperty(const SignalDeclarationProperty &property, AbstractView *view);

View File

@@ -24,20 +24,24 @@ class QMLDESIGNERCORE_EXPORT VariantProperty final : public AbstractProperty
friend Internal::ModelPrivate;
friend AbstractProperty;
using SL = ModelTracing::SourceLocation;
public:
void setValue(const QVariant &value);
const QVariant &value() const;
void setValue(const QVariant &value, SL sl = {});
const QVariant &value(SL sl = {}) const;
const QVariant &operator->() const { return value(); }
const QVariant &operator*() const { return value(); }
void setEnumeration(const EnumerationName &enumerationName);
const Enumeration &enumeration() const;
bool holdsEnumeration() const;
void setEnumeration(const EnumerationName &enumerationName, SL sl = {});
const Enumeration &enumeration(SL sl = {}) const;
bool holdsEnumeration(SL sl = {}) const;
void setDynamicTypeNameAndValue(const TypeName &type, const QVariant &value);
void setDynamicTypeNameAndEnumeration(const TypeName &type, const EnumerationName &enumerationName);
void setDynamicTypeNameAndValue(const TypeName &type, const QVariant &value, SL sl = {});
void setDynamicTypeNameAndEnumeration(const TypeName &type,
const EnumerationName &enumerationName,
SL sl = {});
VariantProperty();
VariantProperty(const VariantProperty &property, AbstractView *view);

View File

@@ -25,8 +25,12 @@ NodeAbstractProperty::NodeAbstractProperty(const Internal::InternalNodeAbstractP
: AbstractProperty(property, model, view)
{}
void NodeAbstractProperty::reparentHere(const ModelNode &modelNode)
void NodeAbstractProperty::reparentHere(const ModelNode &modelNode, SL sl)
{
NanotraceHR::Tracer tracer{"node abstract property reparent here",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid() || !modelNode.isValid())
return;
@@ -84,8 +88,12 @@ void NodeAbstractProperty::reparentHere(const ModelNode &modelNode, bool isNode
}
}
bool NodeAbstractProperty::isEmpty() const
bool NodeAbstractProperty::isEmpty(SL sl) const
{
NanotraceHR::Tracer tracer{"node abstract property is empty",
ModelTracing::category(),
keyValue("caller location", sl)};
if (isValid()) {
Internal::InternalNodeAbstractProperty::Pointer property = internalNode()->nodeAbstractProperty(
name());
@@ -98,8 +106,12 @@ bool NodeAbstractProperty::isEmpty() const
return true;
}
int NodeAbstractProperty::indexOf(const ModelNode &node) const
int NodeAbstractProperty::indexOf(const ModelNode &node, SL sl) const
{
NanotraceHR::Tracer tracer{"node abstract property index of",
ModelTracing::category(),
keyValue("caller location", sl)};
if (isValid()) {
Internal::InternalNodeAbstractProperty::Pointer property = internalNode()->nodeAbstractProperty(
name());
@@ -112,8 +124,12 @@ int NodeAbstractProperty::indexOf(const ModelNode &node) const
return -1;
}
NodeAbstractProperty NodeAbstractProperty::parentProperty() const
NodeAbstractProperty NodeAbstractProperty::parentProperty(SL sl) const
{
NanotraceHR::Tracer tracer{"node abstract property parent property",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return {};
@@ -123,8 +139,12 @@ NodeAbstractProperty NodeAbstractProperty::parentProperty() const
return NodeAbstractProperty(internalNode()->parentProperty()->name(), internalNode()->parentProperty()->propertyOwner(), model(), view());
}
int NodeAbstractProperty::count() const
int NodeAbstractProperty::count(SL sl) const
{
NanotraceHR::Tracer tracer{"node abstract property count",
ModelTracing::category(),
keyValue("caller location", sl)};
Internal::InternalNodeAbstractProperty::Pointer property = internalNode()->nodeAbstractProperty(name());
if (!property)
return 0;
@@ -132,8 +152,12 @@ int NodeAbstractProperty::count() const
return property->count();
}
QList<ModelNode> NodeAbstractProperty::allSubNodes()
QList<ModelNode> NodeAbstractProperty::allSubNodes(SL sl)
{
NanotraceHR::Tracer tracer{"node abstract property all sub nodes",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!internalNode() || !internalNode()->isValid)
return {};
@@ -162,8 +186,12 @@ QList<ModelNode> NodeAbstractProperty::allSubNodes()
return {};
}
QList<ModelNode> NodeAbstractProperty::directSubNodes() const
QList<ModelNode> NodeAbstractProperty::directSubNodes(SL sl) const
{
NanotraceHR::Tracer tracer{"node abstract property direct sub nodes",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!internalNode() || !internalNode()->isValid)
return {};

View File

@@ -50,8 +50,12 @@ static QList<ModelNode> internalNodesToModelNodes(const auto &inputList, Model *
return modelNodeList;
}
QList<ModelNode> NodeListProperty::toModelNodeList() const
QList<ModelNode> NodeListProperty::toModelNodeList(SL sl) const
{
NanotraceHR::Tracer tracer{"node list property to model node list",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return {};
@@ -61,8 +65,12 @@ QList<ModelNode> NodeListProperty::toModelNodeList() const
return {};
}
void NodeListProperty::slide(int from, int to) const
void NodeListProperty::slide(int from, int to, SL sl) const
{
NanotraceHR::Tracer tracer{"node list property slide",
ModelTracing::category(),
keyValue("caller location", sl)};
Internal::WriteLocker locker(model());
if (!isValid())
return;
@@ -74,8 +82,12 @@ void NodeListProperty::slide(int from, int to) const
privateModel()->changeNodeOrder(internalNodeSharedPointer(), name(), from, to);
}
void NodeListProperty::swap(int from, int to) const
void NodeListProperty::swap(int from, int to, SL sl) const
{
NanotraceHR::Tracer tracer{"node list property swap",
ModelTracing::category(),
keyValue("caller location", sl)};
if (from == to)
return;
@@ -92,13 +104,21 @@ void NodeListProperty::swap(int from, int to) const
slide(a + 1, b);
}
void NodeListProperty::reparentHere(const ModelNode &modelNode)
void NodeListProperty::reparentHere(const ModelNode &modelNode, SL sl)
{
NanotraceHR::Tracer tracer{"node list property reparent here",
ModelTracing::category(),
keyValue("caller location", sl)};
NodeAbstractProperty::reparentHere(modelNode, true);
}
ModelNode NodeListProperty::at(int index) const
ModelNode NodeListProperty::at(int index, SL sl) const
{
NanotraceHR::Tracer tracer{"node list property at",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return {};
@@ -108,8 +128,14 @@ ModelNode NodeListProperty::at(int index) const
return ModelNode();
}
void NodeListProperty::iterSwap(NodeListProperty::iterator &first, NodeListProperty::iterator &second)
void NodeListProperty::iterSwap(NodeListProperty::iterator &first,
NodeListProperty::iterator &second,
SL sl)
{
NanotraceHR::Tracer tracer{"node list property iter swap",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return;
@@ -122,8 +148,13 @@ void NodeListProperty::iterSwap(NodeListProperty::iterator &first, NodeListPrope
NodeListProperty::iterator NodeListProperty::rotate(NodeListProperty::iterator first,
NodeListProperty::iterator newFirst,
NodeListProperty::iterator last)
NodeListProperty::iterator last,
SL sl)
{
NanotraceHR::Tracer tracer{"node list property rotate",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return {};
@@ -141,8 +172,12 @@ NodeListProperty::iterator NodeListProperty::rotate(NodeListProperty::iterator f
return {iter - begin, internalNodeListProperty().get(), model(), view()};
}
void NodeListProperty::reverse(NodeListProperty::iterator first, NodeListProperty::iterator last)
void NodeListProperty::reverse(NodeListProperty::iterator first, NodeListProperty::iterator last, SL sl)
{
NanotraceHR::Tracer tracer{"node list property reverse",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return;
@@ -156,8 +191,12 @@ void NodeListProperty::reverse(NodeListProperty::iterator first, NodeListPropert
privateModel()->notifyNodeOrderChanged(m_internalNodeListProperty.get());
}
void NodeListProperty::reverseModelNodes(const QList<ModelNode> &nodes)
void NodeListProperty::reverseModelNodes(const QList<ModelNode> &nodes, SL sl)
{
NanotraceHR::Tracer tracer{"node list property reverse model nodes",
ModelTracing::category(),
keyValue("caller location", sl)};
ModelNode firstNode = nodes.first();
if (!firstNode.isValid())
return;

View File

@@ -10,8 +10,12 @@ namespace QmlDesigner {
NodeProperty::NodeProperty() = default;
void NodeProperty::setModelNode(const ModelNode &modelNode)
void NodeProperty::setModelNode(const ModelNode &modelNode, SL sl)
{
NanotraceHR::Tracer tracer{"node property set model node",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return;
@@ -33,8 +37,12 @@ void NodeProperty::setModelNode(const ModelNode &modelNode)
false); //### we have to add a flag that this is not a list
}
ModelNode NodeProperty::modelNode() const
ModelNode NodeProperty::modelNode(SL sl) const
{
NanotraceHR::Tracer tracer{"node property model node",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return {};
@@ -45,13 +53,23 @@ ModelNode NodeProperty::modelNode() const
return ModelNode();
}
void NodeProperty::reparentHere(const ModelNode &modelNode)
void NodeProperty::reparentHere(const ModelNode &modelNode, SL sl)
{
NanotraceHR::Tracer tracer{"node property reparent here",
ModelTracing::category(),
keyValue("caller location", sl)};
NodeAbstractProperty::reparentHere(modelNode, false);
}
void NodeProperty::setDynamicTypeNameAndsetModelNode(const TypeName &typeName, const ModelNode &modelNode)
void NodeProperty::setDynamicTypeNameAndsetModelNode(const TypeName &typeName,
const ModelNode &modelNode,
SL sl)
{
NanotraceHR::Tracer tracer{"node property set dynamic type and set model node",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!modelNode.isValid())
return;

View File

@@ -19,8 +19,12 @@ SignalHandlerProperty::SignalHandlerProperty(const SignalHandlerProperty &proper
{
}
void SignalHandlerProperty::setSource(const QString &source)
void SignalHandlerProperty::setSource(const QString &source, SL sl)
{
NanotraceHR::Tracer tracer{"signal handler property set source",
ModelTracing::category(),
keyValue("caller location", sl)};
Internal::WriteLocker locker(model());
if (!isValid())
return;
@@ -44,8 +48,12 @@ void SignalHandlerProperty::setSource(const QString &source)
privateModel()->setSignalHandlerProperty(internalNodeSharedPointer(), name(), source);
}
QString SignalHandlerProperty::source() const
QString SignalHandlerProperty::source(SL sl) const
{
NanotraceHR::Tracer tracer{"signal handler property source",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return {};
@@ -55,13 +63,21 @@ QString SignalHandlerProperty::source() const
return QString();
}
QString SignalHandlerProperty::sourceNormalizedWithBraces() const
QString SignalHandlerProperty::sourceNormalizedWithBraces(SL sl) const
{
NanotraceHR::Tracer tracer{"signal handler property source normalized with braces",
ModelTracing::category(),
keyValue("caller location", sl)};
return normalizedSourceWithBraces(source());
}
bool SignalHandlerProperty::useNewFunctionSyntax()
bool SignalHandlerProperty::useNewFunctionSyntax(SL sl)
{
NanotraceHR::Tracer tracer{"signal handler property use new function syntax",
ModelTracing::category(),
keyValue("caller location", sl)};
if (name().contains('.'))
return false;
@@ -74,8 +90,12 @@ bool SignalHandlerProperty::useNewFunctionSyntax()
return parentModelNode().metaInfo().isQtQmlConnections();
}
PropertyName SignalHandlerProperty::prefixAdded(PropertyNameView propertyName)
PropertyName SignalHandlerProperty::prefixAdded(PropertyNameView propertyName, SL sl)
{
NanotraceHR::Tracer tracer{"signal handler property prefix added",
ModelTracing::category(),
keyValue("caller location", sl)};
QString nameAsString = QString::fromUtf8(propertyName);
if (propertyName.startsWith("on"))
return propertyName.toByteArray();
@@ -87,8 +107,12 @@ PropertyName SignalHandlerProperty::prefixAdded(PropertyNameView propertyName)
return nameAsString.toLatin1();
}
PropertyName SignalHandlerProperty::prefixRemoved(PropertyNameView propertyName)
PropertyName SignalHandlerProperty::prefixRemoved(PropertyNameView propertyName, SL sl)
{
NanotraceHR::Tracer tracer{"signal handler property prefix removed",
ModelTracing::category(),
keyValue("caller location", sl)};
QString nameAsString = QString::fromUtf8(propertyName);
if (!nameAsString.startsWith("on"))
return propertyName.toByteArray();
@@ -100,8 +124,12 @@ PropertyName SignalHandlerProperty::prefixRemoved(PropertyNameView propertyName)
return nameAsString.toLatin1();
}
QString SignalHandlerProperty::normalizedSourceWithBraces(const QString &source)
QString SignalHandlerProperty::normalizedSourceWithBraces(const QString &source, SL sl)
{
NanotraceHR::Tracer tracer{"signal handler property normalized source with braces",
ModelTracing::category(),
keyValue("caller location", sl)};
static const QRegularExpression reg("^\\{(\\s*?.*?)*?\\}$");
const QString trimmed = source.trimmed();
@@ -120,8 +148,12 @@ SignalDeclarationProperty::SignalDeclarationProperty(const SignalDeclarationProp
: AbstractProperty(property.name(), property.internalNodeSharedPointer(), property.model(), view)
{}
void SignalDeclarationProperty::setSignature(const QString &signature)
void SignalDeclarationProperty::setSignature(const QString &signature, SL sl)
{
NanotraceHR::Tracer tracer{"signal declaration property set signature",
ModelTracing::category(),
keyValue("caller location", sl)};
Internal::WriteLocker locker(model());
if (!isValid())
return;
@@ -145,8 +177,12 @@ void SignalDeclarationProperty::setSignature(const QString &signature)
privateModel()->setSignalDeclarationProperty(internalNodeSharedPointer(), name(), signature);
}
QString SignalDeclarationProperty::signature() const
QString SignalDeclarationProperty::signature(SL sl) const
{
NanotraceHR::Tracer tracer{"signal declaration property signature",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return {};

View File

@@ -19,8 +19,12 @@ VariantProperty::VariantProperty(const VariantProperty &property, AbstractView *
}
void VariantProperty::setValue(const QVariant &value)
void VariantProperty::setValue(const QVariant &value, SL sl)
{
NanotraceHR::Tracer tracer{"variant property set value",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return;
@@ -47,8 +51,12 @@ void VariantProperty::setValue(const QVariant &value)
privateModel()->setVariantProperty(internalNodeSharedPointer(), name(), value);
}
const QVariant &VariantProperty::value() const
const QVariant &VariantProperty::value(SL sl) const
{
NanotraceHR::Tracer tracer{"variant property value",
ModelTracing::category(),
keyValue("caller location", sl)};
if (isValid()) {
auto property = internalNode()->variantProperty(name());
if (property)
@@ -60,13 +68,21 @@ const QVariant &VariantProperty::value() const
return nullVariant;
}
void VariantProperty::setEnumeration(const EnumerationName &enumerationName)
void VariantProperty::setEnumeration(const EnumerationName &enumerationName, SL sl)
{
NanotraceHR::Tracer tracer{"variant property set enumeration",
ModelTracing::category(),
keyValue("caller location", sl)};
setValue(QVariant::fromValue(Enumeration(enumerationName)));
}
const Enumeration &VariantProperty::enumeration() const
const Enumeration &VariantProperty::enumeration(SL sl) const
{
NanotraceHR::Tracer tracer{"variant property enumeration",
ModelTracing::category(),
keyValue("caller location", sl)};
if (auto enumeration = get_if<Enumeration>(&value()))
return *enumeration;
@@ -75,13 +91,21 @@ const Enumeration &VariantProperty::enumeration() const
return nullEnumeration;
}
bool VariantProperty::holdsEnumeration() const
bool VariantProperty::holdsEnumeration(SL sl) const
{
NanotraceHR::Tracer tracer{"variant property holds enumeration",
ModelTracing::category(),
keyValue("caller location", sl)};
return value().canConvert<Enumeration>();
}
void VariantProperty::setDynamicTypeNameAndValue(const TypeName &type, const QVariant &value)
void VariantProperty::setDynamicTypeNameAndValue(const TypeName &type, const QVariant &value, SL sl)
{
NanotraceHR::Tracer tracer{"variant property set dtnamic type name and value",
ModelTracing::category(),
keyValue("caller location", sl)};
if (!isValid())
return;
@@ -104,8 +128,14 @@ void VariantProperty::setDynamicTypeNameAndValue(const TypeName &type, const QVa
privateModel()->setDynamicVariantProperty(internalNodeSharedPointer(), name(), type, value);
}
void VariantProperty::setDynamicTypeNameAndEnumeration(const TypeName &type, const EnumerationName &enumerationName)
void VariantProperty::setDynamicTypeNameAndEnumeration(const TypeName &type,
const EnumerationName &enumerationName,
SL sl)
{
NanotraceHR::Tracer tracer{"variant property set dynamic type name and enumeration",
ModelTracing::category(),
keyValue("caller location", sl)};
setDynamicTypeNameAndValue(type, QVariant::fromValue(Enumeration(enumerationName)));
}