forked from qt-creator/qt-creator
QmlDesigner: Simply property type name check
Move some repetitive pattern to PropertyMetaInfo Change-Id: Iba8722d3d95881c1db85c12cbc2b2b8c4b629f2c Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -139,7 +139,7 @@ void MaterialEditorView::changeValue(const QString &name)
|
||||
bool propertyTypeUrl = false;
|
||||
|
||||
if (metaInfo.isValid() && metaInfo.hasProperty(propertyName)) {
|
||||
if (metaInfo.property(propertyName).hasPropertyTypeName("QUrl", "url")) {
|
||||
if (metaInfo.property(propertyName).propertyTypeNameIsUrl()) {
|
||||
// turn absolute local file paths into relative paths
|
||||
propertyTypeUrl = true;
|
||||
QString filePath = castedValue.toUrl().toString();
|
||||
|
@@ -63,7 +63,7 @@ QVariant PropertyEditorValue::value() const
|
||||
if (modelNode().isValid()) {
|
||||
if (auto metaInfo = modelNode().metaInfo();
|
||||
metaInfo.isValid() && metaInfo.hasProperty(name())
|
||||
&& metaInfo.property(name()).hasPropertyTypeName("QUrl", "url")) {
|
||||
&& metaInfo.property(name()).propertyTypeNameIsUrl()) {
|
||||
returnValue = returnValue.toUrl().toString();
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ static void fixAmbigousColorNames(const QmlDesigner::ModelNode &modelNode,
|
||||
{
|
||||
if (modelNode.isValid()) {
|
||||
if (auto metaInfo = modelNode.metaInfo();
|
||||
metaInfo.isValid() && metaInfo.property(name).hasPropertyTypeName("QColor", "color")) {
|
||||
metaInfo.isValid() && metaInfo.property(name).propertyTypeNameIsColor()) {
|
||||
if ((value->type() == QVariant::Color)) {
|
||||
QColor color = value->value<QColor>();
|
||||
int alpha = color.alpha();
|
||||
@@ -124,7 +124,7 @@ static void fixUrl(const QmlDesigner::ModelNode &modelNode, const QmlDesigner::P
|
||||
{
|
||||
if (modelNode.isValid()) {
|
||||
if (auto metaInfo = modelNode.metaInfo();
|
||||
metaInfo.isValid() && metaInfo.property(name).hasPropertyTypeName("QUrl", "url"))
|
||||
metaInfo.isValid() && metaInfo.property(name).propertyTypeNameIsUrl())
|
||||
|
||||
if (!value->isValid())
|
||||
*value = QStringLiteral("");
|
||||
@@ -149,7 +149,7 @@ void PropertyEditorValue::setValueWithEmit(const QVariant &value)
|
||||
if (modelNode().isValid()) {
|
||||
if (auto metaInfo = modelNode().metaInfo();
|
||||
metaInfo.isValid() && metaInfo.hasProperty(name())
|
||||
&& metaInfo.property(name()).hasPropertyTypeName("QUrl")) {
|
||||
&& metaInfo.property(name()).propertyTypeNameIsUrl()) {
|
||||
newValue = QUrl(newValue.toString());
|
||||
}
|
||||
}
|
||||
@@ -268,7 +268,7 @@ bool PropertyEditorValue::isTranslated() const
|
||||
if (modelNode().isValid()) {
|
||||
if (auto metaInfo = modelNode().metaInfo();
|
||||
metaInfo.isValid() && metaInfo.hasProperty(name())
|
||||
&& metaInfo.property(name()).hasPropertyTypeName("QString", "string")) {
|
||||
&& metaInfo.property(name()).propertyTypeNameIsString()) {
|
||||
const QmlDesigner::QmlObjectNode objectNode(modelNode());
|
||||
if (objectNode.isValid() && objectNode.hasBindingProperty(name())) {
|
||||
const QRegularExpression rx(
|
||||
@@ -438,7 +438,7 @@ QString PropertyEditorValue::getTranslationContext() const
|
||||
if (modelNode().isValid()) {
|
||||
if (auto metaInfo = modelNode().metaInfo();
|
||||
metaInfo.isValid() && metaInfo.hasProperty(name())
|
||||
&& metaInfo.property(name()).hasPropertyTypeName("QString", "string")) {
|
||||
&& metaInfo.property(name()).propertyTypeNameIsString()) {
|
||||
const QmlDesigner::QmlObjectNode objectNode(modelNode());
|
||||
if (objectNode.isValid() && objectNode.hasBindingProperty(name())) {
|
||||
const QRegularExpression rx(QRegularExpression::anchoredPattern(
|
||||
|
@@ -201,7 +201,7 @@ void PropertyEditorView::changeValue(const QString &name)
|
||||
bool propertyTypeUrl = false;
|
||||
|
||||
if (metaInfo.isValid() && metaInfo.hasProperty(propertyName)
|
||||
&& metaInfo.property(propertyName).hasPropertyTypeName("QUrl", "url")) {
|
||||
&& metaInfo.property(propertyName).propertyTypeNameIsUrl()) {
|
||||
// turn absolute local file paths into relative paths
|
||||
propertyTypeUrl = true;
|
||||
QString filePath = castedValue.toUrl().toString();
|
||||
|
@@ -54,7 +54,7 @@ bool modelNodeHasUrlSource(const QmlDesigner::ModelNode &modelNode)
|
||||
{
|
||||
QmlDesigner::NodeMetaInfo metaInfo = modelNode.metaInfo();
|
||||
return metaInfo.isValid() && metaInfo.hasProperty("source")
|
||||
&& metaInfo.property("source").hasPropertyTypeName("QUrl", "url");
|
||||
&& metaInfo.property("source").propertyTypeNameIsUrl();
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
@@ -59,6 +59,10 @@ public:
|
||||
return ((propertyTypeName_ == typeName) || ...);
|
||||
}
|
||||
|
||||
bool propertyTypeNameIsColor() const { return hasPropertyTypeName("QColor", "color"); }
|
||||
bool propertyTypeNameIsString() const { return hasPropertyTypeName("QString", "string"); }
|
||||
bool propertyTypeNameIsUrl() const { return hasPropertyTypeName("QUrl", "url"); }
|
||||
|
||||
private:
|
||||
QSharedPointer<class NodeMetaInfoPrivate> m_nodeMetaInfoPrivateData;
|
||||
PropertyName m_propertyName;
|
||||
|
@@ -247,7 +247,7 @@ QVariant QmlObjectNode::modelValue(const PropertyName &name) const
|
||||
bool QmlObjectNode::isTranslatableText(const PropertyName &name) const
|
||||
{
|
||||
if (modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name)
|
||||
&& modelNode().metaInfo().property(name).hasPropertyTypeName("QString", "string")) {
|
||||
&& modelNode().metaInfo().property(name).propertyTypeNameIsString()) {
|
||||
if (modelNode().hasBindingProperty(name)) {
|
||||
static QRegularExpression regularExpressionPattern(
|
||||
QLatin1String("^qsTr(|Id|anslate)\\(\".*\"\\)$"));
|
||||
|
@@ -62,6 +62,8 @@ public:
|
||||
auto propertyTypeName_ = propertyTypeName();
|
||||
return ((propertyTypeName_ == typeName) && ...);
|
||||
}
|
||||
|
||||
bool propertyTypeNameIsUrl() const { return hasPropertyTypeName("QUrl", "url"); }
|
||||
};
|
||||
|
||||
using PropertyMetaInfos = std::vector<PropertyMetaInfo>;
|
||||
|
Reference in New Issue
Block a user