[Libreoffice-commits] core.git: 2 commits - chart2/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue Jun 24 18:06:38 PDT 2014


 chart2/source/controller/dialogs/DataBrowserModel.cxx |   46 +++++++++++------
 chart2/source/controller/dialogs/DialogModel.cxx      |   47 ++++++++++++------
 2 files changed, 62 insertions(+), 31 deletions(-)

New commits:
commit 3f9275bd262dd8a7cfc199ad858208b8e400f6d9
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Jun 24 21:05:41 2014 -0400

    Annotate the code a little more, to make it easier to follow.
    
    Change-Id: Iefc61fdc132a18e73b0136f0248d69ab9e07a5e8

diff --git a/chart2/source/controller/dialogs/DataBrowserModel.cxx b/chart2/source/controller/dialogs/DataBrowserModel.cxx
index 6e0e6c7..87c916e 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 e18c7d3..5f6de8c 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 );
     }
commit 1e0c38bb54563788d08336dabe8178a60e4f83e7
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Jun 24 19:07:27 2014 -0400

    Unwind this logic a bit.
    
    Change-Id: I320b28fb319b42eeae7cada31b6f27f9e342db15

diff --git a/chart2/source/controller/dialogs/DataBrowserModel.cxx b/chart2/source/controller/dialogs/DataBrowserModel.cxx
index 27fedf8..6e0e6c7 100644
--- a/chart2/source/controller/dialogs/DataBrowserModel.cxx
+++ b/chart2/source/controller/dialogs/DataBrowserModel.cxx
@@ -748,10 +748,14 @@ OUString DataBrowserModel::getRoleOfColumn( sal_Int32 nColumnIndex ) const
 
 bool DataBrowserModel::isCategoriesColumn( sal_Int32 nColumnIndex ) const
 {
-    bool bIsCategories = false;
-    if( nColumnIndex>=0 && nColumnIndex<static_cast< sal_Int32 >(m_aColumns.size()) )
-        bIsCategories = !m_aColumns[ nColumnIndex ].m_xDataSeries.is();
-    return bIsCategories;
+    if (nColumnIndex < 0)
+        return false;
+
+    if (static_cast<size_t>(nColumnIndex) >= m_aColumns.size())
+        return false;
+
+    // A column is a category when it doesn't have an associated data series.
+    return !m_aColumns[nColumnIndex].m_xDataSeries.is();
 }
 
 sal_Int32 DataBrowserModel::getCategoryColumnCount()


More information about the Libreoffice-commits mailing list