Kaydet (Commit) 5707c812 authored tarafından Laurent Balland-Poirier's avatar Laurent Balland-Poirier Kaydeden (comit) Tomaž Vajngerl

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/9116Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
Tested-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst f84fe39c
......@@ -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;
}
......
......@@ -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
......
......@@ -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 * );
......
......@@ -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: */
......@@ -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;
......
......@@ -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;
};
/*************************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment