From 381c9c6e5d179cf1d4dde9088fa5124fe2c36a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=BCnde=20T=C3=B3th?= Date: Tue, 25 Feb 2020 13:56:52 +0100 Subject: [PATCH] tdf#130777 UI: add Hide legend entry option for pie chart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up of the following commits related to the new UNO property DeletedLegendEntries for pie charts: commit a96ec04a07c35338f5f9a0cb361b9322e5ca9cec (tdf#130225 implement ODF export of deleted legend entries of pie charts) commit 86be3422cd55fa9e44104f1628648061bb6a3495 (tdf#129857 Chart OOXML export: fix deleted legend entries) commit 6e847aa817999ab18acd534f9e6a86685bb268fc (tdf#129859 XLSX import: don't show deleted legend entries) Change-Id: I8b13823da745dfbfbf20f1d30f742c4baf803fc3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89456 Tested-by: László Németh Reviewed-by: László Németh --- chart2/Library_chartcontroller.mk | 1 + chart2/UIConfig_chart2.mk | 1 + .../dialogs/dlg_ObjectProperties.cxx | 5 ++ .../controller/dialogs/tp_DataPointOption.cxx | 68 +++++++++++++++++ .../controller/dialogs/tp_DataPointOption.hxx | 51 +++++++++++++ .../controller/inc/DataPointItemConverter.hxx | 6 +- .../controller/inc/dlg_ObjectProperties.hxx | 2 + .../itemsetwrapper/DataPointItemConverter.cxx | 52 ++++++++++++- .../itemsetwrapper/SchWhichPairs.hxx | 3 +- .../main/ChartController_Properties.cxx | 2 +- .../controller/sidebar/ChartSeriesPanel.cxx | 2 +- .../source/inc/chartview/ChartSfxItemIds.hxx | 3 +- chart2/source/view/main/ChartItemPool.cxx | 1 + chart2/uiconfig/ui/tp_DataPointOption.ui | 76 +++++++++++++++++++ 14 files changed, 266 insertions(+), 7 deletions(-) create mode 100644 chart2/source/controller/dialogs/tp_DataPointOption.cxx create mode 100644 chart2/source/controller/dialogs/tp_DataPointOption.hxx create mode 100644 chart2/uiconfig/ui/tp_DataPointOption.ui diff --git a/chart2/Library_chartcontroller.mk b/chart2/Library_chartcontroller.mk index 8dd1642c0e79..48115dd2a33b 100644 --- a/chart2/Library_chartcontroller.mk +++ b/chart2/Library_chartcontroller.mk @@ -127,6 +127,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcontroller,\ chart2/source/controller/dialogs/tp_AxisPositions \ chart2/source/controller/dialogs/tp_ChartType \ chart2/source/controller/dialogs/tp_DataLabel \ + chart2/source/controller/dialogs/tp_DataPointOption \ chart2/source/controller/dialogs/tp_DataSource \ chart2/source/controller/dialogs/tp_ErrorBars \ chart2/source/controller/dialogs/tp_LegendPosition \ diff --git a/chart2/UIConfig_chart2.mk b/chart2/UIConfig_chart2.mk index fd381de77acb..67d64b18b597 100644 --- a/chart2/UIConfig_chart2.mk +++ b/chart2/UIConfig_chart2.mk @@ -66,6 +66,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/schart,\ chart2/uiconfig/ui/tp_AxisPositions \ chart2/uiconfig/ui/tp_ChartType \ chart2/uiconfig/ui/tp_DataLabel \ + chart2/uiconfig/ui/tp_DataPointOption \ chart2/uiconfig/ui/tp_DataSource \ chart2/uiconfig/ui/tp_ErrorBars \ chart2/uiconfig/ui/tp_LegendPosition \ diff --git a/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx b/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx index 6c45249b284e..f0ad64bb2526 100644 --- a/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx +++ b/chart2/source/controller/dialogs/dlg_ObjectProperties.cxx @@ -30,6 +30,7 @@ #include "tp_SeriesToAxis.hxx" #include "tp_TitleRotation.hxx" #include "tp_PolarOptions.hxx" +#include "tp_DataPointOption.hxx" #include #include #include @@ -91,6 +92,7 @@ ObjectPropertiesDialogParameter::ObjectPropertiesDialogParameter( const OUString , m_bHasNumberProperties(false) , m_bProvidesStartingAngle(false) , m_bProvidesMissingValueTreatments(false) + , m_bIsPieChartDataPoint(false) , m_bHasScaleProperties(false) , m_bCanAxisLabelsBeStaggered(false) , m_bSupportingAxisPositioning(false) @@ -123,6 +125,7 @@ void ObjectPropertiesDialogParameter::init( const uno::Reference< frame::XModel m_bHasGeometryProperties = ChartTypeHelper::isSupportingGeometryProperties( xChartType, nDimensionCount ); m_bHasAreaProperties = ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount ); m_bHasSymbolProperties = ChartTypeHelper::isSupportingSymbolProperties( xChartType, nDimensionCount ); + m_bIsPieChartDataPoint = bHasDataPointproperties && ChartTypeHelper::isSupportingStartingAngle( xChartType ); if( bHasSeriesProperties ) { @@ -364,6 +367,8 @@ SchAttribTabDlg::SchAttribTabDlg(weld::Window* pParent, AddTabPage("options", SchResId(STR_PAGE_OPTIONS),SchOptionTabPage::Create); if( m_pParameter->ProvidesStartingAngle()) AddTabPage("polaroptions", SchResId(STR_PAGE_OPTIONS), PolarOptionsTabPage::Create); + if (m_pParameter->IsPieChartDataPoint()) + AddTabPage("datapointoption", SchResId(STR_PAGE_OPTIONS), DataPointOptionTabPage::Create); if( m_pParameter->HasGeometryProperties() ) AddTabPage("layout", SchResId(STR_PAGE_LAYOUT), SchLayoutTabPage::Create); diff --git a/chart2/source/controller/dialogs/tp_DataPointOption.cxx b/chart2/source/controller/dialogs/tp_DataPointOption.cxx new file mode 100644 index 000000000000..7fb9f230ed7e --- /dev/null +++ b/chart2/source/controller/dialogs/tp_DataPointOption.cxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "tp_DataPointOption.hxx" + +#include +#include + +namespace chart +{ +DataPointOptionTabPage::DataPointOptionTabPage(weld::Container* pPage, + weld::DialogController* pController, + const SfxItemSet& rInAttrs) + : SfxTabPage(pPage, pController, "modules/schart/ui/tp_DataPointOption.ui", + "tp_DataPointOption", &rInAttrs) + , m_xCBHideLegendEntry(m_xBuilder->weld_check_button("CB_LEGEND_ENTRY_HIDDEN")) +{ +} + +DataPointOptionTabPage::~DataPointOptionTabPage() {} + +std::unique_ptr DataPointOptionTabPage::Create(weld::Container* pPage, + weld::DialogController* pController, + const SfxItemSet* rOutAttrs) +{ + return std::make_unique(pPage, pController, *rOutAttrs); +} + +bool DataPointOptionTabPage::FillItemSet(SfxItemSet* rOutAttrs) +{ + if (m_xCBHideLegendEntry->get_visible()) + rOutAttrs->Put( + SfxBoolItem(SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY, m_xCBHideLegendEntry->get_active())); + + return true; +} + +void DataPointOptionTabPage::Reset(const SfxItemSet* rInAttrs) +{ + const SfxPoolItem* pPoolItem = nullptr; + + if (rInAttrs->GetItemState(SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY, true, &pPoolItem) + == SfxItemState::SET) + { + bool bVal = static_cast(pPoolItem)->GetValue(); + m_xCBHideLegendEntry->set_active(bVal); + } +} + +} //namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/controller/dialogs/tp_DataPointOption.hxx b/chart2/source/controller/dialogs/tp_DataPointOption.hxx new file mode 100644 index 000000000000..5473d93c8996 --- /dev/null +++ b/chart2/source/controller/dialogs/tp_DataPointOption.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_DIALOGS_TP_DATAPOINTOPTION_HXX +#define INCLUDED_CHART2_SOURCE_CONTROLLER_DIALOGS_TP_DATAPOINTOPTION_HXX + +#include + +namespace weld +{ +class CheckButton; +} + +namespace chart +{ +class DataPointOptionTabPage : public SfxTabPage +{ +public: + DataPointOptionTabPage(weld::Container* pPage, weld::DialogController* pController, + const SfxItemSet& rInAttrs); + virtual ~DataPointOptionTabPage() override; + + static std::unique_ptr + Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rInAttrs); + virtual bool FillItemSet(SfxItemSet* rOutAttrs) override; + virtual void Reset(const SfxItemSet* rInAttrs) override; + +private: + std::unique_ptr m_xCBHideLegendEntry; +}; + +} //namespace chart + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/controller/inc/DataPointItemConverter.hxx b/chart2/source/controller/inc/DataPointItemConverter.hxx index 58b8cc303418..61a70d9e4020 100644 --- a/chart2/source/controller/inc/DataPointItemConverter.hxx +++ b/chart2/source/controller/inc/DataPointItemConverter.hxx @@ -54,7 +54,8 @@ public: sal_Int32 nSpecialFillColor = 0, bool bOverwriteLabelsForAttributedDataPointsAlso = false, sal_Int32 nNumberFormat = 0, - sal_Int32 nPercentNumberFormat = 0 ); + sal_Int32 nPercentNumberFormat = 0, + sal_Int32 nPointIndex = -1 ); virtual ~DataPointItemConverter() override; @@ -78,6 +79,9 @@ private: sal_Int32 m_nPercentNumberFormat; css::uno::Sequence m_aAvailableLabelPlacements; bool m_bForbidPercentValue; + bool m_bHideLegendEntry; + sal_Int32 m_nPointIndex; + css::uno::Reference m_xSeries; }; }} diff --git a/chart2/source/controller/inc/dlg_ObjectProperties.hxx b/chart2/source/controller/inc/dlg_ObjectProperties.hxx index 4df60ef2b74b..e4ab483b0ce5 100644 --- a/chart2/source/controller/inc/dlg_ObjectProperties.hxx +++ b/chart2/source/controller/inc/dlg_ObjectProperties.hxx @@ -48,6 +48,7 @@ public: bool HasNumberProperties() const { return m_bHasNumberProperties;} bool ProvidesStartingAngle() const { return m_bProvidesStartingAngle;} bool ProvidesMissingValueTreatments() const { return m_bProvidesMissingValueTreatments;} + bool IsPieChartDataPoint() const { return m_bIsPieChartDataPoint;} bool HasScaleProperties() const { return m_bHasScaleProperties;} bool CanAxisLabelsBeStaggered() const { return m_bCanAxisLabelsBeStaggered;} @@ -80,6 +81,7 @@ private: bool m_bHasNumberProperties; bool m_bProvidesStartingAngle; bool m_bProvidesMissingValueTreatments; + bool m_bIsPieChartDataPoint; bool m_bHasScaleProperties; bool m_bCanAxisLabelsBeStaggered; diff --git a/chart2/source/controller/itemsetwrapper/DataPointItemConverter.cxx b/chart2/source/controller/itemsetwrapper/DataPointItemConverter.cxx index 07defe8ebbeb..aae5266a59b7 100644 --- a/chart2/source/controller/itemsetwrapper/DataPointItemConverter.cxx +++ b/chart2/source/controller/itemsetwrapper/DataPointItemConverter.cxx @@ -47,6 +47,7 @@ #include #include #include +#include #include @@ -207,7 +208,8 @@ DataPointItemConverter::DataPointItemConverter( sal_Int32 nSpecialFillColor, bool bOverwriteLabelsForAttributedDataPointsAlso, sal_Int32 nNumberFormat, - sal_Int32 nPercentNumberFormat ) : + sal_Int32 nPercentNumberFormat, + sal_Int32 nPointIndex ) : ItemConverter( rPropertySet, rItemPool ), m_bDataSeries( bDataSeries ), m_bOverwriteLabelsForAttributedDataPointsAlso(m_bDataSeries && bOverwriteLabelsForAttributedDataPointsAlso), @@ -216,7 +218,10 @@ DataPointItemConverter::DataPointItemConverter( m_nNumberFormat(nNumberFormat), m_nPercentNumberFormat(nPercentNumberFormat), m_aAvailableLabelPlacements(), - m_bForbidPercentValue(true) + m_bForbidPercentValue(true), + m_bHideLegendEntry(false), + m_nPointIndex(nPointIndex), + m_xSeries(xSeries) { m_aConverters.emplace_back( new GraphicPropertyItemConverter( rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory, eMapTo )); @@ -235,6 +240,21 @@ DataPointItemConverter::DataPointItemConverter( m_aAvailableLabelPlacements = ChartTypeHelper::getSupportedLabelPlacements( xChartType, bSwapXAndY, xSeries ); m_bForbidPercentValue = ChartTypeHelper::getAxisType( xChartType, 0 ) != AxisType::CATEGORY; + + if (!bDataSeries) + { + uno::Reference xSeriesProp(xSeries, uno::UNO_QUERY); + uno::Sequence deletedLegendEntriesSeq; + xSeriesProp->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq; + for (auto& deletedLegendEntry : deletedLegendEntriesSeq) + { + if (nPointIndex == deletedLegendEntry) + { + m_bHideLegendEntry = true; + break; + } + } + } } DataPointItemConverter::~DataPointItemConverter() @@ -539,6 +559,27 @@ bool DataPointItemConverter::ApplySpecialItem( } } break; + + case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY: + { + bool bHideLegendEntry = static_cast(rItemSet.Get(nWhichId)).GetValue(); + if (bHideLegendEntry != m_bHideLegendEntry) + { + uno::Sequence deletedLegendEntriesSeq; + Reference xSeriesProp(m_xSeries, uno::UNO_QUERY); + xSeriesProp->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq; + std::vector deletedLegendEntries; + for (auto& deletedLegendEntry : deletedLegendEntriesSeq) + { + if (bHideLegendEntry || m_nPointIndex != deletedLegendEntry) + deletedLegendEntries.push_back(deletedLegendEntry); + } + if (bHideLegendEntry) + deletedLegendEntries.push_back(m_nPointIndex); + xSeriesProp->setPropertyValue("DeletedLegendEntries", uno::makeAny(oox::ContainerHelper::vectorToSequence(deletedLegendEntries))); + } + } + break; } return bChanged; @@ -707,6 +748,13 @@ void DataPointItemConverter::FillSpecialItem( } } break; + + case SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY: + { + rOutItemSet.Put(SfxBoolItem(nWhichId, m_bHideLegendEntry)); + break; + } + break; } } diff --git a/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx b/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx index e7c0fca9b855..49ad338711b6 100644 --- a/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx +++ b/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx @@ -98,7 +98,8 @@ const sal_uInt16 nDataLabelWhichPairs[] = SCHATTR_STYLE_START,SCHATTR_STYLE_END, /* 59 - 68 sch/schattr.hxx*/ \ SCHATTR_SYMBOL_BRUSH,SCHATTR_SYMBOL_BRUSH, /* 94 sch/schattr.hxx*/ \ SCHATTR_SYMBOL_SIZE,SCHATTR_SYMBOL_SIZE, /* 97 sch/schattr.hxx*/ \ - SDRATTR_3D_FIRST, SDRATTR_3D_LAST /* 1244 - 1334 svx/svddef.hxx */ + SDRATTR_3D_FIRST, SDRATTR_3D_LAST, /* 1244 - 1334 svx/svddef.hxx */ \ + SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY, SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY const sal_uInt16 nDataPointWhichPairs[] = { diff --git a/chart2/source/controller/main/ChartController_Properties.cxx b/chart2/source/controller/main/ChartController_Properties.cxx index 2adad587dec6..6ee1eb39c7c1 100644 --- a/chart2/source/controller/main/ChartController_Properties.cxx +++ b/chart2/source/controller/main/ChartController_Properties.cxx @@ -246,7 +246,7 @@ wrapper::ItemConverter* createItemConverter( xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ), eMapTo, pRefSize.get(), bDataSeries, bUseSpecialFillColor, nSpecialFillColor, true, - nNumberFormat, nPercentNumberFormat ); + nNumberFormat, nPercentNumberFormat, nPointIndex ); break; } case OBJECTTYPE_GRID: diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx index 7d040f2509a7..365f42adafcb 100644 --- a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx +++ b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx @@ -264,7 +264,7 @@ OUString getCID(const css::uno::Reference& xModel) #if defined DBG_UTIL && !defined NDEBUG ObjectType eType = ObjectIdentifier::getObjectType(aCID); - assert(eType == OBJECTTYPE_DATA_SERIES); + assert(eType == OBJECTTYPE_DATA_SERIES || eType == OBJECTTYPE_DATA_POINT); #endif return aCID; diff --git a/chart2/source/inc/chartview/ChartSfxItemIds.hxx b/chart2/source/inc/chartview/ChartSfxItemIds.hxx index b28bf1e548c7..8b1e4064639c 100644 --- a/chart2/source/inc/chartview/ChartSfxItemIds.hxx +++ b/chart2/source/inc/chartview/ChartSfxItemIds.hxx @@ -141,9 +141,10 @@ class SvxBrushItem; #define SCHATTR_STOCK_VOLUME TypedWhichId(SCHATTR_AXIS_END + 2) #define SCHATTR_STOCK_UPDOWN TypedWhichId(SCHATTR_AXIS_END + 3) #define SCHATTR_SYMBOL_SIZE TypedWhichId(SCHATTR_AXIS_END + 4) +#define SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY TypedWhichId(SCHATTR_AXIS_END + 5) // non persistent items (binary format) -#define SCHATTR_CHARTTYPE_START (SCHATTR_SYMBOL_SIZE + 1) +#define SCHATTR_CHARTTYPE_START (SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY + 1) // new from New Chart #define SCHATTR_BAR_OVERLAP TypedWhichId(SCHATTR_CHARTTYPE_START ) diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx index d0a7b5ce87d7..9b1f66df5bb1 100644 --- a/chart2/source/view/main/ChartItemPool.cxx +++ b/chart2/source/view/main/ChartItemPool.cxx @@ -128,6 +128,7 @@ ChartItemPool::ChartItemPool(): rPoolDefaults[SCHATTR_STOCK_VOLUME - SCHATTR_START] = new SfxBoolItem(SCHATTR_STOCK_VOLUME,false); rPoolDefaults[SCHATTR_STOCK_UPDOWN - SCHATTR_START] = new SfxBoolItem(SCHATTR_STOCK_UPDOWN,false); rPoolDefaults[SCHATTR_SYMBOL_SIZE - SCHATTR_START] = new SvxSizeItem(SCHATTR_SYMBOL_SIZE,Size(0,0)); + rPoolDefaults[SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY - SCHATTR_START] = new SfxBoolItem(SCHATTR_HIDE_DATA_POINT_LEGEND_ENTRY, false); // new for New Chart rPoolDefaults[SCHATTR_BAR_OVERLAP - SCHATTR_START] = new SfxInt32Item(SCHATTR_BAR_OVERLAP,0); diff --git a/chart2/uiconfig/ui/tp_DataPointOption.ui b/chart2/uiconfig/ui/tp_DataPointOption.ui new file mode 100644 index 000000000000..01e93dac9775 --- /dev/null +++ b/chart2/uiconfig/ui/tp_DataPointOption.ui @@ -0,0 +1,76 @@ + + + + + + 600 + 1 + 10 + + + -100 + 100 + 1 + 10 + + + True + False + 6 + vertical + 6 + + + True + False + 0 + none + + + True + False + 6 + 12 + + + True + False + vertical + + + Hide legend entry + True + True + False + start + True + + + False + True + 0 + + + + + + + + + True + False + Legend Entry + + + + + + + + False + True + 3 + + + +