| 114 | } |
| 115 | |
| 116 | QString Ruler::format_freq(double period, unsigned int precision) |
| 117 | { |
| 118 | if (period <= 0) { |
| 119 | return View::Unknown_Str; |
| 120 | } else { |
| 121 | const int order = ceil(log10f(period)); |
| 122 | assert(order >= FirstSIPrefixPower); |
| 123 | const int prefix = ceil((order - FirstSIPrefixPower) / 3.0f); |
| 124 | const double multiplier = pow(10.0, max(-prefix * 3.0 - FirstSIPrefixPower, 0.0)); |
| 125 | |
| 126 | /* |
| 127 | QString s; |
| 128 | QTextStream ts(&s); |
| 129 | ts.setRealNumberPrecision(precision); |
| 130 | ts << fixed << 1 / (period * multiplier) << |
| 131 | FreqPrefixes[prefix] << "Hz"; |
| 132 | return s; |
| 133 | */ |
| 134 | |
| 135 | char buffer[50] = {0}; |
| 136 | char format[15] = {0}; |
| 137 | QString units = FreqPrefixes[prefix] + "Hz"; |
| 138 | sprintf(format, "%%.%df", (int)precision); |
| 139 | sprintf(buffer, format, 1 / (period * multiplier)); |
| 140 | strcat(buffer, units.toUtf8().data()); |
| 141 | return QString(buffer); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | QString Ruler::format_time(double t, int prefix, |
| 146 | unsigned int precision) |