From d02e1dd2354648ef151059abb4dcb73fab48c79a Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Thu, 26 Dec 2019 16:04:54 -0600 Subject: [PATCH] When loading settings, leave unspecified defaults alone. This prevents new charts (such as CPAP_PressureSet, etc.) from being disabled by virtue of their being absent from existing settings. --- oscar/Graphs/gGraphView.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/oscar/Graphs/gGraphView.cpp b/oscar/Graphs/gGraphView.cpp index c4aa7603..ec06879c 100644 --- a/oscar/Graphs/gGraphView.cpp +++ b/oscar/Graphs/gGraphView.cpp @@ -3462,6 +3462,18 @@ void gGraphView::SaveSettings(QString title) f.close(); } + +// Merge and overwrite two hashes. (We can't use QHash::unite because it doesn't overwrite.) +// This is useful for loading settings, where we want to leave the defaults alone for features +// that don't yet have settings specified. +template inline void hashMerge(T & a, const T & b) +{ + for (auto key : b.keys()) { + a[key] = b[key]; + } +} + + bool gGraphView::LoadSettings(QString title) { QString filename = p_profile->Get("{DataFolder}/") + title.toLower() + ".shg"; @@ -3568,10 +3580,9 @@ bool gGraphView::LoadSettings(QString title) if (layertype == LT_LineChart) { gLineChart * lc = dynamic_cast(findLayer(g, LT_LineChart)); if (lc) { - lc->m_flags_enabled = flags_enabled; - lc->m_enabled = plots_enabled; - - lc->m_dot_enabled = dot_enabled; + hashMerge(lc->m_flags_enabled, flags_enabled); + hashMerge(lc->m_enabled, plots_enabled); + hashMerge(lc->m_dot_enabled, dot_enabled); } } }