29using namespace Qt::StringLiterals;
33struct formatter : std::numpunct<wchar_t>
35 formatter( QChar thousands,
bool showThousands, QChar decimal )
36 : mThousands( thousands.unicode() )
37 , mDecimal( decimal.unicode() )
38 , mShowThousands( showThousands )
40 wchar_t do_decimal_point()
const override {
return mDecimal; }
41 wchar_t do_thousands_sep()
const override {
return mThousands; }
42 std::string do_grouping()
const override {
return mShowThousands ?
"\3" :
"\0"; }
46 bool mShowThousands =
true;
61 return QObject::tr(
"Fraction" );
71 std::basic_stringstream<wchar_t> os;
72 os.imbue( std::locale( os.getloc(),
new formatter( mThousandsSeparator.isNull() ? context.
thousandsSeparator() : mThousandsSeparator,
73 mShowThousandsSeparator,
76 unsigned long long num;
77 unsigned long long den;
82 const double fixed = std::floor( std::fabs( value ) );
86 if ( mUseDedicatedUnicode && num == 1 && den == 2 )
88 else if ( mUseDedicatedUnicode && num == 1 && den == 3 )
89 res = QChar( 0x2153 );
90 else if ( mUseDedicatedUnicode && num == 2 && den == 3 )
91 res = QChar( 0x2154 );
92 else if ( mUseDedicatedUnicode && num == 1 && den == 4 )
94 else if ( mUseDedicatedUnicode && num == 3 && den == 4 )
96 else if ( mUseDedicatedUnicode && num == 1 && den == 5 )
97 res = QChar( 0x2155 );
98 else if ( mUseDedicatedUnicode && num == 2 && den == 5 )
99 res = QChar( 0x2156 );
100 else if ( mUseDedicatedUnicode && num == 3 && den == 5 )
101 res = QChar( 0x2157 );
102 else if ( mUseDedicatedUnicode && num == 4 && den == 5 )
103 res = QChar( 0x2158 );
104 else if ( mUseDedicatedUnicode && num == 1 && den == 6 )
105 res = QChar( 0x2159 );
106 else if ( mUseDedicatedUnicode && num == 5 && den == 6 )
107 res = QChar( 0x215A );
108 else if ( mUseDedicatedUnicode && num == 1 && den == 7 )
109 res = QChar( 0x2150 );
110 else if ( mUseDedicatedUnicode && num == 1 && den == 8 )
111 res = QChar( 0x215B );
112 else if ( mUseDedicatedUnicode && num == 3 && den == 8 )
113 res = QChar( 0x215C );
114 else if ( mUseDedicatedUnicode && num == 5 && den == 8 )
115 res = QChar( 0x215D );
116 else if ( mUseDedicatedUnicode && num == 7 && den == 8 )
117 res = QChar( 0x215E );
118 else if ( mUseDedicatedUnicode && num == 1 && den == 9 )
119 res = QChar( 0x2151 );
120 else if ( mUseDedicatedUnicode && num == 1 && den == 10 )
121 res = QChar( 0x2152 );
122 else if ( mUseUnicodeSuperSubscript )
127 res = num == 0 ? QString() : u
"%2/%3"_s.arg( num ).arg( den );
130 os << std::fixed << std::setprecision( 0 );
132 res.prepend( QString::fromStdWString( os.str() ) +
' ' );
136 res = QString::number( 0 );
143 os << std::fixed << std::setprecision( 10 );
145 res = QString::fromStdWString( os.str() );
148 if ( value > 0 && mShowPlusSign )
163 auto res = std::make_unique< QgsFractionNumericFormat >();
165 return res.release();
171 res.insert( u
"show_thousand_separator"_s, mShowThousandsSeparator );
172 res.insert( u
"show_plus"_s, mShowPlusSign );
173 res.insert( u
"thousand_separator"_s, mThousandsSeparator.isNull() ? QVariant() : QVariant::fromValue( mThousandsSeparator ) );
174 res.insert( u
"use_dedicated_unicode"_s, mUseDedicatedUnicode );
175 res.insert( u
"use_unicode_supersubscript"_s, mUseUnicodeSuperSubscript );
186 return mUseDedicatedUnicode;
191 mUseDedicatedUnicode = enabled;
196 return mUseUnicodeSuperSubscript;
201 mUseUnicodeSuperSubscript = enabled;
206 mShowThousandsSeparator =
configuration.value( u
"show_thousand_separator"_s,
true ).toBool();
207 mShowPlusSign =
configuration.value( u
"show_plus"_s,
false ).toBool();
208 mThousandsSeparator =
configuration.value( u
"thousand_separator"_s, QChar() ).toChar();
209 mUseDedicatedUnicode =
configuration.value( u
"use_dedicated_unicode"_s,
false ).toBool();
210 mUseUnicodeSuperSubscript =
configuration.value( u
"use_unicode_supersubscript"_s,
true ).toBool();
215 return mShowThousandsSeparator;
225 return mShowPlusSign;
235 return mThousandsSeparator;
240 mThousandsSeparator = character;
246 for (
int i = 0; i < input.size(); ++i )
248 const QChar
c = input.at( i );
250 res[i] = QChar( 0x2070 );
252 res[i] = QChar( 0x00B9 );
254 res[i] = QChar( 0x00B2 );
256 res[i] = QChar( 0x00B3 );
258 res[i] = QChar( 0x2074 );
260 res[i] = QChar( 0x2075 );
262 res[i] = QChar( 0x2076 );
264 res[i] = QChar( 0x2077 );
266 res[i] = QChar( 0x2078 );
268 res[i] = QChar( 0x2079 );
276 for (
int i = 0; i < input.size(); ++i )
278 const QChar
c = input.at( i );
280 res[i] = QChar( 0x2080 );
282 res[i] = QChar( 0x2081 );
284 res[i] = QChar( 0x2082 );
286 res[i] = QChar( 0x2083 );
288 res[i] = QChar( 0x2084 );
290 res[i] = QChar( 0x2085 );
292 res[i] = QChar( 0x2086 );
294 res[i] = QChar( 0x2087 );
296 res[i] = QChar( 0x2088 );
298 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