31struct formatter : std::numpunct<wchar_t>
33 formatter( QChar thousands,
bool showThousands, QChar decimal )
34 : mThousands( thousands.unicode() )
35 , mDecimal( decimal.unicode() )
36 , mShowThousands( showThousands )
38 wchar_t do_decimal_point()
const override {
return mDecimal; }
39 wchar_t do_thousands_sep()
const override {
return mThousands; }
40 std::string do_grouping()
const override {
return mShowThousands ?
"\3" :
"\0"; }
44 bool mShowThousands =
true;
54 return QStringLiteral(
"fraction" );
59 return QObject::tr(
"Fraction" );
69 std::basic_stringstream<wchar_t> os;
70 os.imbue( std::locale( os.getloc(),
new formatter( mThousandsSeparator.isNull() ? context.
thousandsSeparator() : mThousandsSeparator,
71 mShowThousandsSeparator,
74 unsigned long long num;
75 unsigned long long den;
80 const double fixed = std::floor( std::fabs( value ) );
84 if ( mUseDedicatedUnicode && num == 1 && den == 2 )
86 else if ( mUseDedicatedUnicode && num == 1 && den == 3 )
87 res = QChar( 0x2153 );
88 else if ( mUseDedicatedUnicode && num == 2 && den == 3 )
89 res = QChar( 0x2154 );
90 else if ( mUseDedicatedUnicode && num == 1 && den == 4 )
92 else if ( mUseDedicatedUnicode && num == 3 && den == 4 )
94 else if ( mUseDedicatedUnicode && num == 1 && den == 5 )
95 res = QChar( 0x2155 );
96 else if ( mUseDedicatedUnicode && num == 2 && den == 5 )
97 res = QChar( 0x2156 );
98 else if ( mUseDedicatedUnicode && num == 3 && den == 5 )
99 res = QChar( 0x2157 );
100 else if ( mUseDedicatedUnicode && num == 4 && den == 5 )
101 res = QChar( 0x2158 );
102 else if ( mUseDedicatedUnicode && num == 1 && den == 6 )
103 res = QChar( 0x2159 );
104 else if ( mUseDedicatedUnicode && num == 5 && den == 6 )
105 res = QChar( 0x215A );
106 else if ( mUseDedicatedUnicode && num == 1 && den == 7 )
107 res = QChar( 0x2150 );
108 else if ( mUseDedicatedUnicode && num == 1 && den == 8 )
109 res = QChar( 0x215B );
110 else if ( mUseDedicatedUnicode && num == 3 && den == 8 )
111 res = QChar( 0x215C );
112 else if ( mUseDedicatedUnicode && num == 5 && den == 8 )
113 res = QChar( 0x215D );
114 else if ( mUseDedicatedUnicode && num == 7 && den == 8 )
115 res = QChar( 0x215E );
116 else if ( mUseDedicatedUnicode && num == 1 && den == 9 )
117 res = QChar( 0x2151 );
118 else if ( mUseDedicatedUnicode && num == 1 && den == 10 )
119 res = QChar( 0x2152 );
120 else if ( mUseUnicodeSuperSubscript )
121 res = num == 0 ? QString() : QStringLiteral(
"%1%2%3" ).arg(
toUnicodeSuperscript( QString::number( num ) ),
125 res = num == 0 ? QString() : QStringLiteral(
"%2/%3" ).arg( num ).arg( den );
128 os << std::fixed << std::setprecision( 0 );
130 res.prepend( QString::fromStdWString( os.str() ) +
' ' );
134 res = QString::number( 0 );
141 os << std::fixed << std::setprecision( 10 );
143 res = QString::fromStdWString( os.str() );
146 if ( value > 0 && mShowPlusSign )
161 auto res = std::make_unique< QgsFractionNumericFormat >();
163 return res.release();
169 res.insert( QStringLiteral(
"show_thousand_separator" ), mShowThousandsSeparator );
170 res.insert( QStringLiteral(
"show_plus" ), mShowPlusSign );
171 res.insert( QStringLiteral(
"thousand_separator" ), mThousandsSeparator.isNull() ? QVariant() : QVariant::fromValue( mThousandsSeparator ) );
172 res.insert( QStringLiteral(
"use_dedicated_unicode" ), mUseDedicatedUnicode );
173 res.insert( QStringLiteral(
"use_unicode_supersubscript" ), mUseUnicodeSuperSubscript );
184 return mUseDedicatedUnicode;
189 mUseDedicatedUnicode = enabled;
194 return mUseUnicodeSuperSubscript;
199 mUseUnicodeSuperSubscript = enabled;
204 mShowThousandsSeparator =
configuration.value( QStringLiteral(
"show_thousand_separator" ),
true ).toBool();
205 mShowPlusSign =
configuration.value( QStringLiteral(
"show_plus" ),
false ).toBool();
206 mThousandsSeparator =
configuration.value( QStringLiteral(
"thousand_separator" ), QChar() ).toChar();
207 mUseDedicatedUnicode =
configuration.value( QStringLiteral(
"use_dedicated_unicode" ),
false ).toBool();
208 mUseUnicodeSuperSubscript =
configuration.value( QStringLiteral(
"use_unicode_supersubscript" ),
true ).toBool();
213 return mShowThousandsSeparator;
223 return mShowPlusSign;
233 return mThousandsSeparator;
238 mThousandsSeparator = character;
244 for (
int i = 0; i < input.size(); ++i )
246 const QChar
c = input.at( i );
248 res[i] = QChar( 0x2070 );
250 res[i] = QChar( 0x00B9 );
252 res[i] = QChar( 0x00B2 );
254 res[i] = QChar( 0x00B3 );
256 res[i] = QChar( 0x2074 );
258 res[i] = QChar( 0x2075 );
260 res[i] = QChar( 0x2076 );
262 res[i] = QChar( 0x2077 );
264 res[i] = QChar( 0x2078 );
266 res[i] = QChar( 0x2079 );
274 for (
int i = 0; i < input.size(); ++i )
276 const QChar
c = input.at( i );
278 res[i] = QChar( 0x2080 );
280 res[i] = QChar( 0x2081 );
282 res[i] = QChar( 0x2082 );
284 res[i] = QChar( 0x2083 );
286 res[i] = QChar( 0x2084 );
288 res[i] = QChar( 0x2085 );
290 res[i] = QChar( 0x2086 );
292 res[i] = QChar( 0x2087 );
294 res[i] = QChar( 0x2088 );
296 res[i] = QChar( 0x2089 );
A context for numeric formats.
QChar negativeSign() const
Returns the negative sign character.
QChar thousandsSeparator() const
Returns the thousands separator character.
QChar decimalSeparator() const
Returns the decimal separator character.
QChar positiveSign() const
Returns the positive sign character.
A container for the context for various read/write operations on objects.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c