changeset 1548:bd6af89982d7

Permit getScaleProvidingLayerForUnit to return a dormant layer if there is no visible alternative. This is necessary to avoid the scale disappearing in Tony when the spectrogram is toggled off.
author Chris Cannam
date Thu, 17 Oct 2019 14:44:22 +0100
parents e6362cf5ff1d
children 9a5eede01869 e79731086b0f
files view/View.cpp
diffstat 1 files changed, 28 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/view/View.cpp	Thu Oct 17 11:12:54 2019 +0100
+++ b/view/View.cpp	Thu Oct 17 14:44:22 2019 +0100
@@ -247,9 +247,22 @@
 {
     // Return the layer which is used to provide the min/max/log for
     // any auto-align layer of a given unit. This is also the layer
-    // that will draw the scale, if possible. It is the topmost
-    // visible layer having that unit that is not also auto-aligning.
-    // If there is none such, return null.
+    // that will draw the scale, if possible.
+    //
+    // The returned layer is
+    // 
+    // - the topmost visible layer having that unit that is not also
+    // auto-aligning; or if there is no such layer,
+    //
+    // - the topmost layer of any visibility having that unit that is
+    // not also auto-aligning (because a dormant layer can still draw
+    // a scale, and it makes sense for layers aligned to it not to
+    // jump about when its visibility is toggled); or if there is no
+    // such layer,
+    //
+    // - none
+
+    Layer *dormantOption = nullptr;
     
     for (auto i = m_layerStack.rbegin(); i != m_layerStack.rend(); ++i) { 
 
@@ -260,13 +273,6 @@
                << unit << "): Looking at layer " << layer
                << " (" << layer->getLayerPresentationName() << ")" << endl;
 #endif
-
-        if (layer->isLayerDormant(this)) {
-#ifdef DEBUG_VIEW_SCALE_CHOICE
-            SVCERR << "... it's dormant" << endl;
-#endif
-            continue;
-        }
         
         QString layerUnit;
         double layerMin = 0.0, layerMax = 0.0;
@@ -278,6 +284,7 @@
 #endif
             continue;
         }
+
         if (layerUnit.toLower() != unit.toLower()) {
 #ifdef DEBUG_VIEW_SCALE_CHOICE
             SVCERR << "... it has the wrong unit (" << layerUnit << ")" << endl;
@@ -293,14 +300,23 @@
             continue;
         }
 
+        if (layer->isLayerDormant(this)) {
+#ifdef DEBUG_VIEW_SCALE_CHOICE
+            SVCERR << "... it's dormant" << endl;
+#endif
+            if (!dormantOption) {
+                dormantOption = layer;
+            }
+            continue;
+        }
+
 #ifdef DEBUG_VIEW_SCALE_CHOICE
         SVCERR << "... it's good" << endl;
 #endif
-
         return layer;
     }
 
-    return nullptr;
+    return dormantOption;
 }
 
 bool