forked from qt-creator/qt-creator
QmlDesigner: Add helper functions for translated text
Change-Id: Ib5b5037f492f7f7ee448aebd5215d28e0ccae7f0 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
committed by
Thomas Hartmann
parent
8934100a12
commit
c7dd854842
@@ -72,6 +72,8 @@ public:
|
||||
bool instanceHasBinding(const PropertyName &name) const;
|
||||
bool propertyAffectedByCurrentState(const PropertyName &name) const;
|
||||
QVariant modelValue(const PropertyName &name) const;
|
||||
bool isTranslatableText(const PropertyName &name) const;
|
||||
QString stripedTranslatableText(const PropertyName &name) const;
|
||||
QString expression(const PropertyName &name) const;
|
||||
bool isInBaseState() const;
|
||||
QmlPropertyChanges propertyChangeForCurrentState() const;
|
||||
@@ -98,6 +100,8 @@ public:
|
||||
|
||||
static QVariant instanceValue(const ModelNode &modelNode, const PropertyName &name);
|
||||
|
||||
static QString generateTranslatableText(const QString& text);
|
||||
|
||||
protected:
|
||||
NodeInstance nodeInstance() const;
|
||||
QmlObjectNode nodeForInstance(const NodeInstance &instance) const;
|
||||
|
@@ -175,6 +175,34 @@ QVariant QmlObjectNode::modelValue(const PropertyName &name) const
|
||||
return propertyChanges.modelNode().variantProperty(name).value();
|
||||
}
|
||||
|
||||
bool QmlObjectNode::isTranslatableText(const PropertyName &name) const
|
||||
{
|
||||
if (modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name))
|
||||
if (modelNode().metaInfo().propertyTypeName(name) == "QString" || modelNode().metaInfo().propertyTypeName(name) == "string") {
|
||||
if (modelNode().hasBindingProperty(name)) {
|
||||
static QRegExp regularExpressionPatter("qsTr\\((\".*\")\\)");
|
||||
return regularExpressionPatter.exactMatch(modelNode().bindingProperty(name).expression());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QString QmlObjectNode::stripedTranslatableText(const PropertyName &name) const
|
||||
{
|
||||
if (modelNode().hasBindingProperty(name)) {
|
||||
static QRegExp regularExpressionPatter("qsTr\\(\"(.*)\"\\)");
|
||||
if (regularExpressionPatter.exactMatch(modelNode().bindingProperty(name).expression()))
|
||||
return regularExpressionPatter.cap(1);
|
||||
} else {
|
||||
return modelNode().variantProperty(name).value().toString();
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QmlObjectNode::expression(const PropertyName &name) const
|
||||
{
|
||||
if (!isValid())
|
||||
@@ -387,6 +415,11 @@ QVariant QmlObjectNode::instanceValue(const ModelNode &modelNode, const Property
|
||||
return modelView->instanceForModelNode(modelNode).property(name);
|
||||
}
|
||||
|
||||
QString QmlObjectNode::generateTranslatableText(const QString &text)
|
||||
{
|
||||
return QString("qsTr(\"%1\")").arg(text);
|
||||
}
|
||||
|
||||
TypeName QmlObjectNode::instanceType(const PropertyName &name) const
|
||||
{
|
||||
return nodeInstance().instanceType(name);
|
||||
|
Reference in New Issue
Block a user