aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsannotation_p.h
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-04-15 14:42:26 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2021-04-16 14:29:55 +0200
commitd226e24a5d4288a3e7f263c526cb6cbf72255388 (patch)
treef763e4461eaed0e30d71c54c3bbbf69de3a325b5 /src/qmlcompiler/qqmljsannotation_p.h
parentd506b6360c9e63435f3b4e77c3317186f323e8ae (diff)
qqmljsannotation: Use std::variant instead of QVariant
Makes it easier to reason about the values stored in QQmlJSAnnotation. Change-Id: I13bf8294a25f00edf78fad3b2b91fbc7a313d49e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsannotation_p.h')
-rw-r--r--src/qmlcompiler/qqmljsannotation_p.h42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljsannotation_p.h b/src/qmlcompiler/qqmljsannotation_p.h
index aaeb5b59c7..a36d68855f 100644
--- a/src/qmlcompiler/qqmljsannotation_p.h
+++ b/src/qmlcompiler/qqmljsannotation_p.h
@@ -39,8 +39,9 @@
//
// We mean it.
+#include <variant>
+
#include <private/qqmljsast_p.h>
-#include <qvariant.h>
#include <qglobal.h>
QT_BEGIN_NAMESPACE
@@ -52,11 +53,48 @@ struct QQQmlJSDeprecation
struct QQmlJSAnnotation
{
+ using Value = std::variant<QString, double>;
+
QString name;
- QHash<QString, QVariant> bindings;
+ QHash<QString, Value> bindings;
bool isDeprecation() const;
QQQmlJSDeprecation deprecation() const;
+
+ friend bool operator==(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b) {
+ return a.name == b.name &&
+ a.bindings == b.bindings;
+ }
+
+ friend bool operator!=(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b) {
+ return !(a == b);
+ }
+
+ friend size_t qHash(const QQmlJSAnnotation &annotation, size_t seed = 0)
+ {
+ QtPrivate::QHashCombine combine;
+ seed = combine(seed, annotation.name);
+
+ for (auto it = annotation.bindings.constBegin(); it != annotation.bindings.constEnd(); ++it) {
+ QtPrivate::QHashCombine combine;
+ size_t h = combine(seed, it.key());
+ // use + to keep the result independent of the ordering of the keys
+
+ const auto &var = it.value();
+
+ if (var.index() == std::variant_npos)
+ continue;
+
+ if (std::holds_alternative<double>(var))
+ seed += combine(h, std::get<double>(var));
+ else if (std::holds_alternative<QString>(var))
+ seed += combine(h, std::get<QString>(var));
+ else
+ Q_UNREACHABLE();
+ }
+
+ return seed;
+ }
};
QT_END_NAMESPACE