diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-25 11:58:24 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-25 13:37:23 +0200 |
commit | 39169acf3bc2bc43cc32a6455d43e9588765c84a (patch) | |
tree | 3e0cbee0c68e15c87fe34746d1e9eb148ddd7bd1 /options/bundle.cpp | |
parent | c7532ed82f57e4281d3f5ecded59a95a4f756b04 (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/bundle.cpp')
-rw-r--r-- | options/bundle.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/options/bundle.cpp b/options/bundle.cpp index aa7d0ea8..53298d5d 100644 --- a/options/bundle.cpp +++ b/options/bundle.cpp @@ -23,7 +23,7 @@ void bundle::reload() { QMutexLocker l(&mtx); saved = group(group_name); - const bool has_changes = transient != saved; + const bool has_changes = is_modified(); transient = saved; if (has_changes) @@ -58,11 +58,12 @@ void bundle::save_deferred(QSettings& s) if (group_name.size() == 0) return; - bool modified_ = false; + bool modified_ = is_modified(); + if (modified_) { QMutexLocker l(&mtx); - if (saved != transient) + if (is_modified()) { qDebug() << "bundle" << group_name << "changed, saving"; modified_ = true; @@ -80,10 +81,31 @@ void bundle::save() save_deferred(*group::ini_file()); } -bool bundle::is_modified() const // XXX unused +bool bundle::is_modified() const { QMutexLocker l(mtx); - return transient != saved; + + for (const auto& kv : transient.kvs) + { + const QVariant other = saved.get<QVariant>(kv.first); + if (!saved.contains(kv.first) || !is_equal(kv.first, kv.second, other)) + { + qDebug() << "bundle" << group_name << "modified" << "key" << kv.first << "-" << other << "<>" << kv.second; + return true; + } + } + + for (const auto& kv : saved.kvs) + { + const QVariant other = transient.get<QVariant>(kv.first); + if (!transient.contains(kv.first) || !is_equal(kv.first, kv.second, other)) + { + qDebug() << "bundle" << group_name << "modified" << "key" << kv.first << "-" << other << "<>" << kv.second; + return true; + } + } + + return false; } void bundler::bundle_decf(const bundler::k& key) |