Bug 104969 - Cell properties money/currency does not actually change currency.
Summary: Cell properties money/currency does not actually change currency.
Status: RESOLVED FIXED
Alias: None
Product: calligrasheets
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Laurent Montel
URL:
Keywords:
: 108153 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-05-02 16:04 UTC by Thomas Zander
Modified: 2006-12-13 19:57 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Zander 2005-05-02 16:04:27 UTC
Version:           1.4 beta1 (using KDE 3.4.89 (CVS >= 20050314), compiled sources)
Compiler:          gcc version 3.3.5 (Debian 1:3.3.5-8)
OS:                Linux (i686) release 2.6.10

I type a number in a cell and when I change the cell format to 'Money' I get
a combobox with 'currency'. No matter which currency I select the
spreadsheet always shows a Euro sign. (which is my locale one).

I expected it to show the selected one.
Comment 1 Thomas Zander 2005-05-03 11:32:29 UTC
Ben wrote on the koffice-devel mailinglist:

This was already fixed once; see koffice/kspread/kspread_style.cc,
revision 1.10.2.1 in KOFFICE_1_3_BRANCH or revision 1.31 for HEAD.
Perhaps it's been broken again in HEAD since?
Comment 2 Boris Dušek 2005-07-10 18:21:05 UTC
Hi, I have the same problem with KSpread 1.4.0 and even another problem connected with money format:
if I change "Format -> Cell Format -> Data Format -> Format" (when Money format is selected),
then I observe following misbehaviour:
when format for negative numbers is chosen so that explicit minus sign is enabled (no matter which color of the negative number), then instead of the expected result
"-$ 17.31"
I get the actual result
"$ (17.31)" (extra brackets and no minus sign).
If I choose no explicit minus sign, then expected result always appears.

OS facts: Gentoo, gcc-3.4.4, KDE 3.4.1, KSpread 1.4.0.
Comment 3 Tomas Mecir 2005-07-28 11:03:50 UTC
*** Bug 108153 has been marked as a duplicate of this bug. ***
Comment 4 Kilian Hagemann 2005-10-20 13:37:11 UTC
Indeed this seems to have been fixed before (see patch in bug 69284), but somehow it broke again. I first came across this in 1.4.1 (didn't have to change currencies before), but even in the latest 1.4.2 it's *still* there.
Comment 5 Anne-Marie Mahfouf 2005-11-08 03:01:24 UTC
The refered patch from bug 69284 is included in KSpread svn trunk but the currency change is not working anyway. So there's more to fix! I confirm the bug exists in kde svn trunk, next coming 1.5 version.
Comment 6 Stefan Nikolaus 2006-02-14 20:17:28 UTC
SVN commit 509455 by nikolaus:

fix currency selection
BUG: 104969


 M  +2 -1      dialogs/kspread_dlg_layout.cc  
 M  +4 -0      manipulator.cc  
 M  +9 -0      tests/inspector.cc  
 M  +12 -9     valueformatter.cc  
 M  +3 -2      valueformatter.h  


--- trunk/koffice/kspread/dialogs/kspread_dlg_layout.cc #509454:509455
@@ -1679,7 +1679,8 @@
   tmp = fmt->formatText(dlg->value, newFormatType, precision->value(),
                         floatFormat,
                         prefix->isEnabled() ? prefix->text() : QString::null,
-                        postfix->isEnabled() ? postfix->text() : QString::null);
+                        postfix->isEnabled() ? postfix->text() : QString::null,
+                        newFormatType == Money_format ? dlg->cCurrency.symbol : QString::null);
   if (tmp.length() > 50)
     tmp = tmp.left (50);
   exampleLabel->setText(tmp.prepend("<font color=" + color.name() + ">").append("</font>"));
