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