diff options
-rw-r--r-- | chart2/source/controller/main/ControllerCommandDispatch.cxx | 2 | ||||
-rw-r--r-- | chart2/source/tools/InternalDataProvider.cxx | 4 | ||||
-rw-r--r-- | offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl | 4 | ||||
-rw-r--r-- | sc/inc/PivotTableDataProvider.hxx | 8 | ||||
-rw-r--r-- | sc/source/ui/unoobj/PivotTableDataProvider.cxx | 62 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLChartContext.cxx | 20 |
6 files changed, 64 insertions, 36 deletions
diff --git a/chart2/source/controller/main/ControllerCommandDispatch.cxx b/chart2/source/controller/main/ControllerCommandDispatch.cxx index 89f6c1c9f36f..16b1f5902f75 100644 --- a/chart2/source/controller/main/ControllerCommandDispatch.cxx +++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx @@ -414,7 +414,7 @@ void ModelState::update( const Reference< frame::XModel > & xModel ) { ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartDoc.get()); bHasOwnData = rModel.hasInternalDataProvider(); - bHasDataFromPivotTable = rModel.isDataFromPivotTable(); + bHasDataFromPivotTable = !bHasOwnData && rModel.isDataFromPivotTable(); } bHasMainTitle = TitleHelper::getTitle( TitleHelper::MAIN_TITLE, xModel ).is(); diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx index 7d3ff92bb828..fa77624adc44 100644 --- a/chart2/source/tools/InternalDataProvider.cxx +++ b/chart2/source/tools/InternalDataProvider.cxx @@ -1222,6 +1222,10 @@ OUString SAL_CALL InternalDataProvider::convertRangeToXML( const OUString& aRang OUString SAL_CALL InternalDataProvider::convertRangeFromXML( const OUString& aXMLRange ) { + const OUString aPivotTableID("PT@"); + if (aXMLRange.startsWith(aPivotTableID)) + return aXMLRange.copy(aPivotTableID.getLength(), aXMLRange.getLength() - aPivotTableID.getLength()); + XMLRangeHelper::CellRange aRange( XMLRangeHelper::getCellRangeFromXMLString( aXMLRange )); if( aRange.aUpperLeft.bIsEmpty ) { diff --git a/offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl b/offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl index 731988bc2167..540304113b89 100644 --- a/offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl +++ b/offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl @@ -58,6 +58,10 @@ interface XPivotTableDataProvider : com::sun::star::uno::XInterface */ void setPivotTableName([in] string sPivotTableName); + /** check if the associated pivot table exists + */ + boolean hasPivotTable(); + /** creates a single data sequence of values for the given data series index. * * @param nIndex diff --git a/sc/inc/PivotTableDataProvider.hxx b/sc/inc/PivotTableDataProvider.hxx index 06d6778a8661..67a65f37b07d 100644 --- a/sc/inc/PivotTableDataProvider.hxx +++ b/sc/inc/PivotTableDataProvider.hxx @@ -88,6 +88,8 @@ public: virtual void SAL_CALL setPivotTableName(const OUString& sPivotTableName) override; + virtual sal_Bool SAL_CALL hasPivotTable() override; + virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL createDataSequenceOfValuesByIndex(sal_Int32 nIndex) override; virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL @@ -147,12 +149,6 @@ private: OUString const & sRoleValues, OUString const & sIdValues, std::vector<ValueAndFormat> const & rValues); - void setLabeledDataSequence(css::uno::Reference<css::chart2::data::XLabeledDataSequence> & xResult, - OUString const & sRoleValues, OUString const & sIdValues, - std::vector<ValueAndFormat> const & rValues, - OUString const & sRoleLabel, OUString const & sIdLabel, - std::vector<ValueAndFormat> const & rLabel); - css::uno::Reference<css::chart2::data::XDataSequence> assignLabelsToDataSequence(size_t nIndex); css::uno::Reference<css::chart2::data::XDataSequence> assignValuesToDataSequence(size_t nIndex); diff --git a/sc/source/ui/unoobj/PivotTableDataProvider.cxx b/sc/source/ui/unoobj/PivotTableDataProvider.cxx index f86f6106c331..112acbe96a48 100644 --- a/sc/source/ui/unoobj/PivotTableDataProvider.cxx +++ b/sc/source/ui/unoobj/PivotTableDataProvider.cxx @@ -47,6 +47,9 @@ namespace sc { namespace { +const OUString constIdCategories("categories"); +const OUString constIdLabel("label"); +const OUString constIdData("data"); const SfxItemPropertyMapEntry* lcl_GetDataProviderPropertyMap() { @@ -70,12 +73,17 @@ uno::Reference<frame::XModel> lcl_GetXModel(ScDocument * pDoc) OUString lcl_identifierForData(sal_Int32 index) { - return "Data " + OUString::number(index + 1); + return "PT@" + constIdData + " " + OUString::number(index); } OUString lcl_identifierForLabel(sal_Int32 index) { - return "Label " + OUString::number(index + 1); + return "PT@" + constIdLabel + " " + OUString::number(index); +} + +OUString lcl_identifierForCategories() +{ + return "PT@" + constIdCategories; } } // end anonymous namespace @@ -146,6 +154,7 @@ uno::Reference<chart2::data::XDataSource> SAL_CALL PivotTableDataProvider::createDataSource(const uno::Sequence<beans::PropertyValue>& aArguments) { SolarMutexGuard aGuard; + if (!m_pDocument) throw uno::RuntimeException(); @@ -186,7 +195,7 @@ uno::Reference<chart2::data::XDataSource> SAL_CALL uno::Reference<chart2::data::XDataSource> xResult; - if (aRangeRepresentation == "Categories") + if (aRangeRepresentation == lcl_identifierForCategories()) xResult = createCategoriesDataSource(bOrientCol); else xResult = createValuesDataSource(); @@ -223,23 +232,14 @@ PivotTableDataProvider::createCategoriesDataSource(bool bOrientationIsColumn) uno::Reference<chart2::data::XDataSource> xDataSource; std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences; - if (bOrientationIsColumn) - { - for (std::vector<ValueAndFormat> const & rCategories : m_aCategoriesColumnOrientation) - { - uno::Reference<chart2::data::XLabeledDataSequence> xResult = newLabeledDataSequence(); - setLabeledDataSequenceValues(xResult, "categories", "Categories", rCategories); - aLabeledSequences.push_back(xResult); - } - } - else + std::vector<std::vector<ValueAndFormat>> const & rCategoriesVector = bOrientationIsColumn ? m_aCategoriesColumnOrientation + : m_aCategoriesRowOrientation; + + for (std::vector<ValueAndFormat> const & rCategories : rCategoriesVector) { - for (std::vector<ValueAndFormat> const & rCategories : m_aCategoriesRowOrientation) - { - uno::Reference<chart2::data::XLabeledDataSequence> xResult = newLabeledDataSequence(); - setLabeledDataSequenceValues(xResult, "categories", "Categories", rCategories); - aLabeledSequences.push_back(xResult); - } + uno::Reference<chart2::data::XLabeledDataSequence> xResult = newLabeledDataSequence(); + setLabeledDataSequenceValues(xResult, "categories", lcl_identifierForCategories(), rCategories); + aLabeledSequences.push_back(xResult); } xDataSource.set(new PivotTableDataSource(aLabeledSequences)); @@ -527,8 +527,8 @@ PivotTableDataProvider::assignValuesToDataSequence(size_t nIndex) OUString sDataID = lcl_identifierForData(nIndex); std::vector<ValueAndFormat> const & rRowOfData = m_aDataRowVector[size_t(nIndex)]; - std::unique_ptr<PivotTableDataSequence> pSequence(new PivotTableDataSequence(m_pDocument, m_sPivotTableName, - sDataID, rRowOfData)); + std::unique_ptr<PivotTableDataSequence> pSequence; + pSequence.reset(new PivotTableDataSequence(m_pDocument, m_sPivotTableName, sDataID, rRowOfData)); pSequence->setRole("values-y"); xDataSequence.set(pSequence.release()); return xDataSequence; @@ -591,7 +591,7 @@ uno::Reference<chart2::data::XDataSource> std::back_inserter(aFirstCategories)); } uno::Reference<chart2::data::XLabeledDataSequence> xResult = newLabeledDataSequence(); - setLabeledDataSequenceValues(xResult, "categories", "Categories", aFirstCategories); + setLabeledDataSequenceValues(xResult, "categories", lcl_identifierForCategories(), aFirstCategories); aLabeledSequences.push_back(xResult); } @@ -704,6 +704,20 @@ void PivotTableDataProvider::setPivotTableName(const OUString& sPivotTableName) m_sPivotTableName = sPivotTableName; } +sal_Bool PivotTableDataProvider::hasPivotTable() +{ + if (m_sPivotTableName.isEmpty()) + return false; + + ScDPCollection* pDPCollection = m_pDocument->GetDPCollection(); + ScDPObject* pDPObject = pDPCollection->GetByName(m_sPivotTableName); + + if (pDPObject) + return true; + + return false; +} + uno::Reference<chart2::data::XDataSequence> PivotTableDataProvider::createDataSequenceOfValuesByIndex(sal_Int32 nIndex) { @@ -741,8 +755,8 @@ uno::Reference<css::chart2::data::XDataSequence> std::vector<ValueAndFormat> const & rCategories = m_aCategoriesColumnOrientation[0]; - std::unique_ptr<PivotTableDataSequence> pSequence(new PivotTableDataSequence(m_pDocument, m_sPivotTableName, - "Categories", rCategories)); + std::unique_ptr<PivotTableDataSequence> pSequence; + pSequence.reset(new PivotTableDataSequence(m_pDocument, m_sPivotTableName, lcl_identifierForCategories(), rCategories)); pSequence->setRole("categories"); xDataSequence.set(uno::Reference<chart2::data::XDataSequence>(pSequence.release())); diff --git a/xmloff/source/chart/SchXMLChartContext.cxx b/xmloff/source/chart/SchXMLChartContext.cxx index 1dc1c145e16e..8e264843e2dd 100644 --- a/xmloff/source/chart/SchXMLChartContext.cxx +++ b/xmloff/source/chart/SchXMLChartContext.cxx @@ -241,6 +241,13 @@ SchXMLChartContext::SchXMLChartContext( SchXMLImportHelper& rImpHelper, SchXMLChartContext::~SchXMLChartContext() {} +bool lcl_hasServiceName(Reference<lang::XMultiServiceFactory> & xFactory, OUString const & rServiceName) +{ + const uno::Sequence<OUString> aServiceNames(xFactory->getAvailableServiceNames()); + + return std::find(aServiceNames.begin(), aServiceNames.end(), rServiceName) != aServiceNames.end(); +} + void lcl_setDataProvider(uno::Reference<chart2::XChartDocument> const & xChartDoc, OUString const & sDataPilotSource) { if (!xChartDoc.is()) @@ -264,21 +271,24 @@ void lcl_setDataProvider(uno::Reference<chart2::XChartDocument> const & xChartDo if (bHasDataPilotSource) aDataProviderServiceName = "com.sun.star.chart2.data.PivotTableDataProvider"; - const uno::Sequence<OUString> aServiceNames(xFact->getAvailableServiceNames()); - - if (std::find(aServiceNames.begin(), aServiceNames.end(), aDataProviderServiceName) != aServiceNames.end()) + if (lcl_hasServiceName(xFact, aDataProviderServiceName)) { Reference<chart2::data::XDataProvider> xProvider(xFact->createInstance(aDataProviderServiceName), uno::UNO_QUERY); if (xProvider.is()) { - xDataReceiver->attachDataProvider(xProvider); if (bHasDataPilotSource) { Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xProvider, uno::UNO_QUERY); xPivotTableDataProvider->setPivotTableName(sDataPilotSource); + xDataReceiver->attachDataProvider(xProvider); + bHasOwnData = !xPivotTableDataProvider->hasPivotTable(); + } + else + { + xDataReceiver->attachDataProvider(xProvider); + bHasOwnData = false; } - bHasOwnData = false; } } } |