diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-06-24 21:05:41 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-06-24 21:07:43 -0400 |
commit | 3f9275bd262dd8a7cfc199ad858208b8e400f6d9 (patch) | |
tree | ee2d70ce9c32e2797ad40fc311350d01086c5d9c /chart2/source/controller/dialogs | |
parent | 1e0c38bb54563788d08336dabe8178a60e4f83e7 (diff) |
Annotate the code a little more, to make it easier to follow.
Change-Id: Iefc61fdc132a18e73b0136f0248d69ab9e07a5e8
Diffstat (limited to 'chart2/source/controller/dialogs')
-rw-r--r-- | chart2/source/controller/dialogs/DataBrowserModel.cxx | 34 | ||||
-rw-r--r-- | chart2/source/controller/dialogs/DialogModel.cxx | 47 |
2 files changed, 54 insertions, 27 deletions
diff --git a/chart2/source/controller/dialogs/DataBrowserModel.cxx b/chart2/source/controller/dialogs/DataBrowserModel.cxx index 6e0e6c7409fc..87c916e99c65 100644 --- a/chart2/source/controller/dialogs/DataBrowserModel.cxx +++ b/chart2/source/controller/dialogs/DataBrowserModel.cxx @@ -316,31 +316,39 @@ void DataBrowserModel::insertDataSeries( sal_Int32 nAfterColumnIndex ) return; if( isCategoriesColumn(nAfterColumnIndex) ) + // Move to the last category column. nAfterColumnIndex = getCategoryColumnCount()-1; sal_Int32 nStartCol = 0; - Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartDocument )); - Reference< chart2::XChartType > xChartType; - Reference< chart2::XDataSeries > xSeries; - if( static_cast< tDataColumnVector::size_type >( nAfterColumnIndex ) <= m_aColumns.size()) + Reference<chart2::XDiagram> xDiagram = ChartModelHelper::findDiagram(m_xChartDocument); + Reference<chart2::XChartType> xChartType; + Reference<chart2::XDataSeries> xSeries; + if (static_cast<size_t>(nAfterColumnIndex) < m_aColumns.size()) + // Get the data series at specific column position (if available). xSeries.set( m_aColumns[nAfterColumnIndex].m_xDataSeries ); sal_Int32 nSeriesNumberFormat = 0; if( xSeries.is()) { + // Use the chart type of the currently selected data series. xChartType.set( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries )); + + // Find the corresponding header and determine the last column of this + // data series. tDataHeaderVector::const_iterator aIt( ::std::find_if( m_aHeaders.begin(), m_aHeaders.end(), lcl_DataSeriesOfHeaderMatches( xSeries ))); if( aIt != m_aHeaders.end()) nStartCol = aIt->m_nEndColumn; + // Get the number format too. Reference< beans::XPropertySet > xSeriesProps( xSeries, uno::UNO_QUERY ); if( xSeriesProps.is() ) xSeriesProps->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nSeriesNumberFormat; } else { + // No data series at specified column position. Use the first chart type. xChartType.set( DiagramHelper::getChartTypeByIndex( xDiagram, 0 )); nStartCol = nAfterColumnIndex; } @@ -350,9 +358,10 @@ void DataBrowserModel::insertDataSeries( sal_Int32 nAfterColumnIndex ) sal_Int32 nOffset = 0; if( xDiagram.is() && lcl_ShowCategories( xDiagram )) - nOffset=getCategoryColumnCount(); + nOffset = getCategoryColumnCount(); - // get shared sequences of current series + // Get shared sequences of current series. Normally multiple data series + // only share "values-x" sequences. (TODO: simplify this logic). Reference< chart2::XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY ); lcl_tSharedSeqVec aSharedSequences; if( xSeriesCnt.is()) @@ -362,30 +371,31 @@ void DataBrowserModel::insertDataSeries( sal_Int32 nAfterColumnIndex ) m_apDialogModel->insertSeriesAfter(xSeries, xChartType, true); if (!xNewSeries.is()) + // Failed to insert new data series to the model. Bail out. return; Reference< chart2::data::XDataSource > xSource( xNewSeries, uno::UNO_QUERY ); if (xSource.is()) { - Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSequences( - xSource->getDataSequences()); + Sequence<Reference<chart2::data::XLabeledDataSequence> > aLSequences = xSource->getDataSequences(); sal_Int32 nSeqIdx = 0; sal_Int32 nSeqSize = aLSequences.getLength(); - nStartCol -= (nOffset - 1); - for( sal_Int32 nIndex = nStartCol; - (nSeqIdx < nSeqSize); - ++nSeqIdx ) + nStartCol -= (nOffset - 1); // ??? + for (sal_Int32 nIndex = nStartCol; nSeqIdx < nSeqSize; ++nSeqIdx) { lcl_tSharedSeqVec::const_iterator aSharedIt( ::std::find_if( aSharedSequences.begin(), aSharedSequences.end(), lcl_RolesOfLSeqMatch( aLSequences[nSeqIdx] ))); + if( aSharedIt != aSharedSequences.end()) { + // Shared sequence. Most likely "values-x" sequence. Copy it from existing sequence. aLSequences[nSeqIdx]->setValues( (*aSharedIt)->getValues()); aLSequences[nSeqIdx]->setLabel( (*aSharedIt)->getLabel()); } else { + // Insert a new column in the internal data for the new sequence. xDataProvider->insertSequence( nIndex - 1 ); // values diff --git a/chart2/source/controller/dialogs/DialogModel.cxx b/chart2/source/controller/dialogs/DialogModel.cxx index e18c7d333216..5f6de8c4dc30 100644 --- a/chart2/source/controller/dialogs/DialogModel.cxx +++ b/chart2/source/controller/dialogs/DialogModel.cxx @@ -479,6 +479,37 @@ void addMissingRoles(DialogModel::tRolesWithRanges& rResult, const uno::Sequence } } +/** + * Insert a new data series to chart type at position after specified series + * position. + * + * @param xChartType chart type that contains data series. + * @param xSeries insertion position. The new series will be inserted after + * this one. + * @param xNewSeries new data series to insert. + */ +void addNewSeriesToContainer( + const Reference<XChartType>& xChartType, + const Reference<XDataSeries>& xSeries, + const Reference<XDataSeries>& xNewSeries ) +{ + Reference<XDataSeriesContainer> xSeriesCnt(xChartType, uno::UNO_QUERY_THROW); + std::vector<Reference<XDataSeries> > aSeries = SequenceToVector(xSeriesCnt->getDataSeries()); + + std::vector<Reference<XDataSeries> >::iterator aIt = + std::find( aSeries.begin(), aSeries.end(), xSeries); + + if( aIt == aSeries.end()) + // if we have no series we insert at the first position. + aIt = aSeries.begin(); + else + // vector::insert inserts before, so we have to advance + ++aIt; + + aSeries.insert(aIt, xNewSeries); + xSeriesCnt->setDataSeries(ContainerToSequence(aSeries)); +} + } DialogModel::tRolesWithRanges DialogModel::getRolesWithRanges( @@ -561,21 +592,7 @@ Reference< chart2::XDataSeries > DialogModel::insertSeriesAfter( // add new series to container if( xNewSeries.is()) - { - Reference< XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY_THROW ); - ::std::vector< Reference< XDataSeries > > aSeries( - SequenceToVector( xSeriesCnt->getDataSeries())); - ::std::vector< Reference< XDataSeries > >::iterator aIt = - ::std::find( aSeries.begin(), aSeries.end(), xSeries ); - if( aIt == aSeries.end()) - // if we have no series we insert at the first position. - aIt = aSeries.begin(); - else - // vector::insert inserts before, so we have to advance - ++aIt; - aSeries.insert( aIt, xNewSeries ); - xSeriesCnt->setDataSeries( ContainerToSequence( aSeries )); - } + addNewSeriesToContainer(xChartType, xSeries, xNewSeries); ThreeDHelper::setScheme( xDiagram, e3DScheme ); } |