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

Kohei Yoshida kohei.yoshida at collabora.com
Tue Jun 24 16:01:58 PDT 2014


 chart2/source/controller/dialogs/DataBrowserModel.cxx |  323 +++++++++---------
 1 file changed, 163 insertions(+), 160 deletions(-)

New commits:
commit 3a7f55924b6901e555621e662cbc4e112396dfb9
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Jun 24 19:02:47 2014 -0400

    Reduce indentation levels.
    
    Change-Id: I5de3dea88a1e6f36c995697ba648ce6b82f4e8ae

diff --git a/chart2/source/controller/dialogs/DataBrowserModel.cxx b/chart2/source/controller/dialogs/DataBrowserModel.cxx
index 3ff0dbc..27fedf8 100644
--- a/chart2/source/controller/dialogs/DataBrowserModel.cxx
+++ b/chart2/source/controller/dialogs/DataBrowserModel.cxx
@@ -311,110 +311,113 @@ void DataBrowserModel::insertDataSeries( sal_Int32 nAfterColumnIndex )
     OSL_ASSERT( m_apDialogModel.get());
     Reference< chart2::XInternalDataProvider > xDataProvider(
         m_apDialogModel->getDataProvider(), uno::UNO_QUERY );
-    if( xDataProvider.is())
+
+    if (!xDataProvider.is())
+        return;
+
+    if( isCategoriesColumn(nAfterColumnIndex) )
+        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())
+        xSeries.set( m_aColumns[nAfterColumnIndex].m_xDataSeries );
+
+    sal_Int32 nSeriesNumberFormat = 0;
+    if( xSeries.is())
+    {
+        xChartType.set( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ));
+        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;
+
+        Reference< beans::XPropertySet > xSeriesProps( xSeries, uno::UNO_QUERY );
+        if( xSeriesProps.is() )
+            xSeriesProps->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nSeriesNumberFormat;
+    }
+    else
     {
-        if( isCategoriesColumn(nAfterColumnIndex) )
-            nAfterColumnIndex = getCategoryColumnCount()-1;
+        xChartType.set( DiagramHelper::getChartTypeByIndex( xDiagram, 0 ));
+        nStartCol = nAfterColumnIndex;
+    }
+
+    if (!xChartType.is())
+        return;
 
-        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())
-            xSeries.set( m_aColumns[nAfterColumnIndex].m_xDataSeries );
+    sal_Int32 nOffset = 0;
+    if( xDiagram.is() && lcl_ShowCategories( xDiagram ))
+        nOffset=getCategoryColumnCount();
 
-        sal_Int32 nSeriesNumberFormat = 0;
-        if( xSeries.is())
-        {
-            xChartType.set( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ));
-            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;
-
-            Reference< beans::XPropertySet > xSeriesProps( xSeries, uno::UNO_QUERY );
-            if( xSeriesProps.is() )
-                xSeriesProps->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nSeriesNumberFormat;
-        }
-        else
-        {
-            xChartType.set( DiagramHelper::getChartTypeByIndex( xDiagram, 0 ));
-            nStartCol = nAfterColumnIndex;
-        }
+    // get shared sequences of current series
+    Reference< chart2::XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY );
+    lcl_tSharedSeqVec aSharedSequences;
+    if( xSeriesCnt.is())
+        aSharedSequences = lcl_getSharedSequences( xSeriesCnt->getDataSeries());
+
+    Reference<chart2::XDataSeries> xNewSeries =
+        m_apDialogModel->insertSeriesAfter(xSeries, xChartType, true);
 
-        if( xChartType.is())
+    if (!xNewSeries.is())
+        return;
+
+    Reference< chart2::data::XDataSource > xSource( xNewSeries, uno::UNO_QUERY );
+    if (xSource.is())
+    {
+        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 )
         {
-            sal_Int32 nOffset = 0;
-            if( xDiagram.is() && lcl_ShowCategories( xDiagram ))
-                nOffset=getCategoryColumnCount();
-            // get shared sequences of current series
-            Reference< chart2::XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY );
-            lcl_tSharedSeqVec aSharedSequences;
-            if( xSeriesCnt.is())
-                aSharedSequences = lcl_getSharedSequences( xSeriesCnt->getDataSeries());
-            Reference< chart2::XDataSeries > xNewSeries(
-                m_apDialogModel->insertSeriesAfter( xSeries, xChartType, true /* bCreateDataCachedSequences */ ));
-            if( xNewSeries.is())
+            lcl_tSharedSeqVec::const_iterator aSharedIt(
+                ::std::find_if( aSharedSequences.begin(), aSharedSequences.end(),
+                                lcl_RolesOfLSeqMatch( aLSequences[nSeqIdx] )));
+            if( aSharedIt != aSharedSequences.end())
             {
-                {
-                    Reference< chart2::data::XDataSource > xSource( xNewSeries, uno::UNO_QUERY );
-                    if( xSource.is())
-                    {
-                        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 )
-                        {
-                            lcl_tSharedSeqVec::const_iterator aSharedIt(
-                                ::std::find_if( aSharedSequences.begin(), aSharedSequences.end(),
-                                                lcl_RolesOfLSeqMatch( aLSequences[nSeqIdx] )));
-                            if( aSharedIt != aSharedSequences.end())
-                            {
-                                aLSequences[nSeqIdx]->setValues( (*aSharedIt)->getValues());
-                                aLSequences[nSeqIdx]->setLabel( (*aSharedIt)->getLabel());
-                            }
-                            else
-                            {
-                                xDataProvider->insertSequence( nIndex - 1 );
-
-                                // values
-                                Reference< chart2::data::XDataSequence > xNewSeq(
-                                    xDataProvider->createDataSequenceByRangeRepresentation(
-                                        OUString::number( nIndex )));
-                                lcl_copyDataSequenceProperties(
-                                    aLSequences[nSeqIdx]->getValues(), xNewSeq );
-                                aLSequences[nSeqIdx]->setValues( xNewSeq );
-
-                                // labels
-                                Reference< chart2::data::XDataSequence > xNewLabelSeq(
-                                    xDataProvider->createDataSequenceByRangeRepresentation(
-                                        "label " +
-                                        OUString::number( nIndex )));
-                                lcl_copyDataSequenceProperties(
-                                    aLSequences[nSeqIdx]->getLabel(), xNewLabelSeq );
-                                aLSequences[nSeqIdx]->setLabel( xNewLabelSeq );
-                                ++nIndex;
-                            }
-                        }
-                    }
-                }
-                if( nSeriesNumberFormat != 0 )
-                {
-                    //give the new series the same number format as the former series especially for bubble charts thus the bubble size values can be edited with same format immediately
-                    Reference< beans::XPropertySet > xNewSeriesProps( xNewSeries, uno::UNO_QUERY );
-                    if( xNewSeriesProps.is() )
-                        xNewSeriesProps->setPropertyValue(CHART_UNONAME_NUMFMT , uno::makeAny(nSeriesNumberFormat));
-                }
-
-                updateFromModel();
+                aLSequences[nSeqIdx]->setValues( (*aSharedIt)->getValues());
+                aLSequences[nSeqIdx]->setLabel( (*aSharedIt)->getLabel());
+            }
+            else
+            {
+                xDataProvider->insertSequence( nIndex - 1 );
+
+                // values
+                Reference< chart2::data::XDataSequence > xNewSeq(
+                    xDataProvider->createDataSequenceByRangeRepresentation(
+                        OUString::number( nIndex )));
+                lcl_copyDataSequenceProperties(
+                    aLSequences[nSeqIdx]->getValues(), xNewSeq );
+                aLSequences[nSeqIdx]->setValues( xNewSeq );
+
+                // labels
+                Reference< chart2::data::XDataSequence > xNewLabelSeq(
+                    xDataProvider->createDataSequenceByRangeRepresentation(
+                        "label " +
+                        OUString::number( nIndex )));
+                lcl_copyDataSequenceProperties(
+                    aLSequences[nSeqIdx]->getLabel(), xNewLabelSeq );
+                aLSequences[nSeqIdx]->setLabel( xNewLabelSeq );
+                ++nIndex;
             }
         }
     }
+
+    if( nSeriesNumberFormat != 0 )
+    {
+        //give the new series the same number format as the former series especially for bubble charts thus the bubble size values can be edited with same format immediately
+        Reference< beans::XPropertySet > xNewSeriesProps( xNewSeries, uno::UNO_QUERY );
+        if( xNewSeriesProps.is() )
+            xNewSeriesProps->setPropertyValue(CHART_UNONAME_NUMFMT , uno::makeAny(nSeriesNumberFormat));
+    }
+
+    updateFromModel();
 }
 
 void DataBrowserModel::insertComplexCategoryLevel( sal_Int32 nAfterColumnIndex )
@@ -423,90 +426,90 @@ void DataBrowserModel::insertComplexCategoryLevel( sal_Int32 nAfterColumnIndex )
 
     OSL_ASSERT( m_apDialogModel.get());
     Reference< chart2::XInternalDataProvider > xDataProvider( m_apDialogModel->getDataProvider(), uno::UNO_QUERY );
-    if( xDataProvider.is() )
+    if (!xDataProvider.is())
+        return;
+
+    if( !isCategoriesColumn(nAfterColumnIndex) )
+        nAfterColumnIndex = getCategoryColumnCount()-1;
+
+    if(nAfterColumnIndex<0)
     {
-        if( !isCategoriesColumn(nAfterColumnIndex) )
-            nAfterColumnIndex = getCategoryColumnCount()-1;
+        OSL_FAIL( "wrong index for category level insertion" );
+        return;
+    }
 
-        if(nAfterColumnIndex<0)
-        {
-            OSL_FAIL( "wrong index for category level insertion" );
+    m_apDialogModel->startControllerLockTimer();
+    ControllerLockGuardUNO aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) );
+    xDataProvider->insertComplexCategoryLevel( nAfterColumnIndex+1 );
+    updateFromModel();
+}
+
+void DataBrowserModel::removeDataSeriesOrComplexCategoryLevel( sal_Int32 nAtColumnIndex )
+{
+    OSL_ASSERT( m_apDialogModel.get());
+    if (static_cast<size_t>(nAtColumnIndex) >= m_aColumns.size())
+        return;
+
+    Reference< chart2::XDataSeries > xSeries( m_aColumns[nAtColumnIndex].m_xDataSeries );
+    if (!xSeries.is())
+    {
+        //delete a category column if there is more than one level (in case of a single column we do not get here)
+        OSL_ENSURE(nAtColumnIndex>0, "wrong index for categories deletion" );
+
+        Reference< chart2::XInternalDataProvider > xDataProvider( m_apDialogModel->getDataProvider(), uno::UNO_QUERY );
+        if (!xDataProvider.is())
             return;
-        }
 
         m_apDialogModel->startControllerLockTimer();
         ControllerLockGuardUNO aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) );
-        xDataProvider->insertComplexCategoryLevel( nAfterColumnIndex+1 );
+        xDataProvider->deleteComplexCategoryLevel( nAtColumnIndex );
         updateFromModel();
+
+        return;
     }
-}
 
-void DataBrowserModel::removeDataSeriesOrComplexCategoryLevel( sal_Int32 nAtColumnIndex )
-{
-    OSL_ASSERT( m_apDialogModel.get());
-    if( static_cast< tDataColumnVector::size_type >( nAtColumnIndex ) < m_aColumns.size())
+    m_apDialogModel->deleteSeries(
+        xSeries, getHeaderForSeries( xSeries ).m_xChartType );
+
+    //delete sequences from internal data provider that are not used anymore
+    //but do not delete sequences that are still in use by the remaining series
+    Reference< chart2::XInternalDataProvider > xDataProvider( m_apDialogModel->getDataProvider(), uno::UNO_QUERY );
+    Reference< chart2::data::XDataSource > xSourceOfDeletedSeries( xSeries, uno::UNO_QUERY );
+    if( xDataProvider.is() && xSourceOfDeletedSeries.is())
     {
-        Reference< chart2::XDataSeries > xSeries( m_aColumns[nAtColumnIndex].m_xDataSeries );
-        if( xSeries.is())
+        ::std::vector< sal_Int32 > aSequenceIndexesToDelete;
+        Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequencesOfDeletedSeries( xSourceOfDeletedSeries->getDataSequences() );
+        Reference< chart2::XDataSeriesContainer > xSeriesCnt( getHeaderForSeries( xSeries ).m_xChartType, uno::UNO_QUERY );
+        if( xSeriesCnt.is())
         {
-            m_apDialogModel->deleteSeries(
-                xSeries, getHeaderForSeries( xSeries ).m_xChartType );
-
-            //delete sequences from internal data provider that are not used anymore
-            //but do not delete sequences that are still in use by the remaining series
-            Reference< chart2::XInternalDataProvider > xDataProvider( m_apDialogModel->getDataProvider(), uno::UNO_QUERY );
-            Reference< chart2::data::XDataSource > xSourceOfDeletedSeries( xSeries, uno::UNO_QUERY );
-            if( xDataProvider.is() && xSourceOfDeletedSeries.is())
+            Reference< chart2::data::XDataSource > xRemainingDataSource( DataSeriesHelper::getDataSource( xSeriesCnt->getDataSeries() ) );
+            if( xRemainingDataSource.is() )
             {
-                ::std::vector< sal_Int32 > aSequenceIndexesToDelete;
-                Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequencesOfDeletedSeries( xSourceOfDeletedSeries->getDataSequences() );
-                Reference< chart2::XDataSeriesContainer > xSeriesCnt( getHeaderForSeries( xSeries ).m_xChartType, uno::UNO_QUERY );
-                if( xSeriesCnt.is())
+                ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aRemainingSeq( ContainerHelper::SequenceToVector( xRemainingDataSource->getDataSequences() ) );
+                for( sal_Int32 i=0; i<aSequencesOfDeletedSeries.getLength(); ++i )
                 {
-                    Reference< chart2::data::XDataSource > xRemainingDataSource( DataSeriesHelper::getDataSource( xSeriesCnt->getDataSeries() ) );
-                    if( xRemainingDataSource.is() )
-                    {
-                        ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aRemainingSeq( ContainerHelper::SequenceToVector( xRemainingDataSource->getDataSequences() ) );
-                        for( sal_Int32 i=0; i<aSequencesOfDeletedSeries.getLength(); ++i )
-                        {
-                            ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::const_iterator aHitIt(
-                                ::std::find_if( aRemainingSeq.begin(), aRemainingSeq.end(),
-                                    lcl_RepresentationsOfLSeqMatch( aSequencesOfDeletedSeries[i] )));
-                            // if not used by the remaining series this sequence can be deleted
-                            if( aHitIt == aRemainingSeq.end() )
-                                aSequenceIndexesToDelete.push_back( lcl_getValuesRepresentationIndex( aSequencesOfDeletedSeries[i] ) );
-                        }
-                    }
-                }
-
-                // 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 )
-                {
-                    if( *aIt != -1 )
-                        xDataProvider->deleteSequence( *aIt );
+                    ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::const_iterator aHitIt(
+                        ::std::find_if( aRemainingSeq.begin(), aRemainingSeq.end(),
+                            lcl_RepresentationsOfLSeqMatch( aSequencesOfDeletedSeries[i] )));
+                    // if not used by the remaining series this sequence can be deleted
+                    if( aHitIt == aRemainingSeq.end() )
+                        aSequenceIndexesToDelete.push_back( lcl_getValuesRepresentationIndex( aSequencesOfDeletedSeries[i] ) );
                 }
             }
-            updateFromModel();
         }
-        else
-        {
-            //delete a category column if there is more than one level (in case of a single column we do not get here)
-            OSL_ENSURE(nAtColumnIndex>0, "wrong index for categories deletion" );
 
-            Reference< chart2::XInternalDataProvider > xDataProvider( m_apDialogModel->getDataProvider(), uno::UNO_QUERY );
-            if( xDataProvider.is() )
-            {
-                m_apDialogModel->startControllerLockTimer();
-                ControllerLockGuardUNO aLockedControllers( Reference< frame::XModel >( m_xChartDocument, uno::UNO_QUERY ) );
-                xDataProvider->deleteComplexCategoryLevel( nAtColumnIndex );
-                updateFromModel();
-            }
+        // 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 )
+        {
+            if( *aIt != -1 )
+                xDataProvider->deleteSequence( *aIt );
         }
     }
+    updateFromModel();
 }
 
 void DataBrowserModel::swapDataSeries( sal_Int32 nFirstColumnIndex )


More information about the Libreoffice-commits mailing list