summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-08-10 15:10:09 +0200
committerNorbert Thiebaud <nthiebaud@gmail.com>2015-08-15 22:14:01 +0000
commitb541437c27be33f4c8ab778dde4e1fded58329d9 (patch)
treed418e1cf94feea6e07a3053e7e1aacf9fd0c0bf5
parentcbb45cdac9934aed4d4f98452ecd5a2b0bb05781 (diff)
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 (cherry picked from commit 711b34d590e659ed754f7c57b3b5eb12acfbbd78) Reviewed-on: https://gerrit.libreoffice.org/17627 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com>
-rw-r--r--chart2/source/controller/dialogs/DataBrowser.cxx29
-rw-r--r--chart2/source/controller/dialogs/DataBrowser.hxx2
-rw-r--r--chart2/source/inc/DiagramHelper.hxx1
-rw-r--r--chart2/source/tools/DiagramHelper.cxx49
4 files changed, 66 insertions, 15 deletions
diff --git a/chart2/source/controller/dialogs/DataBrowser.cxx b/chart2/source/controller/dialogs/DataBrowser.cxx
index e39213f77bf3..7ad3c383b12f 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 );
}
}
}
@@ -1101,18 +1106,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;
}
@@ -1154,10 +1155,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 948fa30dd949..69386a2908fb 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 c8bc8ed6c624..2272d9a20bc0 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 82dca03fcd16..5f1dd6e9cc67 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;