[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - chart2/source
Eike Rathke
erack at redhat.com
Tue Aug 25 08:14:46 PDT 2015
chart2/source/controller/dialogs/DataBrowser.cxx | 34 ++++++++-------
chart2/source/controller/dialogs/DataBrowser.hxx | 2
chart2/source/inc/DiagramHelper.hxx | 1
chart2/source/tools/DiagramHelper.cxx | 49 +++++++++++++++++++++++
4 files changed, 70 insertions(+), 16 deletions(-)
New commits:
commit ece62a1610fdffb9177a311c60abdbacf454e90d
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.
(cherry picked from commit 711b34d590e659ed754f7c57b3b5eb12acfbbd78)
Conflicts:
chart2/source/controller/dialogs/DataBrowser.cxx
Change-Id: I016695ad0104366c0bb636b449a2014ade31aca3
Reviewed-on: https://gerrit.libreoffice.org/17630
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/chart2/source/controller/dialogs/DataBrowser.cxx b/chart2/source/controller/dialogs/DataBrowser.cxx
index c62285b..c462e4f 100644
--- a/chart2/source/controller/dialogs/DataBrowser.cxx
+++ b/chart2/source/controller/dialogs/DataBrowser.cxx
@@ -48,6 +48,7 @@
#include <com/sun/star/container/XIndexReplace.hpp>
#include <com/sun/star/util/XNumberFormats.hpp>
+#include <com/sun/star/util/NumberFormat.hpp>
#include <algorithm>
#include <functional>
@@ -667,12 +668,19 @@ OUString DataBrowser::GetCellText( long nRow, sal_uInt16 nColumnId ) const
aResult = aText;
else if( aAny>>=fDouble )
{
- sal_Int32 nLabelColor;
- bool bColorChanged = false;
- 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 );
+ }
}
}
else
@@ -1092,18 +1100,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;
}
@@ -1145,10 +1149,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 f4c82b3..72baa36 100644
--- a/chart2/source/controller/dialogs/DataBrowser.hxx
+++ b/chart2/source/controller/dialogs/DataBrowser.hxx
@@ -85,7 +85,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 375aa70..5d73f8e 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 765937b..31485bd 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