From ba7d320e3056479ef1f233d9f04b6d694154b991 Mon Sep 17 00:00:00 2001 From: taj-ny <79316397+taj-ny@users.noreply.github.com> Date: Sat, 23 May 2026 15:49:18 +0200 Subject: [PATCH] variables: switch from std::any to QVariant --- src/libinputactions/Value.cpp | 10 ++--- src/libinputactions/Value.h | 3 +- .../conditions/VariableCondition.cpp | 8 ++-- .../conditions/VariableCondition.h | 9 ++--- src/libinputactions/config/parsers/core.cpp | 28 ++++++------- src/libinputactions/config/parsers/flags.cpp | 10 ++--- src/libinputactions/config/parsers/flags.h | 2 +- .../config/parsers/triggers.cpp | 2 +- .../variables/LocalVariable.cpp | 6 +-- src/libinputactions/variables/LocalVariable.h | 8 ++-- .../variables/RemoteVariable.cpp | 6 +-- .../variables/RemoteVariable.h | 6 +-- src/libinputactions/variables/Variable.cpp | 10 ++--- src/libinputactions/variables/Variable.h | 11 +++--- .../variables/VariableManager.cpp | 8 ++-- .../variables/VariableManager.h | 10 ++--- .../variables/VariableOperations.cpp | 39 +++++++++---------- .../variables/VariableOperations.h | 11 +++--- .../variables/VariableWrapper.h | 6 +-- tests/libinputactions/Test.h | 4 ++ .../parsers/TestDeviceRuleNodeParser.cpp | 10 ++--- .../TestVariableConditionNodeParser.cpp | 32 ++++++++------- .../triggers/TestTriggerNodeParser.cpp | 10 ++--- 23 files changed, 125 insertions(+), 124 deletions(-) diff --git a/src/libinputactions/Value.cpp b/src/libinputactions/Value.cpp index 19ecd8e..43eecb4 100644 --- a/src/libinputactions/Value.cpp +++ b/src/libinputactions/Value.cpp @@ -89,7 +89,7 @@ Value Value::variable(QString name) return variable->operations()->toString(); } - if (variable->type() != typeid(T)) { + if (variable->type().id() != qMetaTypeId()) { qCWarning(INPUTACTIONS).noquote() << QString("Failed to get value: variable %1 is of type %2, expected %3").arg(name, variable->type().name(), typeid(T).name()); return {}; @@ -136,11 +136,11 @@ bool Value::expensive() const } template -Value::operator Value() const +Value::operator Value() const { - return Value::function([valueProvider = *this] -> std::any { + return Value::function([valueProvider = *this] -> QVariant { if (const auto value = valueProvider.get()) { - return value.value(); + return QVariant::fromValue(value.value()); } return {}; }); @@ -152,7 +152,7 @@ template class Value; template class Value; template class Value; template class Value; -template class Value; template class Value; +template class Value; } \ No newline at end of file diff --git a/src/libinputactions/Value.h b/src/libinputactions/Value.h index eaafdf8..0cdc3de 100644 --- a/src/libinputactions/Value.h +++ b/src/libinputactions/Value.h @@ -19,7 +19,6 @@ #pragma once #include -#include #include #include @@ -60,7 +59,7 @@ class Value */ bool expensive() const; - operator Value() const; + operator Value() const; private: std::variant, std::function()>> m_value; diff --git a/src/libinputactions/conditions/VariableCondition.cpp b/src/libinputactions/conditions/VariableCondition.cpp index 15bbcb1..0af9780 100644 --- a/src/libinputactions/conditions/VariableCondition.cpp +++ b/src/libinputactions/conditions/VariableCondition.cpp @@ -27,15 +27,15 @@ Q_LOGGING_CATEGORY(INPUTACTIONS_CONDITION_VARIABLE, "inputactions.condition.vari namespace InputActions { -VariableCondition::VariableCondition(const QString &variableName, const std::vector> &values, ComparisonOperator comparisonOperator) +VariableCondition::VariableCondition(const QString &variableName, const std::vector> &values, ComparisonOperator comparisonOperator) : m_variableName(variableName) , m_values(values) , m_comparisonOperator(comparisonOperator) { } -VariableCondition::VariableCondition(const QString &variableName, const Value &value, ComparisonOperator comparisonOperator) - : VariableCondition(variableName, std::vector>{value}, comparisonOperator) +VariableCondition::VariableCondition(const QString &variableName, const Value &value, ComparisonOperator comparisonOperator) + : VariableCondition(variableName, std::vector>{value}, comparisonOperator) { } @@ -46,7 +46,7 @@ bool VariableCondition::doEvaluate(const ConditionEvaluationArguments &arguments throw std::runtime_error(std::format("Variable {} does not exist.", m_variableName.toStdString())); } - std::vector values; + std::vector values; for (const auto &valueProvider : m_values) { if (const auto value = valueProvider.get()) { values.push_back(value.value()); diff --git a/src/libinputactions/conditions/VariableCondition.h b/src/libinputactions/conditions/VariableCondition.h index 633f904..f34dd40 100644 --- a/src/libinputactions/conditions/VariableCondition.h +++ b/src/libinputactions/conditions/VariableCondition.h @@ -20,7 +20,6 @@ #include "Condition.h" #include -#include #include namespace InputActions @@ -31,11 +30,11 @@ enum class ComparisonOperator; class VariableCondition : public Condition { public: - VariableCondition(const QString &variableName, const std::vector> &values, ComparisonOperator comparisonOperator); - VariableCondition(const QString &variableName, const Value &value, ComparisonOperator comparisonOperator); + VariableCondition(const QString &variableName, const std::vector> &values, ComparisonOperator comparisonOperator); + VariableCondition(const QString &variableName, const Value &value, ComparisonOperator comparisonOperator); const QString &variableName() const { return m_variableName; } - const std::vector> &values() const { return m_values; } + const std::vector> &values() const { return m_values; } ComparisonOperator comparisonOperator() const { return m_comparisonOperator; } protected: @@ -43,7 +42,7 @@ class VariableCondition : public Condition private: QString m_variableName; - std::vector> m_values; + std::vector> m_values; ComparisonOperator m_comparisonOperator; }; diff --git a/src/libinputactions/config/parsers/core.cpp b/src/libinputactions/config/parsers/core.cpp index 4bb4082..a5449f7 100644 --- a/src/libinputactions/config/parsers/core.cpp +++ b/src/libinputactions/config/parsers/core.cpp @@ -63,21 +63,21 @@ namespace InputActions { -static Value parseAny(const Node *node, const std::type_index &type) +static Value parseVariant(const Node *node, const QMetaType &type) { - if (type == typeid(bool)) { + if (type.id() == qMetaTypeId()) { return node->as>(); - } else if (type == typeid(CursorShape)) { + } else if (type.id() == qMetaTypeId()) { return node->as>(); - } else if (type == typeid(Qt::KeyboardModifiers)) { + } else if (type.id() == qMetaTypeId()) { return Value(node->as(true)); - } else if (type == typeid(InputDeviceTypes)) { + } else if (type.id() == qMetaTypeId()) { return Value(node->as(true)); - } else if (type == typeid(qreal)) { + } else if (type.id() == qMetaTypeId()) { return node->as>(); - } else if (type == typeid(QPointF)) { + } else if (type.id() == qMetaTypeId()) { return node->as>(); - } else if (type == typeid(QString)) { + } else if (type.id() == qMetaTypeId()) { return node->as>(); } throw InvalidValueConfigException(node, "Unexpected type."); @@ -104,8 +104,8 @@ static std::shared_ptr parseVariableCondition(const Node *node, const } ComparisonOperator comparisonOperator; - std::vector> right; - if (firstSpace == -1 && variable->type() == typeid(bool)) { // bool variable condition without operator + std::vector> right; + if (firstSpace == -1 && variable->type().id() == qMetaTypeId()) { // bool variable condition without operator comparisonOperator = ComparisonOperator::EqualTo; right.push_back(Value(true)); } else { @@ -126,14 +126,14 @@ static std::shared_ptr parseVariableCondition(const Node *node, const if (!isTypeFlags(variable->type()) && rightNode->isSequence()) { for (const auto *item : rightNode->sequenceItems()) { - right.push_back(parseAny(item, variable->type())); + right.push_back(parseVariant(item, variable->type())); } } else if (comparisonOperator == ComparisonOperator::Between) { const auto values = parseSeparatedString2>(rightNode.get(), ';'); - right.push_back(parseAny(values.first.get(), variable->type())); - right.push_back(parseAny(values.second.get(), variable->type())); + right.push_back(parseVariant(values.first.get(), variable->type())); + right.push_back(parseVariant(values.second.get(), variable->type())); } else { - right.push_back(parseAny(rightNode.get(), variable->type())); + right.push_back(parseVariant(rightNode.get(), variable->type())); } } diff --git a/src/libinputactions/config/parsers/flags.cpp b/src/libinputactions/config/parsers/flags.cpp index 42d7ea3..9972565 100644 --- a/src/libinputactions/config/parsers/flags.cpp +++ b/src/libinputactions/config/parsers/flags.cpp @@ -22,13 +22,13 @@ namespace InputActions { -bool isTypeFlags(const std::type_index &type) +bool isTypeFlags(const QMetaType &type) { - static const std::set flags{ - typeid(InputDeviceTypes), - typeid(Qt::KeyboardModifiers), + static const std::set flags{ + qMetaTypeId(), + qMetaTypeId(), }; - return flags.contains(type); + return flags.contains(type.id()); } } \ No newline at end of file diff --git a/src/libinputactions/config/parsers/flags.h b/src/libinputactions/config/parsers/flags.h index 6f51f1f..03f5da1 100644 --- a/src/libinputactions/config/parsers/flags.h +++ b/src/libinputactions/config/parsers/flags.h @@ -37,6 +37,6 @@ struct NodeParser> } }; -bool isTypeFlags(const std::type_index &type); +bool isTypeFlags(const QMetaType &type); } \ No newline at end of file diff --git a/src/libinputactions/config/parsers/triggers.cpp b/src/libinputactions/config/parsers/triggers.cpp index c0318ba..5aef355 100644 --- a/src/libinputactions/config/parsers/triggers.cpp +++ b/src/libinputactions/config/parsers/triggers.cpp @@ -128,7 +128,7 @@ void finalizeTrigger(const Node *node, Trigger *trigger) ComparisonOperator::EqualTo)); } else { conditionGroup->append(std::make_shared(BuiltinVariables::Fingers, - std::vector>{ + std::vector>{ Value(range.min().value()), Value(range.max().value())}, ComparisonOperator::Between)); } diff --git a/src/libinputactions/variables/LocalVariable.cpp b/src/libinputactions/variables/LocalVariable.cpp index 6176d70..b13ab62 100644 --- a/src/libinputactions/variables/LocalVariable.cpp +++ b/src/libinputactions/variables/LocalVariable.cpp @@ -21,17 +21,17 @@ namespace InputActions { -LocalVariable::LocalVariable(std::type_index type) +LocalVariable::LocalVariable(QMetaType type) : Variable(std::move(type)) { } -std::any LocalVariable::get() const +QVariant LocalVariable::get() const { return m_value; } -void LocalVariable::set(std::any value) +void LocalVariable::set(QVariant value) { m_value = std::move(value); } diff --git a/src/libinputactions/variables/LocalVariable.h b/src/libinputactions/variables/LocalVariable.h index 62d9b4f..854996e 100644 --- a/src/libinputactions/variables/LocalVariable.h +++ b/src/libinputactions/variables/LocalVariable.h @@ -29,13 +29,13 @@ namespace InputActions class LocalVariable : public Variable { public: - LocalVariable(std::type_index type); + LocalVariable(QMetaType type); - std::any get() const override; - void set(std::any value) override; + QVariant get() const override; + void set(QVariant value) override; private: - std::any m_value; + QVariant m_value; }; } \ No newline at end of file diff --git a/src/libinputactions/variables/RemoteVariable.cpp b/src/libinputactions/variables/RemoteVariable.cpp index 985a83d..4dd5064 100644 --- a/src/libinputactions/variables/RemoteVariable.cpp +++ b/src/libinputactions/variables/RemoteVariable.cpp @@ -21,15 +21,15 @@ namespace InputActions { -RemoteVariable::RemoteVariable(std::type_index type, std::function getter) +RemoteVariable::RemoteVariable(QMetaType type, std::function getter) : Variable(std::move(type)) , m_getter(std::move(getter)) { } -std::any RemoteVariable::get() const +QVariant RemoteVariable::get() const { - std::any value; + QVariant value; m_getter(value); return value; } diff --git a/src/libinputactions/variables/RemoteVariable.h b/src/libinputactions/variables/RemoteVariable.h index e0dd807..520e77f 100644 --- a/src/libinputactions/variables/RemoteVariable.h +++ b/src/libinputactions/variables/RemoteVariable.h @@ -32,12 +32,12 @@ class RemoteVariable : public Variable /** * @param getter Must always return the same type as the variable or empty. */ - RemoteVariable(std::type_index type, std::function getter); + RemoteVariable(QMetaType type, std::function getter); - std::any get() const override; + QVariant get() const override; private: - std::function m_getter; + std::function m_getter; }; } \ No newline at end of file diff --git a/src/libinputactions/variables/Variable.cpp b/src/libinputactions/variables/Variable.cpp index b972c15..3524b3d 100644 --- a/src/libinputactions/variables/Variable.cpp +++ b/src/libinputactions/variables/Variable.cpp @@ -21,20 +21,20 @@ namespace InputActions { -Variable::Variable(std::type_index type) +Variable::Variable(QMetaType type) : m_type(std::move(type)) , m_operations(VariableOperationsBase::create(this)) { } -const std::type_index &Variable::type() const +const VariableOperationsBase *Variable::operations() const { - return m_type; + return m_operations.get(); } -const VariableOperationsBase *Variable::operations() const +const QMetaType &Variable::type() const { - return m_operations.get(); + return m_type; } } \ No newline at end of file diff --git a/src/libinputactions/variables/Variable.h b/src/libinputactions/variables/Variable.h index 7733494..35e01b2 100644 --- a/src/libinputactions/variables/Variable.h +++ b/src/libinputactions/variables/Variable.h @@ -20,7 +20,6 @@ #include "VariableOperations.h" #include -#include #include namespace InputActions @@ -29,24 +28,24 @@ namespace InputActions class Variable { public: - Variable(std::type_index type); + Variable(QMetaType type); virtual ~Variable() = default; /** * @return May be empty. */ - virtual std::any get() const { return {}; } + virtual QVariant get() const { return {}; } /** * @param value Must be the same as the variable's type or empty. */ - virtual void set(std::any value) {} + virtual void set(QVariant value) {} /** * @return Operations for this variable's type. */ const VariableOperationsBase *operations() const; - const std::type_index &type() const; + const QMetaType &type() const; /** * Whether the value should not be shown in the DBus interface. @@ -55,7 +54,7 @@ class Variable void setHidden(bool value) { m_hidden = value; } private: - std::type_index m_type; + QMetaType m_type; std::variant m_value; std::unique_ptr m_operations; bool m_hidden{}; diff --git a/src/libinputactions/variables/VariableManager.cpp b/src/libinputactions/variables/VariableManager.cpp index 60828fb..ef6b321 100644 --- a/src/libinputactions/variables/VariableManager.cpp +++ b/src/libinputactions/variables/VariableManager.cpp @@ -54,7 +54,7 @@ Variable *VariableManager::registerVariable(const QString &name, std::unique_ptr variable->setHidden(hidden); m_variables[name] = std::move(variable); - if (m_variables[name]->type() == typeid(QPointF)) { + if (m_variables[name]->type().id() == qMetaTypeId()) { registerRemoteVariable( name + "_x", [this, name](auto &value) { @@ -93,12 +93,12 @@ std::map VariableManager::extraProcessEnvironment(const QStrin if (const auto *variable = getVariable(variableName)) { const auto value = variable->get(); - if (!value.has_value()) { + if (value.isNull()) { continue; } - if (variable->type() == typeid(bool)) { - if (std::any_cast(value)) { + if (variable->type().id() == qMetaTypeId()) { + if (value.toBool()) { result[variableName] = "1"; } continue; diff --git a/src/libinputactions/variables/VariableManager.h b/src/libinputactions/variables/VariableManager.h index a266f6b..13cb0cd 100644 --- a/src/libinputactions/variables/VariableManager.h +++ b/src/libinputactions/variables/VariableManager.h @@ -80,7 +80,7 @@ class VariableManager auto *variable = getVariable(name); if (!variable) { return {}; - } else if (variable->type() != typeid(T)) { + } else if (variable->type().id() != qMetaTypeId()) { qCWarning(INPUTACTIONS_VARIABLE_MANAGER).noquote() << QString("VariableManager::getVariable called with the wrong type (variable: %1, type: %2").arg(variable->type().name(), typeid(T).name()); return {}; @@ -99,7 +99,7 @@ class VariableManager template VariableWrapper registerLocalVariable(const QString &name, bool hidden = false) { - return {registerVariable(name, std::make_unique(typeid(T)), hidden)}; + return {registerVariable(name, std::make_unique(QMetaType::fromType()), hidden)}; } template void registerLocalVariable(const VariableInfo &variable, bool hidden = false) @@ -109,14 +109,14 @@ class VariableManager template void registerRemoteVariable(const QString &name, const std::function &value)> getter, bool hidden = false) { - const std::function anyGetter = [getter](std::any &value) { + const std::function variantGetter = [getter](QVariant &value) { std::optional optValue; getter(optValue); if (optValue.has_value()) { - value = optValue.value(); + value = QVariant::fromValue(optValue.value()); } }; - registerVariable(name, std::make_unique(typeid(T), anyGetter), hidden); + registerVariable(name, std::make_unique(QMetaType::fromType(), variantGetter), hidden); } void registerVariableAlias(const QString &variable, const QString &alias); diff --git a/src/libinputactions/variables/VariableOperations.cpp b/src/libinputactions/variables/VariableOperations.cpp index 345b5a0..7be089d 100644 --- a/src/libinputactions/variables/VariableOperations.cpp +++ b/src/libinputactions/variables/VariableOperations.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include Q_LOGGING_CATEGORY(INPUTACTIONS_VARIABLE_OPERATIONS, "inputactions.variable.operations") @@ -35,10 +34,10 @@ VariableOperationsBase::VariableOperationsBase(Variable *variable) { } -bool VariableOperationsBase::compare(const std::vector &right, ComparisonOperator comparisonOperator) const +bool VariableOperationsBase::compare(const std::vector &right, ComparisonOperator comparisonOperator) const { const auto left = m_variable->get(); - if (!left.has_value()) { + if (left.isNull()) { return false; } @@ -57,7 +56,7 @@ bool VariableOperationsBase::compare(const std::vector &right, Compari } } -bool VariableOperationsBase::compare(const std::any &left, const std::any &right, ComparisonOperator comparisonOperator) const +bool VariableOperationsBase::compare(const QVariant &left, const QVariant &right, ComparisonOperator comparisonOperator) const { return false; } @@ -67,7 +66,7 @@ QString VariableOperationsBase::toString() const return toString(m_variable->get()); } -QString VariableOperationsBase::toString(const std::any &value) const +QString VariableOperationsBase::toString(const QVariant &value) const { return {}; } @@ -75,19 +74,19 @@ QString VariableOperationsBase::toString(const std::any &value) const std::unique_ptr VariableOperationsBase::create(Variable *variable) { const auto type = variable->type(); - if (type == typeid(bool)) { + if (type.id() == qMetaTypeId()) { return std::make_unique>(variable); - } else if (type == typeid(qreal)) { + } else if (type.id() == qMetaTypeId()) { return std::make_unique>(variable); - } else if (type == typeid(CursorShape)) { + } else if (type.id() == qMetaTypeId()) { return std::make_unique>(variable); - } else if (type == typeid(Qt::KeyboardModifiers)) { + } else if (type.id() == qMetaTypeId()) { return std::make_unique>(variable); - } else if (type == typeid(InputDeviceTypes)) { + } else if (type.id() == qMetaTypeId()) { return std::make_unique>(variable); - } else if (type == typeid(QPointF)) { + } else if (type.id() == qMetaTypeId()) { return std::make_unique>(variable); - } else if (type == typeid(QString)) { + } else if (type.id() == qMetaTypeId()) { return std::make_unique>(variable); } @@ -102,14 +101,14 @@ VariableOperations::VariableOperations(Variable *variable) } template -bool VariableOperations::compare(const std::any &left, const std::any &right, ComparisonOperator comparisonOperator) const +bool VariableOperations::compare(const QVariant &left, const QVariant &right, ComparisonOperator comparisonOperator) const { - if (left.type() != typeid(T) || right.type() != typeid(T)) { - qCWarning(INPUTACTIONS_VARIABLE_OPERATIONS).noquote() << "Attempted illegal variable comparison (left: " << left.type().name() - << ", right: " << right.type().name() << ", expected: " << typeid(T).name(); + if (left.typeId() != qMetaTypeId() || right.typeId() != qMetaTypeId()) { + qCWarning(INPUTACTIONS_VARIABLE_OPERATIONS).noquote() + << "Attempted illegal variable comparison (left: " << left.typeName() << ", right: " << right.typeName() << ", expected: " << typeid(T).name(); return false; } - return compare(std::any_cast(left), std::any_cast(right), comparisonOperator); + return compare(left.value(), right.value(), comparisonOperator); } template<> @@ -222,12 +221,12 @@ QString VariableOperations::toString(const T &value) } template -QString VariableOperations::toString(const std::any &value) const +QString VariableOperations::toString(const QVariant &value) const { - if (!value.has_value()) { + if (value.isNull()) { return ""; } - return toString(std::any_cast(value)); + return toString(value.value()); } template diff --git a/src/libinputactions/variables/VariableOperations.h b/src/libinputactions/variables/VariableOperations.h index 580b586..cb13c7c 100644 --- a/src/libinputactions/variables/VariableOperations.h +++ b/src/libinputactions/variables/VariableOperations.h @@ -19,7 +19,6 @@ #pragma once #include -#include #include namespace InputActions @@ -40,7 +39,7 @@ class VariableOperationsBase * @param right Must contain exactly 2 values if operator is Between. Must contain at least 1 value if operator is OneOf. All other operators require * exactly 1 value. */ - bool compare(const std::vector &right, ComparisonOperator comparisonOperator) const; + bool compare(const std::vector &right, ComparisonOperator comparisonOperator) const; /** * @return A string representation of the variable's value or an empty string if not supported. */ @@ -48,7 +47,7 @@ class VariableOperationsBase /** * @return A string representation of the specified value of the same type as the variable or an empty string if not supported. */ - virtual QString toString(const std::any &value) const; + virtual QString toString(const QVariant &value) const; static std::unique_ptr create(Variable *variable); @@ -58,7 +57,7 @@ class VariableOperationsBase /** * The operators NotEqualTo, OneOf and Between are not handled here. */ - virtual bool compare(const std::any &left, const std::any &right, ComparisonOperator comparisonOperator) const; + virtual bool compare(const QVariant &left, const QVariant &right, ComparisonOperator comparisonOperator) const; private: Variable *m_variable; @@ -72,10 +71,10 @@ class VariableOperations : public VariableOperationsBase static bool compare(const T &left, const T &right, ComparisonOperator comparisonOperator); static QString toString(const T &value); - QString toString(const std::any &value) const override; + QString toString(const QVariant &value) const override; protected: - bool compare(const std::any &left, const std::any &right, ComparisonOperator comparisonOperator) const override; + bool compare(const QVariant &left, const QVariant &right, ComparisonOperator comparisonOperator) const override; }; } \ No newline at end of file diff --git a/src/libinputactions/variables/VariableWrapper.h b/src/libinputactions/variables/VariableWrapper.h index 9e0949a..bcfd7f1 100644 --- a/src/libinputactions/variables/VariableWrapper.h +++ b/src/libinputactions/variables/VariableWrapper.h @@ -35,10 +35,10 @@ class VariableWrapper std::optional get() const { const auto value = m_variable->get(); - if (!value.has_value()) { + if (value.isNull()) { return {}; } - return std::any_cast(value); + return value.value(); } void set(const std::optional &value) @@ -47,7 +47,7 @@ class VariableWrapper m_variable->set({}); return; } - m_variable->set(value.value()); + m_variable->set(QVariant::fromValue(value.value())); } private: diff --git a/tests/libinputactions/Test.h b/tests/libinputactions/Test.h index c2b5316..f486a26 100644 --- a/tests/libinputactions/Test.h +++ b/tests/libinputactions/Test.h @@ -38,6 +38,10 @@ namespace InputActions action; \ QCOMPARE(g_configIssueManager->issues().size(), 0); +#define INPUTACTIONS_COMPARE_VARIANT(variant, T, expected) \ + QCOMPARE(variant.typeId(), qMetaTypeId()); \ + QCOMPARE(variant.value(), expected); + class Test : public QObject { Q_OBJECT diff --git a/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.cpp b/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.cpp index d33b2ab..a04d753 100644 --- a/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.cpp +++ b/tests/libinputactions/config/parsers/TestDeviceRuleNodeParser.cpp @@ -58,7 +58,7 @@ private slots: const auto &conditionValues = condition->values(); QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); + INPUTACTIONS_COMPARE_VARIANT(conditionValues[0].get().value(), bool, true); } void mouse_triggerHandlerSetting_motionTimeout__addsDeprecatedFeatureConfigIssue() @@ -92,7 +92,7 @@ private slots: const auto &conditionValues = condition->values(); QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); + INPUTACTIONS_COMPARE_VARIANT(conditionValues[0].get().value(), bool, true); } void mouse_triggerHandlerSetting_pressTimeout__addsDeprecatedFeatureConfigIssue() @@ -126,7 +126,7 @@ private slots: const auto &conditionValues = condition->values(); QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); + INPUTACTIONS_COMPARE_VARIANT(conditionValues[0].get().value(), bool, true); } void mouse_triggerHandlerSetting_unblockButtonsOnTimeout__addsDeprecatedFeatureConfigIssue() @@ -162,7 +162,7 @@ private slots: const auto &conditionValues = condition->values(); QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), "a"); + INPUTACTIONS_COMPARE_VARIANT(conditionValues[0].get().value(), QString, "a"); } void touchpad_devicesNode__addsDeprecatedFeatureConfigIssue() @@ -198,7 +198,7 @@ private slots: const auto &conditionValues = condition->values(); QCOMPARE(conditionValues.size(), 1); - QCOMPARE(std::any_cast(conditionValues[0].get().value()), true); + INPUTACTIONS_COMPARE_VARIANT(conditionValues[0].get().value(), bool, true); } void touchpad_triggerHandlerSetting_clickTimeout__addsDeprecatedFeatureConfigIssue() diff --git a/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.cpp b/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.cpp index a394edf..ce71eb6 100644 --- a/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.cpp +++ b/tests/libinputactions/config/parsers/conditions/TestVariableConditionNodeParser.cpp @@ -35,7 +35,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), true); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), bool, true); } void negatedBoolVariableWithoutOperator__parsesNodeCorrectly() @@ -50,7 +50,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), true); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), bool, true); } void negated__parsesNodeCorrectly() @@ -65,7 +65,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), 1); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), qreal, 1); } void between__parsesNodeCorrectly() @@ -80,8 +80,8 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 2); - QCOMPARE(std::any_cast(values[0].get().value()), 1); - QCOMPARE(std::any_cast(values[1].get().value()), 2); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), qreal, 1); + INPUTACTIONS_COMPARE_VARIANT(values[1].get().value(), qreal, 2); } void between_point__parsesNodeCorrectly() @@ -96,8 +96,8 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 2); - QCOMPARE(std::any_cast(values[0].get().value()), QPointF(0.1, 0.2)); - QCOMPARE(std::any_cast(values[1].get().value()), QPointF(0.3, 0.4)); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), QPointF, QPointF(0.1, 0.2)); + INPUTACTIONS_COMPARE_VARIANT(values[1].get().value(), QPointF, QPointF(0.3, 0.4)); } void between_invalid_oneValue__throwsInvalidValueConfigException() @@ -124,7 +124,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), "a"); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), QString, "a"); } void contains_flags_sequence__parsesNodeCorrectly() @@ -139,7 +139,9 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::ControlModifier | Qt::KeyboardModifier::MetaModifier); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), + Qt::KeyboardModifiers, + Qt::KeyboardModifier::ControlModifier | Qt::KeyboardModifier::MetaModifier); } void contains_flags_scalar__parsesNodeCorrectly() @@ -154,7 +156,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::MetaModifier); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), Qt::KeyboardModifiers, Qt::KeyboardModifier::MetaModifier); } void oneOf_sequence__parsesNodeCorrectly() @@ -169,8 +171,8 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 2); - QCOMPARE(std::any_cast(values[0].get().value()), "a"); - QCOMPARE(std::any_cast(values[1].get().value()), "b"); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), QString, "a"); + INPUTACTIONS_COMPARE_VARIANT(values[1].get().value(), QString, "b"); } void oneOf_scalar__parsesNodeCorrectly() @@ -185,7 +187,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), "a"); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), QString, "a"); } void matches__parsesNodeCorrectly() @@ -200,7 +202,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), "[a]"); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), QString, "[a]"); } void matches_invalidRegex__throwsInvalidValueConfigException() @@ -237,7 +239,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), 1); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), qreal, 1); } void inGroups__variableManagerPropagated_doesNotThrow() diff --git a/tests/libinputactions/config/parsers/triggers/TestTriggerNodeParser.cpp b/tests/libinputactions/config/parsers/triggers/TestTriggerNodeParser.cpp index 1de4085..ab56656 100644 --- a/tests/libinputactions/config/parsers/triggers/TestTriggerNodeParser.cpp +++ b/tests/libinputactions/config/parsers/triggers/TestTriggerNodeParser.cpp @@ -69,7 +69,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), 2); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), qreal, 2); } void fingers_range__parsesNodeCorrectly() @@ -86,8 +86,8 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 2); - QCOMPARE(std::any_cast(values[0].get().value()), 2); - QCOMPARE(std::any_cast(values[1].get().value()), 3); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), qreal, 2); + INPUTACTIONS_COMPARE_VARIANT(values[1].get().value(), qreal, 3); } void keyboardModifiers__addsDeprecatedFeatureConfigIssue() @@ -122,7 +122,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::MetaModifier | Qt::KeyboardModifier::AltModifier); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), Qt::KeyboardModifiers, Qt::KeyboardModifier::MetaModifier | Qt::KeyboardModifier::AltModifier); } void keyboardModifiers_none__parsesNodeCorrectly() @@ -139,7 +139,7 @@ private slots: const auto &values = condition->values(); QCOMPARE(values.size(), 1); - QCOMPARE(std::any_cast(values[0].get().value()), Qt::KeyboardModifier::NoModifier); + INPUTACTIONS_COMPARE_VARIANT(values[0].get().value(), Qt::KeyboardModifiers, Qt::KeyboardModifier::NoModifier); } void keyboardModifiers_invalid__throwsInvalidValueConfigException()