Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_SeriesToAxis.cxx
blobee6dabc07a6f92086148c9a7a709cc06d931b653
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 <svl/eitem.hxx>
25 #include <svl/intitem.hxx>
26 #include <svl/ilstitem.hxx>
28 #include <com/sun/star/chart/MissingValueTreatment.hpp>
30 namespace chart
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))
55 m_xRbtAxis1->connect_toggled(LINK(this, SchOptionTabPage, EnableHdl));
56 m_xRbtAxis2->connect_toggled(LINK(this, SchOptionTabPage, EnableHdl));
59 SchOptionTabPage::~SchOptionTabPage()
63 IMPL_LINK_NOARG(SchOptionTabPage, EnableHdl, weld::Toggleable&, void)
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());
71 std::unique_ptr<SfxTabPage> SchOptionTabPage::Create(weld::Container* pPage, weld::DialogController* pController,
72 const SfxItemSet* rOutAttrs)
74 return std::make_unique<SchOptionTabPage>(pPage, pController, *rOutAttrs);
77 bool SchOptionTabPage::FillItemSet(SfxItemSet* rOutAttrs)
79 if(m_xRbtAxis2->get_active())
80 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_SECONDARY_Y));
81 else
82 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_PRIMARY_Y));
84 if(m_xMTGap->get_visible())
85 rOutAttrs->Put(SfxInt32Item(SCHATTR_BAR_GAPWIDTH,static_cast< sal_Int32 >( m_xMTGap->get_value(FieldUnit::PERCENT))));
87 if(m_xMTOverlap->get_visible())
88 rOutAttrs->Put(SfxInt32Item(SCHATTR_BAR_OVERLAP,static_cast< sal_Int32 >( m_xMTOverlap->get_value(FieldUnit::PERCENT))));
90 if(m_xCBConnect->get_visible())
91 rOutAttrs->Put(SfxBoolItem(SCHATTR_BAR_CONNECT,m_xCBConnect->get_active()));
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()));
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));
105 if (m_xCBIncludeHiddenCells->get_visible())
106 rOutAttrs->Put(SfxBoolItem(SCHATTR_INCLUDE_HIDDEN_CELLS, m_xCBIncludeHiddenCells->get_active()));
108 if(m_xCBHideLegendEntry->get_visible())
109 rOutAttrs->Put(SfxBoolItem(SCHATTR_HIDE_LEGEND_ENTRY, m_xCBHideLegendEntry->get_active()));
111 return true;
114 void SchOptionTabPage::Reset(const SfxItemSet* rInAttrs)
116 m_xRbtAxis1->set_active(true);
117 m_xRbtAxis2->set_active(false);
118 if (const SfxInt32Item* pAxisItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS))
120 tools::Long nVal = pAxisItem->GetValue();
121 if(nVal==CHART_AXIS_SECONDARY_Y)
123 m_xRbtAxis2->set_active(true);
124 m_xRbtAxis1->set_active(false);
128 tools::Long nTmp;
129 if (const SfxInt32Item* pGapWidthItem = rInAttrs->GetItemIfSet(SCHATTR_BAR_GAPWIDTH))
131 nTmp = static_cast<tools::Long>(pGapWidthItem->GetValue());
132 m_xMTGap->set_value(nTmp, FieldUnit::PERCENT);
135 if (const SfxInt32Item* pOverlapItem = rInAttrs->GetItemIfSet(SCHATTR_BAR_OVERLAP))
137 nTmp = static_cast<tools::Long>(pOverlapItem->GetValue());
138 m_xMTOverlap->set_value(nTmp, FieldUnit::PERCENT);
141 if (const SfxBoolItem* pConnectItem = rInAttrs->GetItemIfSet(SCHATTR_BAR_CONNECT))
143 bool bCheck = pConnectItem->GetValue();
144 m_xCBConnect->set_active(bCheck);
147 if (const SfxInt32Item* pAllSeriesItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_FOR_ALL_SERIES))
149 m_nAllSeriesAxisIndex = pAllSeriesItem->GetValue();
150 m_xCBAxisSideBySide->set_sensitive(false);
152 if (const SfxBoolItem* pPerAxisItem = rInAttrs->GetItemIfSet(SCHATTR_GROUP_BARS_PER_AXIS))
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 );
159 else
161 m_xCBAxisSideBySide->hide();
164 //missing value treatment
166 std::vector< sal_Int32 > aMissingValueTreatments;
167 if (const SfxIntegerListItem* pValueTreatmentsItem = rInAttrs->GetItemIfSet(SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS))
168 aMissingValueTreatments = pValueTreatmentsItem->GetList();
170 const SfxInt32Item* pMissingValueTreatmentItem;
171 if ( aMissingValueTreatments.size()>1 &&
172 (pMissingValueTreatmentItem = rInAttrs->GetItemIfSet(SCHATTR_MISSING_VALUE_TREATMENT)) )
174 m_xRB_DontPaint->set_sensitive(false);
175 m_xRB_AssumeZero->set_sensitive(false);
176 m_xRB_ContinueLine->set_sensitive(false);
178 for(int nVal : aMissingValueTreatments)
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);
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);
196 else
198 m_xGridPlotOptions->hide();
202 // Include hidden cells
203 if (const SfxBoolItem* pHiddenCellsItem = rInAttrs->GetItemIfSet(SCHATTR_INCLUDE_HIDDEN_CELLS))
205 bool bVal = pHiddenCellsItem->GetValue();
206 m_xCBIncludeHiddenCells->set_active(bVal);
208 else
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();
218 if (const SfxBoolItem* pEntryItem = rInAttrs->GetItemIfSet(SCHATTR_HIDE_LEGEND_ENTRY))
220 bool bVal = pEntryItem->GetValue();
221 m_xCBHideLegendEntry->set_active(bVal);
224 AdaptControlPositionsAndVisibility();
227 void SchOptionTabPage::Init( bool bProvidesSecondaryYAxis, bool bProvidesOverlapAndGapWidth, bool bProvidesBarConnectors )
229 m_bProvidesSecondaryYAxis = bProvidesSecondaryYAxis;
230 m_bProvidesOverlapAndGapWidth = bProvidesOverlapAndGapWidth;
231 m_bProvidesBarConnectors = bProvidesBarConnectors;
233 AdaptControlPositionsAndVisibility();
236 void SchOptionTabPage::AdaptControlPositionsAndVisibility()
238 m_xGrpAxis->set_visible(m_bProvidesSecondaryYAxis);
239 m_xGrpBar->set_visible(m_bProvidesOverlapAndGapWidth);
240 m_xCBConnect->set_visible(m_bProvidesBarConnectors);
242 if (!m_xMTGap->get_visible() && !m_xMTOverlap->get_visible())
243 m_xGrpBar->hide();
246 } //namespace chart
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */