comparison 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
comparison
equal deleted inserted replaced
1538:0ca4ca37809e 1539:bfacecf7ea7e
195 bool 195 bool
196 View::getVisibleExtentsForUnit(QString unit, 196 View::getVisibleExtentsForUnit(QString unit,
197 double &min, double &max, 197 double &min, double &max,
198 bool &log) const 198 bool &log) const
199 { 199 {
200 bool have = false; 200 Layer *layer = getScaleProvidingLayerForUnit(unit);
201 201 if (!layer) {
202 // Iterate in reverse order, so as to return display extents of 202 return false;
203 // topmost layer that fits the bill 203 }
204
205 //!!! clumsy
206
207 QString layerUnit;
208 double layerMin, layerMax;
209
210 if (layer->getValueExtents(layerMin, layerMax, log, layerUnit)) {
211 if (layer->getDisplayExtents(min, max)) {
212 return true;
213 } else {
214 min = layerMin;
215 max = layerMax;
216 return true;
217 }
218 } else {
219 return false;
220 }
221 }
222
223 Layer *
224 View::getScaleProvidingLayerForUnit(QString unit) const
225 {
226 // Iterate in reverse order, so as to use topmost layer that fits
227 // the bill
204 228
205 for (auto i = m_layerStack.rbegin(); i != m_layerStack.rend(); ++i) { 229 for (auto i = m_layerStack.rbegin(); i != m_layerStack.rend(); ++i) {
206 230
207 Layer *layer = *i; 231 Layer *layer = *i;
208 232
219 } 243 }
220 if (layerUnit.toLower() != unit.toLower()) { 244 if (layerUnit.toLower() != unit.toLower()) {
221 continue; 245 continue;
222 } 246 }
223 247
224 double displayMin = 0.0, displayMax = 0.0; 248 return layer;
225 249 }
226 if (layer->getDisplayExtents(displayMin, displayMax)) { 250
227 251 return nullptr;
228 min = displayMin;
229 max = displayMax;
230 log = layerLog;
231 have = true;
232 break;
233
234 } else {
235
236 if (!have || layerMin < min) min = layerMin;
237 if (!have || layerMax > max) max = layerMax;
238 if (!have && layerLog) log = true;
239 have = true;
240 }
241 }
242
243 return have;
244 } 252 }
245 253
246 bool 254 bool
247 View::getVisibleExtentsForAnyUnit(double &min, double &max, 255 View::getVisibleExtentsForAnyUnit(double &min, double &max,
248 bool &log, QString &unit) const 256 bool &log, QString &unit) const