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 <com/sun/star/chart/ErrorBarStyle.hpp>
21 #include <com/sun/star/util/XModifyBroadcaster.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include "ChartErrorBarPanel.hxx"
25 #include <ChartController.hxx>
26 #include <vcl/lstbox.hxx>
27 #include <vcl/field.hxx>
28 #include <vcl/button.hxx>
29 #include <vcl/svapp.hxx>
32 using namespace css::uno
;
34 namespace chart
{ namespace sidebar
{
38 enum class ErrorBarDirection
44 css::uno::Reference
<css::beans::XPropertySet
> getErrorBarPropSet(
45 const css::uno::Reference
<css::frame::XModel
>& xModel
, const OUString
& rCID
)
47 return ObjectIdentifier::getObjectPropertySet(rCID
, xModel
);
50 bool showPositiveError(const css::uno::Reference
<css::frame::XModel
>& xModel
,
53 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
54 getErrorBarPropSet(xModel
, rCID
);
59 css::uno::Any aAny
= xPropSet
->getPropertyValue("ShowPositiveError");
69 bool showNegativeError(const css::uno::Reference
<css::frame::XModel
>& xModel
,
72 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
73 getErrorBarPropSet(xModel
, rCID
);
78 css::uno::Any aAny
= xPropSet
->getPropertyValue("ShowNegativeError");
88 void setShowPositiveError(const css::uno::Reference
<css::frame::XModel
>& xModel
,
89 const OUString
& rCID
, bool bShow
)
91 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
92 getErrorBarPropSet(xModel
, rCID
);
97 xPropSet
->setPropertyValue("ShowPositiveError", css::uno::Any(bShow
));
100 void setShowNegativeError(const css::uno::Reference
<css::frame::XModel
>& xModel
,
101 const OUString
& rCID
, bool bShow
)
103 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
104 getErrorBarPropSet(xModel
, rCID
);
109 xPropSet
->setPropertyValue("ShowNegativeError", css::uno::Any(bShow
));
112 struct ErrorBarTypeMap
118 static ErrorBarTypeMap
const aErrorBarType
[] = {
119 { 0, css::chart::ErrorBarStyle::ABSOLUTE
},
120 { 1, css::chart::ErrorBarStyle::RELATIVE
},
121 { 2, css::chart::ErrorBarStyle::FROM_DATA
},
122 { 3, css::chart::ErrorBarStyle::STANDARD_DEVIATION
},
123 { 4, css::chart::ErrorBarStyle::STANDARD_ERROR
},
124 { 5, css::chart::ErrorBarStyle::VARIANCE
},
125 { 6, css::chart::ErrorBarStyle::ERROR_MARGIN
},
128 sal_Int32
getTypePos(const css::uno::Reference
<css::frame::XModel
>& xModel
,
129 const OUString
& rCID
)
131 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
132 getErrorBarPropSet(xModel
, rCID
);
137 css::uno::Any aAny
= xPropSet
->getPropertyValue("ErrorBarStyle");
139 if (!aAny
.hasValue())
145 for (ErrorBarTypeMap
const & i
: aErrorBarType
)
154 void setTypePos(const css::uno::Reference
<css::frame::XModel
>& xModel
,
155 const OUString
& rCID
, sal_Int32 nPos
)
157 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
158 getErrorBarPropSet(xModel
, rCID
);
164 for (ErrorBarTypeMap
const & i
: aErrorBarType
)
170 xPropSet
->setPropertyValue("ErrorBarStyle", css::uno::Any(nApi
));
173 double getValue(const css::uno::Reference
<css::frame::XModel
>& xModel
,
174 const OUString
& rCID
, ErrorBarDirection eDir
)
176 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
177 getErrorBarPropSet(xModel
, rCID
);
182 OUString aName
= "PositiveError";
183 if (eDir
== ErrorBarDirection::NEGATIVE
)
184 aName
= "NegativeError";
186 css::uno::Any aAny
= xPropSet
->getPropertyValue(aName
);
188 if (!aAny
.hasValue())
197 void setValue(const css::uno::Reference
<css::frame::XModel
>& xModel
,
198 const OUString
& rCID
, double nVal
, ErrorBarDirection eDir
)
200 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
201 getErrorBarPropSet(xModel
, rCID
);
206 OUString aName
= "PositiveError";
207 if (eDir
== ErrorBarDirection::NEGATIVE
)
208 aName
= "NegativeError";
210 xPropSet
->setPropertyValue(aName
, css::uno::Any(nVal
));
213 OUString
getCID(const css::uno::Reference
<css::frame::XModel
>& xModel
)
215 css::uno::Reference
<css::frame::XController
> xController(xModel
->getCurrentController());
216 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(xController
, css::uno::UNO_QUERY
);
217 if (!xSelectionSupplier
.is())
220 uno::Any aAny
= xSelectionSupplier
->getSelection();
221 assert(aAny
.hasValue());
224 #if defined DBG_UTIL && !defined NDEBUG
225 ObjectType eType
= ObjectIdentifier::getObjectType(aCID
);
226 assert(eType
== OBJECTTYPE_DATA_ERRORS_X
||
227 eType
== OBJECTTYPE_DATA_ERRORS_Y
||
228 eType
== OBJECTTYPE_DATA_ERRORS_Z
);
236 ChartErrorBarPanel::ChartErrorBarPanel(
237 vcl::Window
* pParent
,
238 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
239 ChartController
* pController
)
240 : PanelLayout(pParent
, "ChartErrorBarPanel", "modules/schart/ui/sidebarerrorbar.ui", rxFrame
),
241 mxModel(pController
->getModel()),
242 mxListener(new ChartSidebarModifyListener(this)),
246 get(mpRBPosAndNeg
, "radiobutton_positive_negative");
247 get(mpRBPos
, "radiobutton_positive");
248 get(mpRBNeg
, "radiobutton_negative");
250 get(mpLBType
, "comboboxtext_type");
252 get(mpMFPos
, "spinbutton_pos");
253 get(mpMFNeg
, "spinbutton_neg");
258 ChartErrorBarPanel::~ChartErrorBarPanel()
263 void ChartErrorBarPanel::dispose()
265 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
266 xBroadcaster
->removeModifyListener(mxListener
);
268 mpRBPosAndNeg
.clear();
277 PanelLayout::dispose();
280 void ChartErrorBarPanel::Initialize()
282 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
283 xBroadcaster
->addModifyListener(mxListener
);
284 mpRBNeg
->Check(false);
285 mpRBPos
->Check(false);
286 mpRBPosAndNeg
->Check(false);
290 Link
<RadioButton
&,void> aLink
= LINK(this, ChartErrorBarPanel
, RadioBtnHdl
);
291 mpRBPosAndNeg
->SetToggleHdl(aLink
);
292 mpRBPos
->SetToggleHdl(aLink
);
293 mpRBNeg
->SetToggleHdl(aLink
);
295 mpLBType
->SetSelectHdl(LINK(this, ChartErrorBarPanel
, ListBoxHdl
));
297 Link
<Edit
&,void> aLink2
= LINK(this, ChartErrorBarPanel
, NumericFieldHdl
);
298 mpMFPos
->SetModifyHdl(aLink2
);
299 mpMFNeg
->SetModifyHdl(aLink2
);
302 void ChartErrorBarPanel::updateData()
307 OUString aCID
= getCID(mxModel
);
308 bool bPos
= showPositiveError(mxModel
, aCID
);
309 bool bNeg
= showNegativeError(mxModel
, aCID
);
311 SolarMutexGuard aGuard
;
314 mpRBPosAndNeg
->Check();
320 sal_Int32 nTypePos
= getTypePos(mxModel
, aCID
);
321 mpLBType
->SelectEntryPos(nTypePos
);
335 double nValPos
= getValue(mxModel
, aCID
, ErrorBarDirection::POSITIVE
);
336 double nValNeg
= getValue(mxModel
, aCID
, ErrorBarDirection::NEGATIVE
);
338 mpMFPos
->SetValue(nValPos
);
339 mpMFNeg
->SetValue(nValNeg
);
348 VclPtr
<vcl::Window
> ChartErrorBarPanel::Create (
349 vcl::Window
* pParent
,
350 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
351 ChartController
* pController
)
353 if (pParent
== nullptr)
354 throw lang::IllegalArgumentException("no parent Window given to ChartErrorBarPanel::Create", nullptr, 0);
356 throw lang::IllegalArgumentException("no XFrame given to ChartErrorBarPanel::Create", nullptr, 1);
358 return VclPtr
<ChartErrorBarPanel
>::Create(
359 pParent
, rxFrame
, pController
);
362 void ChartErrorBarPanel::DataChanged(
363 const DataChangedEvent
& )
368 void ChartErrorBarPanel::HandleContextChange(
369 const vcl::EnumContext
& )
374 void ChartErrorBarPanel::NotifyItemUpdate(
376 SfxItemState
/*eState*/,
377 const SfxPoolItem
* /*pState*/ )
381 void ChartErrorBarPanel::modelInvalid()
383 mbModelValid
= false;
386 void ChartErrorBarPanel::updateModel(
387 css::uno::Reference
<css::frame::XModel
> xModel
)
391 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
392 xBroadcaster
->removeModifyListener(mxListener
);
398 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcasterNew(mxModel
, css::uno::UNO_QUERY_THROW
);
399 xBroadcasterNew
->addModifyListener(mxListener
);
402 IMPL_LINK_NOARG(ChartErrorBarPanel
, RadioBtnHdl
, RadioButton
&, void)
404 OUString aCID
= getCID(mxModel
);
405 bool bPos
= mpRBPosAndNeg
->IsChecked() || mpRBPos
->IsChecked();
406 bool bNeg
= mpRBPosAndNeg
->IsChecked() || mpRBNeg
->IsChecked();
408 setShowPositiveError(mxModel
, aCID
, bPos
);
409 setShowNegativeError(mxModel
, aCID
, bNeg
);
412 IMPL_LINK_NOARG(ChartErrorBarPanel
, ListBoxHdl
, ListBox
&, void)
414 OUString aCID
= getCID(mxModel
);
415 sal_Int32 nPos
= mpLBType
->GetSelectedEntryPos();
417 setTypePos(mxModel
, aCID
, nPos
);
420 IMPL_LINK(ChartErrorBarPanel
, NumericFieldHdl
, Edit
&, rMetricField
, void)
422 OUString aCID
= getCID(mxModel
);
423 double nVal
= static_cast<NumericField
&>(rMetricField
).GetValue();
424 if (&rMetricField
== mpMFPos
.get())
425 setValue(mxModel
, aCID
, nVal
, ErrorBarDirection::POSITIVE
);
426 else if (&rMetricField
== mpMFNeg
.get())
427 setValue(mxModel
, aCID
, nVal
, ErrorBarDirection::NEGATIVE
);
430 }} // end of namespace ::chart::sidebar
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */