[Libreoffice-commits] core.git: Branch 'private/swe/libreoffice-5-2+backports' - chart2/inc chart2/source offapi/com offapi/UnoApi_offapi.mk sc/inc sc/source
Vasily Melenchuk
Vasily.Melenchuk at cib.de
Fri Dec 22 17:59:23 UTC 2017
Rebased ref, commits from common ancestor:
commit 5a8c4244d33ad257d4cd81b40c612ff294015492
Author: Vasily Melenchuk <Vasily.Melenchuk at cib.de>
Date: Fri Nov 10 18:37:25 2017 +0300
tdf#113572: allow switching to data range in copypasted chart
- enable data range toolbar button for charts with internal
data table and possiblilty to switch to data range
- show warning before destoying data table
- recreation of data provider
Conflicts:
chart2/inc/ChartModel.hxx
chart2/inc/strings.hrc
chart2/source/controller/main/ChartController.cxx
chart2/source/controller/main/ControllerCommandDispatch.cxx
sc/source/ui/unoobj/docuno.cxx
Change-Id: I46c703b579cd32405b02543aa5b9e3a74e4b36b6
Reviewed-on: https://gerrit.libreoffice.org/46981
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/chart2/inc/ChartModel.hxx b/chart2/inc/ChartModel.hxx
index b3caaad412c4..f254103e961f 100644
--- a/chart2/inc/ChartModel.hxx
+++ b/chart2/inc/ChartModel.hxx
@@ -579,6 +579,8 @@ public:
void getNextTimePoint();
void setTimeBasedRange(sal_Int32 nStart, sal_Int32 nEnd);
+ void removeDataProviders();
+
OpenGLWindow* getOpenGLWindow() { return mpOpenGLWindow;}
private:
diff --git a/chart2/source/controller/dialogs/Strings.src b/chart2/source/controller/dialogs/Strings.src
index c9d18eb62391..96f7f5598b2a 100644
--- a/chart2/source/controller/dialogs/Strings.src
+++ b/chart2/source/controller/dialogs/Strings.src
@@ -34,6 +34,11 @@ String STR_DLG_STEPPED_LINE_PROPERTIES
Text [ en-US ] = "Stepped Lines" ;
};
+String STR_DLG_REMOVE_DATA_TABLE
+{
+ Text [ en-US ] = "Do you want to delete data table and switch to data ranges?" ;
+};
+
String STR_PAGE_CHARTTYPE
{
Text [ en-US ] = "Chart Type" ;
diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx
index 8482c16a6513..f87f5c74f798 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -66,12 +66,14 @@
#include <com/sun/star/ui/XSidebar.hpp>
#include <com/sun/star/chart2/XChartTypeContainer.hpp>
#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
+#include <com/sun/star/chart2/XDataProviderCreator.hpp>
#include <svx/sidebar/SelectionChangeHandler.hxx>
#include <vcl/msgbox.hxx>
#include <toolkit/awt/vclxwindow.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/svapp.hxx>
+#include <vcl/layout.hxx>
#include <osl/mutex.hxx>
#include <sfx2/sidebar/SidebarController.hxx>
@@ -1395,21 +1397,56 @@ void ChartController::executeDispatch_SourceData()
//convert properties to ItemSet
uno::Reference< XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY );
OSL_ENSURE( xChartDoc.is(), "Invalid XChartDocument" );
- if( !xChartDoc.is())
+ if( !xChartDoc.is() )
return;
- UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard(
- SCH_RESSTR(STR_ACTION_EDIT_DATA_RANGES), m_xUndoManager );
- if( xChartDoc.is())
+ // If there is a data table we should ask user if we really want to destroy it
+ // and switch to data ranges.
+ ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartDoc.get());
+ if ( rModel.hasInternalDataProvider() )
{
+ // Check if we will able to create data provider later
+ Reference< lang::XServiceInfo > xParentServiceInfo( rModel.getParent(), uno::UNO_QUERY );
+ if ( !xParentServiceInfo.is() || !xParentServiceInfo->supportsService("com.sun.star.chart2.XDataProviderCreator") )
+ return;
+
SolarMutexGuard aSolarGuard;
- ScopedVclPtrInstance< ::chart::DataSourceDialog > aDlg( m_pChartWindow, xChartDoc, m_xCC );
- if( aDlg->Execute() == RET_OK )
+
+ ScopedVclPtrInstance< MessageDialog > aQueryBox( m_pChartWindow, SchResId( STR_DLG_REMOVE_DATA_TABLE ), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
+
+ // If "No" then just return
+ if (aQueryBox->Execute() == RET_NO)
+ return;
+
+ // Remove data table
+ rModel.removeDataProviders();
+
+ // Ask parent document to create new data provider
+ css::uno::Reference< com::sun::star::chart2::XDataProviderCreator > xCreatorDoc(
+ rModel.getParent(), uno::UNO_QUERY );
+ OSL_ENSURE( xCreatorDoc.is(), "Invalid XDataProviderCreator" );
+
+ if ( xCreatorDoc.is() )
{
- impl_adaptDataSeriesAutoResize();
- aUndoGuard.commit();
+ uno::Reference< data::XDataProvider > xDataProvider = xCreatorDoc->createDataProvider();
+ OSL_ENSURE( xCreatorDoc.is(), "Data provider was not created" );
+ if ( xDataProvider.is() )
+ {
+ rModel.attachDataProvider(xDataProvider);
+ }
}
}
+
+ UndoLiveUpdateGuard aUndoGuard(
+ SchResId(STR_ACTION_EDIT_DATA_RANGES), m_xUndoManager);
+
+ SolarMutexGuard aSolarGuard;
+ ScopedVclPtrInstance< ::chart::DataSourceDialog > aDlg( m_pChartWindow, xChartDoc, m_xCC );
+ if( aDlg->Execute() == RET_OK )
+ {
+ impl_adaptDataSeriesAutoResize();
+ aUndoGuard.commit();
+ }
}
void ChartController::executeDispatch_MoveSeries( bool bForward )
diff --git a/chart2/source/controller/main/ControllerCommandDispatch.cxx b/chart2/source/controller/main/ControllerCommandDispatch.cxx
index 3f32b4db1558..63e56bdeb156 100644
--- a/chart2/source/controller/main/ControllerCommandDispatch.cxx
+++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx
@@ -528,6 +528,8 @@ void ControllerCommandDispatch::updateCommandAvailability()
bool bShapeContext = m_pChartController && m_pChartController->isShapeContext();
bool bEnableDataTableDialog = false;
+ bool bCanCreateDataProvider = false;
+
if ( m_xController.is() )
{
Reference< beans::XPropertySet > xProps( m_xController->getModel(), uno::UNO_QUERY );
@@ -542,6 +544,19 @@ void ControllerCommandDispatch::updateCommandAvailability()
ASSERT_EXCEPTION( e );
}
}
+
+ Reference< chart2::XChartDocument > xChartDoc(m_xController->getModel(), uno::UNO_QUERY);
+ OSL_ENSURE(xChartDoc.is(), "Invalid XChartDocument");
+ if ( xChartDoc.is() )
+ {
+ ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartDoc.get());
+ Reference< lang::XServiceInfo > xParentServiceInfo(rModel.getParent(), uno::UNO_QUERY);
+ OSL_ENSURE(xParentServiceInfo.is(), "Invalid XServiceInfo");
+ if ( xParentServiceInfo.is() )
+ {
+ bCanCreateDataProvider = xParentServiceInfo->supportsService("com.sun.star.chart2.XDataProviderCreator");
+ }
+ }
}
// edit commands
@@ -614,7 +629,7 @@ void ControllerCommandDispatch::updateCommandAvailability()
m_aCommandAvailability[ ".uno:FormatLegend" ] = m_aCommandAvailability[ ".uno:Legend" ];
// depending on own data
- m_aCommandAvailability[ ".uno:DataRanges" ] = bIsWritable && bModelStateIsValid && (! m_apModelState->bHasOwnData);
+ m_aCommandAvailability[ ".uno:DataRanges" ] = bIsWritable && bModelStateIsValid && bCanCreateDataProvider;
m_aCommandAvailability[ ".uno:DiagramData" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasOwnData && bEnableDataTableDialog;
// titles
diff --git a/chart2/source/inc/Strings.hrc b/chart2/source/inc/Strings.hrc
index 950050ba228f..f08d88be7860 100644
--- a/chart2/source/inc/Strings.hrc
+++ b/chart2/source/inc/Strings.hrc
@@ -22,7 +22,7 @@
// this includes no link dependency
#include <svl/solar.hrc>
-//next free is 305
+//next free is 306
//chart types
//see Strings_ChartTypes.src
@@ -220,6 +220,8 @@
#define STR_CONTROLTEXT_ERROR_BARS_FROM_DATA (RID_APP_START + 276)
#define STR_DLG_CHART_WIZARD (RID_APP_START + 228)
+#define STR_DLG_REMOVE_DATA_TABLE (RID_APP_START + 305)
+
#define STR_PAGE_CHART_ELEMENTS (RID_APP_START + 229)
#define STR_PAGE_CHART_LOCATION (RID_APP_START + 230)
diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx
index 48ec54304805..93f5f1c76408 100644
--- a/chart2/source/model/main/ChartModel.cxx
+++ b/chart2/source/model/main/ChartModel.cxx
@@ -813,6 +813,14 @@ void SAL_CALL ChartModel::createInternalDataProvider( sal_Bool bCloneExistingDat
setModified( true );
}
+void ChartModel::removeDataProviders()
+{
+ if (m_xInternalDataProvider.is())
+ m_xInternalDataProvider.clear();
+ if (m_xDataProvider.is())
+ m_xDataProvider.clear();
+}
+
sal_Bool SAL_CALL ChartModel::hasInternalDataProvider()
throw (uno::RuntimeException, std::exception)
{
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 331de34d25b8..4b040db1d6e1 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -2030,6 +2030,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/chart2,\
XCoordinateSystem \
XCoordinateSystemContainer \
XDataInterpreter \
+ XDataProviderCreator \
XDataSeries \
XDataSeriesContainer \
XDefaultSizeTransmitter \
diff --git a/offapi/com/sun/star/chart2/XDataProviderCreator.idl b/offapi/com/sun/star/chart2/XDataProviderCreator.idl
new file mode 100644
index 000000000000..c7bac38e4b1d
--- /dev/null
+++ b/offapi/com/sun/star/chart2/XDataProviderCreator.idl
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef __com_sun_star_chart2_XDataProviderCreator_idl__
+#define __com_sun_star_chart2_XDataProviderCreator_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+#include <com/sun/star/uno/chart/data/XDataProvider.idl>
+
+module com { module sun { module star { module chart2 {
+
+
+/** creates a chart2 data provider for given document
+
+ */
+interface XDataProviderCreator : com::sun::star::uno::XInterface
+{
+
+ /** creates a data provider for chart2
+
+ @see com::sun::star::chart2::data::XDataProvider
+
+ @since LibreOffice 6.1
+ */
+ com::sun::star::chart2::data::XDataProvider createDataProvider();
+
+};
+
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index b041c0e79487..f9e01f60b323 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -37,6 +37,8 @@
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheets2.hpp>
#include <com/sun/star/sheet/XDocumentAuditing.hpp>
+#include <com/sun/star/chart2/data/XDataProvider.hpp>
+#include <com/sun/star/chart2/XDataProviderCreator.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/util/XProtectable.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
@@ -85,6 +87,7 @@ class SC_DLLPUBLIC ScModelObj : public SfxBaseModel,
public SvxFmMSFactory, ///< derived from XMultiServiceFactory
public css::lang::XServiceInfo,
public css::util::XChangesNotifier,
+ public css::chart2::XDataProviderCreator,
public css::sheet::opencl::XOpenCLSelection
{
private:
@@ -155,6 +158,10 @@ public:
virtual css::uno::Reference< css::sheet::XSpreadsheets > SAL_CALL
getSheets() throw(css::uno::RuntimeException, std::exception) override;
+ /// XDataProviderCreator
+ virtual ::css::uno::Reference< css::chart2::data::XDataProvider > SAL_CALL
+ createDataProvider() throw (com::sun::star::uno::RuntimeException, std::exception) override;
+
/// XStyleFamiliesSupplier
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL
getStyleFamilies() throw(css::uno::RuntimeException, std::exception) override;
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 8776c6490e49..6837bc43a253 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -218,6 +218,7 @@ using sc::TwipsToHMM;
#define SCMODELOBJ_SERVICE "com.sun.star.sheet.SpreadsheetDocument"
#define SCDOCSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetDocumentSettings"
#define SCDOC_SERVICE "com.sun.star.document.OfficeDocument"
+#define SCDATAPROVIDERCREATOR_SERVICE "com.sun.star.chart2.XDataProviderCreator"
SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" )
SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" )
@@ -980,6 +981,7 @@ uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
SC_QUERYINTERFACE( lang::XServiceInfo )
SC_QUERYINTERFACE( util::XChangesNotifier )
SC_QUERYINTERFACE( sheet::opencl::XOpenCLSelection )
+ SC_QUERYINTERFACE( chart2::XDataProviderCreator )
uno::Any aRet(SfxBaseModel::queryInterface( rType ));
if ( !aRet.hasValue()
@@ -1148,6 +1150,16 @@ uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno:
return nullptr;
}
+css::uno::Reference< ::css::chart2::data::XDataProvider > SAL_CALL ScModelObj::createDataProvider() throw (com::sun::star::uno::RuntimeException, std::exception)
+{
+ if (pDocShell)
+ {
+ return css::uno::Reference< ::css::chart2::data::XDataProvider > (
+ ScServiceProvider::MakeInstance(ScServiceProvider::Type::CHDATAPROV, pDocShell), uno::UNO_QUERY);
+ }
+ return nullptr;
+}
+
// XStyleFamiliesSupplier
uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies()
@@ -2601,10 +2613,11 @@ sal_Bool SAL_CALL ScModelObj::supportsService( const OUString& rServiceName )
uno::Sequence<OUString> SAL_CALL ScModelObj::getSupportedServiceNames()
throw(uno::RuntimeException, std::exception)
{
- uno::Sequence<OUString> aRet(3);
+ uno::Sequence<OUString> aRet(4);
aRet[0] = SCMODELOBJ_SERVICE;
aRet[1] = SCDOCSETTINGS_SERVICE;
aRet[2] = SCDOC_SERVICE;
+ aRet[3] = SCDATAPROVIDERCREATOR_SERVICE;
return aRet;
}
More information about the Libreoffice-commits
mailing list