--- trunk/koffice/kspread/manipulator.cc #509454:509455
@@ -730,6 +730,10 @@
   if (m_properties & Format::PFormatType)
   {
     format->setFormatType(m_formatType);
+    if (m_formatType == Money_format)
+    {
+      format->setCurrency(m_currencyType, m_currencySymbol);
+    }
   }
   if (m_properties & Format::PComment)
   {
--- trunk/koffice/kspread/tests/inspector.cc #509454:509455
@@ -118,6 +118,15 @@
   new QListViewItem( formatView, "Protected", format->hasProperty( Format::PVerticalText ) 
     ? "Not specified" : boolAsString( format->isProtected(col, row) ) );
   new QListViewItem( formatView, "Vertical Text", boolAsString( format->verticalText(col, row ) ) );
+
+  Format::Currency currrency;
+  bool valid = format->currencyInfo(currrency);
+  new QListViewItem( formatView, "Currency symbol", valid ? currrency.symbol : "Invalid" );
+  bool ok = false;
+  QString currencyType;
+  if (valid)
+    currencyType = Currency::getChooseString(currrency.type, ok);
+  new QListViewItem( formatView, "Currency type", valid && ok ? currencyType : "Invalid" );
 }
 
 void Inspector::Private::handleSheet()
--- trunk/koffice/kspread/valueformatter.cc #509454:509455
@@ -44,20 +44,23 @@
     return errorFormat (cell);
 
   QString str;
-  
+
   Format::FloatFormat floatFormat =
       cell->format()->floatFormat (cell->column(), cell->row());
   int precision = cell->format()->precision (cell->column(), cell->row());
   QString prefix = cell->format()->prefix (cell->column(), cell->row());
   QString postfix = cell->format()->postfix (cell->column(), cell->row());
+  Format::Currency currency;
+  bool valid = cell->format()->currencyInfo(currency);
+  QString currencySymbol = valid ? currency.symbol : QString::null;
 
   return formatText (cell->value(), fmtType, precision,
-      floatFormat, prefix, postfix);
+      floatFormat, prefix, postfix, currencySymbol);
 }
 
 QString ValueFormatter::formatText (const Value &value,
     FormatType fmtType, int precision, Format::FloatFormat floatFormat,
-    const QString &prefix, const QString &postfix)
+    const QString &prefix, const QString &postfix, const QString &currencySymbol)
 {
   //if we have an array, use its first element
   if (value.isArray())
@@ -107,20 +110,20 @@
 
     // Make a string out of it.
     str = createNumberFormat (v, precision, fmtType,
-        (floatFormat == Format::AlwaysSigned));
+        (floatFormat == Format::AlwaysSigned), currencySymbol);
 
     // Remove trailing zeros and the decimal point if necessary
     // unless the number has no decimal point
     if (precision == -1)
       removeTrailingZeros (str, decimal_point);
   }
-    
+
   if (!prefix.isEmpty())
     str = prefix + ' ' + str;
 
   if( !postfix.isEmpty())
     str += ' ' + postfix;
-  
+
   //kdDebug() << "ValueFormatter says: " << str << endl;
   return str;
 }
@@ -229,7 +232,7 @@
 }
 
 QString ValueFormatter::createNumberFormat ( double value, int precision,
-    FormatType fmt, bool alwaysSigned)
+    FormatType fmt, bool alwaysSigned, const QString& currencySymbol)
 {
   // if precision is -1, ask for a huge number of decimals, we'll remove
   // the zeros later. Is 8 ok ?
@@ -265,8 +268,8 @@
       localizedNumber = converter->locale()->formatNumber (value, p)+ " %";
       break;
     case Money_format:
-      localizedNumber = converter->locale()->formatMoney (value, 
-          converter->locale()->currencySymbol(), p );
+      localizedNumber = converter->locale()->formatMoney (value,
+        currencySymbol.isEmpty() ? converter->locale()->currencySymbol() : currencySymbol, p );
       break;
     case Scientific_format:
       decimal_point = converter->locale()->decimalSymbol()[0];
--- trunk/koffice/kspread/valueformatter.h #509454:509455
@@ -48,7 +48,8 @@
       FormatType fmtType, int precision = -1,
       Format::FloatFormat floatFormat = Format::OnlyNegSigned,
       const QString &prefix = QString::null,
-      const QString &postfix = QString::null);
+      const QString &postfix = QString::null,
+      const QString &currencySymbol = QString::null);
 
   /** create a date format */
   QString dateFormat (const QDate &_date, FormatType fmtType);
@@ -67,7 +68,7 @@
 
   /** create a number format */
   QString createNumberFormat (double value, int precision, FormatType fmt,
-      bool alwaysSigned);
+      bool alwaysSigned, const QString& currencySymbol);
   
   /** create a fraction format */
   QString fractionFormat (double value, FormatType fmtType);
Comment 7 Stefan Nikolaus 2006-02-16 14:45:02 UTC
SVN commit 510124 by nikolaus:

refix currency selection (after commit 509661)
CCBUG: 104969


 M  +6 -8      valueformatter.cc  
 M  +2 -1      valueformatter.h  


--- trunk/koffice/kspread/valueformatter.cc #510123:510124
@@ -65,7 +65,7 @@
   //if we have an array, use its first element
   if (value.isArray())
     return formatText (value.element (0, 0), fmtType, precision,
-        floatFormat, prefix, postfix);
+        floatFormat, prefix, postfix, currencySymbol);
 
   QString str;
   
@@ -102,7 +102,7 @@
     if ((floatFormat == Format::AlwaysUnsigned) && (v < 0))
       v *= -1;
     str = createNumberFormat (v, fmtType,
-        (floatFormat == Format::AlwaysSigned));
+        (floatFormat == Format::AlwaysSigned), currencySymbol);
   }
   else
   {
@@ -242,11 +242,10 @@
 
 
 QString ValueFormatter::createNumberFormat ( long value, FormatType fmt, 
-	 bool alwaysSigned)
+	 bool alwaysSigned, const QString& currencySymbol)
 {
   QString number;
-  int pos = 0;
-  
+
   //multiply value by 100 for percentage format
   if (fmt == Percentage_format)
     value *= 100;
@@ -261,8 +260,7 @@
       number = QString::number(value) + " %";
       break;
     case Money_format:
-      number = converter->locale()->formatMoney (value, 
-          converter->locale()->currencySymbol());
+      number = converter->locale()->formatMoney (value, currencySymbol.isEmpty() ? converter->locale()->currencySymbol() : currencySymbol);
       break;
     default :
       //other formatting?
@@ -287,7 +285,7 @@
   int p = (precision == -1) ? 8 : precision;
   QString localizedNumber;
   int pos = 0;
-  
+
   //multiply value by 100 for percentage format
   if (fmt == Percentage_format)
     value *= 100;
--- trunk/koffice/kspread/valueformatter.h #510123:510124
@@ -67,7 +67,8 @@
       FormatType fmtType);
 
   /** create a number format */
-  QString createNumberFormat (long value, FormatType fmt, bool alwaysSigned);
+  QString createNumberFormat (long value, FormatType fmt, bool alwaysSigned,
+                              const QString& currencySymbol);
   QString createNumberFormat (double value, int precision, FormatType fmt,
       bool alwaysSigned, const QString& currencySymbol);
   
Comment 8 markus 2006-11-23 02:58:08 UTC
This thing does not work for me!!! I have version 1.6. When I set some celld to contain Euro values, the currency sign will not be set. In the format dialog, I may even explicitly pick the Euro currency, together with the symbol. The symbol, however, will not be shown then. 

Some values are right-bound, some will be left bound. That's arbitrary and I cannot set that. 

I would like to request to re-open this bug!
Comment 9 Sebastian Sauer 2006-12-03 14:45:12 UTC
Hi Markus,

it works fine for me. If some if the money-values you defined got aligned to right, then they are interpreted as text. That happens for me e.g. if I put "12.000,12" into a cell while "12000,12" (without the additional dot) works as expected.

Anyway. I would suggest, that you create a new report and propably put a link to this report in + describe how to reproduce the problem. Seems to be easier to deal with an issue at a new report since this report is already quit long. A lot of thanks in advance!
Comment 10 Sebastian Sauer 2006-12-03 14:47:52 UTC
ups, I meaned;
If some of the money-values you defined got aligned to LEFT, then they are interpreted as text.
Comment 11 markus 2006-12-13 19:57:12 UTC
> If some of the money-values you defined got aligned to LEFT, then they are
> interpreted as text.

That's right. I can confirm this: I just made all the cells right bound and 
noticed that when I re-entered the numbers, they immediately got recognized 
as money values. 

Though, the cells should not come to a state where a certain bounding 
direction blocks the correct display. Whenever y field is formatted 
as "money", it should display the values directly as money.