tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / view / axes / Tickmarks_Dates.cxx
blob869d46603fb779e560424cb7001b81c8eaddc28e
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 "Tickmarks_Dates.hxx"
21 #include "DateScaling.hxx"
22 #include <rtl/math.hxx>
23 #include <osl/diagnose.h>
24 #include <DateHelper.hxx>
25 #include <com/sun/star/chart/TimeUnit.hpp>
26 #include <utility>
28 namespace chart
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::chart2;
32 using namespace ::rtl::math;
33 using ::com::sun::star::chart::TimeUnit::DAY;
34 using ::com::sun::star::chart::TimeUnit::MONTH;
35 using ::com::sun::star::chart::TimeUnit::YEAR;
37 DateTickFactory::DateTickFactory(
38 ExplicitScaleData aScale, ExplicitIncrementData aIncrement )
39 : m_aScale(std::move( aScale ))
40 , m_aIncrement(std::move( aIncrement ))
42 //@todo: make sure that the scale is valid for the scaling
44 if( m_aScale.Scaling.is() )
46 m_xInverseScaling = m_aScale.Scaling->getInverseScaling();
47 OSL_ENSURE( m_xInverseScaling.is(), "each Scaling needs to return an inverse Scaling" );
51 DateTickFactory::~DateTickFactory()
55 void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos, bool bShifted ) const
57 rAllTickInfos.resize(2);
58 TickInfoArrayType& rMajorTicks = rAllTickInfos[0];
59 TickInfoArrayType& rMinorTicks = rAllTickInfos[1];
60 rMajorTicks.clear();
61 rMinorTicks.clear();
63 Date aNull(m_aScale.NullDate);
65 Date aDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Minimum));
66 Date aMaxDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Maximum));
68 uno::Reference< chart2::XScaling > xScaling(m_aScale.Scaling);
69 uno::Reference< chart2::XScaling > xInverseScaling(m_xInverseScaling);
70 if( bShifted )
72 xScaling = new DateScaling(aNull,m_aScale.TimeResolution,true/*bShifted*/);
73 xInverseScaling = xScaling->getInverseScaling();
76 //create major date tickinfos
77 while( aDate<= aMaxDate )
79 if( bShifted && aDate==aMaxDate )
80 break;
82 TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull;
84 if( xInverseScaling.is() )
85 aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue);
86 rMajorTicks.push_back( aNewTick );
88 if(m_aIncrement.MajorTimeInterval.Number<=0)
89 break;
91 //find next major date
92 switch( m_aIncrement.MajorTimeInterval.TimeUnit )
94 case DAY:
95 aDate.AddDays( m_aIncrement.MajorTimeInterval.Number );
96 break;
97 case YEAR:
98 aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MajorTimeInterval.Number );
99 break;
100 case MONTH:
101 default:
102 aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MajorTimeInterval.Number );
103 break;
107 //create minor date tickinfos
108 aDate = aNull + static_cast<sal_Int32>(::rtl::math::approxFloor(m_aScale.Minimum));
109 while( aDate<= aMaxDate )
111 if( bShifted && aDate==aMaxDate )
112 break;
114 TickInfo aNewTick(xInverseScaling); aNewTick.fScaledTickValue = aDate - aNull;
115 if( xInverseScaling.is() )
116 aNewTick.fScaledTickValue = xScaling->doScaling(aNewTick.fScaledTickValue);
117 rMinorTicks.push_back( aNewTick );
119 if(m_aIncrement.MinorTimeInterval.Number<=0)
120 break;
122 //find next minor date
123 switch( m_aIncrement.MinorTimeInterval.TimeUnit )
125 case DAY:
126 aDate.AddDays( m_aIncrement.MinorTimeInterval.Number );
127 break;
128 case YEAR:
129 aDate = DateHelper::GetDateSomeYearsAway( aDate, m_aIncrement.MinorTimeInterval.Number );
130 break;
131 case MONTH:
132 default:
133 aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MinorTimeInterval.Number );
134 break;
139 void DateTickFactory::getAllTicks( TickInfoArraysType& rAllTickInfos ) const
141 getAllTicks( rAllTickInfos, false );
144 void DateTickFactory::getAllTicksShifted( TickInfoArraysType& rAllTickInfos ) const
146 getAllTicks( rAllTickInfos, true );
149 } //namespace chart
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */