summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@canonical.com>2015-06-28 11:55:38 +0200
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2015-06-30 10:40:00 +0200
commitf828df4cad83760e2f722ec4b5e6e910c85f6598 (patch)
tree3040fa1b8109ac68f5969b7746ff97c60d6b8e5a
parent0685f902927a263fb724e47731654169dc87a3a6 (diff)
refactor getNumericalData,
- move some functions to be members, were sensible Change-Id: Ie94029f215102c62e96d314809ca78b079f2a6e6
-rw-r--r--sw/inc/unotbl.hxx13
-rw-r--r--sw/source/core/unocore/unochart.cxx35
-rw-r--r--sw/source/core/unocore/unotbl.cxx122
3 files changed, 74 insertions, 96 deletions
diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx
index 9a1d41cc84e4..c4820ce913a8 100644
--- a/sw/inc/unotbl.hxx
+++ b/sw/inc/unotbl.hxx
@@ -67,7 +67,6 @@ class SwXCell SAL_FINAL : public SwXCellBaseClass,
{
friend void sw_setString( SwXCell &rCell, const OUString &rText,
bool bKeepNumberFormat );
- friend double sw_getValue( SwXCell &rCell );
friend void sw_setValue( SwXCell &rCell, double nVal );
const SfxItemPropertySet* m_pPropSet;
@@ -117,8 +116,12 @@ public:
virtual OUString SAL_CALL getFormula( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL setFormula( const OUString& aFormula ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual double SAL_CALL getValue( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+ virtual double SAL_CALL getValue( ) const throw(::com::sun::star::uno::RuntimeException, std::exception)
+ { return const_cast<SwXCell*>(this)->getValue(); };
virtual void SAL_CALL setValue( double nValue ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual ::com::sun::star::table::CellContentType SAL_CALL getType( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+ virtual ::com::sun::star::table::CellContentType SAL_CALL getType( ) const throw(::com::sun::star::uno::RuntimeException, std::exception)
+ { return const_cast<SwXCell*>(this)->getType(); };
virtual sal_Int32 SAL_CALL getError( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
//XText
@@ -147,11 +150,11 @@ public:
virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
- SwTableBox* GetTableBox()const {return pBox;}
- static SwXCell* CreateXCell(SwFrameFormat* pTableFormat, SwTableBox* pBox, SwTable *pTable = 0 );
- SwTableBox* FindBox(SwTable* pTable, SwTableBox* pBox);
-
+ SwTableBox* GetTableBox() const { return pBox; }
+ static SwXCell* CreateXCell(SwFrameFormat* pTableFormat, SwTableBox* pBox, SwTable *pTable = nullptr );
+ SwTableBox* FindBox(SwTable* pTable, SwTableBox* pBox);
SwFrameFormat* GetFrameFormat() const { return const_cast<SwFrameFormat*>(static_cast<const SwFrameFormat*>(GetRegisteredIn())); }
+ double GetForcedNumericalValue() const;
};
class SwXTextTableRow SAL_FINAL : public cppu::WeakImplHelper
diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx
index 92456895ab72..9f5472a5e109 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -2200,26 +2200,23 @@ uno::Sequence< double > SAL_CALL SwChartDataSequence::getNumericalData()
SolarMutexGuard aGuard;
if (bDisposed)
throw lang::DisposedException();
-
- uno::Sequence< double > aRes;
SwFrameFormat* pTableFormat = GetFrameFormat();
- if(pTableFormat)
- {
- SwTable* pTable = SwTable::FindTable( pTableFormat );
- if(!pTable->IsTableComplex())
- {
- SwRangeDescriptor aDesc;
- if (FillRangeDescriptor( aDesc, GetCellRangeName( *pTableFormat, *pTableCrsr ) ))
- {
- SwXCellRange aRange(pTableCrsr, *pTableFormat, aDesc );
-
- // get numerical values and make an effort to return the
- // numerical value for text formatted cells
- aRange.GetDataSequence( 0, 0, &aRes, true );
- }
- }
- }
- return aRes;
+ if(!pTableFormat)
+ return {};
+ SwTable* pTable = SwTable::FindTable(pTableFormat);
+ if(pTable->IsTableComplex())
+ return {};
+ SwRangeDescriptor aDesc;
+ if(!FillRangeDescriptor(aDesc, GetCellRangeName(*pTableFormat,*pTableCrsr)))
+ return {};
+ auto vCells(SwXCellRange(pTableCrsr, *pTableFormat, aDesc).getCells());
+ uno::Sequence< double > vNumData(vCells.size());
+ std::transform(vCells.begin(),
+ vCells.end(),
+ vNumData.begin(),
+ [] (decltype(vCells)::value_type& xCell)
+ { return static_cast<SwXCell*>(xCell.get())->GetForcedNumericalValue(); });
+ return vNumData;
}
uno::Reference< util::XCloneable > SAL_CALL SwChartDataSequence::createClone( )
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index f178a59a41c3..32cfa1dcc61e 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -705,16 +705,6 @@ void sw_setString( SwXCell &rCell, const OUString &rText,
rCell.SwXText::setString(rText);
}
-/* non UNO function call to get value from SwXCell */
-double sw_getValue( SwXCell &rCell )
-{
- double fRet;
- if(rCell.IsValid() && !rCell.getString().isEmpty())
- fRet = rCell.pBox->GetFrameFormat()->GetTableBoxValue().GetValue();
- else
- ::rtl::math::setNan( &fRet );
- return fRet;
-}
/* non UNO function call to set value in SwXCell */
void sw_setValue( SwXCell &rCell, double nVal )
@@ -921,7 +911,12 @@ double SwXCell::getValue() throw( uno::RuntimeException, std::exception )
{
SolarMutexGuard aGuard;
// #i112652# a table cell may contain NaN as a value, do not filter that
- return sw_getValue( *this );
+ double fRet;
+ if(IsValid() && !getString().isEmpty())
+ fRet = pBox->GetFrameFormat()->GetTableBoxValue().GetValue();
+ else
+ ::rtl::math::setNan( &fRet );
+ return fRet;
}
void SwXCell::setValue(double rValue) throw( uno::RuntimeException, std::exception )
@@ -1190,6 +1185,47 @@ SwTableBox* SwXCell::FindBox(SwTable* pTable, SwTableBox* pBox2)
return nullptr;
}
+double SwXCell::GetForcedNumericalValue() const
+{
+ if(table::CellContentType_TEXT != getType())
+ return getValue();
+ // now we'll try to get a useful numerical value
+ // from the text in the cell...
+ sal_uInt32 nFIndex;
+ SvNumberFormatter* pNumFormatter(const_cast<SvNumberFormatter*>(GetDoc()->GetNumberFormatter()));
+ // look for SwTableBoxNumFormat value in parents as well
+ const SfxPoolItem* pItem;
+ auto pBoxFormat(GetTableBox()->GetFrameFormat());
+ SfxItemState eState = pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem);
+
+ if (eState == SfxItemState::SET)
+ {
+ // please note that the language of the numberformat
+ // is implicitly coded into the below value as well
+ nFIndex = static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue();
+
+ // since the current value indicates a text format but the call
+ // to 'IsNumberFormat' below won't work for text formats
+ // we need to get rid of the part that indicates the text format.
+ // According to ER this can be done like this:
+ nFIndex -= (nFIndex % SV_COUNTRY_LANGUAGE_OFFSET);
+ }
+ else
+ {
+ // system language is probably not the best possible choice
+ // but since we have to guess anyway (because the language of at
+ // the text is NOT the one used for the number format!)
+ // it is at least conform to what is used in
+ // SwTableShell::Execute when
+ // SID_ATTR_NUMBERFORMAT_VALUE is set...
+ LanguageType eLang = LANGUAGE_SYSTEM;
+ nFIndex = pNumFormatter->GetStandardIndex( eLang );
+ }
+ double fTmp;
+ pNumFormatter->IsNumberFormat(const_cast<SwXCell*>(this)->getString(), nFIndex, fTmp);
+ return fTmp;
+}
+
OUString SwXCell::getImplementationName() throw( uno::RuntimeException, std::exception )
{ return OUString("SwXCell"); }
@@ -3485,8 +3521,7 @@ void SwXCellRange::GetDataSequence(
const size_t nSize = static_cast<size_t>(nRowCount) * static_cast<size_t>(nColCount);
OUString* pTextData(nullptr);
- double* pDblData(nullptr);
- if (pAnySeq)
+ if (pAnySeq || pDblSeq)
{
assert(false);
}
@@ -3495,11 +3530,6 @@ void SwXCellRange::GetDataSequence(
pTextSeq->realloc(nSize);
pTextData = pTextSeq->getArray();
}
- else if (pDblSeq)
- {
- pDblSeq->realloc(nSize);
- pDblData = pDblSeq->getArray();
- }
else
{
OSL_FAIL( "argument missing" );
@@ -3527,59 +3557,7 @@ void SwXCellRange::GetDataSequence(
SwTableBox * pBox = pXCell ? pXCell->GetTableBox() : 0;
if(!pBox)
throw uno::RuntimeException();
- if (pTextData)
- pTextData[nDtaCnt++] = lcl_getString(*pXCell);
- else
- {
- double fVal = fNan;
- if (!bForceNumberResults || table::CellContentType_TEXT != pXCell->getType())
- fVal = sw_getValue(*pXCell);
- else
- {
- OSL_ENSURE( table::CellContentType_TEXT == pXCell->getType(),
- "this branch of 'if' is only for text formatted cells" );
-
- // now we'll try to get a useful numerical value
- // from the text in the cell...
-
- sal_uInt32 nFIndex;
- SvNumberFormatter* pNumFormatter = m_pTableCrsr->GetDoc()->GetNumberFormatter();
-
- // look for SwTableBoxNumFormat value in parents as well
- const SfxPoolItem* pItem;
- SwFrameFormat *pBoxFormat = pXCell->GetTableBox()->GetFrameFormat();
- SfxItemState eState = pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem);
-
- if (eState == SfxItemState::SET)
- {
- // please note that the language of the numberformat
- // is implicitly coded into the below value as well
- nFIndex = static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue();
-
- // since the current value indicates a text format but the call
- // to 'IsNumberFormat' below won't work for text formats
- // we need to get rid of the part that indicates the text format.
- // According to ER this can be done like this:
- nFIndex -= (nFIndex % SV_COUNTRY_LANGUAGE_OFFSET);
- }
- else
- {
- // system language is probably not the best possible choice
- // but since we have to guess anyway (because the language of at
- // the text is NOT the one used for the number format!)
- // it is at least conform to what is used in
- // SwTableShell::Execute when
- // SID_ATTR_NUMBERFORMAT_VALUE is set...
- LanguageType eLang = LANGUAGE_SYSTEM;
- nFIndex = pNumFormatter->GetStandardIndex( eLang );
- }
-
- double fTmp;
- if (pNumFormatter->IsNumberFormat( lcl_getString(*pXCell), nFIndex, fTmp ))
- fVal = fTmp;
- }
- pDblData[nDtaCnt++] = fVal;
- }
+ pTextData[nDtaCnt++] = lcl_getString(*pXCell);
}
}
assert(nDtaCnt == nSize);
@@ -3611,7 +3589,7 @@ uno::Sequence< uno::Sequence< uno::Any > > SAL_CALL SwXCellRange::getDataArray()
// check if table box value item is set
SwFrameFormat* pBoxFormat(pBox->GetFrameFormat());
const bool bIsNum = pBoxFormat->GetItemState(RES_BOXATR_VALUE, false) == SfxItemState::SET;
- rCellAny = bIsNum ? uno::makeAny(sw_getValue(*pCell)) : uno::makeAny(lcl_getString(*pCell));
+ rCellAny = bIsNum ? uno::makeAny(pCell->getValue()) : uno::makeAny(lcl_getString(*pCell));
++pCurrentCell;
}
}