Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Office
Calligra
Commits
a3c88bb4
Commit
a3c88bb4
authored
Mar 28, 2011
by
Marijn Kruisselbrink
Browse files
add support for number:grouping attribute
BUG: 262061
parent
319fa5a5
Changes
8
Hide whitespace changes
Inline
Side-by-side
libs/odf/KoOdfNumberStyles.cpp
View file @
a3c88bb4
...
...
@@ -67,8 +67,7 @@ QPair<QString, NumericStyleFormat> loadOdfNumberStyle(const KoXmlElement &parent
int
precision
=
-
1
;
int
leadingZ
=
1
;
// Long-standing todo: thousandsSep
//bool thousandsSep = false;
bool
thousandsSep
=
false
;
//todo negred
//bool negRed = false;
bool
ok
=
false
;
...
...
@@ -135,7 +134,9 @@ QPair<QString, NumericStyleFormat> loadOdfNumberStyle(const KoXmlElement &parent
// number:language="de" number:country="DE">€</number:currency-symbol>
// Stefan: localization of the symbol?
}
else
if
(
localName
==
"number"
)
{
// TODO: number:grouping="true"
if
(
e
.
hasAttributeNS
(
KoXmlNS
::
number
,
"grouping"
))
{
thousandsSep
=
e
.
attributeNS
(
KoXmlNS
::
number
,
"grouping"
,
QString
()).
toLower
()
==
"true"
;
}
if
(
e
.
hasAttributeNS
(
KoXmlNS
::
number
,
"decimal-places"
))
{
int
d
=
e
.
attributeNS
(
KoXmlNS
::
number
,
"decimal-places"
,
QString
()).
toInt
(
&
ok
);
if
(
ok
)
...
...
@@ -146,15 +147,15 @@ QPair<QString, NumericStyleFormat> loadOdfNumberStyle(const KoXmlElement &parent
if
(
ok
)
leadingZ
=
d
;
}
//
if (thousandsSep && leadingZ <= 3) {
//
format += "#,";
//
for (i = leadingZ; i <= 3; ++i)
//
format += '#';
//
}
if
(
thousandsSep
&&
leadingZ
<=
3
)
{
format
+=
"#,"
;
for
(
i
=
leadingZ
;
i
<=
3
;
++
i
)
format
+=
'#'
;
}
for
(
i
=
1
;
i
<=
leadingZ
;
++
i
)
{
format
+=
'0'
;
//
if ((i % 3 == 0) && thousandsSep)
//
format = + ',' ;
if
((
i
%
3
==
0
)
&&
thousandsSep
)
format
=
+
','
;
}
if
(
precision
>
-
1
)
{
format
+=
'.'
;
...
...
@@ -186,16 +187,20 @@ QPair<QString, NumericStyleFormat> loadOdfNumberStyle(const KoXmlElement &parent
exp
=
1
;
}
// if (thousandsSep && leadingZ <= 3) {
// format += "#,";
// for (i = leadingZ; i <= 3; ++i)
// format += '#';
// }
if
(
e
.
hasAttributeNS
(
KoXmlNS
::
number
,
"grouping"
))
{
thousandsSep
=
e
.
attributeNS
(
KoXmlNS
::
number
,
"grouping"
,
QString
()).
toLower
()
==
"true"
;
}
if
(
thousandsSep
&&
leadingZ
<=
3
)
{
format
+=
"#,"
;
for
(
i
=
leadingZ
;
i
<=
3
;
++
i
)
format
+=
'#'
;
}
for
(
i
=
1
;
i
<=
leadingZ
;
++
i
)
{
format
+=
'0'
;
//
if ((i % 3 == 0) && thousandsSep)
//
format += ',';
if
((
i
%
3
==
0
)
&&
thousandsSep
)
format
+=
','
;
}
if
(
precision
>
-
1
)
{
...
...
@@ -234,6 +239,9 @@ QPair<QString, NumericStyleFormat> loadOdfNumberStyle(const KoXmlElement &parent
if
(
ok
)
denominatorValue
=
d
;
}
if
(
e
.
hasAttributeNS
(
KoXmlNS
::
number
,
"grouping"
))
{
thousandsSep
=
e
.
attributeNS
(
KoXmlNS
::
number
,
"grouping"
,
QString
()).
toLower
()
==
"true"
;
}
for
(
i
=
0
;
i
<
integer
;
++
i
)
format
+=
'#'
;
...
...
@@ -300,6 +308,7 @@ kDebug()<<"99 ******************************************************************
dataStyle
.
prefix
=
prefix
;
dataStyle
.
suffix
=
suffix
;
dataStyle
.
precision
=
precision
;
dataStyle
.
thousandsSep
=
thousandsSep
;
kDebug
(
30003
)
<<
" finish insert format :"
<<
format
<<
" prefix :"
<<
prefix
<<
" suffix :"
<<
suffix
;
return
QPair
<
QString
,
NumericStyleFormat
>
(
styleName
,
dataStyle
);
}
...
...
@@ -772,7 +781,7 @@ QString saveOdfFractionStyle(KoGenStyles &mainStyles, const QString &_format,
QString
saveOdfNumberStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
_format
,
const
QString
&
_prefix
,
const
QString
&
_suffix
)
const
QString
&
_prefix
,
const
QString
&
_suffix
,
bool
thousandsSep
)
{
//kDebug(30003) << "QString saveOdfNumberStyle( KoGenStyles &mainStyles, const QString & _format ) :" << _format;
QString
format
(
_format
);
...
...
@@ -803,6 +812,8 @@ QString saveOdfNumberStyle(KoGenStyles &mainStyles, const QString &_format,
if
(
!
beforeSeparator
)
elementWriter
.
addAttribute
(
"number:decimal-places"
,
decimalplaces
);
elementWriter
.
addAttribute
(
"number:min-integer-digits"
,
integerdigits
);
if
(
thousandsSep
)
elementWriter
.
addAttribute
(
"number:grouping"
,
true
);
elementWriter
.
endElement
();
text
=
_suffix
;
...
...
@@ -865,7 +876,7 @@ QString saveOdfPercentageStyle(KoGenStyles &mainStyles, const QString &_format,
}
QString
saveOdfScientificStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
_format
,
const
QString
&
_prefix
,
const
QString
&
_suffix
)
const
QString
&
_prefix
,
const
QString
&
_suffix
,
bool
thousandsSep
)
{
//<number:number-style style:name="N60">
//<number:scientific-number number:decimal-places="2" number:min-integer-digits="1" number:min-exponent-digits="3"/>
...
...
@@ -923,6 +934,8 @@ QString saveOdfScientificStyle(KoGenStyles &mainStyles, const QString &_format,
elementWriter
.
addAttribute
(
"number:decimal-places"
,
decimalplace
);
elementWriter
.
addAttribute
(
"number:min-integer-digits"
,
integerdigits
);
elementWriter
.
addAttribute
(
"number:min-exponent-digits"
,
exponentdigits
);
if
(
thousandsSep
)
elementWriter
.
addAttribute
(
"number:grouping"
,
true
);
elementWriter
.
endElement
();
text
=
_suffix
;
...
...
libs/odf/KoOdfNumberStyles.h
View file @
a3c88bb4
...
...
@@ -55,6 +55,7 @@ namespace KoOdfNumberStyles
Format
type
;
int
precision
;
QString
currencySymbol
;
bool
thousandsSep
;
QList
<
QPair
<
QString
,
QString
>
>
styleMaps
;
// conditional formatting, first=condition, second=applyStyleName
};
...
...
@@ -63,8 +64,8 @@ namespace KoOdfNumberStyles
KOODF_EXPORT
QString
saveOdfDateStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
bool
klocaleFormat
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
());
KOODF_EXPORT
QString
saveOdfTimeStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
bool
klocaleFormat
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
());
KOODF_EXPORT
QString
saveOdfFractionStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
());
KOODF_EXPORT
QString
saveOdfScientificStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
());
KOODF_EXPORT
QString
saveOdfNumberStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
());
KOODF_EXPORT
QString
saveOdfScientificStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
()
,
bool
thousandsSep
=
false
);
KOODF_EXPORT
QString
saveOdfNumberStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
()
,
bool
thousandsSep
=
false
);
KOODF_EXPORT
QString
saveOdfPercentageStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
());
KOODF_EXPORT
QString
saveOdfCurrencyStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
const
QString
&
symbol
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
());
KOODF_EXPORT
QString
saveOdfTextStyle
(
KoGenStyles
&
mainStyles
,
const
QString
&
format
,
const
QString
&
prefix
=
QString
(),
const
QString
&
suffix
=
QString
());
...
...
tables/Style.cpp
View file @
a3c88bb4
...
...
@@ -109,6 +109,7 @@ QString SubStyle::name(Style::Key key)
case
Style
::
Prefix
:
name
=
"Prefix"
;
break
;
case
Style
::
Postfix
:
name
=
"Postfix"
;
break
;
case
Style
::
Precision
:
name
=
"Precision"
;
break
;
case
Style
::
ThousandsSep
:
name
=
"Thousands seperator"
;
break
;
case
Style
::
FormatTypeKey
:
name
=
"Format type"
;
break
;
case
Style
::
FloatFormatKey
:
name
=
"Float format"
;
break
;
case
Style
::
FloatColorKey
:
name
=
"Float color"
;
break
;
...
...
@@ -340,6 +341,8 @@ void Style::loadOdfDataStyle(KoOdfStylesReader &stylesReader, const QString &sty
theStyle
->
setPrecision
(
precision
);
}
theStyle
->
setThousandsSep
(
dataStyle
.
thousandsSep
);
theStyle
->
setCustomFormat
(
dataStyle
.
formatStr
);
if
(
styleMaps
.
count
()
>
0
)
{
...
...
@@ -736,14 +739,15 @@ Format::Type Style::fractionType(const QString &_format)
QString
Style
::
saveOdfStyleNumeric
(
KoGenStyle
&
style
,
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
const
QString
&
_prefix
,
const
QString
&
_postfix
,
int
_precision
,
const
QString
&
symbol
)
int
_precision
,
const
QString
&
symbol
,
bool
thousandsSep
)
{
// kDebug(36003) ;
QString
styleName
;
QString
valueType
;
switch
(
_style
)
{
case
Format
::
Number
:
styleName
=
saveOdfStyleNumericNumber
(
mainStyles
,
_style
,
_precision
,
_prefix
,
_postfix
);
styleName
=
saveOdfStyleNumericNumber
(
mainStyles
,
_style
,
_precision
,
_prefix
,
_postfix
,
thousandsSep
);
valueType
=
"float"
;
break
;
case
Format
::
Text
:
...
...
@@ -759,7 +763,7 @@ QString Style::saveOdfStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles,
valueType
=
"percentage"
;
break
;
case
Format
::
Scientific
:
styleName
=
saveOdfStyleNumericScientific
(
mainStyles
,
_style
,
_prefix
,
_postfix
,
_precision
);
styleName
=
saveOdfStyleNumericScientific
(
mainStyles
,
_style
,
_prefix
,
_postfix
,
_precision
,
thousandsSep
);
valueType
=
"float"
;
break
;
case
Format
::
ShortDate
:
...
...
@@ -836,7 +840,7 @@ QString Style::saveOdfStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles,
case
Format
::
Generic
:
case
Format
::
None
:
if
(
_precision
>
-
1
||
!
_prefix
.
isEmpty
()
||
!
_postfix
.
isEmpty
())
{
styleName
=
saveOdfStyleNumericNumber
(
mainStyles
,
_style
,
_precision
,
_prefix
,
_postfix
);
styleName
=
saveOdfStyleNumericNumber
(
mainStyles
,
_style
,
_precision
,
_prefix
,
_postfix
,
thousandsSep
);
valueType
=
"float"
;
}
break
;
...
...
@@ -851,7 +855,7 @@ QString Style::saveOdfStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles,
}
QString
Style
::
saveOdfStyleNumericNumber
(
KoGenStyles
&
mainStyles
,
Format
::
Type
/*_style*/
,
int
_precision
,
const
QString
&
_prefix
,
const
QString
&
_postfix
)
const
QString
&
_prefix
,
const
QString
&
_postfix
,
bool
thousandsSep
)
{
QString
format
;
if
(
_precision
==
-
1
)
...
...
@@ -863,7 +867,7 @@ QString Style::saveOdfStyleNumericNumber(KoGenStyles& mainStyles, Format::Type /
}
format
=
"0."
+
tmp
;
}
return
KoOdfNumberStyles
::
saveOdfNumberStyle
(
mainStyles
,
format
,
_prefix
,
_postfix
);
return
KoOdfNumberStyles
::
saveOdfNumberStyle
(
mainStyles
,
format
,
_prefix
,
_postfix
,
thousandsSep
);
}
QString
Style
::
saveOdfStyleNumericText
(
KoGenStyles
&
/*mainStyles*/
,
Format
::
Type
/*_style*/
,
int
/*_precision*/
,
...
...
@@ -912,7 +916,7 @@ QString Style::saveOdfStyleNumericPercentage(KoGenStyles&mainStyles, Format::Typ
QString
Style
::
saveOdfStyleNumericScientific
(
KoGenStyles
&
mainStyles
,
Format
::
Type
/*_style*/
,
const
QString
&
_prefix
,
const
QString
&
_suffix
,
int
_precision
)
const
QString
&
_prefix
,
const
QString
&
_suffix
,
int
_precision
,
bool
thousandsSep
)
{
//<number:number-style style:name="N60" style:family="data-style">
// <number:scientific-number number:decimal-places="2" number:min-integer-digits="1" number:min-exponent-digits="3"/>
...
...
@@ -927,7 +931,7 @@ QString Style::saveOdfStyleNumericScientific(KoGenStyles&mainStyles, Format::Typ
}
format
=
"0."
+
tmp
+
"E+00"
;
}
return
KoOdfNumberStyles
::
saveOdfScientificStyle
(
mainStyles
,
format
,
_prefix
,
_suffix
);
return
KoOdfNumberStyles
::
saveOdfScientificStyle
(
mainStyles
,
format
,
_prefix
,
_suffix
,
thousandsSep
);
}
QString
Style
::
saveOdfStyleNumericDate
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
...
...
@@ -1431,6 +1435,10 @@ void Style::saveOdfStyle(const QSet<Key>& keysToStore, KoGenStyle &style,
_postfix
=
postfix
();
if
(
keysToStore
.
contains
(
Precision
)
&&
precision
()
!=
-
1
)
_precision
=
precision
();
bool
_thousandsSep
=
false
;
if
(
keysToStore
.
contains
(
ThousandsSep
))
{
_thousandsSep
=
thousandsSep
();
}
QString
currencyCode
;
if
(
keysToStore
.
contains
(
FormatTypeKey
)
&&
formatType
()
==
Format
::
Money
)
{
...
...
@@ -1439,7 +1447,7 @@ void Style::saveOdfStyle(const QSet<Key>& keysToStore, KoGenStyle &style,
QString
numericStyle
=
saveOdfStyleNumeric
(
style
,
mainStyles
,
formatType
(),
_prefix
,
_postfix
,
_precision
,
currencyCode
);
currencyCode
,
_thousandsSep
);
if
(
!
numericStyle
.
isEmpty
())
style
.
addAttribute
(
"style:data-style-name"
,
numericStyle
);
}
...
...
@@ -2069,6 +2077,13 @@ int Style::precision() const
return
static_cast
<
const
SubStyleOne
<
Precision
,
int
>*>
(
d
->
subStyles
[
Precision
].
data
())
->
value1
;
}
bool
Style
::
thousandsSep
()
const
{
if
(
!
d
->
subStyles
.
contains
(
ThousandsSep
))
return
false
;
return
static_cast
<
const
SubStyleOne
<
ThousandsSep
,
bool
>*>
(
d
->
subStyles
[
ThousandsSep
].
data
())
->
value1
;
}
int
Style
::
angle
()
const
{
if
(
!
d
->
subStyles
.
contains
(
Angle
))
...
...
@@ -2272,6 +2287,11 @@ void Style::setPrecision(int precision)
insertSubStyle
(
Precision
,
precision
);
}
void
Style
::
setThousandsSep
(
bool
thousandsSep
)
{
insertSubStyle
(
ThousandsSep
,
thousandsSep
);
}
void
Style
::
setPrefix
(
QString
const
&
prefix
)
{
insertSubStyle
(
Prefix
,
prefix
);
...
...
@@ -2392,6 +2412,8 @@ bool Style::compare(const SubStyle* one, const SubStyle* two)
return
static_cast
<
const
SubStyleOne
<
Postfix
,
QString
>*>
(
one
)
->
value1
==
static_cast
<
const
SubStyleOne
<
Postfix
,
QString
>*>
(
two
)
->
value1
;
case
Precision
:
return
static_cast
<
const
SubStyleOne
<
Precision
,
int
>*>
(
one
)
->
value1
==
static_cast
<
const
SubStyleOne
<
Precision
,
int
>*>
(
two
)
->
value1
;
case
ThousandsSep
:
return
static_cast
<
const
SubStyleOne
<
ThousandsSep
,
bool
>*>
(
one
)
->
value1
==
static_cast
<
const
SubStyleOne
<
ThousandsSep
,
bool
>*>
(
two
)
->
value1
;
case
FormatTypeKey
:
return
static_cast
<
const
SubStyleOne
<
FormatTypeKey
,
Format
::
Type
>*>
(
one
)
->
value1
==
static_cast
<
const
SubStyleOne
<
FormatTypeKey
,
Format
::
Type
>*>
(
two
)
->
value1
;
case
FloatFormatKey
:
...
...
@@ -2588,6 +2610,9 @@ SharedSubStyle Style::createSubStyle(Key key, const QVariant& value)
case
Precision
:
newSubStyle
=
new
SubStyleOne
<
Precision
,
int
>
(
value
.
value
<
int
>
());
break
;
case
ThousandsSep
:
newSubStyle
=
new
SubStyleOne
<
ThousandsSep
,
bool
>
(
value
.
value
<
bool
>
());
break
;
case
FormatTypeKey
:
newSubStyle
=
new
SubStyleOne
<
FormatTypeKey
,
Format
::
Type
>
((
Format
::
Type
)
value
.
value
<
int
>
());
break
;
...
...
tables/Style.h
View file @
a3c88bb4
...
...
@@ -137,6 +137,7 @@ public:
Prefix
,
Postfix
,
Precision
,
ThousandsSep
,
FormatTypeKey
,
FloatFormatKey
,
FloatColorKey
,
...
...
@@ -228,6 +229,7 @@ public:
uint
fontFlags
()
const
;
int
fontSize
()
const
;
int
precision
()
const
;
bool
thousandsSep
()
const
;
int
angle
()
const
;
double
indentation
()
const
;
bool
shrinkToFit
()
const
;
...
...
@@ -280,6 +282,7 @@ public:
void
setFormatType
(
Format
::
Type
format
);
void
setCustomFormat
(
QString
const
&
strFormat
);
void
setPrecision
(
int
precision
);
void
setThousandsSep
(
bool
thousandsSep
);
void
setPrefix
(
QString
const
&
prefix
);
void
setPostfix
(
QString
const
&
postfix
);
void
setCurrency
(
Currency
const
&
currency
);
...
...
@@ -308,7 +311,8 @@ public:
* boolean, text)
*/
static
QString
saveOdfStyleNumeric
(
KoGenStyle
&
style
,
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
const
QString
&
_prefix
,
const
QString
&
_postfix
,
int
_precision
,
const
QString
&
symbol
);
const
QString
&
_prefix
,
const
QString
&
_postfix
,
int
_precision
,
const
QString
&
symbol
,
bool
thousandsSep
);
static
QString
saveOdfStyleNumericDate
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
const
QString
&
_prefix
,
const
QString
&
_suffix
);
static
QString
saveOdfStyleNumericFraction
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
...
...
@@ -318,7 +322,7 @@ public:
static
QString
saveOdfStyleNumericCustom
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
const
QString
&
_prefix
,
const
QString
&
_suffix
);
static
QString
saveOdfStyleNumericScientific
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
const
QString
&
_prefix
,
const
QString
&
_suffix
,
int
_precision
);
const
QString
&
_prefix
,
const
QString
&
_suffix
,
int
_precision
,
bool
thousandsSep
);
static
QString
saveOdfStyleNumericPercentage
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
int
_precision
,
const
QString
&
_prefix
,
const
QString
&
_suffix
);
static
QString
saveOdfStyleNumericMoney
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
...
...
@@ -327,7 +331,7 @@ public:
static
QString
saveOdfStyleNumericText
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
int
_precision
,
const
QString
&
_prefix
,
const
QString
&
_suffix
);
static
QString
saveOdfStyleNumericNumber
(
KoGenStyles
&
mainStyles
,
Format
::
Type
_style
,
int
_precision
,
const
QString
&
_prefix
,
const
QString
&
_suffix
);
const
QString
&
_prefix
,
const
QString
&
_suffix
,
bool
thousandsSep
);
static
QString
saveOdfBackgroundStyle
(
KoGenStyles
&
mainStyles
,
const
QBrush
&
brush
);
/**
...
...
tables/ValueFormatter.cpp
View file @
a3c88bb4
...
...
@@ -48,7 +48,8 @@ const CalculationSettings* ValueFormatter::settings() const
Value
ValueFormatter
::
formatText
(
const
Value
&
value
,
Format
::
Type
fmtType
,
int
precision
,
Style
::
FloatFormat
floatFormat
,
const
QString
&
prefix
,
const
QString
&
postfix
,
const
QString
&
currencySymbol
,
const
QString
&
formatString
)
const
QString
&
postfix
,
const
QString
&
currencySymbol
,
const
QString
&
formatString
,
bool
thousandsSep
)
{
if
(
value
.
isError
())
return
Value
(
value
.
errorMessage
());
...
...
@@ -117,7 +118,7 @@ Value ValueFormatter::formatText(const Value &value, Format::Type fmtType, int p
if
(
value
.
isComplex
())
{
Value
complexValue
=
m_converter
->
asComplex
(
value
,
&
ok
);
if
(
ok
)
{
result
=
Value
(
complexFormat
(
complexValue
,
precision
,
fmtType
,
floatFormat
,
currencySymbol
));
result
=
Value
(
complexFormat
(
complexValue
,
precision
,
fmtType
,
floatFormat
,
currencySymbol
,
thousandsSep
));
result
.
setFormat
(
Value
::
fmt_Number
);
}
}
...
...
@@ -126,7 +127,7 @@ Value ValueFormatter::formatText(const Value &value, Format::Type fmtType, int p
else
{
Number
number
=
m_converter
->
asFloat
(
value
,
&
ok
).
asFloat
();
if
(
ok
)
{
result
=
Value
(
createNumberFormat
(
number
,
precision
,
fmtType
,
floatFormat
,
currencySymbol
,
formatString
));
result
=
Value
(
createNumberFormat
(
number
,
precision
,
fmtType
,
floatFormat
,
currencySymbol
,
formatString
,
thousandsSep
));
result
.
setFormat
(
Value
::
fmt_Number
);
}
}
...
...
@@ -245,7 +246,8 @@ QString ValueFormatter::removeTrailingZeros(const QString& str, const QString& d
}
QString
ValueFormatter
::
createNumberFormat
(
Number
value
,
int
precision
,
Format
::
Type
fmt
,
Style
::
FloatFormat
floatFormat
,
const
QString
&
currencySymbol
,
const
QString
&
_formatString
)
Format
::
Type
fmt
,
Style
::
FloatFormat
floatFormat
,
const
QString
&
currencySymbol
,
const
QString
&
_formatString
,
bool
thousandsSep
)
{
QString
prefix
,
postfix
;
QString
formatString
(
_formatString
);
...
...
@@ -350,6 +352,14 @@ QString ValueFormatter::createNumberFormat(Number value, int precision,
localizedNumber
=
removeTrailingZeros
(
localizedNumber
,
decimalSymbol
);
}
// Remove thousands seperators if necessary
if
(
!
thousandsSep
)
{
QString
seperator
=
m_converter
->
settings
()
->
locale
()
->
thousandsSeparator
();
if
(
!
seperator
.
isNull
())
{
localizedNumber
.
remove
(
seperator
);
}
}
// remove negative sign if prefix already ends with '-'
if
(
!
prefix
.
isEmpty
()
&&
prefix
[
prefix
.
length
()
-
1
]
==
'-'
&&
!
localizedNumber
.
isEmpty
()
&&
localizedNumber
[
0
]
==
'-'
)
{
localizedNumber
=
localizedNumber
.
mid
(
1
);
...
...
@@ -716,14 +726,15 @@ QString ValueFormatter::dateFormat(const QDate &date, Format::Type fmtType, cons
QString
ValueFormatter
::
complexFormat
(
const
Value
&
value
,
int
precision
,
Format
::
Type
formatType
,
Style
::
FloatFormat
floatFormat
,
const
QString
&
currencySymbol
)
const
QString
&
currencySymbol
,
bool
thousandsSep
)
{
// FIXME Stefan: percentage, currency and scientific formats!
QString
str
;
const
Number
real
=
value
.
asComplex
().
real
();
const
Number
imag
=
value
.
asComplex
().
imag
();
str
=
createNumberFormat
(
real
,
precision
,
formatType
,
floatFormat
,
QString
(),
QString
());
str
+=
createNumberFormat
(
imag
,
precision
,
formatType
,
Style
::
AlwaysSigned
,
currencySymbol
,
QString
());
str
=
createNumberFormat
(
real
,
precision
,
formatType
,
floatFormat
,
QString
(),
QString
()
,
thousandsSep
);
str
+=
createNumberFormat
(
imag
,
precision
,
formatType
,
Style
::
AlwaysSigned
,
currencySymbol
,
QString
()
,
thousandsSep
);
str
+=
'i'
;
return
str
;
}
tables/ValueFormatter.h
View file @
a3c88bb4
...
...
@@ -67,7 +67,9 @@ public:
Style
::
FloatFormat
floatFormat
=
Style
::
OnlyNegSigned
,
const
QString
&
prefix
=
QString
(),
const
QString
&
postfix
=
QString
(),
const
QString
&
currencySymbol
=
QString
(),
const
QString
&
formatString
=
QString
());
const
QString
&
currencySymbol
=
QString
(),
const
QString
&
formatString
=
QString
(),
bool
thousandsSep
=
true
);
/**
* Creates a date format.
...
...
@@ -106,7 +108,8 @@ protected:
Format
::
Type
formatType
,
Style
::
FloatFormat
floatFormat
,
const
QString
&
currencySymbol
,
const
QString
&
formatString
);
const
QString
&
formatString
,
bool
thousandsSep
);
/**
* Creates a fraction format.
...
...
@@ -124,7 +127,8 @@ protected:
QString
complexFormat
(
const
Value
&
value
,
int
precision
,
Format
::
Type
formatType
,
Style
::
FloatFormat
floatFormat
,
const
QString
&
currencySymbol
);
const
QString
&
currencySymbol
,
bool
thousandsSep
);
/**
* Removes the trailing zeros and the decimal symbol \p decimalSymbol in
...
...
tables/tests/TestValueFormatter.cpp
View file @
a3c88bb4
...
...
@@ -199,15 +199,23 @@ void TestValueFormatter::testCreateNumberFormat_data()
QTest
::
addColumn
<
Style
::
FloatFormat
>
(
"floatFormat"
);
QTest
::
addColumn
<
QString
>
(
"currencySymbol"
);
QTest
::
addColumn
<
QString
>
(
"formatString"
);
QTest
::
addColumn
<
bool
>
(
"thousandsSep"
);
QTest
::
addColumn
<
QString
>
(
"result"
);
QTest
::
newRow
(
"negative sign in format string"
)
<<
-
5.0
<<
0
<<
Format
::
Number
<<
Style
::
DefaultFloatFormat
<<
""
<<
"(-.)"
<<
"(-5)"
;
-
5.0
<<
0
<<
Format
::
Number
<<
Style
::
DefaultFloatFormat
<<
""
<<
"(-.)"
<<
false
<<
"(-5)"
;
QTest
::
newRow
(
"unspecified precision 1"
)
<<
1.0
<<
-
1
<<
Format
::
Number
<<
Style
::
DefaultFloatFormat
<<
""
<<
"0"
<<
"1"
;
1.0
<<
-
1
<<
Format
::
Number
<<
Style
::
DefaultFloatFormat
<<
""
<<
"0"
<<
false
<<
"1"
;
QTest
::
newRow
(
"unspecified precision 0.5"
)
<<
0.5
<<
-
1
<<
Format
::
Number
<<
Style
::
DefaultFloatFormat
<<
""
<<
"0"
<<
"0.5"
;}
0.5
<<
-
1
<<
Format
::
Number
<<
Style
::
DefaultFloatFormat
<<
""
<<
"0"
<<
false
<<
"0.5"
;
QTest
::
newRow
(
"no thousands seperators"
)
<<
3000.0
<<
0
<<
Format
::
Number
<<
Style
::
DefaultFloatFormat
<<
""
<<
""
<<
false
<<
"3000"
;
QTest
::
newRow
(
"with thousands seperators"
)
<<
3000.0
<<
0
<<
Format
::
Number
<<
Style
::
DefaultFloatFormat
<<
""
<<
""
<<
true
<<
"3,000"
;
}
void
TestValueFormatter
::
testCreateNumberFormat
()
{
...
...
@@ -217,11 +225,12 @@ void TestValueFormatter::testCreateNumberFormat()
QFETCH
(
Style
::
FloatFormat
,
floatFormat
);
QFETCH
(
QString
,
currencySymbol
);
QFETCH
(
QString
,
formatString
);
QFETCH
(
bool
,
thousandsSep
);
QFETCH
(
QString
,
result
);
Number
num
(
value
);
PublicValueFormatter
fmt
(
m_converter
);
QCOMPARE
(
fmt
.
createNumberFormat
(
num
,
precision
,
formatType
,
floatFormat
,
currencySymbol
,
formatString
),
result
);
QCOMPARE
(
fmt
.
createNumberFormat
(
num
,
precision
,
formatType
,
floatFormat
,
currencySymbol
,
formatString
,
thousandsSep
),
result
);
}
...
...
tables/ui/CellView.cpp
View file @
a3c88bb4
...
...
@@ -236,7 +236,8 @@ CellView::CellView(SheetView* sheetView, int col, int row)
value
=
sheet
->
map
()
->
formatter
()
->
formatText
(
cell
.
value
(),
d
->
style
.
formatType
(),
d
->
style
.
precision
(),
d
->
style
.
floatFormat
(),
d
->
style
.
prefix
(),
d
->
style
.
postfix
(),
d
->
style
.
currency
().
symbol
(),
d
->
style
.
customFormat
());
d
->
style
.
currency
().
symbol
(),
d
->
style
.
customFormat
(),
d
->
style
.
thousandsSep
());
d
->
displayText
=
value
.
asString
();
QSharedPointer
<
QTextDocument
>
doc
=
cell
.
richText
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment