LibreOffice Module chart2 (master) 1
tp_SeriesToAxis.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_SeriesToAxis.hxx"
21
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
30namespace chart
31{
32
34 : SfxTabPage(pPage, pController, "modules/schart/ui/tp_SeriesToAxis.ui", "TP_OPTIONS", &rInAttrs)
35 , m_nAllSeriesAxisIndex(0)
36 , m_bProvidesSecondaryYAxis(true)
37 , m_bProvidesOverlapAndGapWidth(false)
38 , m_bProvidesBarConnectors(false)
39 , m_xGrpAxis(m_xBuilder->weld_widget("frameGrpAxis"))
40 , m_xRbtAxis1(m_xBuilder->weld_radio_button("RBT_OPT_AXIS_1"))
41 , m_xRbtAxis2(m_xBuilder->weld_radio_button("RBT_OPT_AXIS_2"))
42 , m_xGrpBar(m_xBuilder->weld_widget("frameSettings"))
43 , m_xMTGap(m_xBuilder->weld_metric_spin_button("MT_GAP", FieldUnit::PERCENT))
44 , m_xMTOverlap(m_xBuilder->weld_metric_spin_button("MT_OVERLAP", FieldUnit::PERCENT))
45 , m_xCBConnect(m_xBuilder->weld_check_button("CB_CONNECTOR"))
46 , m_xCBAxisSideBySide(m_xBuilder->weld_check_button("CB_BARS_SIDE_BY_SIDE"))
47 , m_xGrpPlotOptions(m_xBuilder->weld_widget("frameFL_PLOT_OPTIONS"))
48 , m_xGridPlotOptions(m_xBuilder->weld_widget("gridPLOT_OPTIONS"))
49 , m_xRB_DontPaint(m_xBuilder->weld_radio_button("RB_DONT_PAINT"))
50 , m_xRB_AssumeZero(m_xBuilder->weld_radio_button("RB_ASSUME_ZERO"))
51 , m_xRB_ContinueLine(m_xBuilder->weld_radio_button("RB_CONTINUE_LINE"))
52 , m_xCBIncludeHiddenCells(m_xBuilder->weld_check_button("CB_INCLUDE_HIDDEN_CELLS"))
53 , m_xCBHideLegendEntry(m_xBuilder->weld_check_button("CB_LEGEND_ENTRY_HIDDEN"))
54{
55 m_xRbtAxis1->connect_toggled(LINK(this, SchOptionTabPage, EnableHdl));
56 m_xRbtAxis2->connect_toggled(LINK(this, SchOptionTabPage, EnableHdl));
57}
58
60{
61}
62
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
71std::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
78{
79 if(m_xRbtAxis2->get_active())
81 else
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())
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())
107
108 if(m_xCBHideLegendEntry->get_visible())
110
111 return true;
112}
113
115{
116 m_xRbtAxis1->set_active(true);
117 m_xRbtAxis2->set_active(false);
118 if (const SfxInt32Item* pAxisItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS))
119 {
120 tools::Long nVal = pAxisItem->GetValue();
121 if(nVal==CHART_AXIS_SECONDARY_Y)
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 {
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
225}
226
227void SchOptionTabPage::Init( bool bProvidesSecondaryYAxis, bool bProvidesOverlapAndGapWidth, bool bProvidesBarConnectors )
228{
229 m_bProvidesSecondaryYAxis = bProvidesSecondaryYAxis;
230 m_bProvidesOverlapAndGapWidth = bProvidesOverlapAndGapWidth;
231 m_bProvidesBarConnectors = bProvidesBarConnectors;
232
234}
235
237{
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: */
#define CHART_AXIS_PRIMARY_Y
constexpr TypedWhichId< SfxInt32Item > SCHATTR_MISSING_VALUE_TREATMENT(SCHATTR_CHARTTYPE_START+9)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS(SCHATTR_STYLE_END+1)
constexpr TypedWhichId< SfxIntegerListItem > SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS(SCHATTR_CHARTTYPE_START+10)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_HIDE_LEGEND_ENTRY(SCHATTR_CHARTTYPE_START+12)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_BAR_GAPWIDTH(SCHATTR_CHARTTYPE_START+1)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_BAR_CONNECT(SCHATTR_CHARTTYPE_START+2)
#define CHART_AXIS_SECONDARY_Y
constexpr TypedWhichId< SfxBoolItem > SCHATTR_GROUP_BARS_PER_AXIS(SCHATTR_CHARTTYPE_START+6)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_INCLUDE_HIDDEN_CELLS(SCHATTR_CHARTTYPE_START+11)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_AXIS_FOR_ALL_SERIES(SCHATTR_MISC_START)
constexpr TypedWhichId< SfxInt32Item > SCHATTR_BAR_OVERLAP(SCHATTR_CHARTTYPE_START)
sal_Int32 GetValue() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
std::unique_ptr< weld::RadioButton > m_xRbtAxis2
virtual void Reset(const SfxItemSet *rInAttrs) override
std::unique_ptr< weld::RadioButton > m_xRB_DontPaint
SchOptionTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
virtual ~SchOptionTabPage() override
std::unique_ptr< weld::Widget > m_xGrpAxis
virtual bool FillItemSet(SfxItemSet *rOutAttrs) override
std::unique_ptr< weld::Widget > m_xGridPlotOptions
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rInAttrs)
std::unique_ptr< weld::Widget > m_xGrpPlotOptions
void Init(bool bProvidesSecondaryYAxis, bool bProvidesOverlapAndGapWidth, bool bProvidesBarConnectors)
std::unique_ptr< weld::CheckButton > m_xCBConnect
std::unique_ptr< weld::CheckButton > m_xCBIncludeHiddenCells
std::unique_ptr< weld::RadioButton > m_xRB_ContinueLine
std::unique_ptr< weld::CheckButton > m_xCBAxisSideBySide
std::unique_ptr< weld::CheckButton > m_xCBHideLegendEntry
std::unique_ptr< weld::MetricSpinButton > m_xMTOverlap
std::unique_ptr< weld::RadioButton > m_xRB_AssumeZero
std::unique_ptr< weld::RadioButton > m_xRbtAxis1
std::unique_ptr< weld::MetricSpinButton > m_xMTGap
std::unique_ptr< weld::Widget > m_xGrpBar
FieldUnit
IMPL_LINK_NOARG(SplinePropertiesDialog, SplineTypeListBoxHdl, weld::ComboBox &, void)
long Long
constexpr OUStringLiteral PERCENT(u"Percent")