diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-03-31 11:35:05 +0200 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-04-01 13:59:33 +0200 |
commit | ef13ab6f6dfddbe2301a24840d49c086cba8a604 (patch) | |
tree | 91d6681a7d99eb0d861efd27dc16a1a32201b662 | |
parent | bd00847f1dcf9219410c5e6a74da8aa12fddb820 (diff) |
also refactor description setter
Change-Id: I69deac6d830f63aea94f3512ab4156217fbc7b27
-rw-r--r-- | sw/inc/unotbl.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/unocore/unotbl.cxx | 51 |
2 files changed, 20 insertions, 32 deletions
diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx index 2f4876d0fdaa..ce6048e28285 100644 --- a/sw/inc/unotbl.hxx +++ b/sw/inc/unotbl.hxx @@ -467,6 +467,7 @@ class SwXCellRange : public cppu::WeakImplHelper7 bool m_bFirstColumnAsLabel; std::tuple<sal_uInt32, sal_uInt32, sal_uInt32, sal_uInt32> getLabelCoordinates(bool bRow); css::uno::Sequence<OUString> getLabelDescriptions(bool bRow); + void setLabelDescriptions(const css::uno::Sequence<OUString>& rDesc, bool bRow); public: SwXCellRange(SwUnoCrsr* pCrsr, SwFrmFmt& rFrmFmt, SwRangeDescriptor& rDesc); diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index fe6f27f198a3..c9e3a8120191 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -4006,44 +4006,31 @@ uno::Sequence<OUString> SwXCellRange::getColumnDescriptions(void) throw(uno::RuntimeException, std::exception) { return getLabelDescriptions(false); } -void SwXCellRange::setRowDescriptions(const uno::Sequence<OUString>& rRowDesc) - throw(uno::RuntimeException, std::exception) +void SwXCellRange::setLabelDescriptions(const uno::Sequence<OUString>& rDesc, bool bRow) { SolarMutexGuard aGuard; lcl_EnsureCoreConnected(GetFrmFmt(), static_cast<cppu::OWeakObject*>(this)); - const sal_uInt16 nRowCount = getRowCount(); - if(!m_bFirstColumnAsLabel) - return; // if there are no labels we cannot set descriptions - const OUString* pArray = rRowDesc.getConstArray(); - const sal_uInt16 nStart = m_bFirstColumnAsLabel ? 1 : 0; - if(!nRowCount || rRowDesc.getLength() + nStart < nRowCount) - throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this)); - for(sal_uInt16 i = nStart; i < nRowCount; i++) - { - uno::Reference<text::XText> xCell(getCellByPosition(0, i), uno::UNO_QUERY_THROW); - xCell->setString(pArray[i-nStart]); - } -} -void SwXCellRange::setColumnDescriptions(const uno::Sequence<OUString>& rColumnDesc) - throw(uno::RuntimeException, std::exception) -{ - SolarMutexGuard aGuard; - lcl_EnsureCoreConnected(GetFrmFmt(), static_cast<cppu::OWeakObject*>(this)); - const sal_uInt16 nColumnCount = getColumnCount(); - if(!m_bFirstRowAsLabel) + if(!(bRow ? m_bFirstColumnAsLabel : m_bFirstRowAsLabel)) return; // if there are no labels we cannot set descriptions - const sal_uInt16 nStart = m_bFirstRowAsLabel ? 1 : 0; - if(!nColumnCount || rColumnDesc.getLength() + nStart < nColumnCount) - throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this)); - const OUString* pArray = rColumnDesc.getConstArray(); - for(sal_uInt16 i = nStart; i < nColumnCount; i++) - { - uno::Reference<text::XText> xCell(getCellByPosition(i, 0), uno::UNO_QUERY_THROW); - xCell->setString(pArray[i-nStart]); - } + sal_uInt32 nLeft, nTop, nRight, nBottom; + std::tie(nLeft, nTop, nRight, nBottom) = getLabelCoordinates(bRow); + if(!nRight && !nBottom) + throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(this)); + auto xLabelRange(getCellRangeByPosition(nLeft, nTop, nRight, nBottom)); + auto vCells(static_cast<SwXCellRange*>(xLabelRange.get())->getCells()); + if(rDesc.getLength() != vCells.size()) + throw uno::RuntimeException("Too few or too many descriptions", static_cast<cppu::OWeakObject*>(this)); + auto pDescIterator(rDesc.begin()); + for(auto xCell : vCells) + uno::Reference<text::XText>(xCell, uno::UNO_QUERY_THROW)->setString(*pDescIterator++); } +void SwXCellRange::setRowDescriptions(const uno::Sequence<OUString>& rRowDesc) + throw(uno::RuntimeException, std::exception) +{ setLabelDescriptions(rRowDesc, true); } - +void SwXCellRange::setColumnDescriptions(const uno::Sequence<OUString>& rColumnDesc) + throw(uno::RuntimeException, std::exception) +{ setLabelDescriptions(rColumnDesc, false); } void SAL_CALL SwXCellRange::addChartDataChangeEventListener( const uno::Reference<chart::XChartDataChangeEventListener> & xListener) |