diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 0d9a797abaab..b259689e391a 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -15000,7 +15000,6 @@ xmloff/source/chart/SchXMLRegressionCurveObjectContext.hxx xmloff/source/chart/SchXMLSeries2Context.cxx xmloff/source/chart/SchXMLSeries2Context.hxx xmloff/source/chart/SchXMLSeriesHelper.cxx -xmloff/source/chart/SchXMLTableContext.cxx xmloff/source/chart/SchXMLTableContext.hxx xmloff/source/chart/SchXMLTextListContext.cxx xmloff/source/chart/SchXMLTextListContext.hxx diff --git a/xmloff/source/chart/SchXMLTableContext.cxx b/xmloff/source/chart/SchXMLTableContext.cxx index 76604ff473b9..060cd0a7aa97 100644 --- a/xmloff/source/chart/SchXMLTableContext.cxx +++ b/xmloff/source/chart/SchXMLTableContext.cxx @@ -53,27 +53,25 @@ using ::com::sun::star::uno::Reference; namespace { - constexpr OUString aCategoriesRange = u"categories"_ustr; -typedef ::std::multimap< OUString, OUString > - lcl_tOriginalRangeToInternalRangeMap; +typedef ::std::multimap lcl_tOriginalRangeToInternalRangeMap; struct lcl_ApplyCellToData { - explicit lcl_ApplyCellToData( Sequence< double > & rOutData ) : - m_rData( rOutData ), - m_nIndex( 0 ), - m_nSize( rOutData.getLength()) + explicit lcl_ApplyCellToData(Sequence& rOutData) + : m_rData(rOutData) + , m_nIndex(0) + , m_nSize(rOutData.getLength()) { } - void operator() ( const SchXMLCell & rCell ) + void operator()(const SchXMLCell& rCell) { - if( m_nIndex < m_nSize ) + if (m_nIndex < m_nSize) { auto pData = m_rData.getArray(); - if( rCell.eType == SCH_CELL_TYPE_FLOAT ) + if (rCell.eType == SCH_CELL_TYPE_FLOAT) pData[m_nIndex] = rCell.fValue; else pData[m_nIndex] = std::numeric_limits::quiet_NaN(); @@ -81,69 +79,67 @@ struct lcl_ApplyCellToData ++m_nIndex; } - sal_Int32 getCurrentIndex() const - { - return m_nIndex; - } + sal_Int32 getCurrentIndex() const { return m_nIndex; } private: - Sequence< double > & m_rData; + Sequence& m_rData; sal_Int32 m_nIndex; sal_Int32 m_nSize; }; -void lcl_fillRangeMapping( - const SchXMLTable & rTable, - lcl_tOriginalRangeToInternalRangeMap & rOutRangeMap, - chart::ChartDataRowSource eDataRowSource ) +void lcl_fillRangeMapping(const SchXMLTable& rTable, + lcl_tOriginalRangeToInternalRangeMap& rOutRangeMap, + chart::ChartDataRowSource eDataRowSource) { - sal_Int32 nRowOffset = ( rTable.bHasHeaderRow ? 1 : 0 ); - sal_Int32 nColOffset = ( rTable.bHasHeaderColumn ? 1 : 0 ); + sal_Int32 nRowOffset = (rTable.bHasHeaderRow ? 1 : 0); + sal_Int32 nColOffset = (rTable.bHasHeaderColumn ? 1 : 0); const OUString lcl_aCategoriesRange(aCategoriesRange); static constexpr OUString lcl_aLabelPrefix(u"label "_ustr); // Fill range mapping - const size_t nTableRowCount( rTable.aData.size()); - for( size_t nRow = 0; nRow < nTableRowCount; ++nRow ) + const size_t nTableRowCount(rTable.aData.size()); + for (size_t nRow = 0; nRow < nTableRowCount; ++nRow) { - const ::std::vector< SchXMLCell > & rRow( rTable.aData[nRow] ); - const size_t nTableColCount( rRow.size()); - for( size_t nCol = 0; nCol < nTableColCount; ++nCol ) + const ::std::vector& rRow(rTable.aData[nRow]); + const size_t nTableColCount(rRow.size()); + for (size_t nCol = 0; nCol < nTableColCount; ++nCol) { - const OUString aRangeId( rRow[nCol].aRangeId ); - if( !aRangeId.isEmpty()) + const OUString aRangeId(rRow[nCol].aRangeId); + if (!aRangeId.isEmpty()) { - if( eDataRowSource == chart::ChartDataRowSource_COLUMNS ) + if (eDataRowSource == chart::ChartDataRowSource_COLUMNS) { - if( nCol == 0 && rTable.bHasHeaderColumn ) + if (nCol == 0 && rTable.bHasHeaderColumn) { - SAL_WARN_IF( static_cast< sal_Int32 >( nRow ) != nRowOffset, "xmloff.chart", "nRow != nRowOffset" ); + SAL_WARN_IF(static_cast(nRow) != nRowOffset, "xmloff.chart", + "nRow != nRowOffset"); rOutRangeMap.emplace(aRangeId, lcl_aCategoriesRange); } else { - OUString aColNumStr = OUString::number( nCol - nColOffset); - if( nRow == 0 && rTable.bHasHeaderRow ) - rOutRangeMap.emplace( aRangeId, lcl_aLabelPrefix + aColNumStr ); + OUString aColNumStr = OUString::number(nCol - nColOffset); + if (nRow == 0 && rTable.bHasHeaderRow) + rOutRangeMap.emplace(aRangeId, lcl_aLabelPrefix + aColNumStr); else - rOutRangeMap.emplace( aRangeId, aColNumStr ); + rOutRangeMap.emplace(aRangeId, aColNumStr); } } else // eDataRowSource == chart::ChartDataRowSource_ROWS { - if( nRow == 0 && rTable.bHasHeaderRow ) + if (nRow == 0 && rTable.bHasHeaderRow) { - SAL_WARN_IF( static_cast< sal_Int32 >( nCol ) != nColOffset, "xmloff.chart", "nCol != nColOffset" ); - rOutRangeMap.emplace( aRangeId, lcl_aCategoriesRange ); + SAL_WARN_IF(static_cast(nCol) != nColOffset, "xmloff.chart", + "nCol != nColOffset"); + rOutRangeMap.emplace(aRangeId, lcl_aCategoriesRange); } else { - OUString aRowNumStr = OUString::number( nRow - nRowOffset); - if( nCol == 0 && rTable.bHasHeaderColumn ) - rOutRangeMap.emplace( aRangeId, lcl_aLabelPrefix + aRowNumStr ); + OUString aRowNumStr = OUString::number(nRow - nRowOffset); + if (nCol == 0 && rTable.bHasHeaderColumn) + rOutRangeMap.emplace(aRangeId, lcl_aLabelPrefix + aRowNumStr); else - rOutRangeMap.emplace( aRangeId, aRowNumStr ); + rOutRangeMap.emplace(aRangeId, aRowNumStr); } } } @@ -151,53 +147,45 @@ void lcl_fillRangeMapping( } } -Reference< chart2::data::XDataSequence > - lcl_reassignDataSequence( - const Reference< chart2::data::XDataSequence > & xSequence, - const Reference< chart2::data::XDataProvider > & xDataProvider, - lcl_tOriginalRangeToInternalRangeMap & rRangeMap, - const OUString & rRange ) +Reference +lcl_reassignDataSequence(const Reference& xSequence, + const Reference& xDataProvider, + lcl_tOriginalRangeToInternalRangeMap& rRangeMap, const OUString& rRange) { - Reference< chart2::data::XDataSequence > xResult( xSequence ); - lcl_tOriginalRangeToInternalRangeMap::iterator aIt( rRangeMap.find( rRange )); - if( aIt != rRangeMap.end()) + Reference xResult(xSequence); + lcl_tOriginalRangeToInternalRangeMap::iterator aIt(rRangeMap.find(rRange)); + if (aIt != rRangeMap.end()) { // set sequence with correct data - xResult.set( xDataProvider->createDataSequenceByRangeRepresentation( aIt->second )); + xResult.set(xDataProvider->createDataSequenceByRangeRepresentation(aIt->second)); // remove translation, because it was used - rRangeMap.erase( aIt ); + rRangeMap.erase(aIt); } return xResult; } -bool lcl_mapContainsRange( - lcl_tOriginalRangeToInternalRangeMap & rRangeMap, - const OUString & rRange ) +bool lcl_mapContainsRange(lcl_tOriginalRangeToInternalRangeMap& rRangeMap, const OUString& rRange) { - lcl_tOriginalRangeToInternalRangeMap::iterator aIt( rRangeMap.find( rRange )); - return ( aIt != rRangeMap.end()); + lcl_tOriginalRangeToInternalRangeMap::iterator aIt(rRangeMap.find(rRange)); + return (aIt != rRangeMap.end()); } -bool lcl_tableOfRangeMatches( - std::u16string_view rRange, - std::u16string_view rTableName ) +bool lcl_tableOfRangeMatches(std::u16string_view rRange, std::u16string_view rTableName) { // both strings are non-empty and the table name is part of the range - return ( !rRange.empty() && - !rTableName.empty() && - (rRange.find( rTableName ) != std::u16string_view::npos )); + return (!rRange.empty() && !rTableName.empty() + && (rRange.find(rTableName) != std::u16string_view::npos)); } } // anonymous namespace // class SchXMLTableContext -SchXMLTableContext::SchXMLTableContext( SvXMLImport& rImport, - SchXMLTable& aTable ) : - SvXMLImportContext( rImport ), - mrTable( aTable ), - mbHasRowPermutation( false ), - mbHasColumnPermutation( false ) +SchXMLTableContext::SchXMLTableContext(SvXMLImport& rImport, SchXMLTable& aTable) + : SvXMLImportContext(rImport) + , mrTable(aTable) + , mbHasRowPermutation(false) + , mbHasColumnPermutation(false) { mrTable.nColumnIndex = -1; mrTable.nMaxColumnIndex = -1; @@ -205,38 +193,35 @@ SchXMLTableContext::SchXMLTableContext( SvXMLImport& rImport, mrTable.aData.clear(); } -SchXMLTableContext::~SchXMLTableContext() -{ -} +SchXMLTableContext::~SchXMLTableContext() {} -css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) +css::uno::Reference SchXMLTableContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference&) { SvXMLImportContext* pContext = nullptr; - switch(nElement) + switch (nElement) { case XML_ELEMENT(TABLE, XML_TABLE_HEADER_COLUMNS): mrTable.bHasHeaderColumn = true; [[fallthrough]]; case XML_ELEMENT(TABLE, XML_TABLE_COLUMNS): - pContext = new SchXMLTableColumnsContext( GetImport(), mrTable ); + pContext = new SchXMLTableColumnsContext(GetImport(), mrTable); break; case XML_ELEMENT(TABLE, XML_TABLE_COLUMN): - pContext = new SchXMLTableColumnContext( GetImport(), mrTable ); + pContext = new SchXMLTableColumnContext(GetImport(), mrTable); break; case XML_ELEMENT(TABLE, XML_TABLE_HEADER_ROWS): mrTable.bHasHeaderRow = true; [[fallthrough]]; case XML_ELEMENT(TABLE, XML_TABLE_ROWS): - pContext = new SchXMLTableRowsContext( GetImport(), mrTable ); + pContext = new SchXMLTableRowsContext(GetImport(), mrTable); break; case XML_ELEMENT(TABLE, XML_TABLE_ROW): - pContext = new SchXMLTableRowContext( GetImport(), mrTable ); + pContext = new SchXMLTableRowContext(GetImport(), mrTable); break; default: XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); @@ -245,20 +230,20 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableContext::cr return pContext; } -void SchXMLTableContext::startFastElement (sal_Int32 /*nElement*/, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) +void SchXMLTableContext::startFastElement( + sal_Int32 /*nElement*/, const css::uno::Reference& xAttrList) { // get table-name - for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) + for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList)) { - switch(aIter.getToken()) + switch (aIter.getToken()) { case XML_ELEMENT(TABLE, XML_NAME): mrTable.aTableNameOfFile = aIter.toString(); break; case XML_ELEMENT(TABLE, XML_PROTECTED): - if ( IsXMLToken( aIter, XML_TRUE ) ) + if (IsXMLToken(aIter, XML_TRUE)) { mrTable.bProtected = true; } @@ -269,133 +254,139 @@ void SchXMLTableContext::startFastElement (sal_Int32 /*nElement*/, } } -void SchXMLTableContext::endFastElement(sal_Int32 ) +void SchXMLTableContext::endFastElement(sal_Int32) { - if( mbHasColumnPermutation ) + if (mbHasColumnPermutation) { - SAL_WARN_IF( mbHasRowPermutation, "xmloff.chart", "mbHasColumnPermutation is true" ); - const auto & aPermutation( maColumnPermutation ); - SAL_WARN_IF( !aPermutation.hasElements(), "xmloff.chart", "aPermutation is NULL"); - if( !aPermutation.hasElements()) + SAL_WARN_IF(mbHasRowPermutation, "xmloff.chart", "mbHasColumnPermutation is true"); + const auto& aPermutation(maColumnPermutation); + SAL_WARN_IF(!aPermutation.hasElements(), "xmloff.chart", "aPermutation is NULL"); + if (!aPermutation.hasElements()) return; // permute the values of all rows according to aPermutation - for( auto& rRow : mrTable.aData ) + for (auto& rRow : mrTable.aData) { bool bModified = false; - ::std::vector< SchXMLCell > aModifiedRow; + ::std::vector aModifiedRow; const size_t nPermSize = aPermutation.size(); - SAL_WARN_IF( static_cast< sal_Int32 >( nPermSize ) - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())), "xmloff.chart", "nPermSize - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())"); + SAL_WARN_IF( + static_cast(nPermSize) - 1 + != *(::std::max_element(aPermutation.begin(), aPermutation.end())), + "xmloff.chart", + "nPermSize - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())"); const size_t nRowSize = rRow.size(); - const size_t nDestSize = ::std::min( nPermSize, nRowSize ); - for( size_t nDestinationIndex = 0; nDestinationIndex < nDestSize; ++nDestinationIndex ) + const size_t nDestSize = ::std::min(nPermSize, nRowSize); + for (size_t nDestinationIndex = 0; nDestinationIndex < nDestSize; ++nDestinationIndex) { - const size_t nSourceIndex = static_cast< size_t >( aPermutation[ nDestinationIndex ] ); - if( nSourceIndex != nDestinationIndex && - nSourceIndex < nRowSize ) + const size_t nSourceIndex = static_cast(aPermutation[nDestinationIndex]); + if (nSourceIndex != nDestinationIndex && nSourceIndex < nRowSize) { // copy original on first real permutation - if( !bModified ) + if (!bModified) { - SAL_WARN_IF( !aModifiedRow.empty(), "xmloff.chart", "aModifiedRow is NOT NULL"); - aModifiedRow.insert( aModifiedRow.end(), rRow.begin(), rRow.end() ); - SAL_WARN_IF( aModifiedRow.empty(), "xmloff.chart", "aModifiedRow is NULL"); + SAL_WARN_IF(!aModifiedRow.empty(), "xmloff.chart", + "aModifiedRow is NOT NULL"); + aModifiedRow.insert(aModifiedRow.end(), rRow.begin(), rRow.end()); + SAL_WARN_IF(aModifiedRow.empty(), "xmloff.chart", "aModifiedRow is NULL"); } - SAL_WARN_IF( nDestinationIndex >= aModifiedRow.size(), "xmloff.chart", "nDestinationIndex >= aModifiedRow.size()"); - aModifiedRow[ nDestinationIndex ] = rRow[ nSourceIndex ]; + SAL_WARN_IF(nDestinationIndex >= aModifiedRow.size(), "xmloff.chart", + "nDestinationIndex >= aModifiedRow.size()"); + aModifiedRow[nDestinationIndex] = rRow[nSourceIndex]; bModified = true; } } // copy back - if( bModified ) - ::std::copy( aModifiedRow.begin(), aModifiedRow.end(), rRow.begin()); + if (bModified) + ::std::copy(aModifiedRow.begin(), aModifiedRow.end(), rRow.begin()); } } - else if( mbHasRowPermutation ) + else if (mbHasRowPermutation) { - const auto & aPermutation( maRowPermutation ); - SAL_WARN_IF( !aPermutation.hasElements(), "xmloff.chart", "aPermutation is NULL"); - if( !aPermutation.hasElements()) + const auto& aPermutation(maRowPermutation); + SAL_WARN_IF(!aPermutation.hasElements(), "xmloff.chart", "aPermutation is NULL"); + if (!aPermutation.hasElements()) return; bool bModified = false; const size_t nPermSize = aPermutation.size(); - SAL_WARN_IF( static_cast< sal_Int32 >( nPermSize ) - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())), "xmloff.chart", "nPermSize - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())"); + SAL_WARN_IF( + static_cast(nPermSize) - 1 + != *(::std::max_element(aPermutation.begin(), aPermutation.end())), + "xmloff.chart", + "nPermSize - 1 != *(::std::max_element( aPermutation.begin(), aPermutation.end())"); const size_t nTableRowCount = mrTable.aData.size(); - const size_t nDestSize = ::std::min( nPermSize, nTableRowCount ); - ::std::vector< ::std::vector< SchXMLCell > > aDestination; - for( size_t nDestinationIndex = 0; nDestinationIndex < nDestSize; ++nDestinationIndex ) + const size_t nDestSize = ::std::min(nPermSize, nTableRowCount); + ::std::vector<::std::vector> aDestination; + for (size_t nDestinationIndex = 0; nDestinationIndex < nDestSize; ++nDestinationIndex) { - const size_t nSourceIndex = static_cast< size_t >( aPermutation[ nDestinationIndex ] ); - if( nSourceIndex != nDestinationIndex && - nSourceIndex < nTableRowCount ) + const size_t nSourceIndex = static_cast(aPermutation[nDestinationIndex]); + if (nSourceIndex != nDestinationIndex && nSourceIndex < nTableRowCount) { // copy original on first real permutation - if( !bModified ) + if (!bModified) { - SAL_WARN_IF( !aDestination.empty(), "xmloff.chart", "aDestination is NOT NULL"); - aDestination.insert( aDestination.end(), mrTable.aData.begin(), mrTable.aData.end()); - SAL_WARN_IF( aDestination.empty(), "xmloff.chart", "aDestination is NULL"); + SAL_WARN_IF(!aDestination.empty(), "xmloff.chart", "aDestination is NOT NULL"); + aDestination.insert(aDestination.end(), mrTable.aData.begin(), + mrTable.aData.end()); + SAL_WARN_IF(aDestination.empty(), "xmloff.chart", "aDestination is NULL"); } - SAL_WARN_IF( nDestinationIndex >= aDestination.size(), "xmloff.chart", "nDestinationIndex >= aDestination.size()"); - aDestination[ nDestinationIndex ] = mrTable.aData[ nSourceIndex ]; + SAL_WARN_IF(nDestinationIndex >= aDestination.size(), "xmloff.chart", + "nDestinationIndex >= aDestination.size()"); + aDestination[nDestinationIndex] = mrTable.aData[nSourceIndex]; bModified = true; } } - if( bModified ) + if (bModified) { // copy back - ::std::copy( aDestination.begin(), aDestination.end(), mrTable.aData.begin()); + ::std::copy(aDestination.begin(), aDestination.end(), mrTable.aData.begin()); } } } -void SchXMLTableContext::setRowPermutation( const uno::Sequence< sal_Int32 > & rPermutation ) +void SchXMLTableContext::setRowPermutation(const uno::Sequence& rPermutation) { maRowPermutation = rPermutation; mbHasRowPermutation = rPermutation.hasElements(); - if( mbHasRowPermutation && mbHasColumnPermutation ) + if (mbHasRowPermutation && mbHasColumnPermutation) { mbHasColumnPermutation = false; - maColumnPermutation.realloc( 0 ); + maColumnPermutation.realloc(0); } } -void SchXMLTableContext::setColumnPermutation( const uno::Sequence< sal_Int32 > & rPermutation ) +void SchXMLTableContext::setColumnPermutation(const uno::Sequence& rPermutation) { maColumnPermutation = rPermutation; mbHasColumnPermutation = rPermutation.hasElements(); - if( mbHasColumnPermutation && mbHasRowPermutation ) + if (mbHasColumnPermutation && mbHasRowPermutation) { mbHasRowPermutation = false; - maRowPermutation.realloc( 0 ); + maRowPermutation.realloc(0); } } // classes for columns // class SchXMLTableColumnsContext -SchXMLTableColumnsContext::SchXMLTableColumnsContext( - SvXMLImport& rImport, - SchXMLTable& aTable ) : - SvXMLImportContext( rImport ), - mrTable( aTable ) +SchXMLTableColumnsContext::SchXMLTableColumnsContext(SvXMLImport& rImport, SchXMLTable& aTable) + : SvXMLImportContext(rImport) + , mrTable(aTable) { } -SchXMLTableColumnsContext::~SchXMLTableColumnsContext() -{ -} +SchXMLTableColumnsContext::~SchXMLTableColumnsContext() {} -css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableColumnsContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) +css::uno::Reference +SchXMLTableColumnsContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference&) { SvXMLImportContext* pContext = nullptr; - if( nElement == XML_ELEMENT(TABLE, XML_TABLE_COLUMN) ) - pContext = new SchXMLTableColumnContext( GetImport(), mrTable ); + if (nElement == XML_ELEMENT(TABLE, XML_TABLE_COLUMN)) + pContext = new SchXMLTableColumnContext(GetImport(), mrTable); else XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); @@ -403,35 +394,33 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableColumnsCont } // class SchXMLTableColumnContext -SchXMLTableColumnContext::SchXMLTableColumnContext( - SvXMLImport& rImport, - SchXMLTable& aTable ) : - SvXMLImportContext( rImport ), - mrTable( aTable ) +SchXMLTableColumnContext::SchXMLTableColumnContext(SvXMLImport& rImport, SchXMLTable& aTable) + : SvXMLImportContext(rImport) + , mrTable(aTable) { } -void SchXMLTableColumnContext::startFastElement (sal_Int32 /*nElement*/, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) +void SchXMLTableColumnContext::startFastElement( + sal_Int32 /*nElement*/, const css::uno::Reference& xAttrList) { // get number-columns-repeated attribute sal_Int32 nRepeated = 1; bool bHidden = false; - for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) + for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList)) { - switch(aIter.getToken()) + switch (aIter.getToken()) { case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED): { - if( !aIter.isEmpty()) + if (!aIter.isEmpty()) nRepeated = aIter.toInt32(); break; } case XML_ELEMENT(TABLE, XML_VISIBILITY): { OUString aVisibility = aIter.toString(); - bHidden = aVisibility == GetXMLToken( XML_COLLAPSE ); + bHidden = aVisibility == GetXMLToken(XML_COLLAPSE); break; } default: @@ -443,45 +432,39 @@ void SchXMLTableColumnContext::startFastElement (sal_Int32 /*nElement*/, sal_Int32 nNewCount = nOldCount + nRepeated; mrTable.nNumberOfColsEstimate = nNewCount; - if( bHidden ) + if (bHidden) { //i91578 display of hidden values (copy paste scenario; use hidden flag during migration to locale table upon paste ) - sal_Int32 nColOffset = ( mrTable.bHasHeaderColumn ? 1 : 0 ); - for( sal_Int32 nN = nOldCount; nN=0 ) + sal_Int32 nHiddenColumnIndex = nN - nColOffset; + if (nHiddenColumnIndex >= 0) mrTable.aHiddenColumns.push_back(nHiddenColumnIndex); } } } -SchXMLTableColumnContext::~SchXMLTableColumnContext() -{ -} +SchXMLTableColumnContext::~SchXMLTableColumnContext() {} // classes for rows // class SchXMLTableRowsContext -SchXMLTableRowsContext::SchXMLTableRowsContext( - SvXMLImport& rImport, - SchXMLTable& aTable ) : - SvXMLImportContext( rImport ), - mrTable( aTable ) +SchXMLTableRowsContext::SchXMLTableRowsContext(SvXMLImport& rImport, SchXMLTable& aTable) + : SvXMLImportContext(rImport) + , mrTable(aTable) { } -SchXMLTableRowsContext::~SchXMLTableRowsContext() -{ -} +SchXMLTableRowsContext::~SchXMLTableRowsContext() {} -css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableRowsContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) +css::uno::Reference +SchXMLTableRowsContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference&) { SvXMLImportContext* pContext = nullptr; - if( nElement == XML_ELEMENT(TABLE, XML_TABLE_ROW) ) - pContext = new SchXMLTableRowContext( GetImport(), mrTable ); + if (nElement == XML_ELEMENT(TABLE, XML_TABLE_ROW)) + pContext = new SchXMLTableRowContext(GetImport(), mrTable); else XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); @@ -489,35 +472,31 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableRowsContext } // class SchXMLTableRowContext -SchXMLTableRowContext::SchXMLTableRowContext( - SvXMLImport& rImport, - SchXMLTable& aTable ) : - SvXMLImportContext( rImport ), - mrTable( aTable ) +SchXMLTableRowContext::SchXMLTableRowContext(SvXMLImport& rImport, SchXMLTable& aTable) + : SvXMLImportContext(rImport) + , mrTable(aTable) { mrTable.nColumnIndex = -1; mrTable.nRowIndex++; - std::vector< SchXMLCell > aNewRow; - aNewRow.reserve( mrTable.nNumberOfColsEstimate ); - while( mrTable.aData.size() <= o3tl::make_unsigned(mrTable.nRowIndex) ) - mrTable.aData.push_back( aNewRow ); + std::vector aNewRow; + aNewRow.reserve(mrTable.nNumberOfColsEstimate); + while (mrTable.aData.size() <= o3tl::make_unsigned(mrTable.nRowIndex)) + mrTable.aData.push_back(aNewRow); } -SchXMLTableRowContext::~SchXMLTableRowContext() -{ -} +SchXMLTableRowContext::~SchXMLTableRowContext() {} -css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableRowContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) +css::uno::Reference +SchXMLTableRowContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference&) { SvXMLImportContext* pContext = nullptr; // element - if( nElement == XML_ELEMENT(TABLE, XML_TABLE_CELL) ) + if (nElement == XML_ELEMENT(TABLE, XML_TABLE_CELL)) { - pContext = new SchXMLTableCellContext( GetImport(), mrTable ); + pContext = new SchXMLTableCellContext(GetImport(), mrTable); } else { @@ -528,60 +507,54 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableRowContext: return pContext; } -namespace { - +namespace +{ class SchXMLRangeSomewhereContext : public SvXMLImportContext { -//#i113950# previously the range was exported to attribute text:id, -//but that attribute does not allow arbitrary strings anymore -//so we need to find an alternative to save that range info for copy/paste scenario ... -//-> use description at an empty group element for now + //#i113950# previously the range was exported to attribute text:id, + //but that attribute does not allow arbitrary strings anymore + //so we need to find an alternative to save that range info for copy/paste scenario ... + //-> use description at an empty group element for now private: OUString& mrRangeString; OUStringBuffer maRangeStringBuffer; public: - SchXMLRangeSomewhereContext( SvXMLImport& rImport, - OUString& rRangeString ); + SchXMLRangeSomewhereContext(SvXMLImport& rImport, OUString& rRangeString); - virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + virtual css::uno::Reference SAL_CALL createFastChildContext( sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + const css::uno::Reference& AttrList) override; virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; }; - } // classes for cells and their content // class SchXMLTableCellContext -SchXMLTableCellContext::SchXMLTableCellContext( - SvXMLImport& rImport, - SchXMLTable& aTable) +SchXMLTableCellContext::SchXMLTableCellContext(SvXMLImport& rImport, SchXMLTable& aTable) : SvXMLImportContext(rImport) , mrTable(aTable) , mbReadText(false) { } -SchXMLTableCellContext::~SchXMLTableCellContext() -{ -} +SchXMLTableCellContext::~SchXMLTableCellContext() {} -void SchXMLTableCellContext::startFastElement (sal_Int32 /*nElement*/, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) +void SchXMLTableCellContext::startFastElement( + sal_Int32 /*nElement*/, const css::uno::Reference& xAttrList) { OUString aCellContent; - SchXMLCellType eValueType = SCH_CELL_TYPE_UNKNOWN; + SchXMLCellType eValueType = SCH_CELL_TYPE_UNKNOWN; - for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) + for (auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList)) { - switch(aIter.getToken()) + switch (aIter.getToken()) { case XML_ELEMENT(OFFICE, XML_VALUE_TYPE): - if( IsXMLToken( aIter, XML_FLOAT ) ) + if (IsXMLToken(aIter, XML_FLOAT)) eValueType = SCH_CELL_TYPE_FLOAT; - else if( IsXMLToken( aIter, XML_STRING ) ) + else if (IsXMLToken(aIter, XML_STRING)) eValueType = SCH_CELL_TYPE_STRING; break; @@ -598,50 +571,49 @@ void SchXMLTableCellContext::startFastElement (sal_Int32 /*nElement*/, SchXMLCell aCell; aCell.eType = eValueType; - if( eValueType == SCH_CELL_TYPE_FLOAT ) + if (eValueType == SCH_CELL_TYPE_FLOAT) { double fData; // the result may be false if a NaN is read, but that's ok - ::sax::Converter::convertDouble( fData, aCellContent ); + ::sax::Converter::convertDouble(fData, aCellContent); aCell.fValue = fData; // don't read text from following or element mbReadText = false; } - mrTable.aData[ mrTable.nRowIndex ].push_back(std::move(aCell)); + mrTable.aData[mrTable.nRowIndex].push_back(std::move(aCell)); mrTable.nColumnIndex++; - if( mrTable.nMaxColumnIndex < mrTable.nColumnIndex ) + if (mrTable.nMaxColumnIndex < mrTable.nColumnIndex) mrTable.nMaxColumnIndex = mrTable.nColumnIndex; } -css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableCellContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) +css::uno::Reference +SchXMLTableCellContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference&) { SvXMLImportContext* pContext = nullptr; // element - if( nElement == XML_ELEMENT(TEXT, XML_LIST ) && mbReadText ) + if (nElement == XML_ELEMENT(TEXT, XML_LIST) && mbReadText) { - SchXMLCell& rCell = mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ]; - rCell.aComplexString = Sequence< OUString >(); + SchXMLCell& rCell = mrTable.aData[mrTable.nRowIndex][mrTable.nColumnIndex]; + rCell.aComplexString = Sequence(); rCell.eType = SCH_CELL_TYPE_COMPLEX_STRING; - pContext = new SchXMLTextListContext( GetImport(), rCell.aComplexString ); - mbReadText = false;//don't apply text from + pContext = new SchXMLTextListContext(GetImport(), rCell.aComplexString); + mbReadText = false; //don't apply text from } // element - read text (and range from text:id old version) - else if( nElement == XML_ELEMENT(TEXT, XML_P) || - nElement == XML_ELEMENT(LO_EXT, XML_P) ) + else if (nElement == XML_ELEMENT(TEXT, XML_P) || nElement == XML_ELEMENT(LO_EXT, XML_P)) { - pContext = new SchXMLParagraphContext( GetImport(), maCellContent, &maRangeId ); + pContext = new SchXMLParagraphContext(GetImport(), maCellContent, &maRangeId); } // element - read range - else if( nElement == XML_ELEMENT(DRAW, XML_G) ) + else if (nElement == XML_ELEMENT(DRAW, XML_G)) { //#i113950# previously the range was exported to attribute text:id, but that attribute does not allow arbitrary strings anymore //so we need to find an alternative to save that range info for copy/paste scenario ... -> use description at an empty group element for now - pContext = new SchXMLRangeSomewhereContext( GetImport(), maRangeId ); + pContext = new SchXMLRangeSomewhereContext(GetImport(), maRangeId); } else XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); @@ -649,139 +621,143 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLTableCellContext return pContext; } -void SchXMLTableCellContext::endFastElement(sal_Int32 ) +void SchXMLTableCellContext::endFastElement(sal_Int32) { - if( mbReadText && !maCellContent.isEmpty() ) //apply text from element - mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ].aString = maCellContent; - if( !maRangeId.isEmpty()) - mrTable.aData[ mrTable.nRowIndex ][ mrTable.nColumnIndex ].aRangeId = maRangeId; + if (mbReadText && !maCellContent.isEmpty()) //apply text from element + mrTable.aData[mrTable.nRowIndex][mrTable.nColumnIndex].aString = maCellContent; + if (!maRangeId.isEmpty()) + mrTable.aData[mrTable.nRowIndex][mrTable.nColumnIndex].aRangeId = maRangeId; } -static void lcl_ApplyCellToComplexLabel( const SchXMLCell& rCell, Sequence< uno::Any >& rComplexLabel ) +static void lcl_ApplyCellToComplexLabel(const SchXMLCell& rCell, Sequence& rComplexLabel) { - if( rCell.eType == SCH_CELL_TYPE_STRING ) + if (rCell.eType == SCH_CELL_TYPE_STRING) { rComplexLabel = { uno::Any(rCell.aString) }; } - else if( rCell.aComplexString.hasElements() && rCell.eType == SCH_CELL_TYPE_COMPLEX_STRING ) + else if (rCell.aComplexString.hasElements() && rCell.eType == SCH_CELL_TYPE_COMPLEX_STRING) { sal_Int32 nCount = rCell.aComplexString.getLength(); - rComplexLabel.realloc( nCount ); + rComplexLabel.realloc(nCount); auto pComplexLabel = rComplexLabel.getArray(); - for( sal_Int32 nN=0; nN& xChartDoc ) + const SchXMLTable& rTable, const uno::Reference& xChartDoc) { // apply all data read from the local table to the internal data provider - if( !xChartDoc.is() || !xChartDoc->hasInternalDataProvider() ) + if (!xChartDoc.is() || !xChartDoc->hasInternalDataProvider()) return; - Reference< chart2::data::XDataProvider > xDataProv( xChartDoc->getDataProvider() ); - if( !xDataProv.is() ) + Reference xDataProv(xChartDoc->getDataProvider()); + if (!xDataProv.is()) return; //prepare the read local table data - sal_Int32 nNumRows( static_cast< sal_Int32 >( rTable.aData.size())); + sal_Int32 nNumRows(static_cast(rTable.aData.size())); sal_Int32 nRowOffset = 0; - if( rTable.bHasHeaderRow ) + if (rTable.bHasHeaderRow) { --nNumRows; nRowOffset = 1; } - sal_Int32 nNumColumns( rTable.nMaxColumnIndex + 1 ); + sal_Int32 nNumColumns(rTable.nMaxColumnIndex + 1); sal_Int32 nColOffset = 0; - if( rTable.bHasHeaderColumn ) + if (rTable.bHasHeaderColumn) { --nNumColumns; nColOffset = 1; } - Sequence< Sequence< double > > aDataInRows( nNumRows ); + Sequence> aDataInRows(nNumRows); auto aDataInRowsRange = asNonConstRange(aDataInRows); - Sequence< Sequence< uno::Any > > aComplexRowDescriptions( nNumRows ); + Sequence> aComplexRowDescriptions(nNumRows); auto aComplexRowDescriptionsRange = asNonConstRange(aComplexRowDescriptions); - Sequence< Sequence< uno::Any > > aComplexColumnDescriptions( nNumColumns ); + Sequence> aComplexColumnDescriptions(nNumColumns); auto aComplexColumnDescriptionsRange = asNonConstRange(aComplexColumnDescriptions); - for( sal_Int32 i=0; i& rFirstRow = rTable.aData.front(); + const ::std::vector& rFirstRow = rTable.aData.front(); const sal_Int32 nColumnLabelsSize = aComplexColumnDescriptions.getLength(); - const sal_Int32 nMax = ::std::min< sal_Int32 >( nColumnLabelsSize, static_cast< sal_Int32 >( rFirstRow.size()) - nColOffset ); - SAL_WARN_IF( nMax != nColumnLabelsSize, "xmloff.chart", "nMax != nColumnLabelsSize"); - for( sal_Int32 i=0; i( + nColumnLabelsSize, static_cast(rFirstRow.size()) - nColOffset); + SAL_WARN_IF(nMax != nColumnLabelsSize, "xmloff.chart", "nMax != nColumnLabelsSize"); + for (sal_Int32 i = 0; i < nMax; ++i) + lcl_ApplyCellToComplexLabel(rFirstRow[i + nColOffset], + aComplexColumnDescriptionsRange[i]); } - std::vector< ::std::vector< SchXMLCell > >::const_iterator aRowIter( rTable.aData.begin() + nRowOffset ); - std::vector< ::std::vector< SchXMLCell > >::const_iterator aEnd( rTable.aData.end() ); - for( sal_Int32 nRow = 0; aRowIter != aEnd && nRow < nNumRows; ++aRowIter, ++nRow ) + std::vector<::std::vector>::const_iterator aRowIter(rTable.aData.begin() + + nRowOffset); + std::vector<::std::vector>::const_iterator aEnd(rTable.aData.end()); + for (sal_Int32 nRow = 0; aRowIter != aEnd && nRow < nNumRows; ++aRowIter, ++nRow) { - const ::std::vector< SchXMLCell >& rRow = *aRowIter; - if( !rRow.empty() ) + const ::std::vector& rRow = *aRowIter; + if (!rRow.empty()) { // row label - if( rTable.bHasHeaderColumn ) - lcl_ApplyCellToComplexLabel( rRow.front(), aComplexRowDescriptionsRange[nRow] ); + if (rTable.bHasHeaderColumn) + lcl_ApplyCellToComplexLabel(rRow.front(), aComplexRowDescriptionsRange[nRow]); // values - Sequence< double >& rTargetRow = aDataInRowsRange[nRow]; + Sequence& rTargetRow = aDataInRowsRange[nRow]; auto pTargetRow = rTargetRow.getArray(); - lcl_ApplyCellToData aApplyCellToData = ::std::for_each( rRow.begin() + nColOffset, rRow.end(), lcl_ApplyCellToData( rTargetRow ) ); - for( sal_Int32 nCurrentIndex = aApplyCellToData.getCurrentIndex(); nCurrentIndex::quiet_NaN();//#i110615# + lcl_ApplyCellToData aApplyCellToData = ::std::for_each( + rRow.begin() + nColOffset, rRow.end(), lcl_ApplyCellToData(rTargetRow)); + for (sal_Int32 nCurrentIndex = aApplyCellToData.getCurrentIndex(); + nCurrentIndex < nNumColumns; nCurrentIndex++) + pTargetRow[nCurrentIndex] + = std::numeric_limits::quiet_NaN(); //#i110615# } } } //apply the collected data to the chart - Reference< chart2::XAnyDescriptionAccess > xDataAccess( xDataProv, uno::UNO_QUERY ); - if( !xDataAccess.is() ) + Reference xDataAccess(xDataProv, uno::UNO_QUERY); + if (!xDataAccess.is()) return; - xDataAccess->setData( aDataInRows ); - if( rTable.bHasHeaderColumn ) - xDataAccess->setAnyRowDescriptions( aComplexRowDescriptions ); - if( rTable.bHasHeaderRow ) - xDataAccess->setAnyColumnDescriptions( aComplexColumnDescriptions ); + xDataAccess->setData(aDataInRows); + if (rTable.bHasHeaderColumn) + xDataAccess->setAnyRowDescriptions(aComplexRowDescriptions); + if (rTable.bHasHeaderRow) + xDataAccess->setAnyColumnDescriptions(aComplexColumnDescriptions); - if ( rTable.bProtected ) + if (rTable.bProtected) { try { - Reference< beans::XPropertySet > xProps( xChartDoc, uno::UNO_QUERY ); + Reference xProps(xChartDoc, uno::UNO_QUERY); if (xProps) { - xProps->setPropertyValue( u"DisableDataTableDialog"_ustr, uno::Any( true ) ); - xProps->setPropertyValue( u"DisableComplexChartTypes"_ustr, uno::Any( true ) ); + xProps->setPropertyValue(u"DisableDataTableDialog"_ustr, uno::Any(true)); + xProps->setPropertyValue(u"DisableComplexChartTypes"_ustr, uno::Any(true)); } } - catch ( uno::Exception& ) + catch (uno::Exception&) { } } } void SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary( - const SchXMLTable& rTable, - const tSchXMLLSequencesPerIndex & rLSequencesPerIndex, - const uno::Reference< chart2::XChartDocument >& xChartDoc, - chart::ChartDataRowSource eDataRowSource ) + const SchXMLTable& rTable, const tSchXMLLSequencesPerIndex& rLSequencesPerIndex, + const uno::Reference& xChartDoc, + chart::ChartDataRowSource eDataRowSource) { - if( ! (xChartDoc.is() && xChartDoc->hasInternalDataProvider())) + if (!(xChartDoc.is() && xChartDoc->hasInternalDataProvider())) return; // If the range-strings are valid (starting with "local-table") they should @@ -791,101 +767,112 @@ void SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary( // one table column in the order of appearance, which is: 1. categories, // 2. data series: 2.a) domains, 2.b) values (main-role, usually y-values) - Reference< chart2::data::XDataProvider > xDataProv( xChartDoc->getDataProvider()); + Reference xDataProv(xChartDoc->getDataProvider()); // create a mapping from original ranges to new ranges lcl_tOriginalRangeToInternalRangeMap aRangeMap; - lcl_fillRangeMapping( rTable, aRangeMap, eDataRowSource ); + lcl_fillRangeMapping(rTable, aRangeMap, eDataRowSource); const OUString lcl_aCategoriesRange(aCategoriesRange); bool bCategoriesApplied = false; // translate ranges (using the map created before) - for( const auto& rLSeq : rLSequencesPerIndex ) + for (const auto& rLSeq : rLSequencesPerIndex) { - if( rLSeq.second.is()) + if (rLSeq.second.is()) { // values/error bars/categories - if( rLSeq.first.second == SCH_XML_PART_VALUES || - rLSeq.first.second == SCH_XML_PART_ERROR_BARS ) + if (rLSeq.first.second == SCH_XML_PART_VALUES + || rLSeq.first.second == SCH_XML_PART_ERROR_BARS) { - Reference< chart2::data::XDataSequence > xSeq( rLSeq.second->getValues()); + Reference xSeq(rLSeq.second->getValues()); OUString aRange; - if( xSeq.is() && - SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) && - lcl_mapContainsRange( aRangeMap, aRange )) + if (xSeq.is() + && SchXMLTools::getXMLRangePropertyFromDataSequence(xSeq, aRange, + /* bClearProp = */ true) + && lcl_mapContainsRange(aRangeMap, aRange)) { - Reference< chart2::data::XDataSequence > xNewSeq( - lcl_reassignDataSequence( xSeq, xDataProv, aRangeMap, aRange )); - if( xNewSeq != xSeq ) + Reference xNewSeq( + lcl_reassignDataSequence(xSeq, xDataProv, aRangeMap, aRange)); + if (xNewSeq != xSeq) { - SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ), - Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY )); - rLSeq.second->setValues( xNewSeq ); + SchXMLTools::copyProperties( + Reference(xSeq, uno::UNO_QUERY), + Reference(xNewSeq, uno::UNO_QUERY)); + rLSeq.second->setValues(xNewSeq); } } else { - if( lcl_tableOfRangeMatches( aRange, rTable.aTableNameOfFile )) + if (lcl_tableOfRangeMatches(aRange, rTable.aTableNameOfFile)) { - if( rLSeq.first.first == SCH_XML_CATEGORIES_INDEX ) + if (rLSeq.first.first == SCH_XML_CATEGORIES_INDEX) bCategoriesApplied = true; } else { - if( rLSeq.first.first == SCH_XML_CATEGORIES_INDEX ) + if (rLSeq.first.first == SCH_XML_CATEGORIES_INDEX) { - Reference< beans::XPropertySet > xOldSequenceProp( rLSeq.second->getValues(), uno::UNO_QUERY ); - Reference< chart2::data::XDataSequence > xNewSequence( - xDataProv->createDataSequenceByRangeRepresentation(u"categories"_ustr)); + Reference xOldSequenceProp( + rLSeq.second->getValues(), uno::UNO_QUERY); + Reference xNewSequence( + xDataProv->createDataSequenceByRangeRepresentation( + u"categories"_ustr)); SchXMLTools::copyProperties( - xOldSequenceProp, Reference< beans::XPropertySet >( xNewSequence, uno::UNO_QUERY )); - rLSeq.second->setValues( xNewSequence ); + xOldSequenceProp, + Reference(xNewSequence, uno::UNO_QUERY)); + rLSeq.second->setValues(xNewSequence); bCategoriesApplied = true; } else { - Reference< beans::XPropertySet > xOldSequenceProp( rLSeq.second->getValues(), uno::UNO_QUERY ); - OUString aRep( OUString::number( rLSeq.first.first )); - Reference< chart2::data::XDataSequence > xNewSequence( - xDataProv->createDataSequenceByRangeRepresentation( aRep )); + Reference xOldSequenceProp( + rLSeq.second->getValues(), uno::UNO_QUERY); + OUString aRep(OUString::number(rLSeq.first.first)); + Reference xNewSequence( + xDataProv->createDataSequenceByRangeRepresentation(aRep)); SchXMLTools::copyProperties( - xOldSequenceProp, Reference< beans::XPropertySet >( xNewSequence, uno::UNO_QUERY )); - rLSeq.second->setValues( xNewSequence ); + xOldSequenceProp, + Reference(xNewSequence, uno::UNO_QUERY)); + rLSeq.second->setValues(xNewSequence); } } } } else // labels { - SAL_WARN_IF( rLSeq.first.second != SCH_XML_PART_LABEL, "xmloff.chart", "rLSeq.first.second != SCH_XML_PART_LABEL" ); + SAL_WARN_IF(rLSeq.first.second != SCH_XML_PART_LABEL, "xmloff.chart", + "rLSeq.first.second != SCH_XML_PART_LABEL"); // labels - Reference< chart2::data::XDataSequence > xSeq( rLSeq.second->getLabel()); + Reference xSeq(rLSeq.second->getLabel()); OUString aRange; - if( xSeq.is() && - SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) && - lcl_mapContainsRange( aRangeMap, aRange )) + if (xSeq.is() + && SchXMLTools::getXMLRangePropertyFromDataSequence(xSeq, aRange, + /* bClearProp = */ true) + && lcl_mapContainsRange(aRangeMap, aRange)) { - Reference< chart2::data::XDataSequence > xNewSeq( - lcl_reassignDataSequence( xSeq, xDataProv, aRangeMap, aRange )); - if( xNewSeq != xSeq ) + Reference xNewSeq( + lcl_reassignDataSequence(xSeq, xDataProv, aRangeMap, aRange)); + if (xNewSeq != xSeq) { - SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ), - Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY )); - rLSeq.second->setLabel( xNewSeq ); + SchXMLTools::copyProperties( + Reference(xSeq, uno::UNO_QUERY), + Reference(xNewSeq, uno::UNO_QUERY)); + rLSeq.second->setLabel(xNewSeq); } } - else if( ! lcl_tableOfRangeMatches( aRange, rTable.aTableNameOfFile )) + else if (!lcl_tableOfRangeMatches(aRange, rTable.aTableNameOfFile)) { - OUString aRep = "label " + OUString::number( rLSeq.first.first ); + OUString aRep = "label " + OUString::number(rLSeq.first.first); - Reference< chart2::data::XDataSequence > xNewSeq( - xDataProv->createDataSequenceByRangeRepresentation( aRep )); - SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ), - Reference< beans::XPropertySet >( xNewSeq, uno::UNO_QUERY )); - rLSeq.second->setLabel( xNewSeq ); + Reference xNewSeq( + xDataProv->createDataSequenceByRangeRepresentation(aRep)); + SchXMLTools::copyProperties( + Reference(xSeq, uno::UNO_QUERY), + Reference(xNewSeq, uno::UNO_QUERY)); + rLSeq.second->setLabel(xNewSeq); } } } @@ -894,152 +881,172 @@ void SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary( // there exist files with own data without a categories element but with row // descriptions. The row descriptions were used as categories even without // the categories element - if( ! bCategoriesApplied ) + if (!bCategoriesApplied) { - SchXMLTools::CreateCategories( - xDataProv, xChartDoc, u"categories"_ustr, - 0 /* nCooSysIndex */, 0 /* nDimension */ ); + SchXMLTools::CreateCategories(xDataProv, xChartDoc, u"categories"_ustr, + 0 /* nCooSysIndex */, 0 /* nDimension */); } //i91578 display of hidden values (copy paste scenario; use hidden flag during migration to locale table upon paste ) //remove series that consist only of hidden columns - Reference< chart2::XInternalDataProvider > xInternalDataProvider( xDataProv, uno::UNO_QUERY ); - if( !xInternalDataProvider.is() || rTable.aHiddenColumns.empty() ) + Reference xInternalDataProvider(xDataProv, uno::UNO_QUERY); + if (!xInternalDataProvider.is() || rTable.aHiddenColumns.empty()) return; try { - Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xChartDoc->getFirstDiagram(), uno::UNO_QUERY_THROW ); - const Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() ); - for( const auto& rCooSys : aCooSysSeq ) + Reference xCooSysCnt(xChartDoc->getFirstDiagram(), + uno::UNO_QUERY_THROW); + const Sequence> aCooSysSeq( + xCooSysCnt->getCoordinateSystems()); + for (const auto& rCooSys : aCooSysSeq) { - Reference< chart2::XChartTypeContainer > xCooSysContainer( rCooSys, uno::UNO_QUERY_THROW ); - const Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCooSysContainer->getChartTypes()); - for( const auto& rChartType : aChartTypeSeq ) + Reference xCooSysContainer(rCooSys, uno::UNO_QUERY_THROW); + const Sequence> aChartTypeSeq( + xCooSysContainer->getChartTypes()); + for (const auto& rChartType : aChartTypeSeq) { - Reference< chart2::XDataSeriesContainer > xSeriesContainer( rChartType, uno::UNO_QUERY ); - if(!xSeriesContainer.is()) + Reference xSeriesContainer(rChartType, + uno::UNO_QUERY); + if (!xSeriesContainer.is()) continue; - const Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() ); - std::vector< Reference< chart2::XDataSeries > > aRemainingSeries; + const Sequence> aSeriesSeq( + xSeriesContainer->getDataSeries()); + std::vector> aRemainingSeries; - for( const auto& rSeries : aSeriesSeq ) + for (const auto& rSeries : aSeriesSeq) { - Reference< chart2::data::XDataSource > xDataSource( rSeries, uno::UNO_QUERY ); - if( xDataSource.is() ) + Reference xDataSource(rSeries, uno::UNO_QUERY); + if (xDataSource.is()) { bool bHasUnhiddenColumns = false; OUString aRange; - const uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences() ); - for( const auto& xLabeledSequence : aSequences ) + const uno::Sequence> + aSequences(xDataSource->getDataSequences()); + for (const auto& xLabeledSequence : aSequences) { - if(!xLabeledSequence.is()) + if (!xLabeledSequence.is()) continue; - Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues() ); - if( xValues.is() ) + Reference xValues( + xLabeledSequence->getValues()); + if (xValues.is()) { aRange = xValues->getSourceRangeRepresentation(); - if( ::std::find( rTable.aHiddenColumns.begin(), rTable.aHiddenColumns.end(), aRange.toInt32() ) == rTable.aHiddenColumns.end() ) + if (::std::find(rTable.aHiddenColumns.begin(), + rTable.aHiddenColumns.end(), aRange.toInt32()) + == rTable.aHiddenColumns.end()) bHasUnhiddenColumns = true; } - if( !bHasUnhiddenColumns ) + if (!bHasUnhiddenColumns) { - Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel() ); - if( xLabel.is() ) + Reference xLabel( + xLabeledSequence->getLabel()); + if (xLabel.is()) { aRange = xLabel->getSourceRangeRepresentation(); - const sal_Int32 nId = o3tl::toInt32(o3tl::getToken(aRange, 1, ' ')); - if( ::std::find( rTable.aHiddenColumns.begin(), rTable.aHiddenColumns.end(), nId ) == rTable.aHiddenColumns.end() ) + const sal_Int32 nId + = o3tl::toInt32(o3tl::getToken(aRange, 1, ' ')); + if (::std::find(rTable.aHiddenColumns.begin(), + rTable.aHiddenColumns.end(), nId) + == rTable.aHiddenColumns.end()) bHasUnhiddenColumns = true; } } } - if( bHasUnhiddenColumns ) - aRemainingSeries.push_back( rSeries ); + if (bHasUnhiddenColumns) + aRemainingSeries.push_back(rSeries); } } - if( aRemainingSeries.size() != o3tl::make_unsigned(aSeriesSeq.getLength()) ) + if (aRemainingSeries.size() != o3tl::make_unsigned(aSeriesSeq.getLength())) { //remove the series that have only hidden data - xSeriesContainer->setDataSeries( comphelper::containerToSequence(aRemainingSeries) ); + xSeriesContainer->setDataSeries( + comphelper::containerToSequence(aRemainingSeries)); //remove unused sequences - Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY ); - if( xDataSource.is() ) + Reference xDataSource(xChartDoc, uno::UNO_QUERY); + if (xDataSource.is()) { //first detect which columns are really used - std::map< sal_Int32, bool > aUsageMap; + std::map aUsageMap; OUString aRange; - const Sequence< Reference< chart2::data::XLabeledDataSequence > > aUsedSequences( xDataSource->getDataSequences() ); - for( const auto& xLabeledSequence : aUsedSequences ) + const Sequence> + aUsedSequences(xDataSource->getDataSequences()); + for (const auto& xLabeledSequence : aUsedSequences) { - if(!xLabeledSequence.is()) + if (!xLabeledSequence.is()) continue; - Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues() ); - if( xValues.is() ) + Reference xValues( + xLabeledSequence->getValues()); + if (xValues.is()) { aRange = xValues->getSourceRangeRepresentation(); sal_Int32 nIndex = aRange.toInt32(); - if( nIndex!=0 || aRange != lcl_aCategoriesRange ) + if (nIndex != 0 || aRange != lcl_aCategoriesRange) aUsageMap[nIndex] = true; } - Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel() ); - if( xLabel.is() ) + Reference xLabel( + xLabeledSequence->getLabel()); + if (xLabel.is()) { aRange = xLabel->getSourceRangeRepresentation(); std::u16string_view aSecondToken = o3tl::getToken(aRange, 1, ' '); - if( !aSecondToken.empty() ) + if (!aSecondToken.empty()) aUsageMap[o3tl::toInt32(aSecondToken)] = true; } } - ::std::vector< sal_Int32 > aSequenceIndexesToDelete; - std::ranges::copy_if(rTable.aHiddenColumns, std::back_inserter(aSequenceIndexesToDelete), - [&aUsageMap](sal_Int32 nSequenceIndex) { return aUsageMap.find(nSequenceIndex) == aUsageMap.end(); }); + ::std::vector aSequenceIndexesToDelete; + std::ranges::copy_if( + rTable.aHiddenColumns, std::back_inserter(aSequenceIndexesToDelete), + [&aUsageMap](sal_Int32 nSequenceIndex) { + return aUsageMap.find(nSequenceIndex) == aUsageMap.end(); + }); // delete unnecessary sequences of the internal data // iterate using greatest index first, so that deletion does not // shift other sequences that will be deleted later - ::std::sort( aSequenceIndexesToDelete.begin(), aSequenceIndexesToDelete.end()); - for( ::std::vector< sal_Int32 >::reverse_iterator aIt( - aSequenceIndexesToDelete.rbegin()); aIt != aSequenceIndexesToDelete.rend(); ++aIt ) + ::std::sort(aSequenceIndexesToDelete.begin(), + aSequenceIndexesToDelete.end()); + for (::std::vector::reverse_iterator aIt( + aSequenceIndexesToDelete.rbegin()); + aIt != aSequenceIndexesToDelete.rend(); ++aIt) { - if( *aIt != -1 ) - xInternalDataProvider->deleteSequence( *aIt ); + if (*aIt != -1) + xInternalDataProvider->deleteSequence(*aIt); } } } } } } - catch( const uno::Exception & ) + catch (const uno::Exception&) { } } -SchXMLRangeSomewhereContext::SchXMLRangeSomewhereContext( SvXMLImport& rImport, - OUString& rRangeString ) : - SvXMLImportContext( rImport ), - mrRangeString( rRangeString ) +SchXMLRangeSomewhereContext::SchXMLRangeSomewhereContext(SvXMLImport& rImport, + OUString& rRangeString) + : SvXMLImportContext(rImport) + , mrRangeString(rRangeString) { } -css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLRangeSomewhereContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) +css::uno::Reference +SchXMLRangeSomewhereContext::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference&) { - if( nElement == XML_ELEMENT(SVG, XML_DESC) - || nElement == XML_ELEMENT(SVG_COMPAT, XML_DESC) ) + if (nElement == XML_ELEMENT(SVG, XML_DESC) || nElement == XML_ELEMENT(SVG_COMPAT, XML_DESC)) { - return new XMLStringBufferImportContext( GetImport(), maRangeStringBuffer ); + return new XMLStringBufferImportContext(GetImport(), maRangeStringBuffer); } else XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); return nullptr; } -void SchXMLRangeSomewhereContext::endFastElement(sal_Int32 ) +void SchXMLRangeSomewhereContext::endFastElement(sal_Int32) { mrRangeString = maRangeStringBuffer.makeStringAndClear(); }