summaryrefslogtreecommitdiffhomepage
path: root/options/connector.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-25 11:58:24 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-25 13:37:23 +0200
commit39169acf3bc2bc43cc32a6455d43e9588765c84a (patch)
tree3e0cbee0c68e15c87fe34746d1e9eb148ddd7bd1 /options/connector.cpp
parentc7532ed82f57e4281d3f5ecded59a95a4f756b04 (diff)
options: use non-generic comparison for bundle modification check
The generic QVariant comparison works badly for QList<QPointF>. Create a comparator between two QVariants for base_value in value<tp> ctor, using QVariant::value<tp> which returns right results once it's converted to tp. If a value was registered for a name in a bundle, use that comparator as the comparator for that name. In case conflicting value types were registered always use generic comparison for that name. std::type_index needs to be used here since value<t> can be instantiated in different modules (libraries), resulting in different value for the comparator function pointer. Move group::operator== to bundle type to avoid circular include for connector.h. Also use element_type more consistently in value<tp>.
Diffstat (limited to 'options/connector.cpp')
-rw-r--r--options/connector.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/options/connector.cpp b/options/connector.cpp
index 680283cf..2f4bb0af 100644
--- a/options/connector.cpp
+++ b/options/connector.cpp
@@ -2,11 +2,30 @@
#include "connector.hpp"
#include "value.hpp"
+#include <utility>
+
namespace options {
namespace detail {
+static bool generic_is_equal(const QVariant& val1, const QVariant& val2)
+{
+ return val1 == val2;
+}
+
connector::~connector() {}
+bool connector::is_equal(const QString& name, const QVariant& val1, const QVariant& val2) const
+{
+ QMutexLocker l(get_mtx());
+
+ auto it = connected_values.find(name);
+
+ if (it != connected_values.cend() && std::get<0>((*it).second).size() != 0)
+ return std::get<1>((*it).second)(val1, val2);
+ else
+ return generic_is_equal(val1, val2);
+}
+
bool connector::on_value_destructed_impl(const QString& name, const base_value* val)
{
QMutexLocker l(get_mtx());
@@ -16,7 +35,7 @@ bool connector::on_value_destructed_impl(const QString& name, const base_value*
if (it != connected_values.end())
{
- std::vector<const base_value*>& values = (*it).second;
+ std::vector<const base_value*>& values = std::get<0>((*it).second);
for (auto it = values.begin(); it != values.end(); it++)
{
if (*it == val)
@@ -69,14 +88,19 @@ void connector::on_value_created(const QString& name, const base_value* val)
if (it != connected_values.end())
{
- std::vector<const base_value*>& values = (*it).second;
+ tt& tmp = (*it).second;
+ std::type_index& typeidx = std::get<2>(tmp);
+ std::vector<const base_value*>& values = std::get<0>(tmp);
+
+ if (typeidx != val->type_index)
+ std::get<1>((*it).second) = generic_is_equal;
values.push_back(val);
}
else
{
std::vector<const base_value*> vec;
vec.push_back(val);
- connected_values[name] = vec;
+ connected_values.emplace(name, tt(vec, val->cmp, val->type_index));
}
}
@@ -85,7 +109,7 @@ void connector::notify_values(const QString& name) const
auto it = connected_values.find(name);
if (it != connected_values.cend())
{
- for (const base_value* val : (*it).second)
+ for (const base_value* val : std::get<0>((*it).second))
{
val->bundle_value_changed();
}
@@ -95,7 +119,7 @@ void connector::notify_values(const QString& name) const
void connector::notify_all_values() const
{
for (auto& pair : connected_values)
- for (const base_value* val : pair.second)
+ for (const base_value* val : std::get<0>(pair.second))
val->bundle_value_changed();
}