chart2/source/controller/drawinglayer/DrawViewWrapper.cxx | 7 chart2/source/controller/inc/ChartController.hxx | 2 chart2/source/controller/main/ChartController_Window.cxx | 71 ++++++++ chart2/source/inc/PopupRequest.hxx | 7 chart2/source/view/main/ChartView.cxx | 38 +--- chart2/source/view/main/VLegend.cxx | 14 - offapi/UnoApi_offapi.mk | 1 offapi/com/sun/star/chart2/data/PivotTableFieldEntry.idl | 43 +++++ offapi/com/sun/star/chart2/data/XPivotChartDataProvider.idl | 16 +- sc/inc/PivotChartDataProvider.hxx | 24 ++- sc/source/ui/inc/tabview.hxx | 2 sc/source/ui/unoobj/PivotChartDataProvider.cxx | 96 ++++++------ sc/source/ui/view/tabview3.cxx | 18 -- sc/source/ui/view/tabvwshb.cxx | 29 +++ 14 files changed, 259 insertions(+), 109 deletions(-)
New commits: commit 0c9ff2b3dd8c3de2514b72eaf67bb9423cdf43f2 Author: Tomaž Vajngerl <[email protected]> Date: Fri Mar 10 19:18:14 2017 +0100 pivotcharts: show filter pop-up from charts on field button click This adds the functionallity to show a filter pop-up (from calc) when clicking on row / column / page field buttons. Additionally to implement this it was needed to add a new struct PivotTableFieldEntry, which transports the data for field buttons from the data provider to chart. This was necessary as in addition to the field name, it is needed to transport the dimension index. Other changes are: - some additional data provider fixes and clean-ups - mouse click on field button (mouse button down / up) - ignore other actions when detected a click is on a field button - parameters for the PopupRequest callback - parse parameters and execute the pop-up a the desired position Change-Id: Id40ffccbce7aaaddb045eb1894d55bfe0427ee6d diff --git a/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx b/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx index 50808b5..b66f63a 100644 --- a/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx +++ b/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx @@ -181,8 +181,13 @@ SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const if( pRet ) { - //ignore some special shapes + // ignore some special shapes OUString aShapeName = pRet->GetName(); + + // return right away if it is a field button + if (aShapeName.startsWith("FieldButton")) + return pRet; + if( aShapeName.match("PlotAreaIncludingAxes") || aShapeName.match("PlotAreaExcludingAxes") ) { pRet->SetMarkProtect( true ); diff --git a/chart2/source/controller/inc/ChartController.hxx b/chart2/source/controller/inc/ChartController.hxx index 40b31bc..53defbe 100644 --- a/chart2/source/controller/inc/ChartController.hxx +++ b/chart2/source/controller/inc/ChartController.hxx @@ -496,6 +496,8 @@ private: void executeDispatch_ToggleGridHorizontal(); void executeDispatch_ToggleGridVertical(); + void sendPopupRequest(OUString const & rCID, Rectangle aRectangle); + void impl_ShapeControllerDispatch( const css::util::URL& rURL, const css::uno::Sequence< css::beans::PropertyValue >& rArgs ); diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx index f32e0c2..e9917e9 100644 --- a/chart2/source/controller/main/ChartController_Window.cxx +++ b/chart2/source/controller/main/ChartController_Window.cxx @@ -45,18 +45,23 @@ #include "LegendHelper.hxx" #include "servicenames_charttypes.hxx" #include "DrawCommandDispatch.hxx" +#include "PopupRequest.hxx" #include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/chart2/RelativeSize.hpp> #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> +#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> #include <com/sun/star/awt/PopupMenuDirection.hpp> #include <com/sun/star/frame/DispatchHelper.hpp> #include <com/sun/star/frame/FrameSearchFlag.hpp> #include <com/sun/star/frame/XPopupMenuController.hpp> #include <com/sun/star/util/XUpdatable.hpp> +#include <com/sun/star/awt/Rectangle.hpp> + #include <comphelper/propertysequence.hxx> #include <comphelper/propertyvalue.hxx> +#include <comphelper/sequence.hxx> #include <toolkit/awt/vclxmenu.hxx> @@ -551,7 +556,16 @@ void ChartController::execute_MouseButtonDown( const MouseEvent& rMEvt ) if(!m_pChartWindow || !pDrawViewWrapper ) return; - Point aMPos = m_pChartWindow->PixelToLogic(rMEvt.GetPosPixel()); + Point aMPos = m_pChartWindow->PixelToLogic(rMEvt.GetPosPixel()); + + // Check if button was clicked + SdrObject* pObject = pDrawViewWrapper->getHitObject(aMPos); + if (pObject) + { + OUString aCID = pObject->GetName(); + if (aCID.startsWith("FieldButton")) + return; // Don't take any action if button was clicked + } if ( MOUSE_LEFT == rMEvt.GetButtons() ) { @@ -715,7 +729,19 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) if(!m_pChartWindow || !pDrawViewWrapper) return; - Point aMPos = m_pChartWindow->PixelToLogic(rMEvt.GetPosPixel()); + Point aMPos = m_pChartWindow->PixelToLogic(rMEvt.GetPosPixel()); + + // Check if button was clicked + SdrObject* pObject = pDrawViewWrapper->getHitObject(aMPos); + if (pObject) + { + OUString aCID = pObject->GetName(); + if (aCID.startsWith("FieldButton")) + { + sendPopupRequest(aCID, pObject->GetCurrentBoundRect()); + return; + } + } if(pDrawViewWrapper->IsTextEdit()) { @@ -1952,6 +1978,47 @@ css::uno::Reference<css::uno::XInterface> const & ChartController::getChartView( return m_xChartView; } +void ChartController::sendPopupRequest(OUString const & rCID, Rectangle aRectangle) +{ + ChartModel* pChartModel = dynamic_cast<ChartModel*>(m_aModel->getModel().get()); + if (!pChartModel) + return; + + uno::Reference<chart2::data::XPivotChartDataProvider> xPivotChartDataProvider; + xPivotChartDataProvider.set(pChartModel->getDataProvider(), uno::UNO_QUERY); + if (!xPivotChartDataProvider.is()) + return; + + OUString sPivotTableName = xPivotChartDataProvider->getPivotTableName(); + + PopupRequest* pPopupRequest = dynamic_cast<PopupRequest*>(pChartModel->getPopupRequest().get()); + if (!pPopupRequest) + return; + + // Get dimension index from CID + sal_Int32 nStartPos = rCID.lastIndexOf('.'); + nStartPos++; + sal_Int32 nEndPos = rCID.getLength(); + OUString sDimensionIndex = rCID.copy(nStartPos, nEndPos - nStartPos); + sal_Int32 nDimensionIndex = sDimensionIndex.toInt32(); + + awt::Rectangle xRectangle { + sal_Int32(aRectangle.Left()), + sal_Int32(aRectangle.Top()), + sal_Int32(aRectangle.GetWidth()), + sal_Int32(aRectangle.GetHeight()) + }; + + uno::Sequence<beans::PropertyValue> aCallbackData = comphelper::InitPropertySequence( + { + {"Rectangle", uno::makeAny<awt::Rectangle>(xRectangle)}, + {"DimensionIndex", uno::makeAny<sal_Int32>(nDimensionIndex)}, + {"PivotTableName", uno::makeAny<OUString>(sPivotTableName)}, + }); + + pPopupRequest->getCallback()->notify(uno::makeAny(aCallbackData)); +} + } //namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/inc/PopupRequest.hxx b/chart2/source/inc/PopupRequest.hxx index e564003..61630f5 100644 --- a/chart2/source/inc/PopupRequest.hxx +++ b/chart2/source/inc/PopupRequest.hxx @@ -25,12 +25,17 @@ typedef cppu::WeakComponentImplHelper<css::chart2::data::XPopupRequest> PopupReq } -class PopupRequest : public MutexContainer, public impl::PopupRequest_Base +class OOO_DLLPUBLIC_CHARTTOOLS PopupRequest : public MutexContainer, public impl::PopupRequest_Base { public: explicit PopupRequest(); virtual ~PopupRequest() override; + css::uno::Reference<css::awt::XCallback> getCallback() + { + return m_xCallback; + } + protected: // ____ XRequestCallback ____ virtual void SAL_CALL addCallback(const css::uno::Reference< ::css::awt::XCallback >& xCallback, diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 9d1fe9c..1503714 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -90,6 +90,8 @@ #include <com/sun/star/chart2/XTitled.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/chart2/RelativeSize.hpp> +#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> +#include <com/sun/star/chart2/data/PivotTableFieldEntry.hpp> #include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/GraphicExportFilter.hpp> #include <com/sun/star/drawing/LineStyle.hpp> @@ -113,7 +115,6 @@ #include <comphelper/classids.hxx> #include "servicenames_charttypes.hxx" -#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> #include <rtl/strbuf.hxx> #include <rtl/ustring.hxx> @@ -2493,70 +2494,59 @@ void lcl_createButtons(const uno::Reference< drawing::XShapes>& xPageShapes, { uno::Reference<chart2::data::XPivotChartDataProvider> xPivotChartDataProvider(rModel.getDataProvider(), uno::UNO_QUERY); - uno::Sequence<OUString> aRowFields = xPivotChartDataProvider->getRowFields(); - uno::Sequence<OUString> aPageFields = xPivotChartDataProvider->getPageFields(); - uno::Sequence<OUString> aDataFields = xPivotChartDataProvider->getDataFields(); - uno::Reference<beans::XPropertySet> xModelPage(rModel.getPageBackground()); awt::Size aSize(3000, 700); // size of the button long x = 0; - int nCIDIndex = 0; - if (aPageFields.hasElements()) + if (xPivotChartDataProvider->getPageFields().hasElements()) { x = 0; - nCIDIndex = 0; - for (OUString const & rPageField : aPageFields) + for (css::chart2::data::PivotTableFieldEntry const & rPageFieldEntry : xPivotChartDataProvider->getPageFields()) { std::unique_ptr<VButton> pButton(new VButton); pButton->init(xPageShapes, xShapeFactory); awt::Point aNewPosition = awt::Point(rRemainingSpace.X + x + 100, rRemainingSpace.Y + 100); - pButton->setLabel(rPageField); - pButton->setCID("FieldButton.Page." + OUString::number(nCIDIndex)); + pButton->setLabel(rPageFieldEntry.Name); + pButton->setCID("FieldButton.Page." + OUString::number(rPageFieldEntry.DimensionIndex)); pButton->createShapes(aNewPosition, aSize, xModelPage); x += aSize.Width + 100; - nCIDIndex += 1; } rRemainingSpace.Y += (aSize.Height + 100 + 100); rRemainingSpace.Height -= (aSize.Height + 100 + 100); } - if (aDataFields.hasElements()) + if (xPivotChartDataProvider->getDataFields().hasElements()) { x = 200; - nCIDIndex = 0; - for (OUString const & rDataField : aDataFields) + for (css::chart2::data::PivotTableFieldEntry const & rDataFieldEntry : xPivotChartDataProvider->getDataFields()) { std::unique_ptr<VButton> pButton(new VButton); pButton->init(xPageShapes, xShapeFactory); awt::Point aNewPosition = awt::Point(rRemainingSpace.X + x + 100, rRemainingSpace.Y + 100); - pButton->setLabel(rDataField); - pButton->setCID("FieldButton.Data." + OUString::number(nCIDIndex)); + pButton->setLabel(rDataFieldEntry.Name); + pButton->setCID("FieldButton.Data." + OUString::number(rDataFieldEntry.DimensionIndex)); pButton->createShapes(aNewPosition, aSize, xModelPage); x += aSize.Width + 100; - nCIDIndex += 1; } rRemainingSpace.Y += (aSize.Height + 100 + 100); rRemainingSpace.Height -= (aSize.Height + 100 + 100); } - if (aRowFields.hasElements()) + if (xPivotChartDataProvider->getRowFields().hasElements()) { x = 200; - nCIDIndex = 0; - for (OUString const & rRowField : aRowFields) + for (css::chart2::data::PivotTableFieldEntry const & rRowFieldEntry : xPivotChartDataProvider->getRowFields()) { std::unique_ptr<VButton> pButton(new VButton); pButton->init(xPageShapes, xShapeFactory); awt::Point aNewPosition = awt::Point(rRemainingSpace.X + x + 100, rRemainingSpace.Y + rRemainingSpace.Height - aSize.Height - 100); - pButton->setLabel(rRowField); - pButton->setCID("FieldButton.Column." + OUString::number(nCIDIndex)); + pButton->setLabel(rRowFieldEntry.Name); + pButton->setCID("FieldButton.Row." + OUString::number(rRowFieldEntry.DimensionIndex)); pButton->createShapes(aNewPosition, aSize, xModelPage); x += aSize.Width + 100; - nCIDIndex += 1; } rRemainingSpace.Height -= (aSize.Height + 100 + 100); } diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index 3688411..ceffae7 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -37,10 +37,11 @@ #include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> +#include <com/sun/star/chart2/data/PivotTableFieldEntry.hpp> #include <rtl/ustrbuf.hxx> #include <svl/languageoptions.hxx> -#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> #include <vector> #include <algorithm> @@ -769,28 +770,25 @@ std::vector<std::shared_ptr<VButton>> lcl_createButtons( ChartModel& rModel, long& nUsedHeight) { uno::Reference<chart2::data::XPivotChartDataProvider> xPivotChartDataProvider(rModel.getDataProvider(), uno::UNO_QUERY); - uno::Sequence<OUString> aColumnFields = xPivotChartDataProvider->getColumnFields(); std::vector<std::shared_ptr<VButton>> aButtons; - if (!aColumnFields.hasElements()) + if (!xPivotChartDataProvider->getColumnFields().hasElements()) return aButtons; uno::Reference<beans::XPropertySet> xModelPage(rModel.getPageBackground()); - int nCIDIndex = 0; awt::Size aSize(2000, 700); int y = 100; - for (OUString const & sColumnField : aColumnFields) + for (chart2::data::PivotTableFieldEntry const & sColumnFieldEntry : xPivotChartDataProvider->getColumnFields()) { std::shared_ptr<VButton> pButton(new VButton); aButtons.push_back(pButton); pButton->init(xLegendContainer, xShapeFactory); awt::Point aNewPosition = awt::Point(100, y); - pButton->setLabel(sColumnField); - pButton->setCID("FieldButton.Row." + OUString::number(nCIDIndex)); + pButton->setLabel(sColumnFieldEntry.Name); + pButton->setCID("FieldButton.Column." + OUString::number(sColumnFieldEntry.DimensionIndex)); pButton->createShapes(aNewPosition, aSize, xModelPage); - nCIDIndex += 1; y += aSize.Height + 100;; } nUsedHeight += y + 100; diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 840c191..0146001 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -88,6 +88,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/chart2,\ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/chart2/data,\ DatabaseDataProvider \ LabeledDataSequence \ + PivotTableFieldEntry \ )) $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/configuration,\ ReadOnlyAccess \ diff --git a/offapi/com/sun/star/chart2/data/PivotTableFieldEntry.idl b/offapi/com/sun/star/chart2/data/PivotTableFieldEntry.idl new file mode 100644 index 0000000..168e809 --- /dev/null +++ b/offapi/com/sun/star/chart2/data/PivotTableFieldEntry.idl @@ -0,0 +1,43 @@ +/* -*- 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/. + * + */ +#ifndef com_sun_star_chart2_data_PivotTableFieldEntry_idl +#define com_sun_star_chart2_data_PivotTableFieldEntry_idl + +module com +{ +module sun +{ +module star +{ +module chart2 +{ +module data +{ + +/** + * + * @since LibreOffice 5.3 + */ +struct PivotTableFieldEntry +{ + string Name; + + long DimensionIndex; +}; + +}; // data +}; // chart2 +}; // com +}; // sun +}; // star + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/offapi/com/sun/star/chart2/data/XPivotChartDataProvider.idl b/offapi/com/sun/star/chart2/data/XPivotChartDataProvider.idl index 95b58d4..284d7ac 100644 --- a/offapi/com/sun/star/chart2/data/XPivotChartDataProvider.idl +++ b/offapi/com/sun/star/chart2/data/XPivotChartDataProvider.idl @@ -11,7 +11,7 @@ #define com_sun_star_chart2_data_XPivotChartDataProvider_idl #include <com/sun/star/uno/XInterface.idl> -#include <com/sun/star/chart2/data/XDataSequence.idl> +#include <com/sun/star/chart2/data/PivotTableFieldEntry.idl> module com { module sun { module star { module chart2 { module data { @@ -26,25 +26,31 @@ interface XPivotChartDataProvider : com::sun::star::uno::XInterface * * @since LibreOffice 5.4 */ - sequence<string> getColumnFields(); + sequence<com::sun::star::chart2::data::PivotTableFieldEntry> getColumnFields(); /** names of row fields from the associated pivot table * * @since LibreOffice 5.4 */ - sequence<string> getRowFields(); + sequence<com::sun::star::chart2::data::PivotTableFieldEntry> getRowFields(); /** names of page fields from the associated pivot table * * @since LibreOffice 5.4 */ - sequence<string> getPageFields(); + sequence<com::sun::star::chart2::data::PivotTableFieldEntry> getPageFields(); /** names of data fields from the associated pivot table * * @since LibreOffice 5.4 */ - sequence<string> getDataFields(); + sequence<com::sun::star::chart2::data::PivotTableFieldEntry> getDataFields(); + + /** associated pivot table name + * + * @since LibreOffice 5.4 + */ + string getPivotTableName(); }; };};};};}; diff --git a/sc/inc/PivotChartDataProvider.hxx b/sc/inc/PivotChartDataProvider.hxx index 097fb18..80e3794 100644 --- a/sc/inc/PivotChartDataProvider.hxx +++ b/sc/inc/PivotChartDataProvider.hxx @@ -20,6 +20,7 @@ #include <com/sun/star/chart2/data/XDataSource.hpp> #include <com/sun/star/chart2/data/XDataSequence.hpp> #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp> +#include <com/sun/star/chart2/data/PivotTableFieldEntry.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/util/XCloneable.hpp> @@ -79,10 +80,17 @@ public: virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override; // XPivotChartDataProvider - virtual css::uno::Sequence<OUString> SAL_CALL getColumnFields() override; - virtual css::uno::Sequence<OUString> SAL_CALL getRowFields() override; - virtual css::uno::Sequence<OUString> SAL_CALL getPageFields() override; - virtual css::uno::Sequence<OUString> SAL_CALL getDataFields() override; + virtual css::uno::Sequence<css::chart2::data::PivotTableFieldEntry> SAL_CALL + getColumnFields() override; + virtual css::uno::Sequence<css::chart2::data::PivotTableFieldEntry> SAL_CALL + getRowFields() override; + virtual css::uno::Sequence<css::chart2::data::PivotTableFieldEntry> SAL_CALL + getPageFields() override; + virtual css::uno::Sequence<css::chart2::data::PivotTableFieldEntry> SAL_CALL + getDataFields() override; + + virtual OUString SAL_CALL getPivotTableName() override; + // XPropertySet virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override; @@ -160,10 +168,10 @@ private: std::vector<std::vector<PivotChartItem>> m_aLabels; std::vector<std::vector<PivotChartItem>> m_aDataRowVector; - std::vector<OUString> m_aColumnFields; - std::vector<OUString> m_aRowFields; - std::vector<OUString> m_aPageFields; - std::vector<OUString> m_aDataFields; + std::vector<css::chart2::data::PivotTableFieldEntry> m_aColumnFields; + std::vector<css::chart2::data::PivotTableFieldEntry> m_aRowFields; + std::vector<css::chart2::data::PivotTableFieldEntry> m_aPageFields; + std::vector<css::chart2::data::PivotTableFieldEntry> m_aDataFields; std::vector<css::uno::Reference<css::util::XModifyListener>> m_aValueListeners; }; diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx index d333034..885e48d 100644 --- a/sc/source/ui/inc/tabview.hxx +++ b/sc/source/ui/inc/tabview.hxx @@ -487,7 +487,7 @@ public: void ClearHighlightRanges(); void DoChartSelection( const css::uno::Sequence< css::chart2::data::HighlightedRange > & rHilightRanges ); - void DoDPFieldPopup(Point aPoint, Size aSize); + void DoDPFieldPopup(OUString const & rPivotTableName, sal_Int32 nDimensionIndex, Point aPoint, Size aSize); long GetGridWidth( ScHSplitPos eWhich ); long GetGridHeight( ScVSplitPos eWhich ); diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx index 8b8e6ad..c6fce89 100644 --- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx +++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx @@ -107,9 +107,11 @@ void PivotChartDataProvider::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHin OUString sPivotTableName = static_cast<const ScDataPilotModifiedHint&>(rHint).GetName(); if (sPivotTableName == m_sPivotTableName) { - for (uno::Reference<util::XModifyListener> & xListener : m_aValueListeners) + for (uno::Reference<util::XModifyListener> const & xListener : m_aValueListeners) { - css::chart::ChartDataChangeEvent aEvent(static_cast<cppu::OWeakObject*>(this), css::chart::ChartDataChangeType_ALL, 0, 0, 0, 0); + css::chart::ChartDataChangeEvent aEvent(static_cast<cppu::OWeakObject*>(this), + css::chart::ChartDataChangeType_ALL, + 0, 0, 0, 0); xListener->modified(aEvent); } } @@ -283,11 +285,11 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) std::vector<OUString> aDataFieldNamesVectors; std::unordered_map<OUString, OUString, OUStringHash> aDataFieldCaptionNames; - std::vector<OUString> aDataFieldNames; + std::vector<std::pair<OUString, sal_Int32>> aDataFieldPairs; sheet::DataPilotFieldOrientation eDataFieldOrientation = sheet::DataPilotFieldOrientation_HIDDEN; - for (long nDim = 0; nDim < xDims->getCount(); nDim++) + for (sal_Int32 nDim = 0; nDim < xDims->getCount(); nDim++) { uno::Reference<uno::XInterface> xDim = ScUnoHelpFunctions::AnyToInterface(xDims->getByIndex(nDim)); uno::Reference<beans::XPropertySet> xDimProp(xDim, uno::UNO_QUERY); @@ -304,44 +306,44 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) if (eDimOrient == sheet::DataPilotFieldOrientation_HIDDEN) continue; - uno::Reference<container::XIndexAccess> xHiers = new ScNameToIndexAccess(xDimSupp->getHierarchies()); - long nHierarchy = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_USEDHIERARCHY); - if (nHierarchy >= xHiers->getCount()) + uno::Reference<container::XIndexAccess> xHierarchies = new ScNameToIndexAccess(xDimSupp->getHierarchies()); + sal_Int32 nHierarchy = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_USEDHIERARCHY); + if (nHierarchy >= xHierarchies->getCount()) nHierarchy = 0; - uno::Reference<uno::XInterface> xHier = ScUnoHelpFunctions::AnyToInterface(xHiers->getByIndex(nHierarchy)); + uno::Reference<uno::XInterface> xHierarchy = ScUnoHelpFunctions::AnyToInterface(xHierarchies->getByIndex(nHierarchy)); - uno::Reference<sheet::XLevelsSupplier> xHierSupp(xHier, uno::UNO_QUERY); + uno::Reference<sheet::XLevelsSupplier> xLevelsSupplier(xHierarchy, uno::UNO_QUERY); - if (!xHierSupp.is()) + if (!xLevelsSupplier.is()) continue; - uno::Reference<container::XIndexAccess> xLevels = new ScNameToIndexAccess(xHierSupp->getLevels()); + uno::Reference<container::XIndexAccess> xLevels = new ScNameToIndexAccess(xLevelsSupplier->getLevels()); for (long nLev = 0; nLev < xLevels->getCount(); nLev++) { uno::Reference<uno::XInterface> xLevel = ScUnoHelpFunctions::AnyToInterface(xLevels->getByIndex(nLev)); - uno::Reference<container::XNamed> xLevName(xLevel, uno::UNO_QUERY); - uno::Reference<sheet::XDataPilotMemberResults> xLevRes(xLevel, uno::UNO_QUERY ); + uno::Reference<container::XNamed> xLevelName(xLevel, uno::UNO_QUERY); + uno::Reference<sheet::XDataPilotMemberResults> xLevelResult(xLevel, uno::UNO_QUERY ); bool bIsDataLayout = ScUnoHelpFunctions::GetBoolProperty(xDimProp, SC_UNO_DP_ISDATALAYOUT); long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION); sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO); - if (xLevName.is() && xLevRes.is()) + if (xLevelName.is() && xLevelResult.is()) { switch (eDimOrient) { case sheet::DataPilotFieldOrientation_COLUMN: { - m_aColumnFields.push_back(xLevName->getName()); + m_aColumnFields.push_back(chart2::data::PivotTableFieldEntry{xLevelName->getName(), nDim}); - uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); + uno::Sequence<sheet::MemberResult> aSequence = xLevelResult->getResults(); size_t i = 0; OUString sCaption; OUString sName; - m_aLabels.resize(aSeq.getLength()); - for (sheet::MemberResult & rMember : aSeq) + m_aLabels.resize(aSequence.getLength()); + for (sheet::MemberResult & rMember : aSequence) { if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || rMember.Flags & sheet::MemberResultFlags::CONTINUE) @@ -372,35 +374,29 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) case sheet::DataPilotFieldOrientation_ROW: { - m_aRowFields.push_back(xLevName->getName()); + m_aRowFields.push_back(chart2::data::PivotTableFieldEntry{xLevelName->getName(), nDim}); - uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); - m_aCategoriesRowOrientation.resize(aSeq.getLength()); + uno::Sequence<sheet::MemberResult> aSequence = xLevelResult->getResults(); + m_aCategoriesRowOrientation.resize(aSequence.getLength()); size_t i = 0; - OUString sName; - for (sheet::MemberResult & rMember : aSeq) + for (sheet::MemberResult & rMember : aSequence) { - if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || - rMember.Flags & sheet::MemberResultFlags::CONTINUE) + bool bHasContinueFlag = rMember.Flags & sheet::MemberResultFlags::CONTINUE; + + if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || bHasContinueFlag) { std::unique_ptr<PivotChartItem> pItem; double fValue = rMember.Value; + if (rtl::math::isNan(fValue)) { - if (rMember.Flags & sheet::MemberResultFlags::CONTINUE) - { - pItem.reset(new PivotChartItem("")); - } - else - { - sName = rMember.Name; - pItem.reset(new PivotChartItem(rMember.Caption)); - } + OUString sStringValue = bHasContinueFlag ? "" : rMember.Caption; + pItem.reset(new PivotChartItem(sStringValue)); } else { - if (rMember.Flags & sheet::MemberResultFlags::CONTINUE) + if (bHasContinueFlag) pItem.reset(new PivotChartItem()); else pItem.reset(new PivotChartItem(fValue, nNumberFormat)); @@ -417,8 +413,9 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) if (bIsDataLayout) { // Remember data fields to determine the number format of data - aDataFieldNamesVectors.push_back(sName); + aDataFieldNamesVectors.push_back(rMember.Name); eDataFieldOrientation = sheet::DataPilotFieldOrientation_ROW; + // Remember the caption name aDataFieldCaptionNames[rMember.Name] = rMember.Caption; } @@ -430,14 +427,14 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) case sheet::DataPilotFieldOrientation_PAGE: { - m_aPageFields.push_back(xLevName->getName()); + m_aPageFields.push_back(chart2::data::PivotTableFieldEntry{xLevelName->getName(), nDim}); } break; case sheet::DataPilotFieldOrientation_DATA: { - aDataFieldNumberFormatMap[xLevName->getName()] = nNumberFormat; - aDataFieldNames.push_back(xLevName->getName()); + aDataFieldNumberFormatMap[xLevelName->getName()] = nNumberFormat; + aDataFieldPairs.push_back(std::pair<OUString, sal_Int32>(xLevelName->getName(), nDim)); } break; @@ -448,9 +445,12 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) } } - for (OUString const & rName : aDataFieldNames) + // Fill data field entry info + for (std::pair<OUString, sal_Int32> & rPair : aDataFieldPairs) { - m_aDataFields.push_back(aDataFieldCaptionNames[rName]); + m_aDataFields.push_back(chart2::data::PivotTableFieldEntry{ + aDataFieldCaptionNames[rPair.first], + rPair.second}); } // Apply number format to the data @@ -575,6 +575,7 @@ sal_Bool SAL_CALL PivotChartDataProvider::createDataSequenceByRangeRepresentatio { SolarMutexGuard aGuard; return false; + } uno::Reference< chart2::data::XDataSequence > SAL_CALL @@ -603,26 +604,31 @@ uno::Reference<sheet::XRangeSelection> SAL_CALL PivotChartDataProvider::getRange return xResult; } -uno::Sequence<OUString> PivotChartDataProvider::getColumnFields() +uno::Sequence<chart2::data::PivotTableFieldEntry> PivotChartDataProvider::getColumnFields() { return comphelper::containerToSequence(m_aColumnFields); } -uno::Sequence<OUString> PivotChartDataProvider::getRowFields() +uno::Sequence<chart2::data::PivotTableFieldEntry> PivotChartDataProvider::getRowFields() { return comphelper::containerToSequence(m_aRowFields); } -uno::Sequence<OUString> PivotChartDataProvider::getPageFields() +uno::Sequence<chart2::data::PivotTableFieldEntry> PivotChartDataProvider::getPageFields() { return comphelper::containerToSequence(m_aPageFields); } -uno::Sequence<OUString> PivotChartDataProvider::getDataFields() +uno::Sequence<chart2::data::PivotTableFieldEntry> PivotChartDataProvider::getDataFields() { return comphelper::containerToSequence(m_aDataFields); } +OUString PivotChartDataProvider::getPivotTableName() +{ + return m_sPivotTableName; +} + // XModifyBroadcaster ======================================================== void SAL_CALL PivotChartDataProvider::addModifyListener( const uno::Reference< util::XModifyListener >& aListener ) diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx index 6904b23..5c433ef 100644 --- a/sc/source/ui/view/tabview3.cxx +++ b/sc/source/ui/view/tabview3.cxx @@ -2468,27 +2468,23 @@ void ScTabView::DoChartSelection( } } -void ScTabView::DoDPFieldPopup(Point aPoint, Size /*aSize*/) +void ScTabView::DoDPFieldPopup(OUString const & rPivotTableName, sal_Int32 nDimensionIndex, Point aPoint, Size aSize) { ScDocument& rDocument = aViewData.GetDocShell()->GetDocument(); ScGridWindow* pWin = pGridWin[aViewData.GetActivePart()].get(); + if (!pWin) return; - ScDPCollection* pDPs = rDocument.GetDPCollection(); - // TODO - DP name should be a parameter - ScDPObject* pDPObj = pDPs->GetByName("DataPilot1"); - - pDPObj->BuildAllDimensionMembers(); + ScDPCollection* pDPCollection = rDocument.GetDPCollection(); + ScDPObject* pDPObject = pDPCollection->GetByName(rPivotTableName); - //const ScDPSaveData* pSaveData = pDPObj->GetSaveData(); - //bool bIsDataLayout; - //OUString aDimName = pDPObj->GetDimName(0, bIsDataLayout); + pDPObject->BuildAllDimensionMembers(); Point aScreenPoint = pWin->OutputToScreenPixel(pWin->LogicToPixel(aPoint)); - //Size aScreenSize = pWin->LogicToPixel(aSize); + Size aScreenSize = pWin->LogicToPixel(aSize); - pWin->DPLaunchFieldPopupMenu(aScreenPoint, Size(1, 1), 1, pDPObj); + pWin->DPLaunchFieldPopupMenu(aScreenPoint, aScreenSize, nDimensionIndex, pDPObject); } // PaintGrid - repaint data range diff --git a/sc/source/ui/view/tabvwshb.cxx b/sc/source/ui/view/tabvwshb.cxx index 23b1ec9..ae7f619 100644 --- a/sc/source/ui/view/tabvwshb.cxx +++ b/sc/source/ui/view/tabvwshb.cxx @@ -19,6 +19,7 @@ #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> #include <com/sun/star/chart2/data/XDataReceiver.hpp> +#include <com/sun/star/awt/Rectangle.hpp> #include <com/sun/star/embed/EmbedMisc.hpp> #include <com/sun/star/embed/EmbedStates.hpp> @@ -110,10 +111,32 @@ public: {} // XCallback - virtual void SAL_CALL notify(const css::uno::Any& /*aData*/) override + virtual void SAL_CALL notify(const css::uno::Any& aData) override { - Rectangle aRect = m_pObject->GetLogicRect(); - m_pViewShell->DoDPFieldPopup(aRect.TopLeft(), aRect.GetSize()); + uno::Sequence<beans::PropertyValue> aProperties; + if (aData >>= aProperties) + { + awt::Rectangle xRectangle; + sal_Int32 dimensionIndex = 0; + OUString sPivotTableName("DataPilot1"); + + for (beans::PropertyValue const & rProperty : aProperties) + { + if (rProperty.Name == "Rectangle") + rProperty.Value >>= xRectangle; + if (rProperty.Name == "DimensionIndex") + rProperty.Value >>= dimensionIndex; + if (rProperty.Name == "PivotTableName") + rProperty.Value >>= sPivotTableName; + } + + Rectangle aChartRect = m_pObject->GetLogicRect(); + + Point aPoint(xRectangle.X + aChartRect.Left(), xRectangle.Y + aChartRect.Top()); + Size aSize(xRectangle.Width, xRectangle.Height); + + m_pViewShell->DoDPFieldPopup(sPivotTableName, dimensionIndex, aPoint, aSize); + } } };
_______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
