Rebased ref, commits from common ancestor: commit ed16cd7ba4baacd1fa8f297286d802037bcabf8b Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Mar 7 16:53:27 2017 +0100
charts: add field buttons if we have the pivot table data In ChartView (and VLegend) check if the data provider is a pivot chart data provider and get the pivot table field names to create the buttons on the UI. Change-Id: I08faaa17c953f0f40180e1ac1b0cb1dc6471607e diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 12fc658..54b1297 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -113,6 +113,8 @@ #include <comphelper/classids.hxx> #include "servicenames_charttypes.hxx" +#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> + #include <rtl/strbuf.hxx> #include <rtl/ustring.hxx> @@ -2489,35 +2491,29 @@ void lcl_createButtons(const uno::Reference< drawing::XShapes>& xPageShapes, ChartModel& rModel, awt::Rectangle& rRemainingSpace) { - uno::Reference<beans::XPropertySet> xModelPage(rModel.getPageBackground()); + uno::Reference<chart2::data::XPivotChartDataProvider> xPivotChartDataProvider(rModel.getDataProvider(), uno::UNO_QUERY); -// TODO: Get this from the PivotTable - std::vector<OUString> aPageFields { -// "Subdivision", "Subdivision2" - }; - std::vector<OUString> aDataFields { -// "Sum - Revenue", "Sum - Expenses" - }; - std::vector<OUString> aColumnFields { -// "Group Segment", "Group Segment 2" - }; + 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.empty()) + if (aPageFields.hasElements()) { x = 0; nCIDIndex = 0; - for (OUString const & aPageField : aPageFields) + for (OUString const & rPageField : aPageFields) { 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(aPageField); + pButton->setLabel(rPageField); pButton->setCID("PageFieldButton." + OUString::number(nCIDIndex)); pButton->createShapes(aNewPosition, aSize, xModelPage); x += aSize.Width + 100; @@ -2527,16 +2523,16 @@ void lcl_createButtons(const uno::Reference< drawing::XShapes>& xPageShapes, rRemainingSpace.Height -= (aSize.Height + 100 + 100); } - if (!aDataFields.empty()) + if (aDataFields.hasElements()) { x = 200; nCIDIndex = 0; - for (OUString const & aDataField : aDataFields) + for (OUString const & rDataField : aDataFields) { 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(aDataField); + pButton->setLabel(rDataField); pButton->setCID("DataFieldButton." + OUString::number(nCIDIndex)); pButton->createShapes(aNewPosition, aSize, xModelPage); x += aSize.Width + 100; @@ -2546,17 +2542,17 @@ void lcl_createButtons(const uno::Reference< drawing::XShapes>& xPageShapes, rRemainingSpace.Height -= (aSize.Height + 100 + 100); } - if (!aColumnFields.empty()) + if (aRowFields.hasElements()) { x = 200; nCIDIndex = 0; - for (OUString const & aColumnField : aColumnFields) + for (OUString const & rRowField : aRowFields) { 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(aColumnField); + pButton->setLabel(rRowField); pButton->setCID("ColumnFieldButton." + OUString::number(nCIDIndex)); pButton->createShapes(aNewPosition, aSize, xModelPage); x += aSize.Width + 100; diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index 5cddb57..b79c95a 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -40,6 +40,8 @@ #include <rtl/ustrbuf.hxx> #include <svl/languageoptions.hxx> +#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> + #include <vector> #include <algorithm> @@ -766,14 +768,12 @@ std::vector<std::shared_ptr<VButton>> lcl_createButtons( const uno::Reference< lang::XMultiServiceFactory>& xShapeFactory, ChartModel& rModel, long& nUsedHeight) { -// TODO: get this info from the Pivot Table - std::vector<OUString> aRowFields { -// "Service Months" - }; + 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 (aRowFields.empty()) + if (!aColumnFields.hasElements()) return aButtons; uno::Reference<beans::XPropertySet> xModelPage(rModel.getPageBackground()); @@ -781,13 +781,13 @@ std::vector<std::shared_ptr<VButton>> lcl_createButtons( int nCIDIndex = 0; awt::Size aSize(2000, 700); - for (OUString const & sRowField : aRowFields) + for (OUString const & sColumnField : aColumnFields) { std::shared_ptr<VButton> pButton(new VButton); aButtons.push_back(pButton); pButton->init(xLegendContainer, xShapeFactory); awt::Point aNewPosition = awt::Point(100, 100); - pButton->setLabel(sRowField); + pButton->setLabel(sColumnField); pButton->setCID("RowFieldButton." + OUString::number(nCIDIndex)); pButton->createShapes(aNewPosition, aSize, xModelPage); nCIDIndex += 1; commit e53a8dfc24728990c59a354a864f0d932a6b882b Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Mar 7 16:50:48 2017 +0100 charts: use isDataFromSpreadsheet check in creation wizard Change-Id: I6f4ee2639a3102f4390c6d97491244ede67abc59 diff --git a/chart2/source/controller/dialogs/dlg_CreationWizard.cxx b/chart2/source/controller/dialogs/dlg_CreationWizard.cxx index 07a03b0..b4beb73 100644 --- a/chart2/source/controller/dialogs/dlg_CreationWizard.cxx +++ b/chart2/source/controller/dialogs/dlg_CreationWizard.cxx @@ -77,10 +77,7 @@ CreationWizard::CreationWizard(vcl::Window* pParent, const uno::Reference<frame: aSize.Width() += aAdditionalRoadmapSize.Width(); this->SetSizePixel(aSize); - uno::Reference<chart2::XChartDocument> xChartDoc(m_xChartModel, uno::UNO_QUERY); - bool bHasOwnData = (xChartDoc.is() && xChartDoc->hasInternalDataProvider()); - - if(bHasOwnData) + if (!m_pDialogModel->getModel().isDataFromSpreadsheet()) { enableState(STATE_SIMPLE_RANGE, false); enableState(STATE_DATA_SERIES, false); commit 8043a6478386171d573a00519ac4763b5ed8aa8a Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Mar 7 16:48:24 2017 +0100 clean-up code in chart creation wizard Change-Id: I990dba44d4ce3d3f0538b6038133c289980fa315 diff --git a/chart2/source/controller/dialogs/dlg_CreationWizard.cxx b/chart2/source/controller/dialogs/dlg_CreationWizard.cxx index 501272f..07a03b0 100644 --- a/chart2/source/controller/dialogs/dlg_CreationWizard.cxx +++ b/chart2/source/controller/dialogs/dlg_CreationWizard.cxx @@ -33,10 +33,10 @@ #define CHART_WIZARD_PAGEWIDTH 250 #define CHART_WIZARD_PAGEHEIGHT 170 +using namespace css; + namespace chart { -using namespace ::com::sun::star; - #define PATH_FULL 1 #define STATE_FIRST 0 #define STATE_CHARTTYPE STATE_FIRST @@ -45,41 +45,45 @@ using namespace ::com::sun::star; #define STATE_OBJECTS 3 #define STATE_LAST STATE_OBJECTS -CreationWizard::CreationWizard( vcl::Window* pParent, const uno::Reference< frame::XModel >& xChartModel - , const uno::Reference< uno::XComponentContext >& xContext ) - : svt::RoadmapWizard( pParent ) +CreationWizard::CreationWizard(vcl::Window* pParent, const uno::Reference<frame::XModel>& xChartModel, + const uno::Reference<uno::XComponentContext>& xContext) + : svt::RoadmapWizard(pParent) , m_xChartModel(xChartModel,uno::UNO_QUERY) - , m_xCC( xContext ) + , m_xComponentContext(xContext) , m_pTemplateProvider(nullptr) , m_nLastState(STATE_LAST) - , m_aTimerTriggeredControllerLock( xChartModel ) - , m_bCanTravel( true ) + , m_aTimerTriggeredControllerLock(xChartModel) + , m_bCanTravel(true) { - m_pDialogModel.reset( new DialogModel( m_xChartModel, m_xCC )); - defaultButton( WizardButtonFlags::FINISH ); + m_pDialogModel.reset(new DialogModel(m_xChartModel, m_xComponentContext)); + defaultButton(WizardButtonFlags::FINISH); this->setTitleBase(SCH_RESSTR(STR_DLG_CHART_WIZARD)); - declarePath( PATH_FULL - , {STATE_CHARTTYPE - , STATE_SIMPLE_RANGE - , STATE_DATA_SERIES - , STATE_OBJECTS} - ); - this->SetRoadmapHelpId( HID_SCH_WIZARD_ROADMAP ); - this->SetRoadmapInteractive( true ); - Size aAdditionalRoadmapSize( LogicToPixel( Size( 85, 0 ), MapUnit::MapAppFont ) ); + WizardPath aPath = { + STATE_CHARTTYPE, + STATE_SIMPLE_RANGE, + STATE_DATA_SERIES, + STATE_OBJECTS + }; + + declarePath(PATH_FULL, aPath); + + this->SetRoadmapHelpId(HID_SCH_WIZARD_ROADMAP); + this->SetRoadmapInteractive(true); + + Size aAdditionalRoadmapSize(LogicToPixel(Size(85, 0), MapUnit::MapAppFont)); Size aSize(LogicToPixel(Size(CHART_WIZARD_PAGEWIDTH, CHART_WIZARD_PAGEHEIGHT), MapUnit::MapAppFont)); aSize.Width() += aAdditionalRoadmapSize.Width(); - this->SetSizePixel( aSize ); + this->SetSizePixel(aSize); - uno::Reference< chart2::XChartDocument > xChartDoc( m_xChartModel, uno::UNO_QUERY ); + uno::Reference<chart2::XChartDocument> xChartDoc(m_xChartModel, uno::UNO_QUERY); bool bHasOwnData = (xChartDoc.is() && xChartDoc->hasInternalDataProvider()); - if( bHasOwnData ) + if(bHasOwnData) { - this->enableState( STATE_SIMPLE_RANGE, false ); - this->enableState( STATE_DATA_SERIES, false ); + enableState(STATE_SIMPLE_RANGE, false); + enableState(STATE_DATA_SERIES, false); } // Call ActivatePage, to create and activate the first page @@ -117,15 +121,17 @@ VclPtr<TabPage> CreationWizard::createPage(WizardState nState) break; case STATE_OBJECTS: { - pRet = VclPtr<TitlesAndObjectsTabPage>::Create(this,m_xChartModel,m_xCC); + pRet = VclPtr<TitlesAndObjectsTabPage>::Create(this,m_xChartModel, m_xComponentContext); m_aTimerTriggeredControllerLock.startTimer(); } break; default: break; } - if(pRet) - pRet->SetText(OUString());//remove title of pages to not get them in the wizard title + + if (pRet) + pRet->SetText(OUString()); //remove title of pages to not get them in the wizard title + return pRet; } diff --git a/chart2/source/controller/inc/dlg_CreationWizard.hxx b/chart2/source/controller/inc/dlg_CreationWizard.hxx index fed0190..a1fed3c 100644 --- a/chart2/source/controller/inc/dlg_CreationWizard.hxx +++ b/chart2/source/controller/inc/dlg_CreationWizard.hxx @@ -24,57 +24,56 @@ #include "TabPageNotifiable.hxx" #include <com/sun/star/chart2/XChartDocument.hpp> -#include <svtools/roadmapwizard.hxx> #include <com/sun/star/uno/XComponentContext.hpp> +#include <svtools/roadmapwizard.hxx> + #include <memory> namespace chart { -class RangeChooserTabPage; -class DataSourceTabPage; class DialogModel; class ChartTypeTemplateProvider; class CreationWizard : public svt::RoadmapWizard, public TabPageNotifiable { public: - CreationWizard( vcl::Window* pParent, - const css::uno::Reference< css::frame::XModel >& xChartModel - , const css::uno::Reference< css::uno::XComponentContext >& xContext ); + CreationWizard(vcl::Window* pParent, + const css::uno::Reference<css::frame::XModel>& xChartModel, + const css::uno::Reference<css::uno::XComponentContext>& xContext); CreationWizard() = delete; virtual ~CreationWizard() override; // TabPageNotifiable - virtual void setInvalidPage( TabPage * pTabPage ) override; - virtual void setValidPage( TabPage * pTabPage ) override; + virtual void setInvalidPage(TabPage * pTabPage) override; + virtual void setValidPage(TabPage * pTabPage) override; protected: - virtual bool leaveState( WizardState _nState ) override; - virtual WizardState determineNextState(WizardState nCurrentState) const override; - virtual void enterState(WizardState nState) override; + virtual bool leaveState( WizardState _nState ) override; + virtual WizardState determineNextState(WizardState nCurrentState) const override; + virtual void enterState(WizardState nState) override; - virtual OUString getStateDisplayName( WizardState nState ) const override; + virtual OUString getStateDisplayName(WizardState nState) const override; private: virtual VclPtr<TabPage> createPage(WizardState nState) override; - css::uno::Reference< css::chart2::XChartDocument > m_xChartModel; - css::uno::Reference< css::uno::XComponentContext> m_xCC; - ChartTypeTemplateProvider* m_pTemplateProvider; + css::uno::Reference<css::chart2::XChartDocument> m_xChartModel; + css::uno::Reference<css::uno::XComponentContext> m_xComponentContext; + ChartTypeTemplateProvider* m_pTemplateProvider; std::unique_ptr<DialogModel> m_pDialogModel; WizardState m_nLastState; - TimerTriggeredControllerLock m_aTimerTriggeredControllerLock; + TimerTriggeredControllerLock m_aTimerTriggeredControllerLock; -// RangeChooserTabPage * m_pRangeChooserTabPage; -// DataSourceTabPage * m_pDataSourceTabPage; - bool m_bCanTravel; + bool m_bCanTravel; }; + } //namespace chart + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 37ae36863db12893029fd199506cfaf97a3b0154 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Mar 7 16:42:24 2017 +0100 pivotcharts: Check the data provider on pivot table update Change-Id: I8ae0756357c18c9fc0b0af64e8e3acb36e1a8564 diff --git a/chart2/source/model/main/ChartModel_Persistence.cxx b/chart2/source/model/main/ChartModel_Persistence.cxx index da7ba9c..945bd39 100644 --- a/chart2/source/model/main/ChartModel_Persistence.cxx +++ b/chart2/source/model/main/ChartModel_Persistence.cxx @@ -46,6 +46,8 @@ #include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/ucb/CommandFailedException.hpp> +#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> + #include <ucbhelper/content.hxx> #include <unotools/ucbstreamhelper.hxx> #include <vcl/cvtgrf.hxx> @@ -709,11 +711,11 @@ void SAL_CALL ChartModel::removeModifyListener( // util::XModifyListener void SAL_CALL ChartModel::modified( const lang::EventObject& rEvenObject) { - uno::Reference<chart2::data::XDataProvider> xDataProvider(rEvenObject.Source, uno::UNO_QUERY); - if (xDataProvider.is()) + uno::Reference<chart2::data::XPivotChartDataProvider> xPivotChartDataProvider(rEvenObject.Source, uno::UNO_QUERY); + if (xPivotChartDataProvider.is()) { lockControllers(); - Reference<frame::XModel> xModel(this); + uno::Reference<chart2::data::XDataProvider> xDataProvider(xPivotChartDataProvider, uno::UNO_QUERY); try { uno::Sequence<beans::PropertyValue> aArguments = commit 053dedb1c696ec950942923e6d73d6835cd3fc89 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Mar 7 16:38:07 2017 +0100 chart model: checks if data provider is pivot table or sheet Change-Id: I5f71004f15b72e6d0ef6bef30ee5814f31e4b1e7 diff --git a/chart2/inc/ChartModel.hxx b/chart2/inc/ChartModel.hxx index 04e3be2..d6123bd 100644 --- a/chart2/inc/ChartModel.hxx +++ b/chart2/inc/ChartModel.hxx @@ -469,6 +469,10 @@ public: void setTimeBasedRange(sal_Int32 nStart, sal_Int32 nEnd); + bool isDataFromSpreadsheet(); + + bool isDataFromPivotTable(); + #if HAVE_FEATURE_OPENGL OpenGLWindow* getOpenGLWindow() { return mpOpenGLWindow;} #endif diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx index a8dae67..b1faf4b 100644 --- a/chart2/source/model/main/ChartModel.cxx +++ b/chart2/source/model/main/ChartModel.cxx @@ -38,6 +38,7 @@ #include <vcl/openglwin.hxx> #include <com/sun/star/chart/ChartDataRowSource.hpp> +#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> #include <comphelper/processfactory.hxx> #include <cppuhelper/supportsservice.hxx> @@ -1358,6 +1359,17 @@ void ChartModel::update() #endif } +bool ChartModel::isDataFromSpreadsheet() +{ + return !isDataFromPivotTable() && !hasInternalDataProvider(); +} + +bool ChartModel::isDataFromPivotTable() +{ + uno::Reference<chart2::data::XPivotChartDataProvider> xPivotChartDataProvider(m_xDataProvider, uno::UNO_QUERY); + return xPivotChartDataProvider.is(); +} + } // namespace chart extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL commit f97bd0c422952fd258eeee2434b930d23239ec50 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Mar 7 16:34:14 2017 +0100 Pivot chart specific data provider to get pivot table output data Change-Id: I6e1c4320316e7dcfad5b1de5d55403cfebd01a29 diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 7ae02d6..840c191 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -2065,6 +2065,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/chart2/data,\ XLabeledDataSequence \ XLabeledDataSequence2 \ XNumericalDataSequence \ + XPivotChartDataProvider \ XPopupRequest \ XRangeHighlighter \ XRangeXMLConversion \ diff --git a/offapi/com/sun/star/chart2/data/XPivotChartDataProvider.idl b/offapi/com/sun/star/chart2/data/XPivotChartDataProvider.idl new file mode 100644 index 0000000..95b58d4 --- /dev/null +++ b/offapi/com/sun/star/chart2/data/XPivotChartDataProvider.idl @@ -0,0 +1,54 @@ +/* -*- 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_XPivotChartDataProvider_idl +#define com_sun_star_chart2_data_XPivotChartDataProvider_idl + +#include <com/sun/star/uno/XInterface.idl> +#include <com/sun/star/chart2/data/XDataSequence.idl> + +module com { module sun { module star { module chart2 { module data { + +/** + * Data provider specific for pivot chart data. + * + * @since LibreOffice 5.4 + */ +interface XPivotChartDataProvider : com::sun::star::uno::XInterface +{ + /** names of column fields from the associated pivot table + * + * @since LibreOffice 5.4 + */ + sequence<string> getColumnFields(); + + /** names of row fields from the associated pivot table + * + * @since LibreOffice 5.4 + */ + sequence<string> getRowFields(); + + /** names of page fields from the associated pivot table + * + * @since LibreOffice 5.4 + */ + sequence<string> getPageFields(); + + /** names of data fields from the associated pivot table + * + * @since LibreOffice 5.4 + */ + sequence<string> getDataFields(); +}; + +};};};};}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/PivotChartDataProvider.hxx b/sc/inc/PivotChartDataProvider.hxx index 1c2df5a..097fb18 100644 --- a/sc/inc/PivotChartDataProvider.hxx +++ b/sc/inc/PivotChartDataProvider.hxx @@ -16,6 +16,7 @@ #include "types.hxx" #include <com/sun/star/chart2/data/XDataProvider.hpp> +#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp> #include <com/sun/star/chart2/data/XDataSource.hpp> #include <com/sun/star/chart2/data/XDataSequence.hpp> #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp> @@ -40,6 +41,7 @@ namespace sc class PivotChartItem; typedef cppu::WeakImplHelper<css::chart2::data::XDataProvider, + css::chart2::data::XPivotChartDataProvider, css::beans::XPropertySet, css::lang::XServiceInfo, css::util::XModifyBroadcaster> @@ -76,6 +78,12 @@ 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; + // XPropertySet virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override; @@ -152,6 +160,11 @@ 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::uno::Reference<css::util::XModifyListener>> m_aValueListeners; }; diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx index 37becaf..8b8e6ad 100644 --- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx +++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx @@ -249,6 +249,15 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) uno::Reference<sheet::XDataPilotResults> xDPResults(pDPObject->GetSource(), uno::UNO_QUERY); uno::Sequence<uno::Sequence<sheet::DataResult>> xDataResultsSequence = xDPResults->getResults(); + m_aCategoriesColumnOrientation.clear(); + m_aCategoriesRowOrientation.clear(); + m_aLabels.clear(); + m_aDataRowVector.clear(); + m_aColumnFields.clear(); + m_aRowFields.clear(); + m_aPageFields.clear(); + m_aDataFields.clear(); + double fNan; rtl::math::setNan(&fNan); @@ -273,6 +282,9 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) std::unordered_map<OUString, sal_Int32, OUStringHash> aDataFieldNumberFormatMap; std::vector<OUString> aDataFieldNamesVectors; + std::unordered_map<OUString, OUString, OUStringHash> aDataFieldCaptionNames; + std::vector<OUString> aDataFieldNames; + sheet::DataPilotFieldOrientation eDataFieldOrientation = sheet::DataPilotFieldOrientation_HIDDEN; for (long nDim = 0; nDim < xDims->getCount(); nDim++) @@ -322,6 +334,8 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) { case sheet::DataPilotFieldOrientation_COLUMN: { + m_aColumnFields.push_back(xLevName->getName()); + uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); size_t i = 0; OUString sCaption; @@ -344,16 +358,22 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) if (bIsDataLayout) { + // Remember data fields to determine the number format of data aDataFieldNamesVectors.push_back(sName); eDataFieldOrientation = sheet::DataPilotFieldOrientation_COLUMN; + // Remember the caption name + aDataFieldCaptionNames[rMember.Name] = rMember.Caption; } i++; } } - break; } + break; + case sheet::DataPilotFieldOrientation_ROW: { + m_aRowFields.push_back(xLevName->getName()); + uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); m_aCategoriesRowOrientation.resize(aSeq.getLength()); size_t i = 0; @@ -396,18 +416,31 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) if (bIsDataLayout) { + // Remember data fields to determine the number format of data aDataFieldNamesVectors.push_back(sName); eDataFieldOrientation = sheet::DataPilotFieldOrientation_ROW; + // Remember the caption name + aDataFieldCaptionNames[rMember.Name] = rMember.Caption; } i++; } } - break; } + break; + + case sheet::DataPilotFieldOrientation_PAGE: + { + m_aPageFields.push_back(xLevName->getName()); + } + break; + case sheet::DataPilotFieldOrientation_DATA: { aDataFieldNumberFormatMap[xLevName->getName()] = nNumberFormat; + aDataFieldNames.push_back(xLevName->getName()); } + break; + default: break; } @@ -415,6 +448,11 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) } } + for (OUString const & rName : aDataFieldNames) + { + m_aDataFields.push_back(aDataFieldCaptionNames[rName]); + } + // Apply number format to the data if (eDataFieldOrientation == sheet::DataPilotFieldOrientation_ROW) { @@ -448,11 +486,6 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartDataSource(OUString const & aRangeRepresentation) { - m_aCategoriesColumnOrientation.clear(); - m_aCategoriesRowOrientation.clear(); - m_aLabels.clear(); - m_aDataRowVector.clear(); - uno::Reference<chart2::data::XDataSource> xDataSource; std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences; @@ -570,6 +603,26 @@ uno::Reference<sheet::XRangeSelection> SAL_CALL PivotChartDataProvider::getRange return xResult; } +uno::Sequence<OUString> PivotChartDataProvider::getColumnFields() +{ + return comphelper::containerToSequence(m_aColumnFields); +} + +uno::Sequence<OUString> PivotChartDataProvider::getRowFields() +{ + return comphelper::containerToSequence(m_aRowFields); +} + +uno::Sequence<OUString> PivotChartDataProvider::getPageFields() +{ + return comphelper::containerToSequence(m_aPageFields); +} + +uno::Sequence<OUString> PivotChartDataProvider::getDataFields() +{ + return comphelper::containerToSequence(m_aDataFields); +} + // XModifyBroadcaster ======================================================== void SAL_CALL PivotChartDataProvider::addModifyListener( const uno::Reference< util::XModifyListener >& aListener ) commit c2db9e60e3256888f9ccb0dfe2787a5597524628 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Wed Mar 1 22:40:09 2017 +0100 pivotcharts: collect and set the number format for the data Change-Id: I5eb2e9b9cb5abb798b99a23cfa16d790ff62ff08 diff --git a/sc/inc/PivotChartDataProvider.hxx b/sc/inc/PivotChartDataProvider.hxx index d1139a5..1c2df5a 100644 --- a/sc/inc/PivotChartDataProvider.hxx +++ b/sc/inc/PivotChartDataProvider.hxx @@ -150,6 +150,7 @@ private: std::vector<std::vector<PivotChartItem>> m_aCategoriesColumnOrientation; std::vector<std::vector<PivotChartItem>> m_aCategoriesRowOrientation; std::vector<std::vector<PivotChartItem>> m_aLabels; + std::vector<std::vector<PivotChartItem>> m_aDataRowVector; std::vector<css::uno::Reference<css::util::XModifyListener>> m_aValueListeners; }; diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx index 8d9b3e1..37becaf 100644 --- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx +++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx @@ -41,6 +41,8 @@ #include <com/sun/star/chart/ChartDataChangeEvent.hpp> +#include <unordered_map> + using namespace css; namespace sc @@ -244,9 +246,35 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) { + uno::Reference<sheet::XDataPilotResults> xDPResults(pDPObject->GetSource(), uno::UNO_QUERY); + uno::Sequence<uno::Sequence<sheet::DataResult>> xDataResultsSequence = xDPResults->getResults(); + + double fNan; + rtl::math::setNan(&fNan); + + for (uno::Sequence<sheet::DataResult> const & xDataResults : xDataResultsSequence) + { + size_t nIndex = 0; + for (sheet::DataResult const & rDataResult : xDataResults) + { + if (rDataResult.Flags == 0 || rDataResult.Flags & css::sheet::DataResultFlags::HASDATA) + { + if (nIndex >= m_aDataRowVector.size()) + m_aDataRowVector.resize(nIndex + 1); + m_aDataRowVector[nIndex].push_back(PivotChartItem(rDataResult.Flags ? rDataResult.Value : fNan, 0)); + } + nIndex++; + } + } + uno::Reference<sheet::XDimensionsSupplier> xDimensionsSupplier(pDPObject->GetSource()); uno::Reference<container::XIndexAccess> xDims = new ScNameToIndexAccess(xDimensionsSupplier->getDimensions()); + std::unordered_map<OUString, sal_Int32, OUStringHash> aDataFieldNumberFormatMap; + std::vector<OUString> aDataFieldNamesVectors; + + sheet::DataPilotFieldOrientation eDataFieldOrientation = sheet::DataPilotFieldOrientation_HIDDEN; + for (long nDim = 0; nDim < xDims->getCount(); nDim++) { uno::Reference<uno::XInterface> xDim = ScUnoHelpFunctions::AnyToInterface(xDims->getByIndex(nDim)); @@ -261,11 +289,9 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) ScUnoHelpFunctions::GetEnumProperty(xDimProp, SC_UNO_DP_ORIENTATION, sheet::DataPilotFieldOrientation_HIDDEN)); - long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION); - sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO); - 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()) @@ -286,6 +312,10 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) uno::Reference<container::XNamed> xLevName(xLevel, uno::UNO_QUERY); uno::Reference<sheet::XDataPilotMemberResults> xLevRes(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()) { switch (eDimOrient) @@ -294,7 +324,8 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) { uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); size_t i = 0; - OUString sValue; + OUString sCaption; + OUString sName; m_aLabels.resize(aSeq.getLength()); for (sheet::MemberResult & rMember : aSeq) { @@ -302,12 +333,20 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) rMember.Flags & sheet::MemberResultFlags::CONTINUE) { if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) - sValue = rMember.Caption; + { + sCaption = rMember.Caption; + sName = rMember.Name; + } if (size_t(nDimPos) >= m_aLabels[i].size()) m_aLabels[i].resize(nDimPos + 1); - m_aLabels[i][nDimPos] = PivotChartItem(sValue); + m_aLabels[i][nDimPos] = PivotChartItem(sCaption); + if (bIsDataLayout) + { + aDataFieldNamesVectors.push_back(sName); + eDataFieldOrientation = sheet::DataPilotFieldOrientation_COLUMN; + } i++; } } @@ -318,6 +357,7 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); m_aCategoriesRowOrientation.resize(aSeq.getLength()); size_t i = 0; + OUString sName; for (sheet::MemberResult & rMember : aSeq) { if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || @@ -326,17 +366,24 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) std::unique_ptr<PivotChartItem> pItem; double fValue = rMember.Value; - if (rtl::math::isNan(fValue)) { - OUString sValue; - if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) - sValue = rMember.Caption; - pItem.reset(new PivotChartItem(sValue)); + if (rMember.Flags & sheet::MemberResultFlags::CONTINUE) + { + pItem.reset(new PivotChartItem("")); + } + else + { + sName = rMember.Name; + pItem.reset(new PivotChartItem(rMember.Caption)); + } } else { - pItem.reset(new PivotChartItem(fValue, nNumberFormat)); + if (rMember.Flags & sheet::MemberResultFlags::CONTINUE) + pItem.reset(new PivotChartItem()); + else + pItem.reset(new PivotChartItem(fValue, nNumberFormat)); } if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size()) @@ -347,17 +394,56 @@ void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) m_aCategoriesRowOrientation[i].resize(nDimPos + 1); m_aCategoriesRowOrientation[i][nDimPos] = *pItem; + if (bIsDataLayout) + { + aDataFieldNamesVectors.push_back(sName); + eDataFieldOrientation = sheet::DataPilotFieldOrientation_ROW; + } i++; } } break; } + case sheet::DataPilotFieldOrientation_DATA: + { + aDataFieldNumberFormatMap[xLevName->getName()] = nNumberFormat; + } default: break; } } } } + + // Apply number format to the data + if (eDataFieldOrientation == sheet::DataPilotFieldOrientation_ROW) + { + for (std::vector<PivotChartItem> & rDataRow : m_aDataRowVector) + { + size_t i = 0; + for (PivotChartItem & rItem : rDataRow) + { + OUString sName = aDataFieldNamesVectors[i]; + sal_Int32 nNumberFormat = aDataFieldNumberFormatMap[sName]; + rItem.m_nNumberFormat = nNumberFormat; + i++; + } + } + } + else if (eDataFieldOrientation == sheet::DataPilotFieldOrientation_COLUMN) + { + size_t i = 0; + for (std::vector<PivotChartItem> & rDataRow : m_aDataRowVector) + { + OUString sName = aDataFieldNamesVectors[i]; + sal_Int32 nNumberFormat = aDataFieldNumberFormatMap[sName]; + for (PivotChartItem & rItem : rDataRow) + { + rItem.m_nNumberFormat = nNumberFormat; + } + i++; + } + } } uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartDataSource(OUString const & aRangeRepresentation) @@ -365,6 +451,7 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha m_aCategoriesColumnOrientation.clear(); m_aCategoriesRowOrientation.clear(); m_aLabels.clear(); + m_aDataRowVector.clear(); uno::Reference<chart2::data::XDataSource> xDataSource; std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences; @@ -378,8 +465,6 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha collectPivotTableData(pDPObject); - uno::Reference<sheet::XDataPilotResults> xDPResults(pDPObject->GetSource(), uno::UNO_QUERY); - { std::vector<PivotChartItem> aFirstCategories; std::copy (m_aCategoriesColumnOrientation[0].begin(), @@ -392,35 +477,11 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha } { - uno::Sequence<uno::Sequence<sheet::DataResult>> xDataResultsSequence = xDPResults->getResults(); - - std::vector<std::vector<PivotChartItem>> aDataRowVector; - - double fNan; - rtl::math::setNan(&fNan); - - for (uno::Sequence<sheet::DataResult> const & xDataResults : xDataResultsSequence) - { - size_t nIndex = 0; - for (sheet::DataResult const & rDataResult : xDataResults) - { - if (rDataResult.Flags == 0 || rDataResult.Flags & css::sheet::DataResultFlags::HASDATA) - { - - if (nIndex >= aDataRowVector.size()) - aDataRowVector.resize(nIndex + 1); - aDataRowVector[nIndex].push_back(PivotChartItem(rDataResult.Flags ? rDataResult.Value : fNan, 0)); - } - nIndex++; - } - } - int i = 0; - - for (std::vector<PivotChartItem> const & rDataRow : aDataRowVector) + for (std::vector<PivotChartItem> const & rRowOfData : m_aDataRowVector) { - OUString aValuesId = "Data " + OUString::number(i); - OUString aLabelsId = "Label " + OUString::number(i); + OUString aValuesId = "Data " + OUString::number(i + 1); + OUString aLabelsId = "Label " + OUString::number(i + 1); OUString aLabel; bool bFirst = true; @@ -440,7 +501,7 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha std::vector<PivotChartItem> aLabelVector { PivotChartItem(aLabel) }; uno::Reference<chart2::data::XLabeledDataSequence> xResult = createLabeledDataSequence(xContext); - setLabeledDataSequence(xResult, "values-y", aValuesId, rDataRow, + setLabeledDataSequence(xResult, "values-y", aValuesId, rRowOfData, "values-y", aLabelsId, aLabelVector); aLabeledSequences.push_back(xResult); i++; commit 2408a5d49e51e1b929ee9da1cdb7192475d4907a Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Wed Mar 1 22:36:41 2017 +0100 pivotcharts: modify the pivot chart when the pivot table changes Change-Id: I971e8bf90aaf2363adf3aa530b2cc8fd02abd273 diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx index fe8ada3..a8dae67 100644 --- a/chart2/source/model/main/ChartModel.cxx +++ b/chart2/source/model/main/ChartModel.cxx @@ -63,6 +63,7 @@ #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/document/DocumentProperties.hpp> #include <com/sun/star/chart2/XTimeBased.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> #include <svl/zforlist.hxx> @@ -746,7 +747,7 @@ Reference< chart2::data::XDataSource > ChartModel::impl_createDefaultData() xIni->initialize(aArgs); } //create data - uno::Sequence< beans::PropertyValue > aArgs( 4 ); + uno::Sequence<beans::PropertyValue> aArgs(4); aArgs[0] = beans::PropertyValue( "CellRangeRepresentation", -1, uno::Any( OUString("all") ), beans::PropertyState_DIRECT_VALUE ); @@ -818,6 +819,12 @@ void SAL_CALL ChartModel::attachDataProvider( const uno::Reference< chart2::data } } + uno::Reference<util::XModifyBroadcaster> xModifyBroadcaster(xDataProvider, uno::UNO_QUERY); + if (xModifyBroadcaster.is()) + { + xModifyBroadcaster->addModifyListener(this); + } + m_xDataProvider.set( xDataProvider ); m_xInternalDataProvider.clear(); diff --git a/chart2/source/model/main/ChartModel_Persistence.cxx b/chart2/source/model/main/ChartModel_Persistence.cxx index c19aeaf..da7ba9c 100644 --- a/chart2/source/model/main/ChartModel_Persistence.cxx +++ b/chart2/source/model/main/ChartModel_Persistence.cxx @@ -22,8 +22,10 @@ #include "macros.hxx" #include "ChartViewHelper.hxx" #include "ChartModelHelper.hxx" +#include "DataSourceHelper.hxx" #include "AxisHelper.hxx" #include "ThreeDHelper.hxx" +#include "DiagramHelper.hxx" #include <com/sun/star/chart2/LegendPosition.hpp> #include <com/sun/star/container/XNameAccess.hpp> @@ -49,6 +51,7 @@ #include <vcl/cvtgrf.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/storagehelper.hxx> +#include <comphelper/sequence.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> @@ -704,10 +707,35 @@ void SAL_CALL ChartModel::removeModifyListener( } // util::XModifyListener -void SAL_CALL ChartModel::modified( const lang::EventObject& ) +void SAL_CALL ChartModel::modified( const lang::EventObject& rEvenObject) { - if( m_nInLoad == 0 ) - setModified( true ); + uno::Reference<chart2::data::XDataProvider> xDataProvider(rEvenObject.Source, uno::UNO_QUERY); + if (xDataProvider.is()) + { + lockControllers(); + Reference<frame::XModel> xModel(this); + try + { + uno::Sequence<beans::PropertyValue> aArguments = + DataSourceHelper::createArguments("PivotChart", uno::Sequence<sal_Int32>(), true, true, true); + + Reference<chart2::data::XDataSource> xDataSource(xDataProvider->createDataSource(aArguments)); + Reference<lang::XMultiServiceFactory> xFactory(getChartTypeManager(), uno::UNO_QUERY); + Reference<chart2::XDiagram> xDiagram(getFirstDiagram()); + + DiagramHelper::tTemplateWithServiceName aTemplateAndService = DiagramHelper::getTemplateForDiagram(xDiagram, xFactory); + css::uno::Reference<css::chart2::XChartTypeTemplate> xChartTypeTemplate(aTemplateAndService.first); + xChartTypeTemplate->changeDiagramData(xDiagram, xDataSource, aArguments); + } + catch (const uno::Exception & ex) + { + ASSERT_EXCEPTION(ex); + } + unlockControllers(); + } + + if (m_nInLoad == 0) + setModified(true); } // lang::XEventListener (base of util::XModifyListener) commit 60636b83f6520f6b53fda0f1445ea553b7a88fb7 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Feb 28 11:04:53 2017 +0100 pivotcharts: insert a pivot chart if cursor is in a pivot table Change-Id: I9fbde8e26cf10e68ff7a886e982b7ac1e5d7ef70 diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx index e9e6304..ba4a31f 100644 --- a/sc/source/ui/drawfunc/fuins2.cxx +++ b/sc/source/ui/drawfunc/fuins2.cxx @@ -63,8 +63,7 @@ #include <com/sun/star/chart/ChartDataRowSource.hpp> #include <cppuhelper/bootstrap.hxx> -using namespace ::com::sun::star; - +#include "PivotChartDataProvider.hxx" #include "chart2uno.hxx" #include "fuinsert.hxx" #include "tabvwsh.hxx" @@ -81,16 +80,20 @@ using namespace ::com::sun::star; #include "gridwin.hxx" #include <memory> -namespace { +using namespace css; + +namespace +{ -void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScViewData* pViewData, - const OUString& rRangeParam ) +void lcl_ChartInit(const uno::Reference <embed::XEmbeddedObject>& xObj, ScViewData* pViewData, + const OUString& rRangeParam, bool bRangeIsPivotTable) { ScDocShell* pDocShell = pViewData->GetDocShell(); ScDocument& rScDoc = pDocShell->GetDocument(); - OUString aRangeString( rRangeParam ); - if ( aRangeString.isEmpty() ) + OUString aRangeString(rRangeParam); + + if (aRangeString.isEmpty() && !bRangeIsPivotTable) { SCCOL nCol1 = 0; SCROW nRow1 = 0; @@ -118,7 +121,7 @@ void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScVie } } - if ( !aRangeString.isEmpty() ) + if (!aRangeString.isEmpty()) { // connect to Calc data (if no range string, leave chart alone, with its own data) @@ -129,8 +132,13 @@ void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScVie OSL_ASSERT( xReceiver.is()); if( xReceiver.is() ) { - uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( &rScDoc ); - xReceiver->attachDataProvider( xDataProvider ); + uno::Reference<chart2::data::XDataProvider> xDataProvider; + if (bRangeIsPivotTable) + xDataProvider.set(new sc::PivotChartDataProvider(&rScDoc, aRangeString)); + else + xDataProvider.set(new ScChart2DataProvider(&rScDoc)); + + xReceiver->attachDataProvider(xDataProvider); uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY ); xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier ); @@ -329,7 +337,7 @@ FuInsertOLE::FuInsertOLE(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* // Chart initialisieren ? if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj->getClassID() ) ) ) - lcl_ChartInit( xObj, &pViewSh->GetViewData(), OUString() ); + lcl_ChartInit(xObj, &pViewSh->GetViewData(), OUString(), false); ScViewData& rData = pViewSh->GetViewData(); @@ -393,7 +401,7 @@ FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawV SdrModel* pDoc, SfxRequest& rReq) : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq) { - const SfxItemSet* pReqArgs = rReq.GetArgs(); + const SfxItemSet* pReqArgs = rReq.GetArgs(); if( ! rReq.IsAPI() ) rReq.Done(); @@ -405,6 +413,7 @@ FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawV // get range OUString aRangeString; + bool bRangeIsPivotTable = false; ScRange aPositionRange; // cell range for chart positioning ScMarkData aMark = pViewSh->GetViewData().GetMarkData(); if( pReqArgs ) @@ -417,35 +426,46 @@ FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawV } else { - bool bAutomaticMark = false; - if ( !aMark.IsMarked() && !aMark.IsMultiMarked() ) + ScDocument* pDocument = pViewSh->GetViewData().GetDocument(); + ScDPObject* pObject = pDocument->GetDPAtCursor(pViewSh->GetViewData().GetCurX(), + pViewSh->GetViewData().GetCurY(), + pViewSh->GetViewData().GetTabNo()); + if (pObject) { - pViewSh->GetViewData().GetView()->MarkDataArea(); - bAutomaticMark = true; + aRangeString = pObject->GetName(); + bRangeIsPivotTable = true; } + else + { + bool bAutomaticMark = false; + if ( !aMark.IsMarked() && !aMark.IsMultiMarked() ) + { + pViewSh->GetViewData().GetView()->MarkDataArea(); + bAutomaticMark = true; + } - ScMarkData aMultiMark( aMark ); - aMultiMark.MarkToMulti(); + ScMarkData aMultiMark( aMark ); + aMultiMark.MarkToMulti(); - ScRangeList aRanges; - aMultiMark.FillRangeListWithMarks( &aRanges, false ); - OUString aStr; - ScDocument* pDocument = pViewSh->GetViewData().GetDocument(); - aRanges.Format( aStr, ScRefFlags::RANGE_ABS_3D, pDocument, pDocument->GetAddressConvention() ); - aRangeString = aStr; + ScRangeList aRanges; + aMultiMark.FillRangeListWithMarks( &aRanges, false ); + OUString aStr; + aRanges.Format( aStr, ScRefFlags::RANGE_ABS_3D, pDocument, pDocument->GetAddressConvention() ); + aRangeString = aStr; - // get "total" range for positioning - if ( !aRanges.empty() ) - { - aPositionRange = *aRanges[ 0 ]; - for ( size_t i = 1, nCount = aRanges.size(); i < nCount; ++i ) + // get "total" range for positioning + if ( !aRanges.empty() ) { - aPositionRange.ExtendTo( *aRanges[ i ] ); + aPositionRange = *aRanges[ 0 ]; + for ( size_t i = 1, nCount = aRanges.size(); i < nCount; ++i ) + { + aPositionRange.ExtendTo( *aRanges[ i ] ); + } } - } - if(bAutomaticMark) - pViewSh->GetViewData().GetView()->Unmark(); + if(bAutomaticMark) + pViewSh->GetViewData().GetView()->Unmark(); + } } // adapted old code @@ -568,7 +588,7 @@ FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawV } } - lcl_ChartInit( xObj, &rData, aRangeString ); // set source range, auto-detect column/row headers + lcl_ChartInit(xObj, &rData, aRangeString, bRangeIsPivotTable); // set source range, auto-detect column/row headers // Objekt-Position commit 40e8bffd807e395bf071ba2c800212a9dbcc1199 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Mon Feb 27 16:59:11 2017 +0100 pivotcharts: extract and simplify pivot table data collection Change-Id: I49b0c4d06c3401f07ab3d2857213b12f109f0d8b diff --git a/sc/inc/PivotChartDataProvider.hxx b/sc/inc/PivotChartDataProvider.hxx index e92f847..d1139a5 100644 --- a/sc/inc/PivotChartDataProvider.hxx +++ b/sc/inc/PivotChartDataProvider.hxx @@ -29,7 +29,7 @@ #include <rtl/ustring.hxx> #include <svl/itemprop.hxx> -#include "dpsave.hxx" +#include "dpobject.hxx" #include <memory> #include <vector> @@ -140,6 +140,8 @@ private: css::uno::Reference<css::uno::XComponentContext>& rContext, std::vector<css::uno::Reference<css::chart2::data::XLabeledDataSequence>>& rOutLabeledSequences); + void collectPivotTableData(ScDPObject* pDPObject); + ScDocument* m_pDocument; OUString m_sPivotTableName; SfxItemPropertySet m_aPropSet; @@ -147,6 +149,7 @@ private: std::vector<std::vector<PivotChartItem>> m_aCategoriesColumnOrientation; std::vector<std::vector<PivotChartItem>> m_aCategoriesRowOrientation; + std::vector<std::vector<PivotChartItem>> m_aLabels; std::vector<css::uno::Reference<css::util::XModifyListener>> m_aValueListeners; }; diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx index 520244c..8d9b3e1 100644 --- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx +++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx @@ -36,8 +36,6 @@ #include <com/sun/star/sheet/MemberResultFlags.hpp> #include "dpobject.hxx" -#include "dpsave.hxx" -#include "pivot.hxx" #include "hints.hxx" @@ -244,27 +242,11 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha return xDataSource; } -uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartDataSource(OUString const & aRangeRepresentation) +void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject) { - m_aCategoriesColumnOrientation.clear(); - m_aCategoriesRowOrientation.clear(); - - uno::Reference<chart2::data::XDataSource> xDataSource; - std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences; - - uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); - if (!xContext.is()) - return xDataSource; - - ScDPCollection* pDPCollection = m_pDocument->GetDPCollection(); - ScDPObject* pDPObject = pDPCollection->GetByName(m_sPivotTableName); - uno::Reference<sheet::XDimensionsSupplier> xDimensionsSupplier(pDPObject->GetSource()); - uno::Reference<sheet::XDataPilotResults> xDPResults(xDimensionsSupplier, uno::UNO_QUERY); uno::Reference<container::XIndexAccess> xDims = new ScNameToIndexAccess(xDimensionsSupplier->getDimensions()); - std::vector<std::vector<PivotChartItem>> m_aLabels; - for (long nDim = 0; nDim < xDims->getCount(); nDim++) { uno::Reference<uno::XInterface> xDim = ScUnoHelpFunctions::AnyToInterface(xDims->getByIndex(nDim)); @@ -272,110 +254,131 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha uno::Reference<container::XNamed> xDimName(xDim, uno::UNO_QUERY); uno::Reference<sheet::XHierarchiesSupplier> xDimSupp(xDim, uno::UNO_QUERY); - if (xDimProp.is() && xDimSupp.is()) - { - sheet::DataPilotFieldOrientation eDimOrient = sheet::DataPilotFieldOrientation( - ScUnoHelpFunctions::GetEnumProperty(xDimProp, SC_UNO_DP_ORIENTATION, - sheet::DataPilotFieldOrientation_HIDDEN)); + if (!xDimProp.is() || !xDimSupp.is()) + continue; - long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION); - sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO); + sheet::DataPilotFieldOrientation eDimOrient = sheet::DataPilotFieldOrientation( + ScUnoHelpFunctions::GetEnumProperty(xDimProp, SC_UNO_DP_ORIENTATION, + sheet::DataPilotFieldOrientation_HIDDEN)); - if (eDimOrient != sheet::DataPilotFieldOrientation_HIDDEN) - { - uno::Reference<container::XIndexAccess> xHiers = new ScNameToIndexAccess(xDimSupp->getHierarchies()); - long nHierarchy = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_USEDHIERARCHY); - if (nHierarchy >= xHiers->getCount()) - nHierarchy = 0; + long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION); + sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO); + + 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()) + nHierarchy = 0; + + uno::Reference<uno::XInterface> xHier = ScUnoHelpFunctions::AnyToInterface(xHiers->getByIndex(nHierarchy)); + + uno::Reference<sheet::XLevelsSupplier> xHierSupp(xHier, uno::UNO_QUERY); + + if (!xHierSupp.is()) + continue; - uno::Reference<uno::XInterface> xHier = ScUnoHelpFunctions::AnyToInterface(xHiers->getByIndex(nHierarchy)); + uno::Reference<container::XIndexAccess> xLevels = new ScNameToIndexAccess(xHierSupp->getLevels()); - uno::Reference<sheet::XLevelsSupplier> xHierSupp(xHier, uno::UNO_QUERY); - if (xHierSupp.is()) + 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 ); + + if (xLevName.is() && xLevRes.is()) + { + switch (eDimOrient) { - uno::Reference<container::XIndexAccess> xLevels = new ScNameToIndexAccess(xHierSupp->getLevels()); - long nLevCount = xLevels->getCount(); - for (long nLev = 0; nLev < nLevCount; nLev++) + case sheet::DataPilotFieldOrientation_COLUMN: { + uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); + size_t i = 0; + OUString sValue; + m_aLabels.resize(aSeq.getLength()); + for (sheet::MemberResult & rMember : aSeq) + { + if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || + rMember.Flags & sheet::MemberResultFlags::CONTINUE) + { + if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) + sValue = rMember.Caption; + + if (size_t(nDimPos) >= m_aLabels[i].size()) + m_aLabels[i].resize(nDimPos + 1); + m_aLabels[i][nDimPos] = PivotChartItem(sValue); - 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 ); - if (xLevName.is() && xLevRes.is()) + i++; + } + } + break; + } + case sheet::DataPilotFieldOrientation_ROW: + { + uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); + m_aCategoriesRowOrientation.resize(aSeq.getLength()); + size_t i = 0; + for (sheet::MemberResult & rMember : aSeq) { - switch (eDimOrient) + if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || + rMember.Flags & sheet::MemberResultFlags::CONTINUE) { - case sheet::DataPilotFieldOrientation_COLUMN: + std::unique_ptr<PivotChartItem> pItem; + + double fValue = rMember.Value; + + if (rtl::math::isNan(fValue)) { - uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); - size_t i = 0; OUString sValue; - m_aLabels.resize(aSeq.getLength()); - for (sheet::MemberResult & rMember : aSeq) - { - if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || - rMember.Flags & sheet::MemberResultFlags::CONTINUE) - { - if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) - sValue = rMember.Caption; - - if (size_t(nDimPos) >= m_aLabels[i].size()) - m_aLabels[i].resize(nDimPos + 1); - m_aLabels[i][nDimPos] = PivotChartItem(sValue); - - i++; - } - } - break; + if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) + sValue = rMember.Caption; + pItem.reset(new PivotChartItem(sValue)); } - case sheet::DataPilotFieldOrientation_ROW: + else { - uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults(); - m_aCategoriesRowOrientation.resize(aSeq.getLength()); - size_t i = 0; - for (sheet::MemberResult & rMember : aSeq) - { - if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || - rMember.Flags & sheet::MemberResultFlags::CONTINUE) - { - std::unique_ptr<PivotChartItem> pItem; - - double fValue = rMember.Value; - - if (rtl::math::isNan(fValue)) - { - OUString sValue; - if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) - sValue = rMember.Caption; - pItem.reset(new PivotChartItem(sValue)); - } - else - { - pItem.reset(new PivotChartItem(fValue, nNumberFormat)); - } - - if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size()) - m_aCategoriesColumnOrientation.resize(nDimPos + 1); - m_aCategoriesColumnOrientation[nDimPos].push_back(*pItem); - - if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size()) - m_aCategoriesRowOrientation[i].resize(nDimPos + 1); - m_aCategoriesRowOrientation[i][nDimPos] = *pItem; - - i++; - } - } - break; + pItem.reset(new PivotChartItem(fValue, nNumberFormat)); } - default: - break; + + if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size()) + m_aCategoriesColumnOrientation.resize(nDimPos + 1); + m_aCategoriesColumnOrientation[nDimPos].push_back(*pItem); + + if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size()) + m_aCategoriesRowOrientation[i].resize(nDimPos + 1); + m_aCategoriesRowOrientation[i][nDimPos] = *pItem; + + i++; } } + break; } + default: + break; } } } } +} + +uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartDataSource(OUString const & aRangeRepresentation) +{ + m_aCategoriesColumnOrientation.clear(); + m_aCategoriesRowOrientation.clear(); + m_aLabels.clear(); + + uno::Reference<chart2::data::XDataSource> xDataSource; + std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences; + + uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); + if (!xContext.is()) + return xDataSource; + + ScDPCollection* pDPCollection = m_pDocument->GetDPCollection(); + ScDPObject* pDPObject = pDPCollection->GetByName(m_sPivotTableName); + + collectPivotTableData(pDPObject); + + uno::Reference<sheet::XDataPilotResults> xDPResults(pDPObject->GetSource(), uno::UNO_QUERY); { std::vector<PivotChartItem> aFirstCategories; commit f0284b535cf91292e21b4dff9a6e5e9559bebb51 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Mon Feb 27 16:43:10 2017 +0100 pivotcharts: set the correct number format for categories Change-Id: I54980c3fbf37816c77fee549fe8b9728ae76ba28 diff --git a/sc/inc/PivotChartDataSequence.hxx b/sc/inc/PivotChartDataSequence.hxx index c6655bb..6f4cc7c 100644 --- a/sc/inc/PivotChartDataSequence.hxx +++ b/sc/inc/PivotChartDataSequence.hxx @@ -51,25 +51,29 @@ struct PivotChartItem double m_fValue; OUString m_aString; bool m_bIsValue; + sal_uInt32 m_nNumberFormat; explicit PivotChartItem() : m_fValue(0.0) , m_aString() , m_bIsValue(true) + , m_nNumberFormat(0) { rtl::math::setNan(&m_fValue); } - explicit PivotChartItem(double fValue) + explicit PivotChartItem(double fValue, sal_uInt32 nNumberFormat) : m_fValue(fValue) , m_aString() , m_bIsValue(true) + , m_nNumberFormat(nNumberFormat) {} explicit PivotChartItem(OUString const & rString) : m_fValue(0.0) , m_aString(rString) , m_bIsValue(false) + , m_nNumberFormat(0) { rtl::math::setNan(&m_fValue); } diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx index c5b9e40..520244c 100644 --- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx +++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx @@ -279,6 +279,7 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha sheet::DataPilotFieldOrientation_HIDDEN)); long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION); + sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO); if (eDimOrient != sheet::DataPilotFieldOrientation_HIDDEN) { @@ -337,17 +338,29 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER || rMember.Flags & sheet::MemberResultFlags::CONTINUE) { - OUString sValue; - if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) - sValue = rMember.Caption; + std::unique_ptr<PivotChartItem> pItem; + + double fValue = rMember.Value; + + if (rtl::math::isNan(fValue)) + { + OUString sValue; + if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) + sValue = rMember.Caption; + pItem.reset(new PivotChartItem(sValue)); + } + else + { + pItem.reset(new PivotChartItem(fValue, nNumberFormat)); + } if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size()) m_aCategoriesColumnOrientation.resize(nDimPos + 1); - m_aCategoriesColumnOrientation[nDimPos].push_back(PivotChartItem(sValue)); + m_aCategoriesColumnOrientation[nDimPos].push_back(*pItem); if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size()) m_aCategoriesRowOrientation[i].resize(nDimPos + 1); - m_aCategoriesRowOrientation[i][nDimPos] = PivotChartItem(sValue); + m_aCategoriesRowOrientation[i][nDimPos] = *pItem; i++; } @@ -393,7 +406,7 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha if (nIndex >= aDataRowVector.size()) aDataRowVector.resize(nIndex + 1); - aDataRowVector[nIndex].push_back(PivotChartItem(rDataResult.Flags ? rDataResult.Value : fNan)); + aDataRowVector[nIndex].push_back(PivotChartItem(rDataResult.Flags ? rDataResult.Value : fNan, 0)); } nIndex++; } diff --git a/sc/source/ui/unoobj/PivotChartDataSequence.cxx b/sc/source/ui/unoobj/PivotChartDataSequence.cxx index 477d1cb..6d68db9 100644 --- a/sc/source/ui/unoobj/PivotChartDataSequence.cxx +++ b/sc/source/ui/unoobj/PivotChartDataSequence.cxx @@ -150,10 +150,19 @@ uno::Sequence<OUString> SAL_CALL PivotChartDataSequence::generateLabel(chart2::d return aSeq; } -sal_Int32 SAL_CALL PivotChartDataSequence::getNumberFormatKeyByIndex(sal_Int32 /*nIndex*/) +sal_Int32 SAL_CALL PivotChartDataSequence::getNumberFormatKeyByIndex(sal_Int32 nIndex) { SolarMutexGuard aGuard; - return 0; + if (nIndex == -1 && !m_aData.empty()) + { + return m_aData[0].m_nNumberFormat; + } + else if (nIndex < 0 && size_t(nIndex) >= m_aData.size()) + { + SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'."); + return 0; + } + return m_aData[size_t(nIndex)].m_nNumberFormat; } // XCloneable ================================================================ commit 4563fa831bd489bc695e6b95796bd4e81c775588 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Mon Feb 27 16:39:25 2017 +0100 fix warnings, clean-up and remove unused thing Change-Id: Ia2061663fe1ee87bc37d9a20766ef0363caa21be diff --git a/sc/inc/PivotChartDataSequence.hxx b/sc/inc/PivotChartDataSequence.hxx index c3f6dd2..c6655bb 100644 --- a/sc/inc/PivotChartDataSequence.hxx +++ b/sc/inc/PivotChartDataSequence.hxx @@ -78,7 +78,8 @@ struct PivotChartItem class PivotChartDataSequence : public PivotChartDataSequence_Base, public SfxListener { public: - explicit PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID, std::vector<PivotChartItem> const & rColumnData); + explicit PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID, + std::vector<PivotChartItem> const & rData); virtual ~PivotChartDataSequence() override; PivotChartDataSequence(const PivotChartDataSequence&) = delete; @@ -163,7 +164,7 @@ private: ScDocument* m_pDocument; OUString m_sPivotTableName; OUString m_aID; - std::vector<PivotChartItem> m_aColumnData; + std::vector<PivotChartItem> m_aData; css::uno::Sequence<OUString> m_aShortSideLabels; css::uno::Sequence<OUString> m_aLongSideLabels; SfxItemPropertySet m_aPropSet; diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx index d3be6e4..c5b9e40 100644 --- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx +++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx @@ -209,78 +209,25 @@ void PivotChartDataProvider::setLabeledDataSequence(uno::Reference<chart2::data: xResult->setLabel(uno::Reference<chart2::data::XDataSequence>(pLabelSequence.release())); } - -enum class ArrangeDirection -{ - COLUMNS, - ROWS -}; - -void lclArrange(std::vector<std::vector<PivotChartItem>>& rResult, - std::vector<std::vector<OUString>>& rInput, - std::vector<OUString>& rPath, - size_t index, ArrangeDirection eDirection) +uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartCategoriesDataSource( + OUString const & rRangeRepresentation, + bool bOrientCol) { - if (index >= rInput.size() - 1) - { - if (eDirection == ArrangeDirection::COLUMNS) - { - for (OUString const & rLabel : rInput[index]) - { - rPath[index] = rLabel; - - size_t i = 0; - rResult.resize(rPath.size()); - for (auto it = rPath.begin(); it != rPath.end(); ++it) - { - OUString const & rEach = *it; - rResult[i].push_back(PivotChartItem(rEach)); - i++; - } - } - } - else if (eDirection == ArrangeDirection::ROWS) - { - size_t i = 0; - for (OUString const & rLabel : rInput[index]) - { - rResult.resize(rInput[index].size()); + uno::Reference<chart2::data::XDataSource> xDataSource; + uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); - rPath[index] = rLabel; + if (!xContext.is()) + return xDataSource; - for (auto it = rPath.begin(); it != rPath.end(); ++it) - { - OUString const & rEach = *it; - rResult[i].push_back(PivotChartItem(rEach)); - } - i++; - } - } - } - else - { - for (OUString const & rLabel : rInput[index]) - { - rPath[index] = rLabel; - lclArrange(rResult, rInput, rPath, index + 1, eDirection); - } - } -} + std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences; -void PivotChartDataProvider::createCategories( - ScDPSaveData* pSaveData, bool bOrientCol, - uno::Reference<uno::XComponentContext>& xContext, - std::vector<uno::Reference<chart2::data::XLabeledDataSequence>>& rOutLabeledSequences) -{ - ArrangeDirection eDirection = bOrientCol ? ArrangeDirection::COLUMNS - : ArrangeDirection::ROWS; if (bOrientCol) { for (std::vector<PivotChartItem> const & rCategories : m_aCategoriesColumnOrientation) { uno::Reference<chart2::data::XLabeledDataSequence> xResult = createLabeledDataSequence(xContext); setLabeledDataSequenceValues(xResult, "categories", "Categories", rCategories); - rOutLabeledSequences.push_back(xResult); + aLabeledSequences.push_back(xResult); } } else @@ -289,27 +236,11 @@ void PivotChartDataProvider::createCategories( { uno::Reference<chart2::data::XLabeledDataSequence> xResult = createLabeledDataSequence(xContext); setLabeledDataSequenceValues(xResult, "categories", "Categories", rCategories); - rOutLabeledSequences.push_back(xResult); + aLabeledSequences.push_back(xResult); } } -} - -uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartCategoriesDataSource(OUString const & aRangeRepresentation, bool bOrientCol) -{ - uno::Reference<chart2::data::XDataSource> xDataSource; - uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext()); - if (!xContext.is()) - return xDataSource; - - std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences; - ScDPCollection* pDPs = m_pDocument->GetDPCollection(); - ScDPObject* pDPObject = pDPs->GetByName(m_sPivotTableName); - ScDPSaveData* pSaveData = pDPObject->GetSaveData(); - - createCategories(pSaveData, bOrientCol, xContext, aLabeledSequences); - - xDataSource.set(new PivotChartDataSource(aRangeRepresentation, aLabeledSequences)); + xDataSource.set(new PivotChartDataSource(rRangeRepresentation, aLabeledSequences)); return xDataSource; } @@ -348,9 +279,6 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha sheet::DataPilotFieldOrientation_HIDDEN)); long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION); - bool bIsDataLayout = ScUnoHelpFunctions::GetBoolProperty(xDimProp, SC_UNO_DP_ISDATALAYOUT); - bool bHasHiddenMember = ScUnoHelpFunctions::GetBoolProperty(xDimProp, SC_UNO_DP_HAS_HIDDEN_MEMBER); - sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO); if (eDimOrient != sheet::DataPilotFieldOrientation_HIDDEN) { @@ -370,12 +298,10 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha { uno::Reference<uno::XInterface> xLevel = ScUnoHelpFunctions::AnyToInterface(xLevels->getByIndex(nLev)); - uno::Reference<container::XNamed> xLevNam(xLevel, uno::UNO_QUERY); + uno::Reference<container::XNamed> xLevName(xLevel, uno::UNO_QUERY); uno::Reference<sheet::XDataPilotMemberResults> xLevRes(xLevel, uno::UNO_QUERY ); - if (xLevNam.is() && xLevRes.is()) + if (xLevName.is() && xLevRes.is()) { - OUString aName = xLevNam->getName(); - switch (eDimOrient) { case sheet::DataPilotFieldOrientation_COLUMN: @@ -392,7 +318,7 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) sValue = rMember.Caption; - if (nDimPos >= m_aLabels[i].size()) + if (size_t(nDimPos) >= m_aLabels[i].size()) m_aLabels[i].resize(nDimPos + 1); m_aLabels[i][nDimPos] = PivotChartItem(sValue); @@ -415,11 +341,11 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE)) sValue = rMember.Caption; - if (nDimPos >= m_aCategoriesColumnOrientation.size()) + if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size()) m_aCategoriesColumnOrientation.resize(nDimPos + 1); m_aCategoriesColumnOrientation[nDimPos].push_back(PivotChartItem(sValue)); - if (nDimPos >= m_aCategoriesRowOrientation[i].size()) + if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size()) m_aCategoriesRowOrientation[i].resize(nDimPos + 1); m_aCategoriesRowOrientation[i][nDimPos] = PivotChartItem(sValue); @@ -459,7 +385,6 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha for (uno::Sequence<sheet::DataResult> const & xDataResults : xDataResultsSequence) { - size_t nIndex = 0; for (sheet::DataResult const & rDataResult : xDataResults) { @@ -536,26 +461,23 @@ uno::Sequence<beans::PropertyValue> SAL_CALL PivotChartDataProvider::detectArgum return aArguments; } -sal_Bool SAL_CALL PivotChartDataProvider::createDataSequenceByRangeRepresentationPossible(const OUString& aRangeRepresentation) +sal_Bool SAL_CALL PivotChartDataProvider::createDataSequenceByRangeRepresentationPossible(const OUString& /*aRangeRepresentation*/) { SolarMutexGuard aGuard; - if (!m_pDocument) - return false; - return true; + return false; } uno::Reference< chart2::data::XDataSequence > SAL_CALL - PivotChartDataProvider::createDataSequenceByRangeRepresentation(const OUString& aRangeRepresentation) + PivotChartDataProvider::createDataSequenceByRangeRepresentation(const OUString& /*aRangeRepresentation*/) { SolarMutexGuard aGuard; uno::Reference<chart2::data::XDataSequence> xResult; - return xResult; } uno::Reference<chart2::data::XDataSequence> SAL_CALL - PivotChartDataProvider::createDataSequenceByValueArray(const OUString& aRole, - const OUString& aRangeRepresentation) + PivotChartDataProvider::createDataSequenceByValueArray(const OUString& /*aRole*/, + const OUString& /*aRangeRepresentation*/) { return uno::Reference<chart2::data::XDataSequence>(); } diff --git a/sc/source/ui/unoobj/PivotChartDataSequence.cxx b/sc/source/ui/unoobj/PivotChartDataSequence.cxx index c30f514..477d1cb 100644 --- a/sc/source/ui/unoobj/PivotChartDataSequence.cxx +++ b/sc/source/ui/unoobj/PivotChartDataSequence.cxx @@ -38,11 +38,12 @@ const SfxItemPropertyMapEntry* lcl_GetDataSequencePropertyMap() return aDataSequencePropertyMap_Impl; } -PivotChartDataSequence::PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID, std::vector<PivotChartItem> const & rColumnData) +PivotChartDataSequence::PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID, + std::vector<PivotChartItem> const & rData) : m_pDocument(pDocument) , m_sPivotTableName(sPivotTableName) , m_aID(sID) - , m_aColumnData(rColumnData) + , m_aData(rData) , m_aShortSideLabels() , m_aLongSideLabels() , m_aPropSet(lcl_GetDataSequencePropertyMap()) @@ -74,10 +75,10 @@ uno::Sequence<uno::Any> SAL_CALL PivotChartDataSequence::getData() if (!m_pDocument) throw uno::RuntimeException(); - uno::Sequence<uno::Any> aSeq(m_aColumnData.size()); + uno::Sequence<uno::Any> aSeq(m_aData.size()); size_t i = 0; - for (PivotChartItem const & rItem : m_aColumnData) + for (PivotChartItem const & rItem : m_aData) { if (rItem.m_bIsValue) aSeq[i] = uno::makeAny<double>(rItem.m_fValue); @@ -96,10 +97,10 @@ uno::Sequence<double> SAL_CALL PivotChartDataSequence::getNumericalData() if (!m_pDocument) throw uno::RuntimeException(); - uno::Sequence<double> aSeq(m_aColumnData.size()); + uno::Sequence<double> aSeq(m_aData.size()); size_t i = 0; - for (PivotChartItem const & rItem : m_aColumnData) + for (PivotChartItem const & rItem : m_aData) { aSeq[i] = rItem.m_fValue; i++; @@ -115,10 +116,10 @@ uno::Sequence<OUString> SAL_CALL PivotChartDataSequence::getTextualData() if (!m_pDocument) throw uno::RuntimeException(); - uno::Sequence<OUString> aSeq(m_aColumnData.size()); + uno::Sequence<OUString> aSeq(m_aData.size()); size_t i = 0; - for (PivotChartItem const & rItem : m_aColumnData) + for (PivotChartItem const & rItem : m_aData) { if (!rItem.m_bIsValue) aSeq[i] = rItem.m_aString; @@ -162,7 +163,7 @@ uno::Reference<util::XCloneable> SAL_CALL PivotChartDataSequence::createClone() SolarMutexGuard aGuard; std::unique_ptr<PivotChartDataSequence> pClone; - pClone.reset(new PivotChartDataSequence(m_pDocument, m_sPivotTableName, m_aID, m_aColumnData)); + pClone.reset(new PivotChartDataSequence(m_pDocument, m_sPivotTableName, m_aID, m_aData)); pClone->setRole(m_aRole); pClone->setShortSideLabels(m_aShortSideLabels); pClone->setLongSideLabels(m_aLongSideLabels); commit 4d97a3093ad2d802aba8b5f525c93cf695a1b07f Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Feb 26 22:48:06 2017 +0100 sc: Pivot chart specific data provider Adds a pivot chart specific data provider which uses provides the data from a pivot table to the associated chart. Change-Id: Ifbc5511645ef7ca8f6ff39095f74f76892a0d7bd diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 9068e50..14ddec0 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -573,6 +573,9 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/unoobj/notesuno \ sc/source/ui/unoobj/optuno \ sc/source/ui/unoobj/pageuno \ + sc/source/ui/unoobj/PivotChartDataProvider \ + sc/source/ui/unoobj/PivotChartDataSource \ + sc/source/ui/unoobj/PivotChartDataSequence \ sc/source/ui/unoobj/servuno \ sc/source/ui/unoobj/shapeuno \ sc/source/ui/unoobj/srchuno \ diff --git a/sc/inc/PivotChartDataProvider.hxx b/sc/inc/PivotChartDataProvider.hxx new file mode 100644 index 0000000..e92f847 --- /dev/null +++ b/sc/inc/PivotChartDataProvider.hxx @@ -0,0 +1,158 @@ +/* -*- 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 INCLUDED_SC_INC_PIVOTCHARTDATAPROVIDER_HXX +#define INCLUDED_SC_INC_PIVOTCHARTDATAPROVIDER_HXX + +#include "cellsuno.hxx" +#include "externalrefmgr.hxx" +#include "types.hxx" + +#include <com/sun/star/chart2/data/XDataProvider.hpp> +#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/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> + +#include <svl/lstner.hxx> +#include <cppuhelper/implbase.hxx> +#include <rtl/ustring.hxx> +#include <svl/itemprop.hxx> + +#include "dpsave.hxx" + +#include <memory> +#include <vector> + +namespace sc +{ + +class PivotChartItem; + +typedef cppu::WeakImplHelper<css::chart2::data::XDataProvider, + css::beans::XPropertySet, + css::lang::XServiceInfo, + css::util::XModifyBroadcaster> + PivotChartDataProvider_Base; + +class PivotChartDataProvider : public PivotChartDataProvider_Base, public SfxListener +{ +public: + + explicit PivotChartDataProvider(ScDocument* pDoc, OUString const& sPivotTableName); + virtual ~PivotChartDataProvider() override; + virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override; + + // XDataProvider + virtual sal_Bool SAL_CALL createDataSourcePossible(const css::uno::Sequence<css::beans::PropertyValue>& aArguments) override; + + virtual css::uno::Reference< + css::chart2::data::XDataSource > SAL_CALL createDataSource( + const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override; + + virtual css::uno::Sequence< + css::beans::PropertyValue > SAL_CALL detectArguments( + const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource ) override; + + virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible( + const OUString& aRangeRepresentation ) override; + + virtual css::uno::Reference< + css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation( + const OUString& aRangeRepresentation ) override; + + virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL + createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation ) override; + + virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override; + + // XPropertySet + virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override; + + virtual void SAL_CALL setPropertyValue( + const OUString& rPropertyName, + const css::uno::Any& rValue) override; + + virtual css::uno::Any SAL_CALL getPropertyValue( + const OUString& rPropertyName) override; + + virtual void SAL_CALL addPropertyChangeListener( + const OUString& rPropertyName, + const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override; + + virtual void SAL_CALL removePropertyChangeListener( + const OUString& rPropertyName, + const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override; + + virtual void SAL_CALL addVetoableChangeListener( + const OUString& rPropertyName, + const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override; + + virtual void SAL_CALL removeVetoableChangeListener( + const OUString& rPropertyName, + const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override; + + // XModifyBroadcaster + virtual void SAL_CALL addModifyListener( + const css::uno::Reference<css::util::XModifyListener>& aListener) override; + + virtual void SAL_CALL removeModifyListener( + const css::uno::Reference<css::util::XModifyListener>& aListener) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + + virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override; + + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + +private: + + css::uno::Reference<css::chart2::data::XDataSource> + createPivotChartDataSource(OUString const & aRangeRepresentation); + css::uno::Reference<css::chart2::data::XDataSource> + createPivotChartCategoriesDataSource(OUString const & aRangeRepresentation, bool bOrientCol); + + css::uno::Reference<css::chart2::data::XLabeledDataSequence> + createLabeledDataSequence(css::uno::Reference<css::uno::XComponentContext>& rContext); + + void setLabeledDataSequenceValues(css::uno::Reference<css::chart2::data::XLabeledDataSequence> & xResult, + OUString const & sRoleValues, OUString const & sIdValues, + std::vector<PivotChartItem> const & rValues); + + void setLabeledDataSequence(css::uno::Reference<css::chart2::data::XLabeledDataSequence> & xResult, + OUString const & sRoleValues, OUString const & sIdValues, + std::vector<PivotChartItem> const & rValues, + OUString const & sRoleLabel, OUString const & sIdLabel, + std::vector<PivotChartItem> const & rLabel); + void createCategories( + ScDPSaveData* pSaveData, bool bOrientCol, + css::uno::Reference<css::uno::XComponentContext>& rContext, + std::vector<css::uno::Reference<css::chart2::data::XLabeledDataSequence>>& rOutLabeledSequences); + + ScDocument* m_pDocument; + OUString m_sPivotTableName; + SfxItemPropertySet m_aPropSet; + bool m_bIncludeHiddenCells; + + std::vector<std::vector<PivotChartItem>> m_aCategoriesColumnOrientation; + std::vector<std::vector<PivotChartItem>> m_aCategoriesRowOrientation; + + std::vector<css::uno::Reference<css::util::XModifyListener>> m_aValueListeners; +}; + +} + +#endif // INCLUDED_SC_INC_PIVOTCHARTDATAPROVIDER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/PivotChartDataSequence.hxx b/sc/inc/PivotChartDataSequence.hxx new file mode 100644 index 0000000..c3f6dd2 --- /dev/null +++ b/sc/inc/PivotChartDataSequence.hxx @@ -0,0 +1,178 @@ +/* -*- 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 INCLUDED_SC_INC_PIVOTCHARTDATASEQUENCE_HXX +#define INCLUDED_SC_INC_PIVOTCHARTDATASEQUENCE_HXX + +#include <com/sun/star/chart2/data/XDataProvider.hpp> +#include <com/sun/star/chart2/data/XDataSequence.hpp> +#include <com/sun/star/chart2/data/XTextualDataSequence.hpp> +#include <com/sun/star/chart2/data/XNumericalDataSequence.hpp> +#include <com/sun/star/chart2/data/XLabeledDataSequence.hpp> +#include <com/sun/star/chart2/data/DataSequenceRole.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> + +#include <com/sun/star/sheet/XDataPilotResults.hpp> + +#include <svl/lstner.hxx> +#include <svl/itemprop.hxx> +#include <cppuhelper/implbase.hxx> +#include <rtl/math.hxx> + +#include "unonames.hxx" +#include "document.hxx" + +#include "dpsave.hxx" + +namespace sc +{ + +typedef cppu::WeakImplHelper<css::chart2::data::XDataSequence, + css::chart2::data::XTextualDataSequence, + css::chart2::data::XNumericalDataSequence, + css::util::XCloneable, + css::util::XModifyBroadcaster, + css::beans::XPropertySet, + css::lang::XServiceInfo> + PivotChartDataSequence_Base; + +struct PivotChartItem +{ + double m_fValue; + OUString m_aString; + bool m_bIsValue; + + explicit PivotChartItem() + : m_fValue(0.0) + , m_aString() + , m_bIsValue(true) + { + rtl::math::setNan(&m_fValue); + } + + explicit PivotChartItem(double fValue) + : m_fValue(fValue) + , m_aString() + , m_bIsValue(true) + {} + + explicit PivotChartItem(OUString const & rString) + : m_fValue(0.0) + , m_aString(rString) + , m_bIsValue(false) + { + rtl::math::setNan(&m_fValue); + } +}; + +class PivotChartDataSequence : public PivotChartDataSequence_Base, public SfxListener +{ +public: + explicit PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID, std::vector<PivotChartItem> const & rColumnData); + + virtual ~PivotChartDataSequence() override; + PivotChartDataSequence(const PivotChartDataSequence&) = delete; ... etc. - the rest is truncated
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits