diff view/View.cpp @ 1537:4f8c72adbf43

Clarify naming of some view-related methods. Rename LayerGeometryProvider::getValueExtents to getVisibleExtentsForUnit, and View::getTextLabelHeight to getTextLabelYCoord. Add View::getVisibleExtentsForAnyUnit to be used to determine which unit to adopt in a new e.g. box layer.
author Chris Cannam
date Tue, 15 Oct 2019 11:40:56 +0100
parents 395ef06beab1
children bfacecf7ea7e
line wrap: on
line diff
--- a/view/View.cpp	Tue Oct 15 09:32:24 2019 +0100
+++ b/view/View.cpp	Tue Oct 15 11:40:56 2019 +0100
@@ -193,44 +193,102 @@
 }
 
 bool
-View::getValueExtents(QString unit, double &min, double &max, bool &log) const
+View::getVisibleExtentsForUnit(QString unit,
+                               double &min, double &max,
+                               bool &log) const
 {
     bool have = false;
 
-    for (LayerList::const_iterator i = m_layerStack.begin();
-         i != m_layerStack.end(); ++i) { 
-
+    // Iterate in reverse order, so as to return display extents of
+    // topmost layer that fits the bill
+    
+    for (auto i = m_layerStack.rbegin(); i != m_layerStack.rend(); ++i) { 
+
+        Layer *layer = *i;
+
+        if (layer->isLayerDormant(this)) {
+            continue;
+        }
+        
         QString layerUnit;
         double layerMin = 0.0, layerMax = 0.0;
+        bool layerLog = false;
+
+        if (!layer->getValueExtents(layerMin, layerMax, layerLog, layerUnit)) {
+            continue;
+        }
+        if (layerUnit.toLower() != unit.toLower()) {
+            continue;
+        }
+
         double displayMin = 0.0, displayMax = 0.0;
-        bool layerLog = false;
-
-        if ((*i)->getValueExtents(layerMin, layerMax, layerLog, layerUnit) &&
-            layerUnit.toLower() == unit.toLower()) {
-
-            if ((*i)->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 (layerLog) log = true;
-                have = true;
-            }
+        
+        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 have;
 }
 
+bool
+View::getVisibleExtentsForAnyUnit(double &min, double &max,
+                                  bool &log, QString &unit) const
+{
+    bool have = false;
+
+    // Iterate in reverse order, so as to return display extents of
+    // topmost layer that fits the bill
+    
+    for (auto i = m_layerStack.rbegin(); i != m_layerStack.rend(); ++i) { 
+
+        Layer *layer = *i;
+
+        if (layer->isLayerDormant(this)) {
+            continue;
+        }
+        
+        QString layerUnit;
+        double layerMin = 0.0, layerMax = 0.0;
+        bool layerLog = false;
+
+        if (!layer->getValueExtents(layerMin, layerMax, layerLog, layerUnit)) {
+            continue;
+        }
+        if (layerUnit == "") {
+            continue;
+        }
+
+        double displayMin = 0.0, displayMax = 0.0;
+        
+        if (layer->getDisplayExtents(displayMin, displayMax)) {
+
+            min = displayMin;
+            max = displayMax;
+            log = layerLog;
+            unit = layerUnit;
+            have = true;
+            break;
+        }
+    }
+
+    return have;
+}
+
 int
-View::getTextLabelHeight(const Layer *layer, QPainter &paint) const
+View::getTextLabelYCoord(const Layer *layer, QPainter &paint) const
 {
     std::map<int, Layer *> sortedLayers;