tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / view / axes / VCartesianCoordinateSystem.cxx
blob81fa369c2f603df76d0ba2674b751b83eb6541b8
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 "VCartesianCoordinateSystem.hxx"
21 #include "VCartesianGrid.hxx"
22 #include "VCartesianAxis.hxx"
23 #include <BaseCoordinateSystem.hxx>
24 #include <AxisIndexDefines.hxx>
25 #include <Axis.hxx>
26 #include <DataTable.hxx>
27 #include <Diagram.hxx>
28 #include <AxisHelper.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <ChartModel.hxx>
31 #include <GridProperties.hxx>
32 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
33 #include <com/sun/star/chart2/AxisType.hpp>
35 namespace chart
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::chart2;
39 using ::com::sun::star::uno::Reference;
41 namespace {
43 class TextualDataProvider : public ::cppu::WeakImplHelper<
44 css::chart2::data::XTextualDataSequence
47 public:
48 explicit TextualDataProvider( const uno::Sequence< OUString >& rTextSequence )
49 : m_aTextSequence( rTextSequence )
53 //XTextualDataSequence
54 virtual uno::Sequence< OUString > SAL_CALL getTextualData() override
56 return m_aTextSequence;
59 private: //member
60 uno::Sequence< OUString > m_aTextSequence;
65 VCartesianCoordinateSystem::VCartesianCoordinateSystem( const rtl::Reference< BaseCoordinateSystem >& xCooSys )
66 : VCoordinateSystem(xCooSys)
70 VCartesianCoordinateSystem::~VCartesianCoordinateSystem()
74 void VCartesianCoordinateSystem::createGridShapes()
76 if(!m_xLogicTargetForGrids.is() || !m_xFinalTarget.is() )
77 return;
79 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
80 bool bSwapXAndY = getPropertySwapXAndYAxis();
82 for( sal_Int32 nDimensionIndex=0; nDimensionIndex<3; nDimensionIndex++)
84 sal_Int32 nAxisIndex = MAIN_AXIS_INDEX;
85 rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, nAxisIndex, m_xCooSysModel );
86 if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
87 continue;
89 VCartesianGrid aGrid(nDimensionIndex,nDimensionCount, getGridListFromAxis( xAxis ));
90 aGrid.setExplicitScaleAndIncrement( getExplicitScale(nDimensionIndex,nAxisIndex)
91 , getExplicitIncrement(nDimensionIndex,nAxisIndex) );
92 aGrid.set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
94 aGrid.initPlotter(m_xLogicTargetForGrids,m_xFinalTarget
95 , createCIDForGrid( nDimensionIndex,nAxisIndex ) );
96 if(nDimensionCount==2)
97 aGrid.setTransformationSceneToScreen( m_aMatrixSceneToScreen );
98 aGrid.setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
99 aGrid.createShapes();
103 void VCartesianCoordinateSystem::createVAxisList(
104 const rtl::Reference<::chart::ChartModel> & xChartDoc,
105 const awt::Size& rFontReferenceSize,
106 const awt::Rectangle& rMaximumSpaceForLabels,
107 bool bLimitSpaceForLabels,
108 std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList,
109 uno::Reference<uno::XComponentContext> const& rComponentContext)
111 // note: using xChartDoc itself as XNumberFormatsSupplier would cause
112 // a leak from VCartesianAxis due to cyclic reference
113 uno::Reference<util::XNumberFormatsSupplier> const xNumberFormatsSupplier(
114 xChartDoc->getNumberFormatsSupplier());
116 m_aAxisMap.clear();
118 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
119 bool bSwapXAndY = getPropertySwapXAndYAxis();
121 if(nDimensionCount<=0)
122 return;
124 sal_Int32 nDimensionIndex = 0;
126 // dimension index -> x, y or z axis.
127 for( nDimensionIndex = 0; nDimensionIndex < nDimensionCount; nDimensionIndex++ )
129 // axis index -> primary or secondary axis.
130 sal_Int32 nMaxAxisIndex = m_xCooSysModel->getMaximumAxisIndexByDimension(nDimensionIndex);
131 for( sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaxAxisIndex; nAxisIndex++ )
133 rtl::Reference< Axis > xAxis = getAxisByDimension(nDimensionIndex,nAxisIndex);
134 if(!xAxis.is() || !AxisHelper::shouldAxisBeDisplayed( xAxis, m_xCooSysModel ))
135 continue;
137 rtl::Reference<Diagram> xDiagram(xChartDoc->getFirstChartDiagram());
138 AxisProperties aAxisProperties(xAxis, getExplicitCategoriesProvider(), xDiagram->getDataTableRef());
139 aAxisProperties.m_nDimensionIndex = nDimensionIndex;
140 aAxisProperties.m_bSwapXAndY = bSwapXAndY;
141 aAxisProperties.m_bIsMainAxis = (nAxisIndex==0);
142 aAxisProperties.m_bLimitSpaceForLabels = bLimitSpaceForLabels;
143 rtl::Reference< Axis > xCrossingMainAxis = AxisHelper::getCrossingMainAxis( xAxis, m_xCooSysModel );
144 if( xCrossingMainAxis.is() )
146 ScaleData aCrossingScale( xCrossingMainAxis->getScaleData() );
147 aAxisProperties.m_bCrossingAxisHasReverseDirection = (aCrossingScale.Orientation==AxisOrientation_REVERSE);
149 if( aCrossingScale.AxisType == AxisType::CATEGORY )
150 aAxisProperties.m_bCrossingAxisIsCategoryAxes = true;
153 if( nDimensionIndex == 2 )
155 aAxisProperties.m_xAxisTextProvider = new TextualDataProvider( m_aSeriesNamesForZAxis );
157 //for the z axis copy the positioning properties from the x axis (or from the y axis for swapped coordinate systems)
158 rtl::Reference< Axis > xSisterAxis = AxisHelper::getCrossingMainAxis( xCrossingMainAxis, m_xCooSysModel );
159 aAxisProperties.initAxisPositioning( xSisterAxis );
161 aAxisProperties.init(true);
162 if(aAxisProperties.m_bDisplayLabels)
163 aAxisProperties.m_nNumberFormatKey = getNumberFormatKeyForAxis(xAxis, xChartDoc);
165 auto apVAxis = std::make_shared<VCartesianAxis>(aAxisProperties,xNumberFormatsSupplier,nDimensionIndex,nDimensionCount);
166 tFullAxisIndex aFullAxisIndex( nDimensionIndex, nAxisIndex );
167 m_aAxisMap[aFullAxisIndex] = apVAxis;
168 apVAxis->set3DWallPositions( m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
170 apVAxis->initAxisLabelProperties(rFontReferenceSize,rMaximumSpaceForLabels);
171 apVAxis->createDataTableView(rSeriesPlotterList, xNumberFormatsSupplier, xChartDoc, rComponentContext);
176 void VCartesianCoordinateSystem::initVAxisInList()
178 if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
179 return;
181 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
182 bool bSwapXAndY = getPropertySwapXAndYAxis();
184 for (auto const& [nIndexPair, pVAxis] : m_aAxisMap)
186 if (pVAxis)
188 auto [nDimensionIndex, nAxisIndex] = nIndexPair;
189 pVAxis->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex, nAxisIndex ), getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
190 pVAxis->initPlotter(m_xLogicTargetForAxes, m_xFinalTarget, createCIDForAxis( nDimensionIndex, nAxisIndex ) );
191 if(nDimensionCount==2)
192 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
193 pVAxis->setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
198 void VCartesianCoordinateSystem::updateScalesAndIncrementsOnAxes()
200 if(!m_xLogicTargetForAxes.is() || !m_xFinalTarget.is() || !m_xCooSysModel.is() )
201 return;
203 sal_Int32 nDimensionCount = m_xCooSysModel->getDimension();
204 bool bSwapXAndY = getPropertySwapXAndYAxis();
206 for (auto const& [nIndexPair, pVAxis] : m_aAxisMap)
208 if (pVAxis)
210 auto [nDimensionIndex, nAxisIndex] = nIndexPair;
212 pVAxis->setExplicitScaleAndIncrement( getExplicitScale( nDimensionIndex, nAxisIndex ), getExplicitIncrement( nDimensionIndex, nAxisIndex ) );
213 if(nDimensionCount==2)
214 pVAxis->setTransformationSceneToScreen( m_aMatrixSceneToScreen );
215 pVAxis->setScales( getExplicitScales(nDimensionIndex,nAxisIndex), bSwapXAndY );
220 } //namespace chart
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */