* @brief Draws the frequency axis (X) -- grid, tick marks, labels. */
| 938 | * @brief Draws the frequency axis (X) -- grid, tick marks, labels. |
| 939 | */ |
| 940 | void Widgets::Waterfall::drawXAxis(QPainter* painter, const QRectF& plotRect) const |
| 941 | { |
| 942 | if (m_samplingRate <= 0) |
| 943 | return; |
| 944 | |
| 945 | const double nyquist = m_samplingRate * 0.5; |
| 946 | const double srcW = nyquist / m_xZoom; |
| 947 | const double maxPan = qMax(0.0, (nyquist - srcW) * 0.5); |
| 948 | const double center = nyquist * 0.5 + qBound(-maxPan, m_xPan * nyquist, maxPan); |
| 949 | const double xMinHz = center - srcW * 0.5; |
| 950 | const double xMaxHz = center + srcW * 0.5; |
| 951 | |
| 952 | const AxisTicks ticks = computeFreqTicks(srcW, kAxisTickCount); |
| 953 | |
| 954 | const QFontMetrics fm(painter->font()); |
| 955 | const double tickTopY = plotRect.bottom(); |
| 956 | const double tickBotY = plotRect.bottom() + kAxisTickPx; |
| 957 | const double labelY = tickBotY + kAxisLabelPad; |
| 958 | |
| 959 | const double step = ticks.step; |
| 960 | const double invStep = 1.0 / step; |
| 961 | const double first = std::ceil(xMinHz * invStep - 1e-9) * step; |
| 962 | const double xRange = xMaxHz - xMinHz; |
| 963 | const double invXRange = xRange > 0.0 ? 1.0 / xRange : 0.0; |
| 964 | |
| 965 | for (double v = first; v <= xMaxHz + 1e-6; v += step) { |
| 966 | const double t = (v - xMinHz) * invXRange; |
| 967 | if (t < 0.0 || t > 1.0) |
| 968 | continue; |
| 969 | |
| 970 | const double x = plotRect.left() + t * plotRect.width(); |
| 971 | |
| 972 | painter->setPen(QPen(m_gridColor, 1, Qt::DotLine)); |
| 973 | painter->drawLine(QPointF(x, plotRect.top()), QPointF(x, plotRect.bottom())); |
| 974 | |
| 975 | painter->setPen(QPen(m_borderColor, 1)); |
| 976 | painter->drawLine(QPointF(x, tickTopY), QPointF(x, tickBotY)); |
| 977 | |
| 978 | const QString label = formatFreqTick(v); |
| 979 | const int labelWidth = fm.horizontalAdvance(label); |
| 980 | painter->setPen(m_textColor); |
| 981 | painter->drawText(QPointF(x - labelWidth * 0.5, labelY + fm.ascent()), label); |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | /** |
| 986 | * @brief Draws the Y axis (time or Campbell-mode dataset value). |