28struct formatter : std::numpunct<wchar_t>
30 formatter( QChar thousands,
bool showThousands, QChar decimal )
31 : mThousands( thousands.unicode() )
32 , mDecimal( decimal.unicode() )
33 , mShowThousands( showThousands )
35 wchar_t do_decimal_point()
const override {
return mDecimal; }
36 wchar_t do_thousands_sep()
const override {
return mThousands; }
37 std::string do_grouping()
const override {
return mShowThousands ?
"\3" :
"\0"; }
41 bool mShowThousands =
true;
51 return QStringLiteral(
"fraction" );
56 return QObject::tr(
"Fraction" );
66 std::basic_stringstream<wchar_t> os;
67 os.imbue( std::locale( os.getloc(),
new formatter( mThousandsSeparator.isNull() ? context.
thousandsSeparator() : mThousandsSeparator,
68 mShowThousandsSeparator,
71 unsigned long long num;
72 unsigned long long den;
77 const double fixed = std::floor( std::fabs( value ) );
81 if ( mUseDedicatedUnicode && num == 1 && den == 2 )
83 else if ( mUseDedicatedUnicode && num == 1 && den == 3 )
84 res = QChar( 0x2153 );
85 else if ( mUseDedicatedUnicode && num == 2 && den == 3 )
86 res = QChar( 0x2154 );
87 else if ( mUseDedicatedUnicode && num == 1 && den == 4 )
89 else if ( mUseDedicatedUnicode && num == 3 && den == 4 )
91 else if ( mUseDedicatedUnicode && num == 1 && den == 5 )
92 res = QChar( 0x2155 );
93 else if ( mUseDedicatedUnicode && num == 2 && den == 5 )
94 res = QChar( 0x2156 );
95 else if ( mUseDedicatedUnicode && num == 3 && den == 5 )
96 res = QChar( 0x2157 );
97 else if ( mUseDedicatedUnicode && num == 4 && den == 5 )
98 res = QChar( 0x2158 );
99 else if ( mUseDedicatedUnicode && num == 1 && den == 6 )
100 res = QChar( 0x2159 );
101 else if ( mUseDedicatedUnicode && num == 5 && den == 6 )
102 res = QChar( 0x215A );
103 else if ( mUseDedicatedUnicode && num == 1 && den == 7 )
104 res = QChar( 0x2150 );
105 else if ( mUseDedicatedUnicode && num == 1 && den == 8 )
106 res = QChar( 0x215B );
107 else if ( mUseDedicatedUnicode && num == 3 && den == 8 )
108 res = QChar( 0x215C );
109 else if ( mUseDedicatedUnicode && num == 5 && den == 8 )
110 res = QChar( 0x215D );
111 else if ( mUseDedicatedUnicode && num == 7 && den == 8 )
112 res = QChar( 0x215E );
113 else if ( mUseDedicatedUnicode && num == 1 && den == 9 )
114 res = QChar( 0x2151 );
115 else if ( mUseDedicatedUnicode && num == 1 && den == 10 )
116 res = QChar( 0x2152 );
117 else if ( mUseUnicodeSuperSubscript )
118 res = num == 0 ? QString() : QStringLiteral(
"%1%2%3" ).arg(
toUnicodeSuperscript( QString::number( num ) ),
122 res = num == 0 ? QString() : QStringLiteral(
"%2/%3" ).arg( num ).arg( den );
125 os << std::fixed << std::setprecision( 0 );
127 res.prepend( QString::fromStdWString( os.str() ) +
' ' );
131 res = QString::number( 0 );
138 os << std::fixed << std::setprecision( 10 );
140 res = QString::fromStdWString( os.str() );
143 if ( value > 0 && mShowPlusSign )
158 std::unique_ptr< QgsFractionNumericFormat > res = std::make_unique< QgsFractionNumericFormat >();
160 return res.release();
166 res.insert( QStringLiteral(
"show_thousand_separator" ), mShowThousandsSeparator );
167 res.insert( QStringLiteral(
"show_plus" ), mShowPlusSign );
168 res.insert( QStringLiteral(
"thousand_separator" ), mThousandsSeparator.isNull() ? QVariant() : QVariant::fromValue( mThousandsSeparator ) );
169 res.insert( QStringLiteral(
"use_dedicated_unicode" ), mUseDedicatedUnicode );
170 res.insert( QStringLiteral(
"use_unicode_supersubscript" ), mUseUnicodeSuperSubscript );
181 return mUseDedicatedUnicode;
186 mUseDedicatedUnicode = enabled;
191 return mUseUnicodeSuperSubscript;
196 mUseUnicodeSuperSubscript = enabled;
201 mShowThousandsSeparator =
configuration.value( QStringLiteral(
"show_thousand_separator" ),
true ).toBool();
202 mShowPlusSign =
configuration.value( QStringLiteral(
"show_plus" ),
false ).toBool();
203 mThousandsSeparator =
configuration.value( QStringLiteral(
"thousand_separator" ), QChar() ).toChar();
204 mUseDedicatedUnicode =
configuration.value( QStringLiteral(
"use_dedicated_unicode" ),
false ).toBool();
205 mUseUnicodeSuperSubscript =
configuration.value( QStringLiteral(
"use_unicode_supersubscript" ),
true ).toBool();
210 return mShowThousandsSeparator;
220 return mShowPlusSign;
230 return mThousandsSeparator;
235 mThousandsSeparator = character;
241 for (
int i = 0; i < input.size(); ++i )
243 const QChar
c = input.at( i );
245 res[i] = QChar( 0x2070 );
247 res[i] = QChar( 0x00B9 );
249 res[i] = QChar( 0x00B2 );
251 res[i] = QChar( 0x00B3 );
253 res[i] = QChar( 0x2074 );
255 res[i] = QChar( 0x2075 );
257 res[i] = QChar( 0x2076 );
259 res[i] = QChar( 0x2077 );
261 res[i] = QChar( 0x2078 );
263 res[i] = QChar( 0x2079 );
271 for (
int i = 0; i < input.size(); ++i )
273 const QChar
c = input.at( i );
275 res[i] = QChar( 0x2080 );
277 res[i] = QChar( 0x2081 );
279 res[i] = QChar( 0x2082 );
281 res[i] = QChar( 0x2083 );
283 res[i] = QChar( 0x2084 );
285 res[i] = QChar( 0x2085 );
287 res[i] = QChar( 0x2086 );
289 res[i] = QChar( 0x2087 );
291 res[i] = QChar( 0x2088 );
293 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.
The class is used as a container of context for various read/write operations on other 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