summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-08-10 15:10:09 +0200
committerAndras Timar <andras.timar@collabora.com>2015-09-28 10:06:48 +0200
commit0cd78fa1f553d5d01ca9f28fb04213ed9b126397 (patch)
tree705f69d12dd70b34db4695f184f27cfb9be36b8c
parent8591c93f27736cf4fb810a43e2911060a0015094 (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. (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@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit 3af71f7e35876f12f182cc6ebc41981e6279a1fd)
-rw-r--r--chart2/source/controller/dialogs/DataBrowser.cxx34
-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, 70 insertions, 16 deletions
diff --git a/chart2/source/controller/dialogs/DataBrowser.cxx b/chart2/source/controller/dialogs/DataBrowser.cxx
index bf4f089e8c86..a27d4e79e42c 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>
@@ -683,12 +684,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
@@ -1118,18 +1126,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;
}
@@ -1171,10 +1175,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 f32363a50b95..88420e02debb 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 375aa70d51ca..5d73f8eb572b 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 dec53afaa768..9ea830b763c1 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -1189,6 +1189,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;