summaryrefslogtreecommitdiff
path: root/chart2/source/model
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-03-16 09:32:07 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-03-21 08:44:53 +0000
commitdf12a23157f4515ba5e78c0bd293dfd1609de668 (patch)
treeda9345306eb70127d8850e29abe93fb067093ee3 /chart2/source/model
parentfd32093df9fdf5d46ed4def9fd8dada7d0d5e361 (diff)
move getVertical/setVertical inside chart2::Diagram
Change-Id: Ide512e20fea94b1d7d038290d1c833f1d8cf42ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149164 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2/source/model')
-rw-r--r--chart2/source/model/main/Diagram.cxx85
-rw-r--r--chart2/source/model/template/BarChartTypeTemplate.cxx6
-rw-r--r--chart2/source/model/template/StockChartTypeTemplate.cxx2
3 files changed, 89 insertions, 4 deletions
diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx
index d2068529f93d..5d6f84adbb86 100644
--- a/chart2/source/model/main/Diagram.cxx
+++ b/chart2/source/model/main/Diagram.cxx
@@ -55,6 +55,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <o3tl/safeint.hxx>
+#include <rtl/math.hxx>
#include <algorithm>
#include <utility>
@@ -1536,6 +1537,90 @@ StackMode Diagram::getStackMode( bool& rbFound, bool& rbAmbiguous )
return eGlobalStackMode;
}
+void Diagram::setVertical( bool bVertical /* = true */ )
+{
+ try
+ {
+ uno::Any aValue;
+ aValue <<= bVertical;
+ for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : getBaseCoordinateSystems() )
+ {
+ bool bChanged = false;
+ bool bOldSwap = false;
+ if( !(xCooSys->getPropertyValue("SwapXAndYAxis") >>= bOldSwap)
+ || bVertical != bOldSwap )
+ bChanged = true;
+
+ if( bChanged )
+ xCooSys->setPropertyValue("SwapXAndYAxis", aValue);
+
+ const sal_Int32 nDimensionCount = xCooSys->getDimension();
+ sal_Int32 nDimIndex = 0;
+ for (nDimIndex=0; nDimIndex < nDimensionCount; ++nDimIndex)
+ {
+ const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(nDimIndex);
+ for (sal_Int32 nI = 0; nI <= nMaximumScaleIndex; ++nI)
+ {
+ rtl::Reference<Axis> xAxis = xCooSys->getAxisByDimension2(nDimIndex,nI);
+ if (!xAxis.is())
+ continue;
+
+ //adapt title rotation only when axis swapping has changed
+ if (!bChanged)
+ continue;
+
+ Reference< beans::XPropertySet > xTitleProps( xAxis->getTitleObject(), uno::UNO_QUERY );
+ if (!xTitleProps.is())
+ continue;
+
+ double fAngleDegree = 0.0;
+ xTitleProps->getPropertyValue("TextRotation") >>= fAngleDegree;
+ if (fAngleDegree != 0.0 &&
+ !rtl::math::approxEqual(fAngleDegree, 90.0))
+ continue;
+
+ double fNewAngleDegree = 0.0;
+ if( !bVertical && nDimIndex == 1 )
+ fNewAngleDegree = 90.0;
+ else if( bVertical && nDimIndex == 0 )
+ fNewAngleDegree = 90.0;
+
+ xTitleProps->setPropertyValue("TextRotation", uno::Any(fNewAngleDegree));
+ }
+ }
+ }
+ }
+ catch( const uno::Exception & )
+ {
+ DBG_UNHANDLED_EXCEPTION("chart2");
+ }
+}
+
+bool Diagram::getVertical( bool& rbFound, bool& rbAmbiguous )
+{
+ bool bValue = false;
+ rbFound = false;
+ rbAmbiguous = false;
+
+ for (rtl::Reference<BaseCoordinateSystem> const & coords : getBaseCoordinateSystems())
+ {
+ bool bCurrent = false;
+ if (coords->getPropertyValue("SwapXAndYAxis") >>= bCurrent)
+ {
+ if (!rbFound)
+ {
+ bValue = bCurrent;
+ rbFound = true;
+ }
+ else if (bCurrent != bValue)
+ {
+ // ambiguous -> choose always first found
+ rbAmbiguous = true;
+ }
+ }
+ }
+ return bValue;
+}
} // namespace chart
diff --git a/chart2/source/model/template/BarChartTypeTemplate.cxx b/chart2/source/model/template/BarChartTypeTemplate.cxx
index 9cadbadb8980..54f4f155186b 100644
--- a/chart2/source/model/template/BarChartTypeTemplate.cxx
+++ b/chart2/source/model/template/BarChartTypeTemplate.cxx
@@ -170,7 +170,7 @@ bool BarChartTypeTemplate::matchesTemplate2(
{
bool bFound = false;
bool bAmbiguous = false;
- bool bVertical = DiagramHelper::getVertical( xDiagram, bFound, bAmbiguous );
+ bool bVertical = xDiagram->getVertical( bFound, bAmbiguous );
if( m_eBarDirection == HORIZONTAL )
bResult = bVertical;
else if( m_eBarDirection == VERTICAL )
@@ -272,7 +272,7 @@ void BarChartTypeTemplate::resetStyles2(
}
}
- DiagramHelper::setVertical( xDiagram, false );
+ xDiagram->setVertical( false );
}
void BarChartTypeTemplate::createCoordinateSystems(
@@ -280,7 +280,7 @@ void BarChartTypeTemplate::createCoordinateSystems(
{
ChartTypeTemplate::createCoordinateSystems( xDiagram );
- DiagramHelper::setVertical( xDiagram, m_eBarDirection == HORIZONTAL );
+ xDiagram->setVertical( m_eBarDirection == HORIZONTAL );
}
IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet )
diff --git a/chart2/source/model/template/StockChartTypeTemplate.cxx b/chart2/source/model/template/StockChartTypeTemplate.cxx
index 24662ebdd57a..e05981bebbeb 100644
--- a/chart2/source/model/template/StockChartTypeTemplate.cxx
+++ b/chart2/source/model/template/StockChartTypeTemplate.cxx
@@ -238,7 +238,7 @@ void StockChartTypeTemplate::resetStyles2(
}
}
- DiagramHelper::setVertical( xDiagram, false );
+ xDiagram->setVertical( false );
}
rtl::Reference< ChartType > StockChartTypeTemplate::getChartTypeForIndex( sal_Int32 nChartTypeIndex )