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

Laurent Balland-Poirier laurent.balland-poirier at laposte.net
Tue May 6 13:04:32 PDT 2014


 chart2/source/controller/dialogs/dlg_ObjectProperties.cxx |   69 +++++++++++++-
 chart2/source/controller/dialogs/res_Trendline.cxx        |   25 +++--
 chart2/source/controller/dialogs/res_Trendline.hxx        |    2 
 chart2/source/controller/dialogs/tp_Trendline.cxx         |    5 +
 chart2/source/controller/dialogs/tp_Trendline.hxx         |    1 
 chart2/source/controller/inc/dlg_ObjectProperties.hxx     |    4 
 6 files changed, 99 insertions(+), 7 deletions(-)

New commits:
commit 5707c81218c3212bd2e62c274f3169cd0d6cbba2
Author: Laurent Balland-Poirier <laurent.balland-poirier at laposte.net>
Date:   Mon Apr 21 22:03:23 2014 +0200

    fdo#77739 UI trendline: limit max values of Degree and Period
    
    Retrieve the number of valid points and limit Degree and Period values
    
    Change-Id: I4e956149e3376eebf39f9e4812bb69a6a06e1758
    Reviewed-on: https://gerrit.libreoffice.org/9116
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx b/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx
index f011de5..9e707cb 100644
--- a/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx
+++ b/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx
@@ -45,6 +45,8 @@
 #include "AxisHelper.hxx"
 #include "ExplicitCategoriesProvider.hxx"
 #include "ChartModel.hxx"
+#include "CommonConverters.hxx"
+#include "../../tools/RegressionCalculationHelper.hxx"
 
 #include <com/sun/star/chart2/XAxis.hpp>
 #include <com/sun/star/chart2/XChartType.hpp>
@@ -73,6 +75,9 @@ namespace chart
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::chart2;
 using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::uno::Exception;
+using ::com::sun::star::beans::XPropertySet;
 
 ObjectPropertiesDialogParameter::ObjectPropertiesDialogParameter( const OUString& rObjectCID )
         : m_aObjectCID( rObjectCID )
@@ -97,6 +102,7 @@ ObjectPropertiesDialogParameter::ObjectPropertiesDialogParameter( const OUString
         , m_aCategories()
         , m_xChartDocument( 0 )
         , m_bComplexCategoriesAxis( false )
+        , m_nNbPoints( 0 )
 {
     OUString aParticleID = ObjectIdentifier::getParticleID( m_aObjectCID );
     m_bAffectsMultipleObjects = (aParticleID == "ALLELEMENTS");
@@ -211,7 +217,63 @@ void ObjectPropertiesDialogParameter::init( const uno::Reference< frame::XModel
         m_bCanAxisLabelsBeStaggered = nDimensionCount==2;
     }
 
-    //create gui name for this object
+    if( OBJECTTYPE_DATA_CURVE == m_eObjectType )
+    {
+        uno::Reference< data::XDataSource > xSource( xSeries, uno::UNO_QUERY );
+        Sequence< Reference< data::XLabeledDataSequence > > aDataSeqs( xSource->getDataSequences());
+        Sequence< double > aXValues, aYValues;
+        bool bXValuesFound = false, bYValuesFound = false;
+        m_nNbPoints = 0;
+        sal_Int32 i = 0;
+        for( i=0;
+             ! (bXValuesFound && bYValuesFound) && i<aDataSeqs.getLength();
+             ++i )
+        {
+            try
+            {
+                Reference< data::XDataSequence > xSeq( aDataSeqs[i]->getValues());
+                Reference< XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW );
+                OUString aRole;
+                if( xProp->getPropertyValue( "Role" ) >>= aRole )
+                {
+                    if( !bXValuesFound && aRole == "values-x" )
+                    {
+                        aXValues = DataSequenceToDoubleSequence( xSeq );
+                        bXValuesFound = true;
+                    }
+                    else if( !bYValuesFound && aRole == "values-y" )
+                    {
+                        aYValues = DataSequenceToDoubleSequence( xSeq );
+                        bYValuesFound = true;
+                    }
+                }
+            }
+            catch( const Exception & ex )
+            {
+                ASSERT_EXCEPTION( ex );
+            }
+        }
+        if( !bXValuesFound && bYValuesFound )
+        {
+            // initialize with 1, 2, ...
+            //first category (index 0) matches with real number 1.0
+            aXValues.realloc( aYValues.getLength() );
+            for( i=0; i<aXValues.getLength(); ++i )
+                aXValues[i] = i+1;
+            bXValuesFound = true;
+        }
+
+        if( bXValuesFound && bYValuesFound &&
+            aXValues.getLength() > 0 &&
+            aYValues.getLength() > 0 )
+        {
+            RegressionCalculationHelper::tDoubleVectorPair aValues(
+                RegressionCalculationHelper::cleanup( aXValues, aYValues, RegressionCalculationHelper::isValid()));
+            m_nNbPoints = aValues.second.size();
+        }
+    }
+
+     //create gui name for this object
     {
         if( !m_bAffectsMultipleObjects && OBJECTTYPE_AXIS == m_eObjectType )
         {
@@ -323,6 +385,10 @@ bool ObjectPropertiesDialogParameter::IsComplexCategoriesAxis() const
 {
     return m_bComplexCategoriesAxis;
 }
+sal_Int32 ObjectPropertiesDialogParameter::getNbPoints() const
+{
+    return m_nNbPoints;
+}
 
 const sal_uInt16 nNoArrowNoShadowDlg    = 1101;
 
@@ -644,6 +710,7 @@ void SchAttribTabDlg::PageCreated(sal_uInt16 nId, SfxTabPage &rPage)
             if(pTrendlineTabPage)
             {
                 pTrendlineTabPage->SetNumFormatter( m_pNumberFormatter );
+                pTrendlineTabPage->SetNbPoints( m_pParameter->getNbPoints() );
             }
             break;
         }
diff --git a/chart2/source/controller/dialogs/res_Trendline.cxx b/chart2/source/controller/dialogs/res_Trendline.cxx
index 624330d..2ec92e5 100644
--- a/chart2/source/controller/dialogs/res_Trendline.cxx
+++ b/chart2/source/controller/dialogs/res_Trendline.cxx
@@ -42,7 +42,8 @@ void lcl_setValue( FormattedField& rFmtField, double fValue )
 TrendlineResources::TrendlineResources( Window * pParent, const SfxItemSet& rInAttrs ) :
         m_eTrendLineType( CHREGRESS_LINEAR ),
         m_bTrendLineUnique( true ),
-        m_pNumFormatter(NULL)
+        m_pNumFormatter( NULL ),
+        m_nNbPoints( 0 )
 {
     SfxTabPage* pTabPage = reinterpret_cast<SfxTabPage*>(pParent);
     pTabPage->get(m_pRB_Linear,"linear");
@@ -293,19 +294,26 @@ void TrendlineResources::FillValueSets()
 
 void TrendlineResources::UpdateControlStates()
 {
+    if( m_nNbPoints > 0 )
+    {
+        sal_Int32 nMaxValue = m_nNbPoints - 1 + ( m_pCB_SetIntercept->IsChecked()?1:0 );
+//        if( nMaxValue > 10) nMaxValue = 10;
+        m_pNF_Degree->SetMax( nMaxValue );
+        m_pNF_Period->SetMax( m_nNbPoints - 1 );
+    }
     bool bMovingAverage = ( m_eTrendLineType == CHREGRESS_MOVING_AVERAGE );
     bool bInterceptAvailable = ( m_eTrendLineType == CHREGRESS_LINEAR ) || ( m_eTrendLineType == CHREGRESS_POLYNOMIAL );
-    m_pFmtFld_ExtrapolateForward->Enable(!bMovingAverage);
-    m_pFmtFld_ExtrapolateBackward->Enable(!bMovingAverage);
+    m_pFmtFld_ExtrapolateForward->Enable( !bMovingAverage );
+    m_pFmtFld_ExtrapolateBackward->Enable( !bMovingAverage );
     m_pCB_SetIntercept->Enable( bInterceptAvailable );
     m_pFmtFld_InterceptValue->Enable( bInterceptAvailable );
-    if(bMovingAverage)
+    if( bMovingAverage )
     {
         m_pCB_ShowEquation->SetState( TRISTATE_FALSE );
         m_pCB_ShowCorrelationCoeff->SetState( TRISTATE_FALSE );
     }
-    m_pCB_ShowEquation->Enable(!bMovingAverage);
-    m_pCB_ShowCorrelationCoeff->Enable(!bMovingAverage);
+    m_pCB_ShowEquation->Enable( !bMovingAverage );
+    m_pCB_ShowCorrelationCoeff->Enable( !bMovingAverage );
 }
 
 IMPL_LINK( TrendlineResources, ChangeValue, void *, pNumericField)
@@ -344,6 +352,11 @@ void TrendlineResources::SetNumFormatter( SvNumberFormatter* pFormatter )
     m_pFmtFld_InterceptValue->SetFormatter( m_pNumFormatter );
 }
 
+void TrendlineResources::SetNbPoints( sal_Int32 nNbPoints )
+{
+    m_nNbPoints = nNbPoints;
+    UpdateControlStates();
+}
 
 } //  namespace chart
 
diff --git a/chart2/source/controller/dialogs/res_Trendline.hxx b/chart2/source/controller/dialogs/res_Trendline.hxx
index 8399b61..4e51ecf 100644
--- a/chart2/source/controller/dialogs/res_Trendline.hxx
+++ b/chart2/source/controller/dialogs/res_Trendline.hxx
@@ -43,6 +43,7 @@ public:
     void FillValueSets();
 
     void SetNumFormatter( SvNumberFormatter* pFormatter );
+    void SetNbPoints( sal_Int32 nNbPoints );
 
 private:
     RadioButton* m_pRB_Linear;
@@ -74,6 +75,7 @@ private:
     bool                m_bTrendLineUnique;
 
     SvNumberFormatter*  m_pNumFormatter;
+    sal_Int32           m_nNbPoints;
 
     void UpdateControlStates();
     DECL_LINK( SelectTrendLine, RadioButton * );
diff --git a/chart2/source/controller/dialogs/tp_Trendline.cxx b/chart2/source/controller/dialogs/tp_Trendline.cxx
index 2b796cc..a08f895 100644
--- a/chart2/source/controller/dialogs/tp_Trendline.cxx
+++ b/chart2/source/controller/dialogs/tp_Trendline.cxx
@@ -64,6 +64,11 @@ void TrendlineTabPage::SetNumFormatter( SvNumberFormatter* pNumFormatter )
     m_aTrendlineResources.SetNumFormatter( pNumFormatter );
 }
 
+void TrendlineTabPage::SetNbPoints( sal_Int32 nNbPoints )
+{
+    m_aTrendlineResources.SetNbPoints( nNbPoints );
+}
+
 } //namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/controller/dialogs/tp_Trendline.hxx b/chart2/source/controller/dialogs/tp_Trendline.hxx
index 63bfe13..b11c7d7 100644
--- a/chart2/source/controller/dialogs/tp_Trendline.hxx
+++ b/chart2/source/controller/dialogs/tp_Trendline.hxx
@@ -38,6 +38,7 @@ public:
 
     virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
     void SetNumFormatter( SvNumberFormatter* pFormatter );
+    void SetNbPoints( sal_Int32 nNbPoints );
 
 private:
     TrendlineResources   m_aTrendlineResources;
diff --git a/chart2/source/controller/inc/dlg_ObjectProperties.hxx b/chart2/source/controller/inc/dlg_ObjectProperties.hxx
index ff7289d..598f8fc 100644
--- a/chart2/source/controller/inc/dlg_ObjectProperties.hxx
+++ b/chart2/source/controller/inc/dlg_ObjectProperties.hxx
@@ -60,6 +60,8 @@ public:
 
     bool IsComplexCategoriesAxis() const;
 
+    sal_Int32 getNbPoints() const;
+
 private:
     OUString   m_aObjectCID;
     ObjectType      m_eObjectType;
@@ -89,6 +91,8 @@ private:
     ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument > m_xChartDocument;
 
     bool m_bComplexCategoriesAxis;
+
+    sal_Int32 m_nNbPoints;
 };
 
 /*************************************************************************


More information about the Libreoffice-commits mailing list