LibreOffice Module chart2 (master) 1
tp_AxisPositions.cxx
Go to the documentation of this file.
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 "tp_AxisPositions.hxx"
21
23#include <AxisHelper.hxx>
24
25#include <rtl/math.hxx>
26#include <svx/chrtitem.hxx>
27#include <svl/intitem.hxx>
28#include <vcl/formatter.hxx>
29
30using namespace ::com::sun::star;
31
32namespace chart
33{
34
36 : SfxTabPage(pPage, pController, "modules/schart/ui/tp_AxisPositions.ui", "tp_AxisPositions", &rInAttrs)
37 , m_pNumFormatter(nullptr)
38 , m_bCrossingAxisIsCategoryAxis(false)
39 , m_bSupportAxisPositioning(false)
40 , m_bSupportCategoryPositioning(false)
41 , m_xFL_AxisLine(m_xBuilder->weld_frame("FL_AXIS_LINE"))
42 , m_xLB_CrossesAt(m_xBuilder->weld_combo_box("LB_CROSSES_OTHER_AXIS_AT"))
43 , m_xED_CrossesAt(m_xBuilder->weld_formatted_spin_button("EDT_CROSSES_OTHER_AXIS_AT"))
44 , m_xED_CrossesAtCategory(m_xBuilder->weld_combo_box( "EDT_CROSSES_OTHER_AXIS_AT_CATEGORY"))
45 , m_xFL_Position(m_xBuilder->weld_frame("FL_POSITION"))
46 , m_xRB_On(m_xBuilder->weld_radio_button("RB_ON"))
47 , m_xRB_Between(m_xBuilder->weld_radio_button("RB_BETWEEN"))
48 , m_xFL_Labels(m_xBuilder->weld_frame("FL_LABELS"))
49 , m_xLB_PlaceLabels(m_xBuilder->weld_combo_box("LB_PLACE_LABELS"))
50 , m_xCB_TicksInner(m_xBuilder->weld_check_button("CB_TICKS_INNER"))
51 , m_xCB_TicksOuter(m_xBuilder->weld_check_button("CB_TICKS_OUTER"))
52 , m_xCB_MinorInner(m_xBuilder->weld_check_button("CB_MINOR_INNER"))
53 , m_xCB_MinorOuter(m_xBuilder->weld_check_button("CB_MINOR_OUTER"))
54 , m_xBxPlaceTicks(m_xBuilder->weld_widget("boxPLACE_TICKS"))
55 , m_xLB_PlaceTicks(m_xBuilder->weld_combo_box("LB_PLACE_TICKS"))
56{
57 m_xLB_CrossesAt->connect_changed(LINK(this, AxisPositionsTabPage, CrossesAtSelectHdl));
58 m_xLB_PlaceLabels->connect_changed(LINK(this, AxisPositionsTabPage, PlaceLabelsSelectHdl));
59
60 Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter();
61 rCrossFormatter.ClearMinValue();
62 rCrossFormatter.ClearMaxValue();
63 Formatter& rDistanceFormatter = m_xED_CrossesAt->GetFormatter();
64 rDistanceFormatter.ClearMinValue();
65 rDistanceFormatter.ClearMaxValue();
66}
67
69{
70}
71
72std::unique_ptr<SfxTabPage> AxisPositionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs)
73{
74 return std::make_unique<AxisPositionsTabPage>(pPage, pController, *rOutAttrs);
75}
76
78{
79 // axis line
80 sal_Int32 nPos = m_xLB_CrossesAt->get_active();
81 rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_POSITION, nPos+1 ));
82 if( nPos==2 )
83 {
84 Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter();
85 double fCrossover = rCrossFormatter.GetValue();
87 fCrossover = m_xED_CrossesAtCategory->get_active()+1;
88 rOutAttrs->Put(SvxDoubleItem(fCrossover,SCHATTR_AXIS_POSITION_VALUE));
89 }
90
91 // shifted category position
92 if (m_xFL_Position->get_visible())
94
95 // labels
96 sal_Int32 nLabelPos = m_xLB_PlaceLabels->get_active();
97 if (nLabelPos != -1)
98 rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION, nLabelPos ));
99
100 // tick marks
101 sal_Int32 nTicks=0;
102 sal_Int32 nMinorTicks=0;
103
104 if(m_xCB_MinorInner->get_active())
105 nMinorTicks|=CHAXIS_MARK_INNER;
106 if(m_xCB_MinorOuter->get_active())
107 nMinorTicks|=CHAXIS_MARK_OUTER;
108 if(m_xCB_TicksInner->get_active())
109 nTicks|=CHAXIS_MARK_INNER;
110 if(m_xCB_TicksOuter->get_active())
111 nTicks|=CHAXIS_MARK_OUTER;
112
113 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TICKS,nTicks));
114 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS,nMinorTicks));
115
116 sal_Int32 nMarkPos = m_xLB_PlaceTicks->get_active();
117 if (nMarkPos != -1)
118 rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION, nMarkPos ));
119
120 return true;
121}
122
124{
125 //init and enable controls
129 {
130 for( auto const & cat : std::as_const(m_aCategories) )
131 m_xED_CrossesAtCategory->append_text(cat);
132 }
133
134 if( m_xLB_CrossesAt->get_count() > 3 )
135 {
137 m_xLB_CrossesAt->remove(2);
138 else
139 m_xLB_CrossesAt->remove(3);
140 }
141
142 //fill controls
143
144 //axis line
145 if(SfxInt32Item const * pPositionItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_POSITION))
146 {
147 bool bZero = false;
148 sal_Int32 nPos = pPositionItem->GetValue();
149 if(nPos==0)
150 {
151 //switch to value
152 bZero = true;
153 nPos = 2;
154 }
155 else
156 nPos--;
157
158 if( nPos < m_xLB_CrossesAt->get_count() )
159 m_xLB_CrossesAt->set_active( nPos );
160 CrossesAtSelectHdl( *m_xLB_CrossesAt );
161
162 const SvxDoubleItem* pPosValueItem;
163 if( (pPosValueItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_POSITION_VALUE)) || bZero )
164 {
165 double fCrossover = 0.0;
166 if( !bZero )
167 fCrossover = pPosValueItem->GetValue();
169 m_xED_CrossesAtCategory->set_active( static_cast<sal_uInt16>(::rtl::math::round(fCrossover-1.0)) );
170 else
171 {
172 Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter();
173 rCrossFormatter.SetValue(fCrossover);
174 }
175 }
176 else
177 {
178 m_xED_CrossesAtCategory->set_active(-1);
179 m_xED_CrossesAt->set_text("");
180 }
181 }
182 else
183 {
184 m_xLB_CrossesAt->set_active(-1);
185 m_xED_CrossesAt->set_sensitive( false );
186 }
187
188 // shifted category position
189 const SfxBoolItem* pCatPosItem;
191 {
192 if (pCatPosItem->GetValue())
193 m_xRB_Between->set_active(true);
194 else
195 m_xRB_On->set_active(true);
196 }
197 else
198 m_xFL_Position->hide();
199
200 // Labels
201 if( const SfxInt32Item* pLabelPosItem = rInAttrs->GetItemIfSet( SCHATTR_AXIS_LABEL_POSITION, false) )
202 {
203 sal_Int32 nPos = pLabelPosItem->GetValue();
204 if( nPos < m_xLB_PlaceLabels->get_count() )
205 m_xLB_PlaceLabels->set_active( nPos );
206 }
207 else
208 m_xLB_PlaceLabels->set_active(-1);
209 PlaceLabelsSelectHdl( *m_xLB_PlaceLabels );
210
211 // Tick marks
212 tools::Long nTicks = 0, nMinorTicks = 0;
213 if (const SfxInt32Item* pTicksItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_TICKS))
214 nTicks = pTicksItem->GetValue();
215 if (const SfxInt32Item* pHelpTicksItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_HELPTICKS))
216 nMinorTicks = pHelpTicksItem->GetValue();
217
218 m_xCB_TicksInner->set_active(bool(nTicks&CHAXIS_MARK_INNER));
219 m_xCB_TicksOuter->set_active(bool(nTicks&CHAXIS_MARK_OUTER));
220 m_xCB_MinorInner->set_active(bool(nMinorTicks&CHAXIS_MARK_INNER));
221 m_xCB_MinorOuter->set_active(bool(nMinorTicks&CHAXIS_MARK_OUTER));
222
223 // Tick position
224 if( const SfxInt32Item* pMarkPosItem = rInAttrs->GetItemIfSet( SCHATTR_AXIS_MARK_POSITION, false) )
225 {
226 sal_Int32 nPos = pMarkPosItem->GetValue();
227 if( nPos < m_xLB_PlaceTicks->get_count() )
228 m_xLB_PlaceTicks->set_active( nPos );
229 }
230 else
231 m_xLB_PlaceTicks->set_active(-1);
232
234 {
235 m_xFL_AxisLine->hide();
236 m_xFL_Labels->hide();
237 m_xBxPlaceTicks->hide();
238 }
240 {
241 m_xFL_AxisLine->set_sensitive(false);
242 m_xFL_Labels->set_sensitive(false);
243 m_xBxPlaceTicks->set_sensitive(false);
244 //todo: maybe set a special help id to all those controls
245 }
246}
247
249{
250 if( pItemSet )
251 FillItemSet( pItemSet );
252
253 return DeactivateRC::LeavePage;
254}
255
257{
258 m_pNumFormatter = pFormatter;
259 Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter();
260 rCrossFormatter.SetFormatter(m_pNumFormatter);
261 rCrossFormatter.UseInputStringForFormatting();
262
263 if( const SfxUInt32Item* pNumFormatItem = GetItemSet().GetItemIfSet(SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT) )
264 {
265 sal_uInt32 nFmt = pNumFormatItem->GetValue();
266 rCrossFormatter.SetFormatKey(nFmt);
267 }
268}
269
270void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis )
271{
272 m_bCrossingAxisIsCategoryAxis = bCrossingAxisIsCategoryAxis;
273}
274
275void AxisPositionsTabPage::SetCategories( const css::uno::Sequence< OUString >& rCategories )
276{
277 m_aCategories = rCategories;
278}
279
280void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning )
281{
282 m_bSupportAxisPositioning = bSupportAxisPositioning;
283}
284
285void AxisPositionsTabPage::SupportCategoryPositioning( bool bSupportCategoryPositioning )
286{
287 m_bSupportCategoryPositioning = bSupportCategoryPositioning;
288}
289
291{
292 sal_Int32 nPos = m_xLB_CrossesAt->get_active();
293 m_xED_CrossesAt->set_visible( (nPos==2) && !m_bCrossingAxisIsCategoryAxis );
294 m_xED_CrossesAtCategory->set_visible( (nPos==2) && m_bCrossingAxisIsCategoryAxis );
295
296 if (m_xED_CrossesAt->get_text().isEmpty())
297 m_xED_CrossesAt->GetFormatter().SetValue(0.0);
298 if (m_xED_CrossesAtCategory->get_active() == -1)
299 m_xED_CrossesAtCategory->set_active(0);
300
301 PlaceLabelsSelectHdl(*m_xLB_PlaceLabels);
302}
303
305{
306 sal_Int32 nLabelPos = m_xLB_PlaceLabels->get_active();
307
308 bool bEnableTickmarkPlacement = (nLabelPos>1);
309 if( bEnableTickmarkPlacement )
310 {
311 sal_Int32 nAxisPos = m_xLB_CrossesAt->get_active();
312 if( nLabelPos-2 == nAxisPos )
313 bEnableTickmarkPlacement=false;
314 }
315 m_xBxPlaceTicks->set_sensitive(bEnableTickmarkPlacement);
316}
317
318} //namespace chart
319
320/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nPos
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_TICKS(SCHATTR_AXIS_POSITION_START)
constexpr TypedWhichId< SfxUInt32Item > SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT(SCHATTR_AXIS_POSITION_START+4)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION(SCHATTR_AXIS_POSITION_START+5)
constexpr TypedWhichId< SvxDoubleItem > SCHATTR_AXIS_POSITION_VALUE(SCHATTR_AXIS_POSITION_START+3)
#define CHAXIS_MARK_OUTER
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_HELPTICKS(SCHATTR_AXIS_POSITION_START+1)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_POSITION(SCHATTR_AXIS_POSITION_START+2)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_LABEL_POSITION(SCHATTR_AXIS_POSITION_START+6)
#define CHAXIS_MARK_INNER
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_MARK_POSITION(SCHATTR_AXIS_POSITION_START+7)
void SetValue(double dVal)
void UseInputStringForFormatting()
virtual void ClearMinValue()
void SetFormatter(SvNumberFormatter *pFormatter, bool bResetFormat=true)
void SetFormatKey(sal_uLong nFormatKey)
virtual void ClearMaxValue()
double GetValue()
bool GetValue() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxItemSet & GetItemSet() const
double GetValue() const
static bool isAxisPositioningEnabled()
virtual void Reset(const SfxItemSet *rInAttrs) override
std::unique_ptr< weld::Frame > m_xFL_Labels
std::unique_ptr< weld::Frame > m_xFL_Position
std::unique_ptr< weld::Frame > m_xFL_AxisLine
std::unique_ptr< weld::CheckButton > m_xCB_MinorInner
void SetNumFormatter(SvNumberFormatter *pFormatter)
SvNumberFormatter * m_pNumFormatter
std::unique_ptr< weld::FormattedSpinButton > m_xED_CrossesAt
std::unique_ptr< weld::CheckButton > m_xCB_TicksInner
css::uno::Sequence< OUString > m_aCategories
std::unique_ptr< weld::RadioButton > m_xRB_Between
std::unique_ptr< weld::ComboBox > m_xLB_PlaceLabels
virtual DeactivateRC DeactivatePage(SfxItemSet *pItemSet) override
void SetCrossingAxisIsCategoryAxis(bool bCrossingAxisIsCategoryAxis)
void SupportCategoryPositioning(bool bSupportCategoryPositioning)
std::unique_ptr< weld::Widget > m_xBxPlaceTicks
virtual bool FillItemSet(SfxItemSet *rOutAttrs) override
std::unique_ptr< weld::CheckButton > m_xCB_MinorOuter
std::unique_ptr< weld::ComboBox > m_xLB_PlaceTicks
virtual ~AxisPositionsTabPage() override
AxisPositionsTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
std::unique_ptr< weld::ComboBox > m_xED_CrossesAtCategory
std::unique_ptr< weld::CheckButton > m_xCB_TicksOuter
void SupportAxisPositioning(bool bSupportAxisPositioning)
std::unique_ptr< weld::ComboBox > m_xLB_CrossesAt
void SetCategories(const css::uno::Sequence< OUString > &rCategories)
std::unique_ptr< weld::RadioButton > m_xRB_On
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rInAttrs)
IMPL_LINK_NOARG(SplinePropertiesDialog, SplineTypeListBoxHdl, weld::ComboBox &, void)
long Long
DeactivateRC