diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2015-07-17 01:41:10 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2015-07-17 01:42:42 +0200 |
commit | 07ff2841ccf6d4f93941838305248f7048fec803 (patch) | |
tree | 4bf5db10b939a45f150918d8537c153b1b95aa5c | |
parent | d84f954cc0ad22cf62e279da2e473f79d1fb889b (diff) |
add data label handling to series panel
Change-Id: I37415b5effb6ac320184008b9b25988804387715
-rw-r--r-- | chart2/source/controller/sidebar/ChartSeriesPanel.cxx | 97 | ||||
-rw-r--r-- | chart2/source/controller/sidebar/ChartSeriesPanel.hxx | 3 |
2 files changed, 99 insertions, 1 deletions
diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx index 389ec28414fa..b8b1b5a9ac04 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 a0c773b72e55..32cce9551c57 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 |