cid#1640468 Dereference after null check
[LibreOffice.git] / chart2 / source / controller / dialogs / dlg_InsertErrorBars.cxx
blob693af9b5caae47c3259a0984cfd556e8b8a6bf6e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <dlg_InsertErrorBars.hxx>
21 #include <res_ErrorBar.hxx>
22 #include <chartview/ExplicitScaleValues.hxx>
23 #include <chartview/ExplicitValueProvider.hxx>
24 #include <ChartModel.hxx>
25 #include <ChartView.hxx>
26 #include <ObjectIdentifier.hxx>
27 #include <Diagram.hxx>
28 #include <Axis.hxx>
29 #include <AxisHelper.hxx>
30 #include <ObjectNameProvider.hxx>
31 #include <DataSeries.hxx>
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::chart2;
36 namespace chart
39 InsertErrorBarsDialog::InsertErrorBarsDialog(
40 weld::Window* pParent, const SfxItemSet& rMyAttrs,
41 const rtl::Reference<::chart::ChartModel> & xChartDocument,
42 ErrorBarResources::tErrorBarType eType /* = ErrorBarResources::ERROR_BAR_Y */ )
43 : GenericDialogController(pParent, u"modules/schart/ui/dlg_InsertErrorBars.ui"_ustr, u"dlg_InsertErrorBars"_ustr)
44 , m_apErrorBarResources( new ErrorBarResources(
45 m_xBuilder.get(), this, rMyAttrs,
46 /* bNoneAvailable = */ true, eType ))
48 ObjectType objType = eType == ErrorBarResources::ERROR_BAR_Y ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X;
50 m_xDialog->set_title(ObjectNameProvider::getName_ObjectForAllSeries(objType));
52 m_apErrorBarResources->SetChartDocumentForRangeChoosing( xChartDocument );
55 void InsertErrorBarsDialog::FillItemSet(SfxItemSet& rOutAttrs)
57 m_apErrorBarResources->FillItemSet(rOutAttrs);
60 void InsertErrorBarsDialog::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
62 m_apErrorBarResources->SetAxisMinorStepWidthForErrorBarDecimals( fMinorStepWidth );
65 double InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals(
66 const rtl::Reference<::chart::ChartModel>& xChartModel,
67 const rtl::Reference<::chart::ChartView>& xChartView,
68 std::u16string_view rSelectedObjectCID )
70 double fStepWidth = 0.001;
72 ExplicitValueProvider* pExplicitValueProvider( xChartView.get() );
73 if( pExplicitValueProvider )
75 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
76 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedObjectCID, xChartModel );
77 rtl::Reference< Axis > xAxis = xDiagram->getAttachedAxis( xSeries );
78 if(!xAxis.is())
79 xAxis = AxisHelper::getAxis( 1/*nDimensionIndex*/, true/*bMainAxis*/, xDiagram );
80 if(xAxis.is())
82 ExplicitScaleData aExplicitScale;
83 ExplicitIncrementData aExplicitIncrement;
84 pExplicitValueProvider->getExplicitValuesForAxis( xAxis,aExplicitScale, aExplicitIncrement );
86 fStepWidth = aExplicitIncrement.Distance;
87 if( !aExplicitIncrement.SubIncrements.empty() && aExplicitIncrement.SubIncrements[0].IntervalCount>0 )
88 fStepWidth=fStepWidth/double(aExplicitIncrement.SubIncrements[0].IntervalCount);
89 else
90 fStepWidth/=10;
94 return fStepWidth;
97 } //namespace chart
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */