1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/sidebar/ControlFactory.hxx>
22 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
23 #include <com/sun/star/chart/ErrorBarStyle.hpp>
25 #include "ChartErrorBarPanel.hxx"
26 #include <ChartController.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <vcl/fixed.hxx>
30 #include <vcl/lstbox.hxx>
31 #include <vcl/field.hxx>
32 #include <vcl/toolbox.hxx>
33 #include <svl/intitem.hxx>
34 #include <svl/stritem.hxx>
37 using namespace css::uno
;
39 namespace chart
{ namespace sidebar
{
43 enum class ErrorBarDirection
49 css::uno::Reference
<css::beans::XPropertySet
> getErrorBarPropSet(
50 const css::uno::Reference
<css::frame::XModel
>& xModel
, const OUString
& rCID
)
52 return ObjectIdentifier::getObjectPropertySet(rCID
, xModel
);
55 bool showPositiveError(const css::uno::Reference
<css::frame::XModel
>& xModel
,
58 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
59 getErrorBarPropSet(xModel
, rCID
);
64 css::uno::Any aAny
= xPropSet
->getPropertyValue("ShowPositiveError");
74 bool showNegativeError(const css::uno::Reference
<css::frame::XModel
>& xModel
,
77 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
78 getErrorBarPropSet(xModel
, rCID
);
83 css::uno::Any aAny
= xPropSet
->getPropertyValue("ShowNegativeError");
93 void setShowPositiveError(const css::uno::Reference
<css::frame::XModel
>& xModel
,
94 const OUString
& rCID
, bool bShow
)
96 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
97 getErrorBarPropSet(xModel
, rCID
);
102 xPropSet
->setPropertyValue("ShowPositiveError", css::uno::Any(bShow
));
105 void setShowNegativeError(const css::uno::Reference
<css::frame::XModel
>& xModel
,
106 const OUString
& rCID
, bool bShow
)
108 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
109 getErrorBarPropSet(xModel
, rCID
);
114 xPropSet
->setPropertyValue("ShowNegativeError", css::uno::Any(bShow
));
117 struct ErrorBarTypeMap
123 ErrorBarTypeMap aErrorBarType
[] = {
124 { 0, css::chart::ErrorBarStyle::ABSOLUTE
},
125 { 1, css::chart::ErrorBarStyle::RELATIVE
},
126 { 2, css::chart::ErrorBarStyle::FROM_DATA
},
127 { 3, css::chart::ErrorBarStyle::STANDARD_DEVIATION
},
128 { 4, css::chart::ErrorBarStyle::STANDARD_ERROR
},
129 { 5, css::chart::ErrorBarStyle::VARIANCE
},
130 { 6, css::chart::ErrorBarStyle::ERROR_MARGIN
},
133 sal_Int32
getTypePos(const css::uno::Reference
<css::frame::XModel
>& xModel
,
134 const OUString
& rCID
)
136 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
137 getErrorBarPropSet(xModel
, rCID
);
142 css::uno::Any aAny
= xPropSet
->getPropertyValue("ErrorBarStyle");
144 if (!aAny
.hasValue())
150 for (ErrorBarTypeMap
& i
: aErrorBarType
)
159 void setTypePos(const css::uno::Reference
<css::frame::XModel
>& xModel
,
160 const OUString
& rCID
, sal_Int32 nPos
)
162 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
163 getErrorBarPropSet(xModel
, rCID
);
169 for (ErrorBarTypeMap
& i
: aErrorBarType
)
175 xPropSet
->setPropertyValue("ErrorBarStyle", css::uno::Any(nApi
));
178 double getValue(const css::uno::Reference
<css::frame::XModel
>& xModel
,
179 const OUString
& rCID
, ErrorBarDirection eDir
)
181 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
182 getErrorBarPropSet(xModel
, rCID
);
187 OUString aName
= "PositiveError";
188 if (eDir
== ErrorBarDirection::NEGATIVE
)
189 aName
= "NegativeError";
191 css::uno::Any aAny
= xPropSet
->getPropertyValue(aName
);
193 if (!aAny
.hasValue())
202 void setValue(const css::uno::Reference
<css::frame::XModel
>& xModel
,
203 const OUString
& rCID
, double nVal
, ErrorBarDirection eDir
)
205 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
206 getErrorBarPropSet(xModel
, rCID
);
211 OUString aName
= "PositiveError";
212 if (eDir
== ErrorBarDirection::NEGATIVE
)
213 aName
= "NegativeError";
215 xPropSet
->setPropertyValue(aName
, css::uno::Any(nVal
));
218 OUString
getCID(const css::uno::Reference
<css::frame::XModel
>& xModel
)
220 css::uno::Reference
<css::frame::XController
> xController(xModel
->getCurrentController());
221 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(xController
, css::uno::UNO_QUERY
);
222 if (!xSelectionSupplier
.is())
225 uno::Any aAny
= xSelectionSupplier
->getSelection();
226 assert(aAny
.hasValue());
230 ObjectType eType
= ObjectIdentifier::getObjectType(aCID
);
231 assert(eType
== OBJECTTYPE_DATA_ERRORS_X
||
232 eType
== OBJECTTYPE_DATA_ERRORS_Y
||
233 eType
== OBJECTTYPE_DATA_ERRORS_Z
);
241 ChartErrorBarPanel::ChartErrorBarPanel(
242 vcl::Window
* pParent
,
243 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
244 ChartController
* pController
)
245 : PanelLayout(pParent
, "ChartErrorBarPanel", "modules/schart/ui/sidebarerrorbar.ui", rxFrame
),
246 mxModel(pController
->getModel()),
247 mxListener(new ChartSidebarModifyListener(this)),
251 get(mpRBPosAndNeg
, "radiobutton_positive_negative");
252 get(mpRBPos
, "radiobutton_positive");
253 get(mpRBNeg
, "radiobutton_negative");
255 get(mpLBType
, "comboboxtext_type");
257 get(mpMFPos
, "spinbutton_pos");
258 get(mpMFNeg
, "spinbutton_neg");
263 ChartErrorBarPanel::~ChartErrorBarPanel()
268 void ChartErrorBarPanel::dispose()
270 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
271 xBroadcaster
->removeModifyListener(mxListener
);
273 mpRBPosAndNeg
.clear();
282 PanelLayout::dispose();
285 void ChartErrorBarPanel::Initialize()
287 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
288 xBroadcaster
->addModifyListener(mxListener
);
289 mpRBNeg
->Check(false);
290 mpRBPos
->Check(false);
291 mpRBPosAndNeg
->Check(false);
295 Link
<RadioButton
&,void> aLink
= LINK(this, ChartErrorBarPanel
, RadioBtnHdl
);
296 mpRBPosAndNeg
->SetToggleHdl(aLink
);
297 mpRBPos
->SetToggleHdl(aLink
);
298 mpRBNeg
->SetToggleHdl(aLink
);
300 mpLBType
->SetSelectHdl(LINK(this, ChartErrorBarPanel
, ListBoxHdl
));
302 Link
<Edit
&,void> aLink2
= LINK(this, ChartErrorBarPanel
, NumericFieldHdl
);
303 mpMFPos
->SetModifyHdl(aLink2
);
304 mpMFNeg
->SetModifyHdl(aLink2
);
307 void ChartErrorBarPanel::updateData()
312 OUString aCID
= getCID(mxModel
);
313 bool bPos
= showPositiveError(mxModel
, aCID
);
314 bool bNeg
= showNegativeError(mxModel
, aCID
);
316 SolarMutexGuard aGuard
;
319 mpRBPosAndNeg
->Check();
325 sal_Int32 nTypePos
= getTypePos(mxModel
, aCID
);
326 mpLBType
->SelectEntryPos(nTypePos
);
340 double nValPos
= getValue(mxModel
, aCID
, ErrorBarDirection::POSITIVE
);
341 double nValNeg
= getValue(mxModel
, aCID
, ErrorBarDirection::NEGATIVE
);
343 mpMFPos
->SetValue(nValPos
);
344 mpMFNeg
->SetValue(nValNeg
);
353 VclPtr
<vcl::Window
> ChartErrorBarPanel::Create (
354 vcl::Window
* pParent
,
355 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
356 ChartController
* pController
)
358 if (pParent
== nullptr)
359 throw lang::IllegalArgumentException("no parent Window given to ChartErrorBarPanel::Create", nullptr, 0);
361 throw lang::IllegalArgumentException("no XFrame given to ChartErrorBarPanel::Create", nullptr, 1);
363 return VclPtr
<ChartErrorBarPanel
>::Create(
364 pParent
, rxFrame
, pController
);
367 void ChartErrorBarPanel::DataChanged(
368 const DataChangedEvent
& )
373 void ChartErrorBarPanel::HandleContextChange(
374 const vcl::EnumContext
& )
379 void ChartErrorBarPanel::NotifyItemUpdate(
381 SfxItemState
/*eState*/,
382 const SfxPoolItem
* /*pState*/,
387 void ChartErrorBarPanel::modelInvalid()
389 mbModelValid
= false;
392 void ChartErrorBarPanel::updateModel(
393 css::uno::Reference
<css::frame::XModel
> xModel
)
397 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
398 xBroadcaster
->removeModifyListener(mxListener
);
404 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcasterNew(mxModel
, css::uno::UNO_QUERY_THROW
);
405 xBroadcasterNew
->addModifyListener(mxListener
);
408 IMPL_LINK_NOARG(ChartErrorBarPanel
, RadioBtnHdl
, RadioButton
&, void)
410 OUString aCID
= getCID(mxModel
);
411 bool bPos
= mpRBPosAndNeg
->IsChecked() || mpRBPos
->IsChecked();
412 bool bNeg
= mpRBPosAndNeg
->IsChecked() || mpRBNeg
->IsChecked();
414 setShowPositiveError(mxModel
, aCID
, bPos
);
415 setShowNegativeError(mxModel
, aCID
, bNeg
);
418 IMPL_LINK_NOARG(ChartErrorBarPanel
, ListBoxHdl
, ListBox
&, void)
420 OUString aCID
= getCID(mxModel
);
421 sal_Int32 nPos
= mpLBType
->GetSelectedEntryPos();
423 setTypePos(mxModel
, aCID
, nPos
);
426 IMPL_LINK(ChartErrorBarPanel
, NumericFieldHdl
, Edit
&, rMetricField
, void)
428 OUString aCID
= getCID(mxModel
);
429 double nVal
= static_cast<NumericField
&>(rMetricField
).GetValue();
430 if (&rMetricField
== mpMFPos
.get())
431 setValue(mxModel
, aCID
, nVal
, ErrorBarDirection::POSITIVE
);
432 else if (&rMetricField
== mpMFNeg
.get())
433 setValue(mxModel
, aCID
, nVal
, ErrorBarDirection::NEGATIVE
);
436 }} // end of namespace ::chart::sidebar
438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */