Debian Codegraph @

chart2/source/controller/dialogs/tp_SeriesToAxis.cxx

raw
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_SeriesToAxis.hxx"
21
22 #include <chartview/ChartSfxItemIds.hxx>
23
24 #include <svl/eitem.hxx>
25 #include <svl/intitem.hxx>
26 #include <svl/ilstitem.hxx>
27
28 #include <com/sun/star/chart/MissingValueTreatment.hpp>
29
30 namespace chart
31 {
32
33 SchOptionTabPage::SchOptionTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
34 : SfxTabPage(pPage, pController, u"modules/schart/ui/tp_SeriesToAxis.ui"_ustr, u"TP_OPTIONS"_ustr, &rInAttrs)
35 , m_nAllSeriesAxisIndex(0)
36 , m_bProvidesSecondaryYAxis(true)
37 , m_bProvidesOverlapAndGapWidth(false)
38 , m_bProvidesBarConnectors(false)
39 , m_xGrpAxis(m_xBuilder->weld_widget(u"frameGrpAxis"_ustr))
40 , m_xRbtAxis1(m_xBuilder->weld_radio_button(u"RBT_OPT_AXIS_1"_ustr))
41 , m_xRbtAxis2(m_xBuilder->weld_radio_button(u"RBT_OPT_AXIS_2"_ustr))
42 , m_xGrpBar(m_xBuilder->weld_widget(u"frameSettings"_ustr))
43 , m_xMTGap(m_xBuilder->weld_metric_spin_button(u"MT_GAP"_ustr, FieldUnit::PERCENT))
44 , m_xMTOverlap(m_xBuilder->weld_metric_spin_button(u"MT_OVERLAP"_ustr, FieldUnit::PERCENT))
45 , m_xCBConnect(m_xBuilder->weld_check_button(u"CB_CONNECTOR"_ustr))
46 , m_xCBAxisSideBySide(m_xBuilder->weld_check_button(u"CB_BARS_SIDE_BY_SIDE"_ustr))
47 , m_xGrpPlotOptions(m_xBuilder->weld_widget(u"frameFL_PLOT_OPTIONS"_ustr))
48 , m_xGridPlotOptions(m_xBuilder->weld_widget(u"gridPLOT_OPTIONS"_ustr))
49 , m_xRB_DontPaint(m_xBuilder->weld_radio_button(u"RB_DONT_PAINT"_ustr))
50 , m_xRB_AssumeZero(m_xBuilder->weld_radio_button(u"RB_ASSUME_ZERO"_ustr))
51 , m_xRB_ContinueLine(m_xBuilder->weld_radio_button(u"RB_CONTINUE_LINE"_ustr))
52 , m_xCBIncludeHiddenCells(m_xBuilder->weld_check_button(u"CB_INCLUDE_HIDDEN_CELLS"_ustr))
53 , m_xCBHideLegendEntry(m_xBuilder->weld_check_button(u"CB_LEGEND_ENTRY_HIDDEN"_ustr))
54 {
55 m_xRbtAxis1->connect_toggled(LINK(this, SchOptionTabPage, EnableHdl));
56 m_xRbtAxis2->connect_toggled(LINK(this, SchOptionTabPage, EnableHdl));
57 }
58
59 SchOptionTabPage::~SchOptionTabPage()
60 {
61 }
62
63 IMPL_LINK_NOARG(SchOptionTabPage, EnableHdl, weld::Toggleable&, void)
64 {
65 if( m_nAllSeriesAxisIndex == 0 )
66 m_xCBAxisSideBySide->set_sensitive( m_xRbtAxis2->get_active());
67 else if( m_nAllSeriesAxisIndex == 1 )
68 m_xCBAxisSideBySide->set_sensitive( m_xRbtAxis1->get_active());
69 }
70
71 std::unique_ptr<SfxTabPage> SchOptionTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
72 const SfxItemSet* rOutAttrs)
73 {
74 return std::make_unique<SchOptionTabPage>(pPage, pController, *rOutAttrs);
75 }
76
77 bool SchOptionTabPage::FillItemSet(SfxItemSet* rOutAttrs)
78 {
79 if(m_xRbtAxis2->get_active())
80 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS,AFAxix::toNum(AxisAtr::SecondaryY)));
81 else
82 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS,AFAxix::toNum(AxisAtr::PrimaryY)));
83
84 if(m_xMTGap->get_visible())
85 rOutAttrs->Put(SfxInt32Item(SCHATTR_BAR_GAPWIDTH,static_cast< sal_Int32 >( m_xMTGap->get_value(FieldUnit::PERCENT))));
86
87 if(m_xMTOverlap->get_visible())
88 rOutAttrs->Put(SfxInt32Item(SCHATTR_BAR_OVERLAP,static_cast< sal_Int32 >( m_xMTOverlap->get_value(FieldUnit::PERCENT))));
89
90 if(m_xCBConnect->get_visible())
91 rOutAttrs->Put(SfxBoolItem(SCHATTR_BAR_CONNECT,m_xCBConnect->get_active()));
92
93 // model property is "group bars per axis", UI feature is the other way
94 // round: "show bars side by side"
95 if(m_xCBAxisSideBySide->get_visible())
96 rOutAttrs->Put(SfxBoolItem(SCHATTR_GROUP_BARS_PER_AXIS, ! m_xCBAxisSideBySide->get_active()));
97
98 if(m_xRB_DontPaint->get_active())
99 rOutAttrs->Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,css::chart::MissingValueTreatment::LEAVE_GAP));
100 else if(m_xRB_AssumeZero->get_active())
101 rOutAttrs->Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,css::chart::MissingValueTreatment::USE_ZERO));
102 else if(m_xRB_ContinueLine->get_active())
103 rOutAttrs->Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,css::chart::MissingValueTreatment::CONTINUE));
104
105 if (m_xCBIncludeHiddenCells->get_visible())
106 rOutAttrs->Put(SfxBoolItem(SCHATTR_INCLUDE_HIDDEN_CELLS, m_xCBIncludeHiddenCells->get_active()));
107
108 if(m_xCBHideLegendEntry->get_visible())
109 rOutAttrs->Put(SfxBoolItem(SCHATTR_HIDE_LEGEND_ENTRY, m_xCBHideLegendEntry->get_active()));
110
111 return true;
112 }
113
114 void SchOptionTabPage::Reset(const SfxItemSet* rInAttrs)
115 {
116 m_xRbtAxis1->set_active(true);
117 m_xRbtAxis2->set_active(false);
118 if (const SfxInt32Item* pAxisItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS))
119 {
120 sal_Int32 nVal = pAxisItem->GetValue();
121 if(nVal==AFAxix(AxisAtr::SecondaryY))
122 {
123 m_xRbtAxis2->set_active(true);
124 m_xRbtAxis1->set_active(false);
125 }
126 }
127
128 tools::Long nTmp;
129 if (const SfxInt32Item* pGapWidthItem = rInAttrs->GetItemIfSet(SCHATTR_BAR_GAPWIDTH))
130 {
131 nTmp = static_cast<tools::Long>(pGapWidthItem->GetValue());
132 m_xMTGap->set_value(nTmp, FieldUnit::PERCENT);
133 }
134
135 if (const SfxInt32Item* pOverlapItem = rInAttrs->GetItemIfSet(SCHATTR_BAR_OVERLAP))
136 {
137 nTmp = static_cast<tools::Long>(pOverlapItem->GetValue());
138 m_xMTOverlap->set_value(nTmp, FieldUnit::PERCENT);
139 }
140
141 if (const SfxBoolItem* pConnectItem = rInAttrs->GetItemIfSet(SCHATTR_BAR_CONNECT))
142 {
143 bool bCheck = pConnectItem->GetValue();
144 m_xCBConnect->set_active(bCheck);
145 }
146
147 if (const SfxInt32Item* pAllSeriesItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_FOR_ALL_SERIES))
148 {
149 m_nAllSeriesAxisIndex = pAllSeriesItem->GetValue();
150 m_xCBAxisSideBySide->set_sensitive(false);
151 }
152 if (const SfxBoolItem* pPerAxisItem = rInAttrs->GetItemIfSet(SCHATTR_GROUP_BARS_PER_AXIS))
153 {
154 // model property is "group bars per axis", UI feature is the other way
155 // round: "show bars side by side"
156 bool bCheck = ! pPerAxisItem->GetValue();
157 m_xCBAxisSideBySide->set_active( bCheck );
158 }
159 else
160 {
161 m_xCBAxisSideBySide->hide();
162 }
163
164 //missing value treatment
165 {
166 std::vector< sal_Int32 > aMissingValueTreatments;
167 if (const SfxIntegerListItem* pValueTreatmentsItem = rInAttrs->GetItemIfSet(SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS))
168 aMissingValueTreatments = pValueTreatmentsItem->GetList();
169
170 const SfxInt32Item* pMissingValueTreatmentItem;
171 if ( aMissingValueTreatments.size()>1 &&
172 (pMissingValueTreatmentItem = rInAttrs->GetItemIfSet(SCHATTR_MISSING_VALUE_TREATMENT)) )
173 {
174 m_xRB_DontPaint->set_sensitive(false);
175 m_xRB_AssumeZero->set_sensitive(false);
176 m_xRB_ContinueLine->set_sensitive(false);
177
178 for(int nVal : aMissingValueTreatments)
179 {
180 if(nVal==css::chart::MissingValueTreatment::LEAVE_GAP)
181 m_xRB_DontPaint->set_sensitive(true);
182 else if(nVal==css::chart::MissingValueTreatment::USE_ZERO)
183 m_xRB_AssumeZero->set_sensitive(true);
184 else if(nVal==css::chart::MissingValueTreatment::CONTINUE)
185 m_xRB_ContinueLine->set_sensitive(true);
186 }
187
188 tools::Long nVal=pMissingValueTreatmentItem->GetValue();
189 if(nVal==css::chart::MissingValueTreatment::LEAVE_GAP)
190 m_xRB_DontPaint->set_active(true);
191 else if(nVal==css::chart::MissingValueTreatment::USE_ZERO)
192 m_xRB_AssumeZero->set_active(true);
193 else if(nVal==css::chart::MissingValueTreatment::CONTINUE)
194 m_xRB_ContinueLine->set_active(true);
195 }
196 else
197 {
198 m_xGridPlotOptions->hide();
199 }
200 }
201
202 // Include hidden cells
203 if (const SfxBoolItem* pHiddenCellsItem = rInAttrs->GetItemIfSet(SCHATTR_INCLUDE_HIDDEN_CELLS))
204 {
205 bool bVal = pHiddenCellsItem->GetValue();
206 m_xCBIncludeHiddenCells->set_active(bVal);
207 }
208 else
209 {
210 m_xCBIncludeHiddenCells->hide();
211 // check if the radiobutton guys above
212 // are visible. If they aren't, we can
213 // as well hide the whole frame
214 if(!m_xGridPlotOptions->get_visible())
215 m_xGrpPlotOptions->hide();
216 }
217
218 if (const SfxBoolItem* pEntryItem = rInAttrs->GetItemIfSet(SCHATTR_HIDE_LEGEND_ENTRY))
219 {
220 bool bVal = pEntryItem->GetValue();
221 m_xCBHideLegendEntry->set_active(bVal);
222 }
223
224 AdaptControlPositionsAndVisibility();
225 }
226
227 void SchOptionTabPage::Init( bool bProvidesSecondaryYAxis, bool bProvidesOverlapAndGapWidth, bool bProvidesBarConnectors )
228 {
229 m_bProvidesSecondaryYAxis = bProvidesSecondaryYAxis;
230 m_bProvidesOverlapAndGapWidth = bProvidesOverlapAndGapWidth;
231 m_bProvidesBarConnectors = bProvidesBarConnectors;
232
233 AdaptControlPositionsAndVisibility();
234 }
235
236 void SchOptionTabPage::AdaptControlPositionsAndVisibility()
237 {
238 m_xGrpAxis->set_visible(m_bProvidesSecondaryYAxis);
239 m_xGrpBar->set_visible(m_bProvidesOverlapAndGapWidth);
240 m_xCBConnect->set_visible(m_bProvidesBarConnectors);
241
242 if (!m_xMTGap->get_visible() && !m_xMTOverlap->get_visible())
243 m_xGrpBar->hide();
244 }
245
246 } //namespace chart
247
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */