summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-01-13 22:42:59 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-01-15 19:21:57 +0100
commitcb27ed30f7bc58474eba991f837843eb76cbd339 (patch)
treef0b4c5b93301792e01ae42ec4fbfc9d582ddff31 /tests
parentda6c8b2fc6bc1a29b8a88c4ecce53eaf811eb06c (diff)
QCSS: Support Qt 5-style integer property selectors
In Qt 5 style sheets, objects could be selected by an enum-type property using the integer value of the enum value, e.g QToolButton[popupMode="1"] { ... } In Qt 6, the the new meta type system and QVariant implementation enabled QVariant::toString to return the string representation of the enum value instead for a property containing an enum. Since QStyleSheetStyle's attribute matching is string based, this breaks the Qt 5 style selector, and QCSS code instead needs to use e.g. QToolButton[popupMode=MenuButtonPopup] { ... } While the new syntax is arguably preferable, this is an unintentional change that silently breaks style sheet code (no error or warning at compile- or run-time). To support Qt 5-style selectors, we have to change the StyleSelector interface of the QCssParser API so that we can pass through what type of value the attribute extractor should return; if an integer string "1" is provided, then we need to compare the enum integer value; if the string provided does not represent a number, then we need to compare the name of the enum value. Since the pure virtual attribute() method that needs to be implemented to extract the attribute value of the node is implemented in modules outside qtbase, add a second virtual method that takes the entire QCss::AttributeSelector, which includes the value to match. Extractor implementations can use it to evaluate which type of data to return for an exact match. The default implementation calls the old attribute() method so that existing StyleSelector implementations continue to work. Make the respective change in the QStyleSheetStyleSelector, and simplify the surrounding code. Adjust other StyleSelector implemnentations in qtbase. As a drive-by, remove the superfluous virtual declaration from those overrides. Once submodules are adjusted to override this virtual function instead of the (now no longer pure) virtual attribute() method, that method can be removed. Pick-to: 6.3 6.2 Fixes: QTBUG-99642 Change-Id: I9a2b3498f77bf7cab5e90980b7dab2f621d3d859 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/text/qcssparser/tst_qcssparser.cpp30
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp2
2 files changed, 16 insertions, 16 deletions
diff --git a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
index f51c0eab20..7c16f4aa76 100644
--- a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
+++ b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
@@ -886,32 +886,34 @@ public:
styleSheets.append(sheet);
}
- virtual QStringList nodeNames(NodePtr node) const override { return QStringList(reinterpret_cast<QDomElement *>(node.ptr)->tagName()); }
- virtual QString attribute(NodePtr node, const QString &name) const override { return reinterpret_cast<QDomElement *>(node.ptr)->attribute(name); }
- virtual bool hasAttribute(NodePtr node, const QString &name) const { return reinterpret_cast<QDomElement *>(node.ptr)->hasAttribute(name); }
- virtual bool hasAttributes(NodePtr node) const override { return reinterpret_cast<QDomElement *>(node.ptr)->hasAttributes(); }
-
- virtual bool isNullNode(NodePtr node) const override {
- return reinterpret_cast<QDomElement *>(node.ptr)->isNull();
- }
- virtual NodePtr parentNode(NodePtr node) const override {
+ QStringList nodeNames(NodePtr node) const override
+ { return QStringList(reinterpret_cast<QDomElement *>(node.ptr)->tagName()); }
+ QString attributeValue(NodePtr node, const QCss::AttributeSelector &aSel) const override
+ { return reinterpret_cast<QDomElement *>(node.ptr)->attribute(aSel.name); }
+ bool hasAttribute(NodePtr node, const QString &name) const
+ { return reinterpret_cast<QDomElement *>(node.ptr)->hasAttribute(name); }
+ bool hasAttributes(NodePtr node) const override
+ { return reinterpret_cast<QDomElement *>(node.ptr)->hasAttributes(); }
+
+ bool isNullNode(NodePtr node) const override
+ { return reinterpret_cast<QDomElement *>(node.ptr)->isNull(); }
+ NodePtr parentNode(NodePtr node) const override {
NodePtr parent;
parent.ptr = new QDomElement(reinterpret_cast<QDomElement *>(node.ptr)->parentNode().toElement());
return parent;
}
- virtual NodePtr duplicateNode(NodePtr node) const override {
+ NodePtr duplicateNode(NodePtr node) const override {
NodePtr n;
n.ptr = new QDomElement(*reinterpret_cast<QDomElement *>(node.ptr));
return n;
}
- virtual NodePtr previousSiblingNode(NodePtr node) const override {
+ NodePtr previousSiblingNode(NodePtr node) const override {
NodePtr sibling;
sibling.ptr = new QDomElement(reinterpret_cast<QDomElement *>(node.ptr)->previousSiblingElement());
return sibling;
}
- virtual void freeNode(NodePtr node) const override {
- delete reinterpret_cast<QDomElement *>(node.ptr);
- }
+ void freeNode(NodePtr node) const override
+ { delete reinterpret_cast<QDomElement *>(node.ptr); }
private:
QDomDocument doc;
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index 6409a669fe..492b206019 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -2371,8 +2371,6 @@ void tst_QStyleSheetStyle::enumPropertySelector()
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QEXPECT_FAIL("Enum value", "In Qt 5, style sheet selectors have to use integer enum values", Continue);
-#else
- QEXPECT_FAIL("Int value", "In Qt 6, style sheet selectors must use the enum value name", Continue);
#endif
QVERIFY(styledSizeHint.width() > unstyledSizeHint.width());