diff options
Diffstat (limited to 'chart2/source/controller/sidebar/ChartErrorBarPanel.cxx')
-rw-r--r-- | chart2/source/controller/sidebar/ChartErrorBarPanel.cxx | 129 |
1 files changed, 60 insertions, 69 deletions
diff --git a/chart2/source/controller/sidebar/ChartErrorBarPanel.cxx b/chart2/source/controller/sidebar/ChartErrorBarPanel.cxx index cb768d34dd15..87be2b47d185 100644 --- a/chart2/source/controller/sidebar/ChartErrorBarPanel.cxx +++ b/chart2/source/controller/sidebar/ChartErrorBarPanel.cxx @@ -18,11 +18,11 @@ */ #include <com/sun/star/chart/ErrorBarStyle.hpp> -#include <com/sun/star/util/XModifyBroadcaster.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include "ChartErrorBarPanel.hxx" #include <ChartController.hxx> +#include <ChartModel.hxx> #include <vcl/svapp.hxx> #include <sal/log.hxx> @@ -41,13 +41,13 @@ enum class ErrorBarDirection }; css::uno::Reference<css::beans::XPropertySet> getErrorBarPropSet( - const css::uno::Reference<css::frame::XModel>& xModel, const OUString& rCID) + const rtl::Reference<::chart::ChartModel>& xModel, std::u16string_view rCID) { return ObjectIdentifier::getObjectPropertySet(rCID, xModel); } -bool showPositiveError(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rCID) +bool showPositiveError(const rtl::Reference<::chart::ChartModel>& xModel, + std::u16string_view rCID) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getErrorBarPropSet(xModel, rCID); @@ -55,7 +55,7 @@ bool showPositiveError(const css::uno::Reference<css::frame::XModel>& xModel, if (!xPropSet.is()) return false; - css::uno::Any aAny = xPropSet->getPropertyValue("ShowPositiveError"); + css::uno::Any aAny = xPropSet->getPropertyValue(u"ShowPositiveError"_ustr); if (!aAny.hasValue()) return false; @@ -65,8 +65,8 @@ bool showPositiveError(const css::uno::Reference<css::frame::XModel>& xModel, return bShow; } -bool showNegativeError(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rCID) +bool showNegativeError(const rtl::Reference<::chart::ChartModel>& xModel, + std::u16string_view rCID) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getErrorBarPropSet(xModel, rCID); @@ -74,7 +74,7 @@ bool showNegativeError(const css::uno::Reference<css::frame::XModel>& xModel, if (!xPropSet.is()) return false; - css::uno::Any aAny = xPropSet->getPropertyValue("ShowNegativeError"); + css::uno::Any aAny = xPropSet->getPropertyValue(u"ShowNegativeError"_ustr); if (!aAny.hasValue()) return false; @@ -84,8 +84,8 @@ bool showNegativeError(const css::uno::Reference<css::frame::XModel>& xModel, return bShow; } -void setShowPositiveError(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rCID, bool bShow) +void setShowPositiveError(const rtl::Reference<::chart::ChartModel>& xModel, + std::u16string_view rCID, bool bShow) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getErrorBarPropSet(xModel, rCID); @@ -93,11 +93,11 @@ void setShowPositiveError(const css::uno::Reference<css::frame::XModel>& xModel, if (!xPropSet.is()) return; - xPropSet->setPropertyValue("ShowPositiveError", css::uno::Any(bShow)); + xPropSet->setPropertyValue(u"ShowPositiveError"_ustr, css::uno::Any(bShow)); } -void setShowNegativeError(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rCID, bool bShow) +void setShowNegativeError(const rtl::Reference<::chart::ChartModel>& xModel, + std::u16string_view rCID, bool bShow) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getErrorBarPropSet(xModel, rCID); @@ -105,7 +105,7 @@ void setShowNegativeError(const css::uno::Reference<css::frame::XModel>& xModel, if (!xPropSet.is()) return; - xPropSet->setPropertyValue("ShowNegativeError", css::uno::Any(bShow)); + xPropSet->setPropertyValue(u"ShowNegativeError"_ustr, css::uno::Any(bShow)); } struct ErrorBarTypeMap @@ -124,8 +124,8 @@ ErrorBarTypeMap const aErrorBarType[] = { { 6, css::chart::ErrorBarStyle::ERROR_MARGIN }, }; -sal_Int32 getTypePos(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rCID) +sal_Int32 getTypePos(const rtl::Reference<::chart::ChartModel>& xModel, + std::u16string_view rCID) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getErrorBarPropSet(xModel, rCID); @@ -133,7 +133,7 @@ sal_Int32 getTypePos(const css::uno::Reference<css::frame::XModel>& xModel, if (!xPropSet.is()) return 0; - css::uno::Any aAny = xPropSet->getPropertyValue("ErrorBarStyle"); + css::uno::Any aAny = xPropSet->getPropertyValue(u"ErrorBarStyle"_ustr); if (!aAny.hasValue()) return 0; @@ -150,8 +150,8 @@ sal_Int32 getTypePos(const css::uno::Reference<css::frame::XModel>& xModel, return 0; } -void setTypePos(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rCID, sal_Int32 nPos) +void setTypePos(const rtl::Reference<::chart::ChartModel>& xModel, + std::u16string_view rCID, sal_Int32 nPos) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getErrorBarPropSet(xModel, rCID); @@ -166,11 +166,11 @@ void setTypePos(const css::uno::Reference<css::frame::XModel>& xModel, nApi = i.nApi; } - xPropSet->setPropertyValue("ErrorBarStyle", css::uno::Any(nApi)); + xPropSet->setPropertyValue(u"ErrorBarStyle"_ustr, css::uno::Any(nApi)); } -double getValue(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rCID, ErrorBarDirection eDir) +double getValue(const rtl::Reference<::chart::ChartModel>& xModel, + std::u16string_view rCID, ErrorBarDirection eDir) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getErrorBarPropSet(xModel, rCID); @@ -178,7 +178,7 @@ double getValue(const css::uno::Reference<css::frame::XModel>& xModel, if (!xPropSet.is()) return 0; - OUString aName = "PositiveError"; + OUString aName = u"PositiveError"_ustr; if (eDir == ErrorBarDirection::NEGATIVE) aName = "NegativeError"; @@ -193,8 +193,8 @@ double getValue(const css::uno::Reference<css::frame::XModel>& xModel, return nVal; } -void setValue(const css::uno::Reference<css::frame::XModel>& xModel, - const OUString& rCID, double nVal, ErrorBarDirection eDir) +void setValue(const rtl::Reference<::chart::ChartModel>& xModel, + std::u16string_view rCID, double nVal, ErrorBarDirection eDir) { css::uno::Reference<css::beans::XPropertySet> xPropSet = getErrorBarPropSet(xModel, rCID); @@ -202,14 +202,14 @@ void setValue(const css::uno::Reference<css::frame::XModel>& xModel, if (!xPropSet.is()) return; - OUString aName = "PositiveError"; + OUString aName = u"PositiveError"_ustr; if (eDir == ErrorBarDirection::NEGATIVE) aName = "NegativeError"; xPropSet->setPropertyValue(aName, css::uno::Any(nVal)); } -OUString getCID(const css::uno::Reference<css::frame::XModel>& xModel) +OUString getCID(const rtl::Reference<::chart::ChartModel>& xModel) { css::uno::Reference<css::frame::XController> xController(xModel->getCurrentController()); css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY); @@ -234,17 +234,15 @@ OUString getCID(const css::uno::Reference<css::frame::XModel>& xModel) } -ChartErrorBarPanel::ChartErrorBarPanel( - vcl::Window* pParent, - const css::uno::Reference<css::frame::XFrame>& rxFrame, ChartController* pController) - : PanelLayout(pParent, "ChartErrorBarPanel", "modules/schart/ui/sidebarerrorbar.ui", rxFrame) - , mxRBPosAndNeg(m_xBuilder->weld_radio_button("radiobutton_positive_negative")) - , mxRBPos(m_xBuilder->weld_radio_button("radiobutton_positive")) - , mxRBNeg(m_xBuilder->weld_radio_button("radiobutton_negative")) - , mxLBType(m_xBuilder->weld_combo_box("comboboxtext_type")) - , mxMFPos(m_xBuilder->weld_spin_button("spinbutton_pos")) - , mxMFNeg(m_xBuilder->weld_spin_button("spinbutton_neg")) - , mxModel(pController->getModel()) +ChartErrorBarPanel::ChartErrorBarPanel(weld::Widget* pParent, ChartController* pController) + : PanelLayout(pParent, u"ChartErrorBarPanel"_ustr, u"modules/schart/ui/sidebarerrorbar.ui"_ustr) + , mxRBPosAndNeg(m_xBuilder->weld_radio_button(u"radiobutton_positive_negative"_ustr)) + , mxRBPos(m_xBuilder->weld_radio_button(u"radiobutton_positive"_ustr)) + , mxRBNeg(m_xBuilder->weld_radio_button(u"radiobutton_negative"_ustr)) + , mxLBType(m_xBuilder->weld_combo_box(u"comboboxtext_type"_ustr)) + , mxMFPos(m_xBuilder->weld_spin_button(u"spinbutton_pos"_ustr)) + , mxMFNeg(m_xBuilder->weld_spin_button(u"spinbutton_neg"_ustr)) + , mxModel(pController->getChartModel()) , mxListener(new ChartSidebarModifyListener(this)) , mbModelValid(true) { @@ -253,13 +251,7 @@ ChartErrorBarPanel::ChartErrorBarPanel( ChartErrorBarPanel::~ChartErrorBarPanel() { - disposeOnce(); -} - -void ChartErrorBarPanel::dispose() -{ - css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW); - xBroadcaster->removeModifyListener(mxListener); + doUpdateModel(nullptr); mxRBPosAndNeg.reset(); mxRBPos.reset(); @@ -269,21 +261,18 @@ void ChartErrorBarPanel::dispose() mxMFPos.reset(); mxMFNeg.reset(); - - PanelLayout::dispose(); } void ChartErrorBarPanel::Initialize() { - css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW); - xBroadcaster->addModifyListener(mxListener); + mxModel->addModifyListener(mxListener); mxRBNeg->set_active(false); mxRBPos->set_active(false); mxRBPosAndNeg->set_active(false); updateData(); - Link<weld::ToggleButton&,void> aLink = LINK(this, ChartErrorBarPanel, RadioBtnHdl); + Link<weld::Toggleable&,void> aLink = LINK(this, ChartErrorBarPanel, RadioBtnHdl); mxRBPosAndNeg->connect_toggled(aLink); mxRBPos->connect_toggled(aLink); mxRBNeg->connect_toggled(aLink); @@ -347,23 +336,18 @@ void ChartErrorBarPanel::updateData() } } -VclPtr<vcl::Window> ChartErrorBarPanel::Create ( - vcl::Window* pParent, - const css::uno::Reference<css::frame::XFrame>& rxFrame, +std::unique_ptr<PanelLayout> ChartErrorBarPanel::Create ( + weld::Widget* pParent, ChartController* pController) { if (pParent == nullptr) - throw lang::IllegalArgumentException("no parent Window given to ChartErrorBarPanel::Create", nullptr, 0); - if ( ! rxFrame.is()) - throw lang::IllegalArgumentException("no XFrame given to ChartErrorBarPanel::Create", nullptr, 1); - - return VclPtr<ChartErrorBarPanel>::Create( - pParent, rxFrame, pController); + throw lang::IllegalArgumentException(u"no parent Window given to ChartErrorBarPanel::Create"_ustr, nullptr, 0); + return std::make_unique<ChartErrorBarPanel>(pParent, pController); } -void ChartErrorBarPanel::DataChanged( - const DataChangedEvent& ) +void ChartErrorBarPanel::DataChanged(const DataChangedEvent& rEvent) { + PanelLayout::DataChanged(rEvent); updateData(); } @@ -385,23 +369,30 @@ void ChartErrorBarPanel::modelInvalid() mbModelValid = false; } -void ChartErrorBarPanel::updateModel( - css::uno::Reference<css::frame::XModel> xModel) +void ChartErrorBarPanel::doUpdateModel(const rtl::Reference<::chart::ChartModel>& xModel) { if (mbModelValid) { - css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW); - xBroadcaster->removeModifyListener(mxListener); + mxModel->removeModifyListener(mxListener); } mxModel = xModel; - mbModelValid = true; + mbModelValid = mxModel.is(); - css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW); - xBroadcasterNew->addModifyListener(mxListener); + if (!mbModelValid) + return; + + mxModel->addModifyListener(mxListener); +} + +void ChartErrorBarPanel::updateModel(css::uno::Reference<css::frame::XModel> xModel) +{ + ::chart::ChartModel* pModel = dynamic_cast<::chart::ChartModel*>(xModel.get()); + assert(!xModel || pModel); + doUpdateModel(pModel); } -IMPL_LINK_NOARG(ChartErrorBarPanel, RadioBtnHdl, weld::ToggleButton&, void) +IMPL_LINK_NOARG(ChartErrorBarPanel, RadioBtnHdl, weld::Toggleable&, void) { OUString aCID = getCID(mxModel); bool bPos = mxRBPosAndNeg->get_active() || mxRBPos->get_active(); |