changeset 1315:1d7921b1852f

Ensure scale appears for layer when drawn in AutoAlign mode without any other layer present to align to
author Chris Cannam
date Wed, 04 Jul 2018 15:34:16 +0100
parents 769d7890203b
children c0d8356e274f
files layer/Layer.cpp layer/Layer.h layer/NoteLayer.cpp layer/SingleColourLayer.h layer/TimeValueLayer.cpp view/Pane.cpp
diffstat 6 files changed, 44 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Layer.cpp	Wed Jul 04 15:33:47 2018 +0100
+++ b/layer/Layer.cpp	Wed Jul 04 15:34:16 2018 +0100
@@ -588,6 +588,31 @@
     v->drawMeasurementRect(paint, this, r.pixrect.normalized(), focus);
 }
 
+bool
+Layer::valueExtentsMatchMine(LayerGeometryProvider *v) const
+{
+    double min, min_;
+    double max, max_;
+    bool logarithmic, logarithmic_;
+    QString unit;
+
+    if (!getValueExtents(min_, max_, logarithmic_, unit)) {
+        return false;
+    }
+
+    if (!v->getValueExtents(unit, min, max, logarithmic)) {
+        return false;
+    }
+
+    if (min != min_ ||
+        max != max_ ||
+        logarithmic != logarithmic_) {
+        return false;
+    }
+
+    return true;
+}
+
 void
 Layer::toXml(QTextStream &stream,
              QString indent, QString extraAttributes) const
--- a/layer/Layer.h	Wed Jul 04 15:33:47 2018 +0100
+++ b/layer/Layer.h	Wed Jul 04 15:34:16 2018 +0100
@@ -626,6 +626,8 @@
     void paintMeasurementRect(LayerGeometryProvider *v, QPainter &paint,
                               const MeasureRect &r, bool focus) const;
 
+    bool valueExtentsMatchMine(LayerGeometryProvider *v) const;
+    
     QString m_presentationName;
 
 private:
--- a/layer/NoteLayer.cpp	Wed Jul 04 15:33:47 2018 +0100
+++ b/layer/NoteLayer.cpp	Wed Jul 04 15:34:16 2018 +0100
@@ -61,7 +61,7 @@
     m_scaleMinimum(0),
     m_scaleMaximum(0)
 {
-          SVDEBUG << "constructed NoteLayer" << endl;
+    SVDEBUG << "constructed NoteLayer" << endl;
 }
 
 void
@@ -833,14 +833,18 @@
 int
 NoteLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const
 {
-    if (!m_model || shouldAutoAlign()) {
+    if (!m_model) {
         return 0;
-    } else  {
-        if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) {
-            return LogNumericalScale().getWidth(v, paint) + 10; // for piano
-        } else {
-            return LinearNumericalScale().getWidth(v, paint);
-        }
+    }
+
+    if (shouldAutoAlign() && !valueExtentsMatchMine(v)) {
+        return 0;
+    }
+
+    if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) {
+        return LogNumericalScale().getWidth(v, paint) + 10; // for piano
+    } else {
+        return LinearNumericalScale().getWidth(v, paint);
     }
 }
 
--- a/layer/SingleColourLayer.h	Wed Jul 04 15:33:47 2018 +0100
+++ b/layer/SingleColourLayer.h	Wed Jul 04 15:34:16 2018 +0100
@@ -13,8 +13,8 @@
     COPYING included with this distribution for more information.
 */
 
-#ifndef _SINGLE_COLOUR_LAYER_H_
-#define _SINGLE_COLOUR_LAYER_H_
+#ifndef SV_SINGLE_COLOUR_LAYER_H
+#define SV_SINGLE_COLOUR_LAYER_H
 
 #include "Layer.h"
 #include <QColor>
--- a/layer/TimeValueLayer.cpp	Wed Jul 04 15:33:47 2018 +0100
+++ b/layer/TimeValueLayer.cpp	Wed Jul 04 15:34:16 2018 +0100
@@ -1238,7 +1238,9 @@
 int
 TimeValueLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const
 {
-    if (!m_model || shouldAutoAlign()) {
+    if (!m_model) {
+        return 0;
+    } else if (shouldAutoAlign() && !valueExtentsMatchMine(v)) {
         return 0;
     } else if (m_plotStyle == PlotSegmentation) {
         if (m_verticalScale == LogScale) {
--- a/view/Pane.cpp	Wed Jul 04 15:33:47 2018 +0100
+++ b/view/Pane.cpp	Wed Jul 04 15:34:16 2018 +0100
@@ -594,8 +594,6 @@
 
     int sw = topLayer->getVerticalScaleWidth
         (this, m_manager->shouldShowVerticalColourScale(), paint);
-
-//    cerr << "sw = " << sw << endl;
     
     if (sw > 0) {
         scaleLayer = topLayer;