diff options
author | Balazs Varga <balazs.varga991@gmail.com> | 2019-07-17 12:57:47 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2019-07-24 14:04:06 +0200 |
commit | fa0a981af41a2606541eec1cb20a379a739691e0 (patch) | |
tree | a90104181609266bdd21538ef85b1bafbb297465 /oox | |
parent | 9c4945a6767c298258f8aab053841242dc4f7afc (diff) |
tdf#114166 DOCX chart import: fix missing complex categories
Now complex category labels are visible, and the inner data
table contains the correct texts of the category columns.
Note: repeating call of createDataSequenceByValueArray() API function
can create all columns of the complex categories. See also
commit 6c4e21a234f12e1310ba06f9859e08b424acf8bf
"bnc#812796: Correctly handle static value array for OOXML charts."
Change-Id: I333b79be35a24a912bb9e662116d0c85809a8fb2
Reviewed-on: https://gerrit.libreoffice.org/75776
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/chart/chartconverter.cxx | 29 | ||||
-rw-r--r-- | oox/source/drawingml/chart/datasourcecontext.cxx | 25 | ||||
-rw-r--r-- | oox/source/drawingml/chart/datasourcemodel.cxx | 3 | ||||
-rw-r--r-- | oox/source/export/chartexport.cxx | 8 |
4 files changed, 49 insertions, 16 deletions
diff --git a/oox/source/drawingml/chart/chartconverter.cxx b/oox/source/drawingml/chart/chartconverter.cxx index f86ea8adb760..538f9956abc7 100644 --- a/oox/source/drawingml/chart/chartconverter.cxx +++ b/oox/source/drawingml/chart/chartconverter.cxx @@ -56,12 +56,12 @@ static OUString lclGenerateApiString( const OUString& rString ) return "\"" + aRetString + "\""; } -static OUString lclGenerateApiArray(const std::vector<Any>& rRow) +static OUString lclGenerateApiArray(const std::vector<Any>& rRow, sal_Int32 nStart, sal_Int32 nCount) { OSL_ENSURE( !rRow.empty(), "ChartConverter::lclGenerateApiArray - missing matrix values" ); OUStringBuffer aBuffer; aBuffer.append( API_TOKEN_ARRAY_OPEN ); - for (auto aBeg = rRow.begin(), aIt = aBeg, aEnd = rRow.end(); aIt != aEnd; ++aIt) + for (auto aBeg = rRow.begin() + nStart, aIt = aBeg, aEnd = aBeg + nCount; aIt != aEnd; ++aIt) { double fValue = 0.0; OUString aString; @@ -124,21 +124,26 @@ Reference< XDataSequence > ChartConverter::createDataSequence( if( rxDataProvider.is() ) { OUString aRangeRep; - if( !rDataSeq.maData.empty() ) + if( !rDataSeq.maData.empty() ) try { // create a single-row array from constant source data - std::vector<Any> aRow(rDataSeq.mnPointCount); + // (multiple levels in the case of complex categories) + std::vector<Any> aRow(rDataSeq.mnLevelCount * rDataSeq.mnPointCount); for (auto const& elem : rDataSeq.maData) aRow.at(elem.first) = elem.second; - aRangeRep = lclGenerateApiArray(aRow); - } - - if( !aRangeRep.isEmpty() ) try - { - // create the data sequence - xDataSeq = rxDataProvider->createDataSequenceByValueArray(rRole, aRangeRep); - return xDataSeq; + for (sal_Int32 i = rDataSeq.mnLevelCount-1; i >= 0; i--) + { + aRangeRep = lclGenerateApiArray( aRow, i * rDataSeq.mnPointCount, rDataSeq.mnPointCount); + + if (!aRangeRep.isEmpty()) + { + // create or add a new level to the data sequence + xDataSeq = rxDataProvider->createDataSequenceByValueArray(rRole, aRangeRep); + if (i == 0) + return xDataSeq; + } + } } catch( Exception& ) { diff --git a/oox/source/drawingml/chart/datasourcecontext.cxx b/oox/source/drawingml/chart/datasourcecontext.cxx index e50723b378d0..7fa7b12852a7 100644 --- a/oox/source/drawingml/chart/datasourcecontext.cxx +++ b/oox/source/drawingml/chart/datasourcecontext.cxx @@ -180,6 +180,7 @@ ContextHandlerRef StringSequenceContext::onCreateContext( sal_Int32 nElement, co switch( nElement ) { case C_TOKEN( f ): + case C_TOKEN( multiLvlStrCache ): return this; } break; @@ -206,6 +207,28 @@ ContextHandlerRef StringSequenceContext::onCreateContext( sal_Int32 nElement, co } break; + case C_TOKEN( multiLvlStrCache ): + switch (nElement) + { + case C_TOKEN( ptCount ): + mrModel.mnPointCount = rAttribs.getInteger(XML_val, -1); + mrModel.mnLevelCount--; // normalize level count + return nullptr; + case C_TOKEN( lvl ): + mrModel.mnLevelCount++; + return this; + } + break; + + case C_TOKEN( lvl ): + switch (nElement) + { + case C_TOKEN(pt): + mnPtIndex = rAttribs.getInteger(XML_idx, -1); + return this; + } + break; + case C_TOKEN( pt ): switch( nElement ) { @@ -226,7 +249,7 @@ void StringSequenceContext::onCharacters( const OUString& rChars ) break; case C_TOKEN( v ): if( mnPtIndex >= 0 ) - mrModel.maData[ mnPtIndex ] <<= rChars; + mrModel.maData[ (mrModel.mnLevelCount-1) * mrModel.mnPointCount + mnPtIndex ] <<= rChars; break; } } diff --git a/oox/source/drawingml/chart/datasourcemodel.cxx b/oox/source/drawingml/chart/datasourcemodel.cxx index c5c054e67a99..ecb9afe4f2cb 100644 --- a/oox/source/drawingml/chart/datasourcemodel.cxx +++ b/oox/source/drawingml/chart/datasourcemodel.cxx @@ -24,7 +24,8 @@ namespace drawingml { namespace chart { DataSequenceModel::DataSequenceModel() : - mnPointCount( -1 ) + mnPointCount( -1 ), + mnLevelCount( 1 ) { } diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index dd9d19651e29..ec19bc4042ad 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -515,8 +515,12 @@ Sequence< Sequence< OUString > > ChartExport::getSplitCategoriesList( const OUSt aFinalSplitSource[nLevelCount - i - 1].realloc(aAnyCategories.getLength()); for (auto const& elemLabel : aAnyCategories) { - aFinalSplitSource[nLevelCount - i - 1][nElemLabel] = elemLabel[i].get<OUString>(); - nElemLabel++; + // make sure elemLabel[i] exists! + if (elemLabel.getLength() > i) + { + aFinalSplitSource[nLevelCount - i - 1][nElemLabel] = elemLabel[i].get<OUString>(); + nElemLabel++; + } } } return aFinalSplitSource; |