Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_SeriesToAxis.cxx
blob9690c47ec91bcda4271b4101b962f89b835c99ea
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 "tp_SeriesToAxis.hxx"
22 #include <chartview/ChartSfxItemIds.hxx>
24 #include <editeng/sizeitem.hxx>
25 #include <svl/eitem.hxx>
26 #include <svl/intitem.hxx>
27 #include <svl/ilstitem.hxx>
28 #include <svtools/controldims.hxx>
29 #include <svx/chrtitem.hxx>
31 #include <com/sun/star/chart/MissingValueTreatment.hpp>
33 namespace chart
36 SchOptionTabPage::SchOptionTabPage(vcl::Window* pWindow,const SfxItemSet& rInAttrs)
37 : SfxTabPage(pWindow,
38 "TP_OPTIONS",
39 "modules/schart/ui/tp_SeriesToAxis.ui",
40 &rInAttrs)
41 , m_nAllSeriesAxisIndex(0)
42 , m_bProvidesSecondaryYAxis(true)
43 , m_bProvidesOverlapAndGapWidth(false)
44 , m_bProvidesBarConnectors(false)
46 get(m_pGrpAxis,"frameGrpAxis");
47 get(m_pRbtAxis1,"RBT_OPT_AXIS_1");
48 get(m_pRbtAxis2,"RBT_OPT_AXIS_2");
50 get(m_pGrpBar,"frameSettings");
51 get(m_pMTGap,"MT_GAP");
52 get(m_pMTOverlap,"MT_OVERLAP");
53 get(m_pCBConnect,"CB_CONNECTOR");
54 get(m_pCBAxisSideBySide,"CB_BARS_SIDE_BY_SIDE");
56 get(m_pGrpPlotOptions,"frameFL_PLOT_OPTIONS" );
57 get(m_pGridPlotOptions,"gridPLOT_OPTIONS");
58 get(m_pRB_DontPaint,"RB_DONT_PAINT");
59 get(m_pRB_AssumeZero,"RB_ASSUME_ZERO");
60 get(m_pRB_ContinueLine,"RB_CONTINUE_LINE");
61 get(m_pCBIncludeHiddenCells,"CB_INCLUDE_HIDDEN_CELLS");
63 m_pRbtAxis1->SetClickHdl( LINK( this, SchOptionTabPage, EnableHdl ));
64 m_pRbtAxis2->SetClickHdl( LINK( this, SchOptionTabPage, EnableHdl ));
67 SchOptionTabPage::~SchOptionTabPage()
69 disposeOnce();
72 void SchOptionTabPage::dispose()
74 m_pGrpAxis.clear();
75 m_pRbtAxis1.clear();
76 m_pRbtAxis2.clear();
77 m_pGrpBar.clear();
78 m_pMTGap.clear();
79 m_pMTOverlap.clear();
80 m_pCBConnect.clear();
81 m_pCBAxisSideBySide.clear();
82 m_pGrpPlotOptions.clear();
83 m_pGridPlotOptions.clear();
84 m_pRB_DontPaint.clear();
85 m_pRB_AssumeZero.clear();
86 m_pRB_ContinueLine.clear();
87 m_pCBIncludeHiddenCells.clear();
88 SfxTabPage::dispose();
91 IMPL_LINK_NOARG(SchOptionTabPage, EnableHdl, Button*, void)
93 if( m_nAllSeriesAxisIndex == 0 )
94 m_pCBAxisSideBySide->Enable( m_pRbtAxis2->IsChecked());
95 else if( m_nAllSeriesAxisIndex == 1 )
96 m_pCBAxisSideBySide->Enable( m_pRbtAxis1->IsChecked());
99 VclPtr<SfxTabPage> SchOptionTabPage::Create(TabPageParent pWindow,
100 const SfxItemSet* rOutAttrs)
102 return VclPtr<SchOptionTabPage>::Create(pWindow.pParent, *rOutAttrs);
105 bool SchOptionTabPage::FillItemSet(SfxItemSet* rOutAttrs)
107 if(m_pRbtAxis2->IsChecked())
108 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_SECONDARY_Y));
109 else
110 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_PRIMARY_Y));
112 if(m_pMTGap->IsVisible())
113 rOutAttrs->Put(SfxInt32Item(SCHATTR_BAR_GAPWIDTH,static_cast< sal_Int32 >( m_pMTGap->GetValue())));
115 if(m_pMTOverlap->IsVisible())
116 rOutAttrs->Put(SfxInt32Item(SCHATTR_BAR_OVERLAP,static_cast< sal_Int32 >( m_pMTOverlap->GetValue())));
118 if(m_pCBConnect->IsVisible())
119 rOutAttrs->Put(SfxBoolItem(SCHATTR_BAR_CONNECT,m_pCBConnect->IsChecked()));
121 // model property is "group bars per axis", UI feature is the other way
122 // round: "show bars side by side"
123 if(m_pCBAxisSideBySide->IsVisible())
124 rOutAttrs->Put(SfxBoolItem(SCHATTR_GROUP_BARS_PER_AXIS, ! m_pCBAxisSideBySide->IsChecked()));
126 if(m_pRB_DontPaint->IsChecked())
127 rOutAttrs->Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,css::chart::MissingValueTreatment::LEAVE_GAP));
128 else if(m_pRB_AssumeZero->IsChecked())
129 rOutAttrs->Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,css::chart::MissingValueTreatment::USE_ZERO));
130 else if(m_pRB_ContinueLine->IsChecked())
131 rOutAttrs->Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,css::chart::MissingValueTreatment::CONTINUE));
133 if (m_pCBIncludeHiddenCells->IsVisible())
134 rOutAttrs->Put(SfxBoolItem(SCHATTR_INCLUDE_HIDDEN_CELLS, m_pCBIncludeHiddenCells->IsChecked()));
136 return true;
139 void SchOptionTabPage::Reset(const SfxItemSet* rInAttrs)
141 const SfxPoolItem *pPoolItem = nullptr;
143 m_pRbtAxis1->Check();
144 m_pRbtAxis2->Check(false);
145 if (rInAttrs->GetItemState(SCHATTR_AXIS,true, &pPoolItem) == SfxItemState::SET)
147 long nVal=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
148 if(nVal==CHART_AXIS_SECONDARY_Y)
150 m_pRbtAxis2->Check();
151 m_pRbtAxis1->Check(false);
155 long nTmp;
156 if (rInAttrs->GetItemState(SCHATTR_BAR_GAPWIDTH, true, &pPoolItem) == SfxItemState::SET)
158 nTmp = static_cast<long>(static_cast<const SfxInt32Item*>(pPoolItem)->GetValue());
159 m_pMTGap->SetValue(nTmp);
162 if (rInAttrs->GetItemState(SCHATTR_BAR_OVERLAP, true, &pPoolItem) == SfxItemState::SET)
164 nTmp = static_cast<long>(static_cast<const SfxInt32Item*>(pPoolItem)->GetValue());
165 m_pMTOverlap->SetValue(nTmp);
168 if (rInAttrs->GetItemState(SCHATTR_BAR_CONNECT, true, &pPoolItem) == SfxItemState::SET)
170 bool bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
171 m_pCBConnect->Check(bCheck);
174 if (rInAttrs->GetItemState(SCHATTR_AXIS_FOR_ALL_SERIES, true, &pPoolItem) == SfxItemState::SET)
176 m_nAllSeriesAxisIndex = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
177 m_pCBAxisSideBySide->Disable();
179 if (rInAttrs->GetItemState(SCHATTR_GROUP_BARS_PER_AXIS, true, &pPoolItem) == SfxItemState::SET)
181 // model property is "group bars per axis", UI feature is the other way
182 // round: "show bars side by side"
183 bool bCheck = ! static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
184 m_pCBAxisSideBySide->Check( bCheck );
186 else
188 m_pCBAxisSideBySide->Show(false);
191 //missing value treatment
193 std::vector< sal_Int32 > aMissingValueTreatments;
194 if( rInAttrs->GetItemState(SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS, true, &pPoolItem) == SfxItemState::SET )
195 aMissingValueTreatments = static_cast<const SfxIntegerListItem*>(pPoolItem)->GetList();
197 if ( aMissingValueTreatments.size()>1 && rInAttrs->GetItemState(SCHATTR_MISSING_VALUE_TREATMENT,true, &pPoolItem) == SfxItemState::SET)
199 m_pRB_DontPaint->Enable(false);
200 m_pRB_AssumeZero->Enable(false);
201 m_pRB_ContinueLine->Enable(false);
203 for(int nVal : aMissingValueTreatments)
205 if(nVal==css::chart::MissingValueTreatment::LEAVE_GAP)
206 m_pRB_DontPaint->Enable();
207 else if(nVal==css::chart::MissingValueTreatment::USE_ZERO)
208 m_pRB_AssumeZero->Enable();
209 else if(nVal==css::chart::MissingValueTreatment::CONTINUE)
210 m_pRB_ContinueLine->Enable();
213 long nVal=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
214 if(nVal==css::chart::MissingValueTreatment::LEAVE_GAP)
215 m_pRB_DontPaint->Check();
216 else if(nVal==css::chart::MissingValueTreatment::USE_ZERO)
217 m_pRB_AssumeZero->Check();
218 else if(nVal==css::chart::MissingValueTreatment::CONTINUE)
219 m_pRB_ContinueLine->Check();
221 else
223 m_pGridPlotOptions->Show(false);
227 // Include hidden cells
228 if (rInAttrs->GetItemState(SCHATTR_INCLUDE_HIDDEN_CELLS, true, &pPoolItem) == SfxItemState::SET)
230 bool bVal = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
231 m_pCBIncludeHiddenCells->Check(bVal);
233 else
235 m_pCBIncludeHiddenCells->Show(false);
236 // check if the radiobutton guys above
237 // are visible. If they aren't, we can
238 // as well hide the whole frame
239 if(!m_pGridPlotOptions->IsVisible())
240 m_pGrpPlotOptions->Show(false);
243 AdaptControlPositionsAndVisibility();
246 void SchOptionTabPage::Init( bool bProvidesSecondaryYAxis, bool bProvidesOverlapAndGapWidth, bool bProvidesBarConnectors )
248 m_bProvidesSecondaryYAxis = bProvidesSecondaryYAxis;
249 m_bProvidesOverlapAndGapWidth = bProvidesOverlapAndGapWidth;
250 m_bProvidesBarConnectors = bProvidesBarConnectors;
252 AdaptControlPositionsAndVisibility();
255 void SchOptionTabPage::AdaptControlPositionsAndVisibility()
257 m_pGrpAxis->Show(m_bProvidesSecondaryYAxis);
259 m_pGrpBar->Show(m_bProvidesOverlapAndGapWidth);
261 m_pCBConnect->Show(m_bProvidesBarConnectors);
263 if( !m_pMTGap->IsVisible() && !m_pMTOverlap->IsVisible() )
265 m_pGrpBar->Show(false);
268 } //namespace chart
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */