# HG changeset patch # User Chris Cannam # Date 1571136056 -3600 # Node ID 4f8c72adbf434f5ab680a2ce459e1b5def1ed342 # Parent 5a215033b85387a141d162c18920c3152134af50 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. diff -r 5a215033b853 -r 4f8c72adbf43 layer/BoxLayer.cpp --- a/layer/BoxLayer.cpp Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/BoxLayer.cpp Tue Oct 15 11:40:56 2019 +0100 @@ -472,7 +472,7 @@ if (m_verticalScale == AutoAlignScale) { - if (!v->getValueExtents(queryUnits, min, max, log)) { + if (!v->getVisibleExtentsForUnit(queryUnits, min, max, log)) { min = model->getValueMinimum(); max = model->getValueMaximum(); diff -r 5a215033b853 -r 4f8c72adbf43 layer/FlexiNoteLayer.cpp --- a/layer/FlexiNoteLayer.cpp Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/FlexiNoteLayer.cpp Tue Oct 15 11:40:56 2019 +0100 @@ -675,7 +675,7 @@ if (shouldAutoAlign()) { - if (!v->getValueExtents(queryUnits, min, max, log)) { + if (!v->getVisibleExtentsForUnit(queryUnits, min, max, log)) { auto model = ModelById::getAs(m_model); min = model->getValueMinimum(); diff -r 5a215033b853 -r 4f8c72adbf43 layer/Layer.cpp --- a/layer/Layer.cpp Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/Layer.cpp Tue Oct 15 11:40:56 2019 +0100 @@ -630,7 +630,7 @@ return false; } - if (!v->getValueExtents(unit, min, max, logarithmic)) { + if (!v->getVisibleExtentsForUnit(unit, min, max, logarithmic)) { return false; } diff -r 5a215033b853 -r 4f8c72adbf43 layer/Layer.h --- a/layer/Layer.h Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/Layer.h Tue Oct 15 11:40:56 2019 +0100 @@ -457,18 +457,20 @@ * these values if known. * * This function returns the "normal" extents for the layer, not - * necessarily the extents actually in use in the display. + * necessarily the extents actually in use in the display (see + * getDisplayExtents). */ virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const = 0; /** - * Return the minimum and maximum values within the displayed - * range for the y axis, if only a subset of the whole range of - * the model (returned by getValueExtents) is being displayed. - * Return false if the layer is not imposing a particular display - * extent (using the normal layer extents or deferring to whatever - * is in use for the same units elsewhere in the view). + * Return the minimum and maximum values within the visible area + * for the y axis of this layer. + * + * Return false if the layer has no display extents of its + * own. This could be because the layer is "auto-aligning" against + * another layer with the same units elsewhere in the view, or + * because the layer has no concept of a vertical scale at all. */ virtual bool getDisplayExtents(double & /* min */, double & /* max */) const { diff -r 5a215033b853 -r 4f8c72adbf43 layer/LayerGeometryProvider.h --- a/layer/LayerGeometryProvider.h Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/LayerGeometryProvider.h Tue Oct 15 11:40:56 2019 +0100 @@ -142,10 +142,32 @@ double minFreq, double maxFreq, bool logarithmic) const = 0; - virtual int getTextLabelHeight(const Layer *layer, QPainter &) const = 0; + /** + * Return a y-coordinate at which text labels for individual items + * in a layer may be drawn, so as not to overlap with those of + * other layers. The returned coordinate will be near the top of + * the visible widget, but adjusted downward depending on how many + * other visible layers return true from their implementation of + * Layer::needsTextLabelHeight(). + */ + virtual int getTextLabelYCoord(const Layer *layer, QPainter &) const = 0; - virtual bool getValueExtents(QString unit, double &min, double &max, - bool &log) const = 0; + /** + * Return the visible vertical extents for the given unit, if any. + * That is: + * + * - if at least one non-dormant layer uses the same unit and + * returns some values from its getDisplayExtents() method, + * return the extents from the topmost of those + * + * - otherwise, if at least one non-dormant layer uses the same + * unit, return the union of the value extents of all of those + * + * - otherwise return false + */ + virtual bool getVisibleExtentsForUnit(QString unit, + double &min, double &max, + bool &log) const = 0; /** * Return the zoom level, i.e. the number of frames per pixel or diff -r 5a215033b853 -r 4f8c72adbf43 layer/NoteLayer.cpp --- a/layer/NoteLayer.cpp Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/NoteLayer.cpp Tue Oct 15 11:40:56 2019 +0100 @@ -599,7 +599,7 @@ if (shouldAutoAlign()) { - if (!v->getValueExtents(queryUnits, min, max, log)) { + if (!v->getVisibleExtentsForUnit(queryUnits, min, max, log)) { min = model->getValueMinimum(); max = model->getValueMaximum(); diff -r 5a215033b853 -r 4f8c72adbf43 layer/RegionLayer.cpp --- a/layer/RegionLayer.cpp Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/RegionLayer.cpp Tue Oct 15 11:40:56 2019 +0100 @@ -608,7 +608,7 @@ if (m_verticalScale == AutoAlignScale) { - if (!v->getValueExtents(queryUnits, min, max, log)) { + if (!v->getVisibleExtentsForUnit(queryUnits, min, max, log)) { min = model->getValueMinimum(); max = model->getValueMaximum(); @@ -1027,7 +1027,7 @@ - paint.fontMetrics().descent(); } else { labelX = x + 5; - labelY = v->getTextLabelHeight(this, paint); + labelY = v->getTextLabelYCoord(this, paint); if (labelX < nextLabelMinX) { if (lastLabelY < v->getPaintHeight()/2) { labelY = lastLabelY + fontHeight; diff -r 5a215033b853 -r 4f8c72adbf43 layer/TimeInstantLayer.cpp --- a/layer/TimeInstantLayer.cpp Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/TimeInstantLayer.cpp Tue Oct 15 11:40:56 2019 +0100 @@ -378,7 +378,7 @@ } int prevX = -1; - int textY = v->getTextLabelHeight(this, paint); + int textY = v->getTextLabelYCoord(this, paint); for (EventVector::const_iterator i = points.begin(); i != points.end(); ++i) { diff -r 5a215033b853 -r 4f8c72adbf43 layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Tue Oct 15 09:32:24 2019 +0100 +++ b/layer/TimeValueLayer.cpp Tue Oct 15 11:40:56 2019 +0100 @@ -781,7 +781,7 @@ if (shouldAutoAlign()) { - if (!v->getValueExtents(getScaleUnits(), min, max, log)) { + if (!v->getVisibleExtentsForUnit(getScaleUnits(), min, max, log)) { min = model->getValueMinimum(); max = model->getValueMaximum(); } else if (log) { @@ -968,7 +968,7 @@ int textY = 0; if (m_plotStyle == PlotSegmentation) { - textY = v->getTextLabelHeight(this, paint); + textY = v->getTextLabelYCoord(this, paint); } else { int originY = getYForValue(v, 0.f); if (originY > 0 && originY < v->getPaintHeight()) { diff -r 5a215033b853 -r 4f8c72adbf43 view/Pane.h --- a/view/Pane.h Tue Oct 15 09:32:24 2019 +0100 +++ b/view/Pane.h Tue Oct 15 11:40:56 2019 +0100 @@ -106,10 +106,6 @@ void mouseEnteredWidget(); void mouseLeftWidget(); - bool getTopLayerDisplayExtents(double &valueMin, double &valueMax, - double &displayMin, double &displayMax, - QString *unit = 0); - protected slots: void playbackScheduleTimerElapsed(); @@ -154,6 +150,9 @@ bool canTopLayerMoveVertical(); bool setTopLayerDisplayExtents(double displayMin, double displayMax); + bool getTopLayerDisplayExtents(double &valueMin, double &valueMax, + double &displayMin, double &displayMax, + QString *unit = 0); void dragTopLayer(QMouseEvent *e); void dragExtendSelection(QMouseEvent *e); diff -r 5a215033b853 -r 4f8c72adbf43 view/View.cpp --- 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 sortedLayers; diff -r 5a215033b853 -r 4f8c72adbf43 view/View.h --- a/view/View.h Tue Oct 15 09:32:24 2019 +0100 +++ b/view/View.h Tue Oct 15 11:40:56 2019 +0100 @@ -350,11 +350,25 @@ */ virtual bool renderPartToSvgFile(QString filename, sv_frame_t f0, sv_frame_t f1); + + /** + * Return the visible vertical extents for the given unit, if any. + * Overridden from LayerGeometryProvider (see docs there). + */ + bool getVisibleExtentsForUnit(QString unit, double &min, double &max, + bool &log) const override; + + /** + * Return some visible vertical extents and unit. That is, if at + * least one non-dormant layer has a non-empty unit and returns + * some values from its getDisplayExtents() method, return the + * extents and unit from the topmost of those. Otherwise return + * false. + */ + bool getVisibleExtentsForAnyUnit(double &min, double &max, + bool &logarithmic, QString &unit) const; - int getTextLabelHeight(const Layer *layer, QPainter &) const override; - - bool getValueExtents(QString unit, double &min, double &max, - bool &log) const override; + int getTextLabelYCoord(const Layer *layer, QPainter &) const override; void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const override; diff -r 5a215033b853 -r 4f8c72adbf43 view/ViewProxy.h --- a/view/ViewProxy.h Tue Oct 15 09:32:24 2019 +0100 +++ b/view/ViewProxy.h Tue Oct 15 11:40:56 2019 +0100 @@ -95,27 +95,23 @@ return m_view->getFrequencyForY (y / m_scaleFactor, minFreq, maxFreq, logarithmic); } - int getTextLabelHeight(const Layer *layer, QPainter &paint) const override { - return m_scaleFactor * m_view->getTextLabelHeight(layer, paint); + int getTextLabelYCoord(const Layer *layer, QPainter &paint) const override { + return m_scaleFactor * m_view->getTextLabelYCoord(layer, paint); } - bool getValueExtents(QString unit, double &min, double &max, - bool &log) const override { - return m_view->getValueExtents(unit, min, max, log); + bool getVisibleExtentsForUnit(QString unit, double &min, double &max, + bool &log) const override { + return m_view->getVisibleExtentsForUnit(unit, min, max, log); } ZoomLevel getZoomLevel() const override { ZoomLevel z = m_view->getZoomLevel(); - //!!! -// cerr << "getZoomLevel: from " << z << " to "; if (z.zone == ZoomLevel::FramesPerPixel) { z.level /= m_scaleFactor; if (z.level < 1) { z.level = 1; } } else { - //!!!??? z.level *= m_scaleFactor; } -// cerr << z << endl; return z; } QRect getPaintRect() const override {