chart2/source/controller/sidebar/ChartSeriesPanel.cxx | 160 +++++++++++++++++- chart2/source/controller/sidebar/ChartSeriesPanel.hxx | 7 chart2/uiconfig/ui/sidebarseries.ui | 2 3 files changed, 167 insertions(+), 2 deletions(-)
New commits: commit 07ff2841ccf6d4f93941838305248f7048fec803 Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Fri Jul 17 01:41:10 2015 +0200 add data label handling to series panel Change-Id: I37415b5effb6ac320184008b9b25988804387715 diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx index 389ec28..b8b1b5a 100644 --- a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx +++ b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx @@ -24,6 +24,7 @@ #include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/chart/DataLabelPlacement.hpp> #include "ChartSeriesPanel.hxx" #include "ChartController.hxx" @@ -76,6 +77,68 @@ void setDataLabelVisible(css::uno::Reference<css::frame::XModel> xModel, const O DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints(xSeries); } +struct LabelPlacementMap +{ + sal_Int32 nPos; + sal_Int32 nApi; +}; + +LabelPlacementMap aLabelPlacementMap[] = { + { 0, css::chart::DataLabelPlacement::TOP }, + { 1, css::chart::DataLabelPlacement::BOTTOM }, + { 2, css::chart::DataLabelPlacement::CENTER }, + { 3, css::chart::DataLabelPlacement::OUTSIDE }, + { 4, css::chart::DataLabelPlacement::INSIDE }, + { 5, css::chart::DataLabelPlacement::NEAR_ORIGIN } +}; + +sal_Int32 getDataLabelPlacement(css::uno::Reference<css::frame::XModel> xModel, + const OUString& rCID) +{ + css::uno::Reference< css::beans::XPropertySet > xSeries( + ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY ); + + if (!xSeries.is()) + return false; + + css::uno::Any aAny = xSeries->getPropertyValue("LabelPlacement"); + if (!aAny.hasValue()) + return 0; + + sal_Int32 nPlacement = 0; + aAny >>= nPlacement; + + for (size_t i = 0; i < SAL_N_ELEMENTS(aLabelPlacementMap); ++i) + { + if (aLabelPlacementMap[i].nApi == nPlacement) + return aLabelPlacementMap[i].nPos; + } + + return 0; +} + +void setDataLabelPlacement(css::uno::Reference<css::frame::XModel> xModel, + const OUString& rCID, sal_Int32 nPos) +{ + css::uno::Reference< css::beans::XPropertySet > xSeries( + ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY ); + + if (!xSeries.is()) + return; + + sal_Int32 nApi = 0; + for (size_t i = 0; i < SAL_N_ELEMENTS(aLabelPlacementMap); ++i) + { + if (aLabelPlacementMap[i].nPos == nPos) + { + nApi = aLabelPlacementMap[i].nApi; + break; + } + } + + xSeries->setPropertyValue("LabelPlacement", css::uno::makeAny(nApi)); +} + bool isTrendlineVisible(css::uno::Reference<css::frame::XModel> xModel, const OUString& rCID) { @@ -192,6 +255,8 @@ ChartSeriesPanel::ChartSeriesPanel( get(mpRBPrimaryAxis, "radiobutton_primary_axis"); get(mpRBSecondaryAxis, "radiobutton_secondary_axis"); + get(mpLBLabelPlacement, "comboboxtext_label"); + Initialize(); } @@ -213,6 +278,8 @@ void ChartSeriesPanel::dispose() mpRBPrimaryAxis.clear(); mpRBSecondaryAxis.clear(); + mpLBLabelPlacement.clear(); + PanelLayout::dispose(); } @@ -232,6 +299,8 @@ void ChartSeriesPanel::Initialize() aLink = LINK(this, ChartSeriesPanel, RadioBtnHdl); mpRBPrimaryAxis->SetToggleHdl(aLink); mpRBSecondaryAxis->SetToggleHdl(aLink); + + mpLBLabelPlacement->SetSelectHdl(LINK(this, ChartSeriesPanel, ListBoxHdl)); } void ChartSeriesPanel::updateData() @@ -250,7 +319,8 @@ void ChartSeriesPanel::updateData() assert(eType == OBJECTTYPE_DATA_SERIES); #endif SolarMutexGuard aGuard; - mpCBLabel->Check(isDataLabelVisible(mxModel, aCID)); + bool bLabelVisible = isDataLabelVisible(mxModel, aCID); + mpCBLabel->Check(bLabelVisible); mpCBTrendline->Check(isTrendlineVisible(mxModel, aCID)); mpCBXError->Check(isErrorBarVisible(mxModel, aCID, false)); mpCBYError->Check(isErrorBarVisible(mxModel, aCID, true)); @@ -258,6 +328,9 @@ void ChartSeriesPanel::updateData() bool bPrimaryAxis = isPrimaryAxis(mxModel, aCID); mpRBPrimaryAxis->Check(bPrimaryAxis); mpRBSecondaryAxis->Check(!bPrimaryAxis); + + mpLBLabelPlacement->Enable(bLabelVisible); + mpLBLabelPlacement->SelectEntryPos(getDataLabelPlacement(mxModel, aCID)); } VclPtr<vcl::Window> ChartSeriesPanel::Create ( @@ -353,6 +426,28 @@ IMPL_LINK_NOARG(ChartSeriesPanel, RadioBtnHdl) return 0; } +IMPL_LINK_NOARG(ChartSeriesPanel, ListBoxHdl) +{ + css::uno::Reference<css::frame::XController> xController(mxModel->getCurrentController()); + css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY); + if (!xSelectionSupplier.is()) + return 0; + + uno::Any aAny = xSelectionSupplier->getSelection(); + assert(aAny.hasValue()); + OUString aCID; + aAny >>= aCID; +#ifdef DBG_UTIL + ObjectType eType = ObjectIdentifier::getObjectType(aCID); + assert(eType == OBJECTTYPE_DATA_SERIES); +#endif + + sal_Int32 nPos = mpLBLabelPlacement->GetSelectEntryPos(); + setDataLabelPlacement(mxModel, aCID, nPos); + + return 0; +} + }} // end of namespace ::chart::sidebar /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.hxx b/chart2/source/controller/sidebar/ChartSeriesPanel.hxx index a0c773b..32cce955 100644 --- a/chart2/source/controller/sidebar/ChartSeriesPanel.hxx +++ b/chart2/source/controller/sidebar/ChartSeriesPanel.hxx @@ -83,6 +83,8 @@ private: VclPtr<RadioButton> mpRBPrimaryAxis; VclPtr<RadioButton> mpRBSecondaryAxis; + VclPtr<ListBox> mpLBLabelPlacement; + css::uno::Reference<css::frame::XFrame> mxFrame; ::sfx2::sidebar::EnumContext maContext; SfxBindings* mpBindings; @@ -94,6 +96,7 @@ private: DECL_LINK(CheckBoxHdl, CheckBox*); DECL_LINK(RadioBtnHdl, void*); + DECL_LINK(ListBoxHdl, void*); }; } } // end of namespace ::chart::sidebar commit d84f954cc0ad22cf62e279da2e473f79d1fb889b Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Fri Jul 17 01:08:12 2015 +0200 also handle primary vs secondary axis in series panel Change-Id: Ieed69e1e7ebd88b15dd6a6fb51863fab4f57479c diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx index b318f59..389ec28 100644 --- a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx +++ b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx @@ -23,6 +23,7 @@ #include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include "ChartSeriesPanel.hxx" #include "ChartController.hxx" @@ -144,6 +145,31 @@ void setErrorBarVisible(css::uno::Reference<css::frame::XModel> } } +bool isPrimaryAxis(css::uno::Reference<css::frame::XModel> + xModel, const OUString& rCID) +{ + css::uno::Reference< css::chart2::XDataSeries > xSeries( + ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY ); + + if (!xSeries.is()) + return true; + + return DataSeriesHelper::getAttachedAxisIndex(xSeries) == 0; +} + +void setAttachedAxisType(css::uno::Reference<css::frame::XModel> + xModel, const OUString& rCID, bool bPrimary) +{ + css::uno::Reference< css::beans::XPropertySet > xSeries( + ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY ); + + if (!xSeries.is()) + return; + + sal_Int32 nIndex = bPrimary ? 0 : 1; + xSeries->setPropertyValue("AttachedAxisIndex", css::uno::makeAny(nIndex)); +} + } ChartSeriesPanel::ChartSeriesPanel( @@ -163,6 +189,9 @@ ChartSeriesPanel::ChartSeriesPanel( get(mpCBXError, "checkbutton_x_error"); get(mpCBYError, "checkbutton_y_error"); + get(mpRBPrimaryAxis, "radiobutton_primary_axis"); + get(mpRBSecondaryAxis, "radiobutton_secondary_axis"); + Initialize(); } @@ -181,6 +210,9 @@ void ChartSeriesPanel::dispose() mpCBXError.clear(); mpCBYError.clear(); + mpRBPrimaryAxis.clear(); + mpRBSecondaryAxis.clear(); + PanelLayout::dispose(); } @@ -196,6 +228,10 @@ void ChartSeriesPanel::Initialize() mpCBTrendline->SetClickHdl(aLink); mpCBXError->SetClickHdl(aLink); mpCBYError->SetClickHdl(aLink); + + aLink = LINK(this, ChartSeriesPanel, RadioBtnHdl); + mpRBPrimaryAxis->SetToggleHdl(aLink); + mpRBSecondaryAxis->SetToggleHdl(aLink); } void ChartSeriesPanel::updateData() @@ -218,6 +254,10 @@ void ChartSeriesPanel::updateData() mpCBTrendline->Check(isTrendlineVisible(mxModel, aCID)); mpCBXError->Check(isErrorBarVisible(mxModel, aCID, false)); mpCBYError->Check(isErrorBarVisible(mxModel, aCID, true)); + + bool bPrimaryAxis = isPrimaryAxis(mxModel, aCID); + mpRBPrimaryAxis->Check(bPrimaryAxis); + mpRBSecondaryAxis->Check(!bPrimaryAxis); } VclPtr<vcl::Window> ChartSeriesPanel::Create ( @@ -290,6 +330,29 @@ IMPL_LINK(ChartSeriesPanel, CheckBoxHdl, CheckBox*, pCheckBox) return 0; } +IMPL_LINK_NOARG(ChartSeriesPanel, RadioBtnHdl) +{ + css::uno::Reference<css::frame::XController> xController(mxModel->getCurrentController()); + css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY); + if (!xSelectionSupplier.is()) + return 0; + + uno::Any aAny = xSelectionSupplier->getSelection(); + assert(aAny.hasValue()); + OUString aCID; + aAny >>= aCID; +#ifdef DBG_UTIL + ObjectType eType = ObjectIdentifier::getObjectType(aCID); + assert(eType == OBJECTTYPE_DATA_SERIES); +#endif + + bool bChecked = mpRBPrimaryAxis->IsChecked(); + + setAttachedAxisType(mxModel, aCID, bChecked); + + return 0; +} + }} // end of namespace ::chart::sidebar /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.hxx b/chart2/source/controller/sidebar/ChartSeriesPanel.hxx index 7594e28..a0c773b 100644 --- a/chart2/source/controller/sidebar/ChartSeriesPanel.hxx +++ b/chart2/source/controller/sidebar/ChartSeriesPanel.hxx @@ -80,6 +80,9 @@ private: VclPtr<CheckBox> mpCBXError; VclPtr<CheckBox> mpCBYError; + VclPtr<RadioButton> mpRBPrimaryAxis; + VclPtr<RadioButton> mpRBSecondaryAxis; + css::uno::Reference<css::frame::XFrame> mxFrame; ::sfx2::sidebar::EnumContext maContext; SfxBindings* mpBindings; @@ -90,6 +93,7 @@ private: void Initialize(); DECL_LINK(CheckBoxHdl, CheckBox*); + DECL_LINK(RadioBtnHdl, void*); }; } } // end of namespace ::chart::sidebar diff --git a/chart2/uiconfig/ui/sidebarseries.ui b/chart2/uiconfig/ui/sidebarseries.ui index afcc7a9..88180b5 100644 --- a/chart2/uiconfig/ui/sidebarseries.ui +++ b/chart2/uiconfig/ui/sidebarseries.ui @@ -2,7 +2,7 @@ <!-- Generated with glade 3.18.3 --> <interface> <requires lib="gtk+" version="3.12"/> - <object class="GtkGrid" id="DataSeriesPanel"> + <object class="GtkGrid" id="ChartSeriesPanel"> <property name="visible">True</property> <property name="can_focus">False</property> <child> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits