[Libreoffice-commits] core.git: chart2/source

Eike Rathke erack at redhat.com
Mon Aug 10 06:20:50 PDT 2015


 chart2/source/controller/dialogs/DataBrowser.cxx |   29 +++++++------
 chart2/source/controller/dialogs/DataBrowser.hxx |    2 
 chart2/source/inc/DiagramHelper.hxx              |    1 
 chart2/source/tools/DiagramHelper.cxx            |   49 +++++++++++++++++++++++
 4 files changed, 66 insertions(+), 15 deletions(-)

New commits:
commit 711b34d590e659ed754f7c57b3b5eb12acfbbd78
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Aug 10 15:10:09 2015 +0200

    tdf#92997 obtain a date/time edit format according to field value
    
    Bloody workaround hack for the fact that Chart does not handle
    category/x-axis times internally and is not able to pass its own axis
    numberformat to its own databrowser editor.
    
    Change-Id: I016695ad0104366c0bb636b449a2014ade31aca3

diff --git a/chart2/source/controller/dialogs/DataBrowser.cxx b/chart2/source/controller/dialogs/DataBrowser.cxx
index 9af794b..3162e1d 100644
--- a/chart2/source/controller/dialogs/DataBrowser.cxx
+++ b/chart2/source/controller/dialogs/DataBrowser.cxx
@@ -674,13 +674,18 @@ OUString DataBrowser::GetCellText( long nRow, sal_uInt16 nColumnId ) const
                 aResult = aText;
             else if( aAny>>=fDouble )
             {
-                sal_Int32 nLabelColor;
-                sal_Int32 nDateNumberFormat = DiagramHelper::getDateNumberFormat( Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY) );
                 if( ! ::rtl::math::isNan( fDouble ) && m_spNumberFormatterWrapper.get() )
                 {
+                    // If a numberformat was available here we could directly
+                    // obtain the corresponding edit format in
+                    // getDateTimeInputNumberFormat() instead of doing the
+                    // guess work.
+                    sal_Int32 nNumberFormat = DiagramHelper::getDateTimeInputNumberFormat(
+                            Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY), fDouble );
+                    sal_Int32 nLabelColor;
                     bool bColorChanged = false;
                     aResult = m_spNumberFormatterWrapper->getFormattedString(
-                        nDateNumberFormat, fDouble, nLabelColor, bColorChanged );
+                        nNumberFormat, fDouble, nLabelColor, bColorChanged );
                 }
             }
         }
@@ -1096,18 +1101,14 @@ sal_uInt32 DataBrowser::GetNumberFormatKey( sal_Int32 nRow, sal_uInt16 nCol ) co
     return m_apDataBrowserModel->getNumberFormatKey( lcl_getColumnInData( nCol ), lcl_getRowInData( nRow ));
 }
 
-bool DataBrowser::isDateString( const OUString& aInputString, double& fOutDateValue )
+bool DataBrowser::isDateTimeString( const OUString& aInputString, double& fOutDateTimeValue )
 {
     sal_uInt32 nNumberFormat=0;
     SvNumberFormatter* pSvNumberFormatter = m_spNumberFormatterWrapper.get() ? m_spNumberFormatterWrapper->getSvNumberFormatter() : 0;
-    if( !aInputString.isEmpty() &&  pSvNumberFormatter && pSvNumberFormatter->IsNumberFormat( aInputString, nNumberFormat, fOutDateValue ) )
+    if( !aInputString.isEmpty() &&  pSvNumberFormatter && pSvNumberFormatter->IsNumberFormat( aInputString, nNumberFormat, fOutDateTimeValue ) )
     {
-        Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( m_xChartDoc, uno::UNO_QUERY );
-        Reference< util::XNumberFormats > xNumberFormats;
-        if( xNumberFormatsSupplier.is() )
-             xNumberFormats = Reference< util::XNumberFormats >( xNumberFormatsSupplier->getNumberFormats() );
-        if( DiagramHelper::isDateNumberFormat( nNumberFormat, xNumberFormats ) )
-            return true;
+        short nType = pSvNumberFormatter->GetType( nNumberFormat);
+        return (nType & util::NumberFormat::DATE) || (nType & util::NumberFormat::TIME);
     }
     return false;
 }
@@ -1149,10 +1150,10 @@ bool DataBrowser::SaveModified()
         case DataBrowserModel::TEXTORDATE:
         {
             OUString aText( m_aTextEditField->GetText() );
-            double fDateValue = 0.0;
+            double fValue = 0.0;
             bChangeValid = false;
-            if( isDateString( aText, fDateValue ) )
-                bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::makeAny( fDateValue ) );
+            if( isDateTimeString( aText, fValue ) )
+                bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::makeAny( fValue ) );
             if(!bChangeValid)
                 bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::makeAny( aText ) );
         }
diff --git a/chart2/source/controller/dialogs/DataBrowser.hxx b/chart2/source/controller/dialogs/DataBrowser.hxx
index 79fee95..514b697 100644
--- a/chart2/source/controller/dialogs/DataBrowser.hxx
+++ b/chart2/source/controller/dialogs/DataBrowser.hxx
@@ -86,7 +86,7 @@ public:
     */
     double GetCellNumber( long nRow, sal_uInt16 nColumnId ) const;
 
-    bool isDateString( const OUString& aInputString, double& fOutDateValue );
+    bool isDateTimeString( const OUString& aInputString, double& fOutDateTimeValue );
 
     // Window
     virtual void Resize() SAL_OVERRIDE;
diff --git a/chart2/source/inc/DiagramHelper.hxx b/chart2/source/inc/DiagramHelper.hxx
index c8bc8ed..2272d9a 100644
--- a/chart2/source/inc/DiagramHelper.hxx
+++ b/chart2/source/inc/DiagramHelper.hxx
@@ -244,6 +244,7 @@ public:
     static bool isSupportingDateAxis( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram );
     static bool isDateNumberFormat( sal_Int32 nNumberFormat, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& xNumberFormats );
     static sal_Int32 getDateNumberFormat( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier );
+    static sal_Int32 getDateTimeInputNumberFormat( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier, double fNumber );
 
     static sal_Int32 getPercentNumberFormat( const ::com::sun::star::uno::Reference<
                 ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier );
diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx
index 8023956..2b522b1 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -1190,6 +1190,55 @@ sal_Int32 DiagramHelper::getDateNumberFormat( const Reference< util::XNumberForm
     return nRet;
 }
 
+sal_Int32 DiagramHelper::getDateTimeInputNumberFormat( const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier, double fNumber )
+{
+    sal_Int32 nRet = 0;
+
+    // Get the most detailed date/time format according to fNumber.
+    NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
+    SvNumberFormatter* pNumFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
+    if (!pNumFormatter)
+        SAL_WARN("chart2", "DiagramHelper::getDateTimeInputNumberFormat - no SvNumberFormatter");
+    else
+    {
+        // Categorize the format according to the implementation of
+        // SvNumberFormatter::GetEditFormat(), making assumptions about what
+        // would be time only.
+        /* TODO: implement a method at SvNumberFormatter that does this and
+         * call instead, if Chart isn't able transport the proper format of the
+         * Axis, which of course would be much better.. */
+        short nType;
+        if (0.0 <= fNumber && fNumber < 1.0)
+        {
+            // Clearly a time.
+            nType = util::NumberFormat::TIME;
+            nRet = pNumFormatter->GetFormatIndex( NF_TIME_HHMM, LANGUAGE_SYSTEM);
+        }
+        else if (fabs( fNumber) * 24 < 0x7fff)
+        {
+            // Assuming time within 32k hours or 3.7 years.
+            nType = util::NumberFormat::TIME;
+            nRet = pNumFormatter->GetFormatIndex( NF_TIME_HH_MMSS, LANGUAGE_SYSTEM);
+        }
+        else if (rtl::math::approxFloor( fNumber) != fNumber)
+        {
+            // Date+Time.
+            nType = util::NumberFormat::DATETIME;
+            nRet = pNumFormatter->GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, LANGUAGE_SYSTEM);
+        }
+        else
+        {
+            // Date only.
+            nType = util::NumberFormat::DATE;
+            nRet = pNumFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM);
+        }
+
+        // Obtain the corresponding edit format.
+        nRet = pNumFormatter->GetEditFormat( fNumber, nRet, nType, LANGUAGE_SYSTEM, NULL);
+    }
+    return nRet;
+}
+
 sal_Int32 DiagramHelper::getPercentNumberFormat( const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier )
 {
     sal_Int32 nRet=-1;


More information about the Libreoffice-commits mailing list