Debian Codegraph @

chart2/source/controller/dialogs/dlg_InsertErrorBars.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <dlg_InsertErrorBars.hxx>
21 #include <res_ErrorBar.hxx>
22 #include <chartview/ExplicitScaleValues.hxx>
23 #include <ChartModel.hxx>
24 #include <ChartView.hxx>
25 #include <ObjectIdentifier.hxx>
26 #include <Diagram.hxx>
27 #include <Axis.hxx>
28 #include <AxisHelper.hxx>
29 #include <ObjectNameProvider.hxx>
30 #include <DataSeries.hxx>
31
32 using namespace ::com::sun::star;
33
34 namespace chart
35 {
36
37 InsertErrorBarsDialog::InsertErrorBarsDialog(
38 weld::Window* pParent, const SfxItemSet& rMyAttrs,
39 const rtl::Reference<::chart::ChartModel> & xChartDocument,
40 ErrorBarResources::tErrorBarType eType /* = ErrorBarResources::ERROR_BAR_Y */ )
41 : GenericDialogController(pParent, u"modules/schart/ui/dlg_InsertErrorBars.ui"_ustr, u"dlg_InsertErrorBars"_ustr)
42 , m_apErrorBarResources( new ErrorBarResources(
43 m_xBuilder.get(), this, rMyAttrs,
44 /* bNoneAvailable = */ true, eType ))
45 {
46 ObjectType objType = eType == ErrorBarResources::ERROR_BAR_Y ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X;
47
48 m_xDialog->set_title(ObjectNameProvider::getName_ObjectForAllSeries(objType));
49
50 m_apErrorBarResources->SetChartDocumentForRangeChoosing( xChartDocument );
51 }
52
53 void InsertErrorBarsDialog::FillItemSet(SfxItemSet& rOutAttrs)
54 {
55 m_apErrorBarResources->FillItemSet(rOutAttrs);
56 }
57
58 void InsertErrorBarsDialog::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
59 {
60 m_apErrorBarResources->SetAxisMinorStepWidthForErrorBarDecimals( fMinorStepWidth );
61 }
62
63 double InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals(
64 const rtl::Reference<::chart::ChartModel>& xChartModel,
65 const rtl::Reference<::chart::ChartView>& xChartView,
66 std::u16string_view rSelectedObjectCID )
67 {
68 double fStepWidth = 0.001;
69
70 ChartView* pExplicitValueProvider( xChartView.get() );
71 if( pExplicitValueProvider )
72 {
73 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
74 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedObjectCID, xChartModel );
75 rtl::Reference< Axis > xAxis = xDiagram->getAttachedAxis( xSeries );
76 if(!xAxis.is())
77 xAxis = AxisHelper::getAxis( 1/*nDimensionIndex*/, true/*bMainAxis*/, xDiagram );
78 if(xAxis.is())
79 {
80 ExplicitScaleData aExplicitScale;
81 ExplicitIncrementData aExplicitIncrement;
82 pExplicitValueProvider->getExplicitValuesForAxis( xAxis,aExplicitScale, aExplicitIncrement );
83
84 fStepWidth = aExplicitIncrement.Distance;
85 if( !aExplicitIncrement.SubIncrements.empty() && aExplicitIncrement.SubIncrements[0].IntervalCount>0 )
86 fStepWidth=fStepWidth/double(aExplicitIncrement.SubIncrements[0].IntervalCount);
87 else
88 fStepWidth/=10;
89 }
90 }
91
92 return fStepWidth;
93 }
94
95 } //namespace chart
96
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */