Changeset View
Standalone View
src/lib/util/kformatprivate.cpp
Show First 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 101 | if (prefix == KFormat::UnitPrefix::Unity && | |||
---|---|---|---|---|---|
103 | precision = 0; | 103 | precision = 0; | ||
104 | } | 104 | } | ||
105 | 105 | | |||
106 | struct PrefixMapEntry | 106 | struct PrefixMapEntry | ||
107 | { | 107 | { | ||
108 | KFormat::UnitPrefix prefix; | 108 | KFormat::UnitPrefix prefix; | ||
109 | double decimalFactor; | 109 | double decimalFactor; | ||
110 | double binaryFactor; | 110 | double binaryFactor; | ||
111 | QChar prefixChar; | 111 | QString prefixCharSI; | ||
112 | QString prefixCharIEC; | ||||
112 | }; | 113 | }; | ||
113 | 114 | | |||
114 | const PrefixMapEntry map[] = { | 115 | const PrefixMapEntry map[] = { | ||
115 | { KFormat::UnitPrefix::Yocto, 1e-24, bpow(-80), u'y' }, | 116 | { KFormat::UnitPrefix::Yocto, 1e-24, bpow(-80), tr("y", "SI prefix for 10^⁻24"), QString() }, | ||
116 | { KFormat::UnitPrefix::Zepto, 1e-21, bpow(-70), u'z' }, | 117 | { KFormat::UnitPrefix::Zepto, 1e-21, bpow(-70), tr("z", "SI prefix for 10^⁻21"), QString() }, | ||
117 | { KFormat::UnitPrefix::Atto, 1e-18, bpow(-60), u'a' }, | 118 | { KFormat::UnitPrefix::Atto, 1e-18, bpow(-60), tr("a", "SI prefix for 10^⁻18"), QString() }, | ||
118 | { KFormat::UnitPrefix::Femto, 1e-15, bpow(-50), u'f' }, | 119 | { KFormat::UnitPrefix::Femto, 1e-15, bpow(-50), tr("f", "SI prefix for 10^⁻15"), QString() }, | ||
119 | { KFormat::UnitPrefix::Pico, 1e-12, bpow(-40), u'p' }, | 120 | { KFormat::UnitPrefix::Pico, 1e-12, bpow(-40), tr("p", "SI prefix for 10^⁻12"), QString() }, | ||
120 | { KFormat::UnitPrefix::Nano, 1e-9, bpow(-30), u'n' }, | 121 | { KFormat::UnitPrefix::Nano, 1e-9, bpow(-30), tr("n", "SI prefix for 10^⁻9") , QString() }, | ||
121 | // Thanks to broken MSVC, we can not use u'µ', but have to use the unicode codepoint | 122 | { KFormat::UnitPrefix::Micro, 1e-6, bpow(-20), tr("µ", "SI prefix for 10^⁻6") , QString() }, | ||
122 | { KFormat::UnitPrefix::Micro, 1e-6, bpow(-20), QChar(0xB5) }, | 123 | { KFormat::UnitPrefix::Milli, 1e-3, bpow(-10), tr("m", "SI prefix for 10^⁻3") , QString() }, | ||
123 | { KFormat::UnitPrefix::Milli, 1e-3, bpow(-10), u'm' }, | 124 | { KFormat::UnitPrefix::Unity, 1.0, 1.0 , QString() , QString() }, | ||
safaalfulaij: Space before `}`? | |||||
124 | { KFormat::UnitPrefix::Unity, 1.0, 1.0, u'\0' }, | 125 | { KFormat::UnitPrefix::Kilo, 1e3, bpow(10) , tr("k", "SI prefix for 10^3") , tr("Ki", "IEC binary prefix for 2^10") }, | ||
safaalfulaij: Space before `}`? | |||||
125 | { KFormat::UnitPrefix::Kilo, 1e3, bpow(10), u'k' }, | 126 | { KFormat::UnitPrefix::Mega, 1e6, bpow(20) , tr("M", "SI prefix for 10^6") , tr("Mi", "IEC binary prefix for 2^20") }, | ||
126 | { KFormat::UnitPrefix::Mega, 1e6, bpow(20), u'M' }, | 127 | { KFormat::UnitPrefix::Giga, 1e9, bpow(30) , tr("G", "SI prefix for 10^9") , tr("Gi", "IEC binary prefix for 2^30") }, | ||
safaalfulaij: Extra space after `}`? | |||||
127 | { KFormat::UnitPrefix::Giga, 1e9, bpow(30), u'G' }, | 128 | { KFormat::UnitPrefix::Tera, 1e12, bpow(40) , tr("T", "SI prefix for 10^12") , tr("Ti", "IEC binary prefix for 2^40") }, | ||
128 | { KFormat::UnitPrefix::Tera, 1e12, bpow(40), u'T' }, | 129 | { KFormat::UnitPrefix::Peta, 1e15, bpow(50) , tr("P", "SI prefix for 10^15") , tr("Pi", "IEC binary prefix for 2^50") }, | ||
129 | { KFormat::UnitPrefix::Peta, 1e15, bpow(50), u'P' }, | 130 | { KFormat::UnitPrefix::Exa, 1e18, bpow(60) , tr("E", "SI prefix for 10^18") , tr("Ei", "IEC binary prefix for 2^60") }, | ||
130 | { KFormat::UnitPrefix::Exa, 1e18, bpow(60), u'E' }, | 131 | { KFormat::UnitPrefix::Zetta, 1e21, bpow(70) , tr("Z", "SI prefix for 10^21") , tr("Zi", "IEC binary prefix for 2^70") }, | ||
131 | { KFormat::UnitPrefix::Zetta, 1e21, bpow(70), u'Z' }, | 132 | { KFormat::UnitPrefix::Yotta, 1e24, bpow(80) , tr("Y", "SI prefix for 10^24") , tr("Yi", "IEC binary prefix for 2^80") }, | ||
Line 160: } else { value /= entry->binaryFactor; prefixString = QString(entry->prefixChar).toUpper(); How this is “Metric”? safaalfulaij: Line 160:
```
} else {
value /= entry->binaryFactor;
prefixString = QString… | |||||
The prefixes for the IEC binary prefixes (for e.g. 2^10) are made up by the SI prefixes plus an "i", see below. But it actually is an SI prefix, to be more precise. astippich: The prefixes for the IEC binary prefixes (for e.g. 2^10) are made up by the SI prefixes plus an… | |||||
132 | { KFormat::UnitPrefix::Yotta, 1e24, bpow(80), u'Y' }, | | |||
133 | }; | 133 | }; | ||
134 | 134 | | |||
135 | auto entry = std::find_if(std::begin(map), std::end(map), | 135 | auto entry = std::find_if(std::begin(map), std::end(map), | ||
136 | [prefix](const PrefixMapEntry& e) { return e.prefix == prefix; }); | 136 | [prefix](const PrefixMapEntry& e) { return e.prefix == prefix; }); | ||
137 | 137 | | |||
138 | switch (unit) { | 138 | switch (unit) { | ||
139 | case KFormat::Unit::Bit: | 139 | case KFormat::Unit::Bit: | ||
140 | unitString = QStringLiteral("bit"); | 140 | unitString = tr("bit", "Symbol of binary digit"); | ||
141 | break; | 141 | break; | ||
142 | case KFormat::Unit::Byte: | 142 | case KFormat::Unit::Byte: | ||
143 | unitString = QStringLiteral("B"); | 143 | unitString = tr("B", "Symbol of byte"); | ||
144 | break; | 144 | break; | ||
145 | case KFormat::Unit::Meter: | 145 | case KFormat::Unit::Meter: | ||
146 | unitString = QStringLiteral("m"); | 146 | unitString = tr("m", "Symbol of meter"); | ||
147 | break; | 147 | break; | ||
148 | case KFormat::Unit::Hertz: | 148 | case KFormat::Unit::Hertz: | ||
149 | unitString = QStringLiteral("Hz"); | 149 | unitString = tr("Hz", "Symbol of hertz"); | ||
150 | break; | 150 | break; | ||
151 | case KFormat::Unit::Other: | 151 | case KFormat::Unit::Other: | ||
152 | break; | 152 | break; | ||
153 | } | 153 | } | ||
154 | 154 | | |||
155 | if (prefix == KFormat::UnitPrefix::Unity) { | 155 | if (prefix == KFormat::UnitPrefix::Unity) { | ||
156 | QString numString = m_locale.toString(value, 'f', precision); | 156 | QString numString = m_locale.toString(value, 'f', precision); | ||
157 | //: value without prefix, format "<val> <unit>" | 157 | //: value without prefix, format "<val> <unit>" | ||
158 | return tr("%1 %2", "no Prefix").arg(numString, unitString); | 158 | return tr("%1 %2", "no Prefix").arg(numString, unitString); | ||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | QString prefixString; | 161 | QString prefixString; | ||
162 | if (dialect == KFormat::MetricBinaryDialect) { | 162 | if (dialect == KFormat::MetricBinaryDialect) { | ||
163 | value /= entry->decimalFactor; | 163 | value /= entry->decimalFactor; | ||
164 | prefixString = entry->prefixChar; | 164 | prefixString = entry->prefixCharSI; | ||
165 | } else { | 165 | } else { | ||
166 | value /= entry->binaryFactor; | 166 | value /= entry->binaryFactor; | ||
167 | prefixString = QString(entry->prefixChar).toUpper(); | | |||
168 | if (dialect == KFormat::IECBinaryDialect) { | 167 | if (dialect == KFormat::IECBinaryDialect) { | ||
169 | prefixString += u'i'; | 168 | prefixString = entry->prefixCharIEC; | ||
169 | } else { | ||||
170 | prefixString = entry->prefixCharSI.toUpper(); | ||||
safaalfulaij: And what about this? //It should never be a puzzle string by the way.// | |||||
Overlooked that one. Must this then be something like tr("1%2%).arg(... ...)? astippich: Overlooked that one. Must this then be something like tr("1%2%).arg(... ...)? | |||||
Well, I searched other languages and no one seems to do as Arabic does. We do not abbreviate in this case and just write the whole "Mebi.Byte" ("Byte" is always written, "M.Byte" > "MB"). safaalfulaij: Well, I searched other languages and no one seems to do as Arabic does. We do not abbreviate in… | |||||
I uploaded a new version, but with what you describe, this will not suffice to fulfill your needs for IEC binary prefixes (please confirm). For the record, I haven't seen it anywhere in English that dots are put in between. I'm away for the next week, so will continue to work on the patch afterwards. astippich: I uploaded a new version, but with what you describe, this will not suffice to fulfill your… | |||||
170 | } | 171 | } | ||
171 | } | 172 | } | ||
172 | 173 | | |||
173 | QString numString = m_locale.toString(value, 'f', precision); | 174 | QString numString = m_locale.toString(value, 'f', precision); | ||
174 | 175 | | |||
175 | //: value with prefix, format "<val> <prefix><unit>" | 176 | //: value with prefix, format "<val> <prefix><unit>" | ||
176 | return tr("%1 %2%3", "MetricBinaryDialect").arg(numString, prefixString, unitString); | 177 | return tr("%1 %2%3", "MetricBinaryDialect").arg(numString, prefixString, unitString); | ||
177 | } | 178 | } | ||
▲ Show 20 Lines • Show All 396 Lines • Show Last 20 Lines |
Space before }?