aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-07-26 16:29:02 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2022-07-29 09:20:42 +0200
commit9eccc92beab97769b0fb2f8edb871afd919ce66f (patch)
treeb72af228b753741fdfee83b6d140885adfbbc4f8
parent5ffd81567f816523ce09896e2f2608238fb43bb1 (diff)
Support RegExpLiteral bindings in qmltc
Task-number: QTBUG-91956 Change-Id: I02f8c6d1f0d6e4411985ffe3f22fb3c51fb36db6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 2d5f3eb86e1eed13f143173eec0cbc724ed5d9a9)
-rw-r--r--src/qmlcompiler/qqmljsmetatypes.cpp8
-rw-r--r--src/qmlcompiler/qqmljsmetatypes_p.h2
-rw-r--r--src/quick/util/qquickforeignutils_p.h2
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/regexpBindings.qml5
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp12
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.h1
-rw-r--r--tools/qmltc/qmltccompiler.cpp6
8 files changed, 36 insertions, 1 deletions
diff --git a/src/qmlcompiler/qqmljsmetatypes.cpp b/src/qmlcompiler/qqmljsmetatypes.cpp
index 7d16d46c59..afc7315adf 100644
--- a/src/qmlcompiler/qqmljsmetatypes.cpp
+++ b/src/qmlcompiler/qqmljsmetatypes.cpp
@@ -52,6 +52,14 @@ QString QQmlJSMetaPropertyBinding::stringValue() const
return {};
}
+QString QQmlJSMetaPropertyBinding::regExpValue() const
+{
+ if (auto regexpLiteral = std::get_if<Content::RegexpLiteral>(&m_bindingContent))
+ return regexpLiteral->value;
+ // warn
+ return {};
+}
+
/*!
\internal
Uses \a resolver to return the correct type for the stored literal
diff --git a/src/qmlcompiler/qqmljsmetatypes_p.h b/src/qmlcompiler/qqmljsmetatypes_p.h
index e101cbefc1..75f635d5d0 100644
--- a/src/qmlcompiler/qqmljsmetatypes_p.h
+++ b/src/qmlcompiler/qqmljsmetatypes_p.h
@@ -665,6 +665,8 @@ public:
QString stringValue() const;
+ QString regExpValue() const;
+
QSharedPointer<const QQmlJSScope> literalType(const QQmlJSTypeResolver *resolver) const;
QQmlJSMetaMethod::RelativeFunctionIndex scriptIndex() const
diff --git a/src/quick/util/qquickforeignutils_p.h b/src/quick/util/qquickforeignutils_p.h
index 118ae21189..25e2f7e998 100644
--- a/src/quick/util/qquickforeignutils_p.h
+++ b/src/quick/util/qquickforeignutils_p.h
@@ -4,7 +4,7 @@
#ifndef QTQUICKFOREIGN_P_H
#define QTQUICKFOREIGN_P_H
-#include <qtquickglobal_p.h>
+#include <QtQuick/private/qtquickglobal_p.h>
#include <QtGui/qstylehints.h>
#if QT_CONFIG(im)
diff --git a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
index e46ca0daee..243a75e9fb 100644
--- a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
+++ b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
@@ -35,6 +35,7 @@ set(qml_sources
extensionTypeBindings.qml
nonStandardInclude.qml
memberProperties.qml
+ regexpBindings.qml
qtbug103956/SubComponent.qml
qtbug103956/MainComponent.qml
diff --git a/tests/auto/qml/qmltc/QmltcTests/regexpBindings.qml b/tests/auto/qml/qmltc/QmltcTests/regexpBindings.qml
new file mode 100644
index 0000000000..e1fd6de373
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/regexpBindings.qml
@@ -0,0 +1,5 @@
+import QtQuick
+
+RegularExpressionValidator {
+ regularExpression: /ab*c/
+}
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index 6d2db3a698..af0ba4878e 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -25,6 +25,7 @@
#include "qtbug103956_main.h"
#include "nonstandardinclude.h"
#include "memberproperties.h"
+#include "regexpbindings.h"
#include "signalhandlers.h"
#include "javascriptfunctions.h"
@@ -124,6 +125,9 @@ void tst_qmltc::initTestCase()
QUrl("qrc:/QmltcTests/deferredProperties_attached.qml"),
QUrl("qrc:/QmltcTests/deferredProperties_complex.qml"),
QUrl("qrc:/QmltcTests/extensionTypeBindings.qml"),
+ QUrl("qrc:/QmltcTests/nonStandardInclude.qml"),
+ QUrl("qrc:/QmltcTests/memberProperties.qml"),
+ QUrl("qrc:/QmltcTests/regexpBindings.qml"),
QUrl("qrc:/QmltcTests/signalHandlers.qml"),
QUrl("qrc:/QmltcTests/javaScriptFunctions.qml"),
@@ -847,6 +851,14 @@ void tst_qmltc::memberProperties()
QCOMPARE(created.m_y, u"foo"_s);
}
+void tst_qmltc::regexpBindings()
+{
+ QQmlEngine e;
+ PREPEND_NAMESPACE(regexpBindings) created(&e);
+ QCOMPARE(created.regularExpression().pattern(), u"ab*c");
+ QVERIFY(created.regularExpression().match(u"abbbc"_s).hasMatch());
+}
+
void tst_qmltc::signalHandlers()
{
QQmlEngine e;
diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h
index 6563fb052d..31c15f5aa6 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.h
+++ b/tests/auto/qml/qmltc/tst_qmltc.h
@@ -37,6 +37,7 @@ private slots:
void visibleAliasMethods(); // QTBUG-103956
void nonStandardIncludesInsideModule(); // QTBUG-104094
void memberProperties();
+ void regexpBindings();
void signalHandlers();
void jsFunctions();
diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp
index 7da38a989a..f1d291ff62 100644
--- a/tools/qmltc/qmltccompiler.cpp
+++ b/tools/qmltc/qmltccompiler.cpp
@@ -859,6 +859,12 @@ void QmltcCompiler::compileBinding(QmltcType &current, const QQmlJSMetaPropertyB
assignToProperty(p, QQmlJSUtils::toLiteral(binding.stringValue()));
break;
}
+ case QQmlJSMetaPropertyBinding::RegExpLiteral: {
+ const QString value =
+ u"QRegularExpression(%1)"_s.arg(QQmlJSUtils::toLiteral(binding.regExpValue()));
+ assignToProperty(p, value);
+ break;
+ }
case QQmlJSMetaPropertyBinding::Null: {
// poor check: null bindings are only supported for var and objects
Q_ASSERT(propertyType->isSameType(m_typeResolver->varType())