Kaydet (Commit) b541437c authored tarafından Eike Rathke's avatar Eike Rathke Kaydeden (comit) Norbert Thiebaud

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 711b34d5)
Reviewed-on: https://gerrit.libreoffice.org/17627Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNorbert Thiebaud <nthiebaud@gmail.com>
üst cbb45cda
......@@ -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 ) );
}
......
......@@ -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;
......
......@@ -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 );
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment