diff view/View.cpp @ 1539:bfacecf7ea7e

Overhaul choice of layer to show scale, in Pane::drawVerticalScale, making it call out to the same logic used by View::getVisibleExtentsForUnit when appropriate. Also refuse to accept scale from dormant top layer.
author Chris Cannam
date Tue, 15 Oct 2019 14:53:25 +0100
parents 4f8c72adbf43
children b4b5b8dd5fe1
line wrap: on
line diff
--- a/view/View.cpp	Tue Oct 15 14:51:58 2019 +0100
+++ b/view/View.cpp	Tue Oct 15 14:53:25 2019 +0100
@@ -197,10 +197,34 @@
                                double &min, double &max,
                                bool &log) const
 {
-    bool have = false;
-
-    // Iterate in reverse order, so as to return display extents of
-    // topmost layer that fits the bill
+    Layer *layer = getScaleProvidingLayerForUnit(unit);
+    if (!layer) {
+        return false;
+    }
+
+    //!!! clumsy
+
+    QString layerUnit;
+    double layerMin, layerMax;
+
+    if (layer->getValueExtents(layerMin, layerMax, log, layerUnit)) {
+        if (layer->getDisplayExtents(min, max)) {
+            return true;
+        } else {
+            min = layerMin;
+            max = layerMax;
+            return true;
+        }
+    } else {
+        return false;
+    }
+}
+        
+Layer *
+View::getScaleProvidingLayerForUnit(QString unit) const
+{
+    // Iterate in reverse order, so as to use topmost layer that fits
+    // the bill
     
     for (auto i = m_layerStack.rbegin(); i != m_layerStack.rend(); ++i) { 
 
@@ -221,26 +245,10 @@
             continue;
         }
 
-        double displayMin = 0.0, displayMax = 0.0;
-        
-        if (layer->getDisplayExtents(displayMin, displayMax)) {
-
-            min = displayMin;
-            max = displayMax;
-            log = layerLog;
-            have = true;
-            break;
-
-        } else {
-
-            if (!have || layerMin < min) min = layerMin;
-            if (!have || layerMax > max) max = layerMax;
-            if (!have && layerLog) log = true;
-            have = true;
-        }
+        return layer;
     }
 
-    return have;
+    return nullptr;
 }
 
 bool