! Changes the data range such that all color maps associated with this color scale are fully mapped to the gradient in the data dimension. \see setDataRange */
| 19585 | \see setDataRange |
| 19586 | */ |
| 19587 | void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) |
| 19588 | { |
| 19589 | QList<QCPColorMap*> maps = colorMaps(); |
| 19590 | QCPRange newRange; |
| 19591 | bool haveRange = false; |
| 19592 | QCP::SignDomain sign = QCP::sdBoth; |
| 19593 | if (mDataScaleType == QCPAxis::stLogarithmic) |
| 19594 | sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); |
| 19595 | for (int i=0; i<maps.size(); ++i) |
| 19596 | { |
| 19597 | if (!maps.at(i)->realVisibility() && onlyVisibleMaps) |
| 19598 | continue; |
| 19599 | QCPRange mapRange; |
| 19600 | if (maps.at(i)->colorScale() == this) |
| 19601 | { |
| 19602 | bool currentFoundRange = true; |
| 19603 | mapRange = maps.at(i)->data()->dataBounds(); |
| 19604 | if (sign == QCP::sdPositive) |
| 19605 | { |
| 19606 | if (mapRange.lower <= 0 && mapRange.upper > 0) |
| 19607 | mapRange.lower = mapRange.upper*1e-3; |
| 19608 | else if (mapRange.lower <= 0 && mapRange.upper <= 0) |
| 19609 | currentFoundRange = false; |
| 19610 | } else if (sign == QCP::sdNegative) |
| 19611 | { |
| 19612 | if (mapRange.upper >= 0 && mapRange.lower < 0) |
| 19613 | mapRange.upper = mapRange.lower*1e-3; |
| 19614 | else if (mapRange.upper >= 0 && mapRange.lower >= 0) |
| 19615 | currentFoundRange = false; |
| 19616 | } |
| 19617 | if (currentFoundRange) |
| 19618 | { |
| 19619 | if (!haveRange) |
| 19620 | newRange = mapRange; |
| 19621 | else |
| 19622 | newRange.expand(mapRange); |
| 19623 | haveRange = true; |
| 19624 | } |
| 19625 | } |
| 19626 | } |
| 19627 | if (haveRange) |
| 19628 | { |
| 19629 | if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data |
| 19630 | { |
| 19631 | double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason |
| 19632 | if (mDataScaleType == QCPAxis::stLinear) |
| 19633 | { |
| 19634 | newRange.lower = center-mDataRange.size()/2.0; |
| 19635 | newRange.upper = center+mDataRange.size()/2.0; |
| 19636 | } else // mScaleType == stLogarithmic |
| 19637 | { |
| 19638 | newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); |
| 19639 | newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); |
| 19640 | } |
| 19641 | } |
| 19642 | setDataRange(newRange); |
| 19643 | } |
| 19644 | } |
nothing calls this directly
no test coverage detected