diff options
author | Vasily Melenchuk <Vasily.Melenchuk@cib.de> | 2017-11-10 18:37:25 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-01-10 01:24:06 +0100 |
commit | 0074951704022d173a5fdb9df933f47be1dcbb91 (patch) | |
tree | 73503c1938be3b4757ecaa082f6307396f296b8b | |
parent | 8c15140f92a0dff2aa7cc9e1f8bb5d8a0df34bf8 (diff) |
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
Change-Id: I2a08b723be80d411e970bfe2ee53dee7d3d52faa
Reviewed-on: https://gerrit.libreoffice.org/44605
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | chart2/inc/ChartModel.hxx | 2 | ||||
-rw-r--r-- | chart2/inc/strings.hrc | 1 | ||||
-rw-r--r-- | chart2/source/controller/main/ChartController.cxx | 53 | ||||
-rw-r--r-- | chart2/source/controller/main/ControllerCommandDispatch.cxx | 18 | ||||
-rw-r--r-- | chart2/source/model/main/ChartModel.cxx | 8 | ||||
-rw-r--r-- | offapi/UnoApi_offapi.mk | 1 | ||||
-rw-r--r-- | offapi/com/sun/star/chart2/XDataProviderAccess.idl | 40 | ||||
-rw-r--r-- | sc/inc/docuno.hxx | 7 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 14 |
9 files changed, 133 insertions, 11 deletions
diff --git a/chart2/inc/ChartModel.hxx b/chart2/inc/ChartModel.hxx index 063e3fc6a72b..191533418943 100644 --- a/chart2/inc/ChartModel.hxx +++ b/chart2/inc/ChartModel.hxx @@ -474,6 +474,8 @@ public: bool isDataFromPivotTable(); + void removeDataProviders(); + #if HAVE_FEATURE_OPENGL OpenGLWindow* getOpenGLWindow() { return mpOpenGLWindow;} #endif diff --git a/chart2/inc/strings.hrc b/chart2/inc/strings.hrc index fac728c6e4dd..e4a1844d1f18 100644 --- a/chart2/inc/strings.hrc +++ b/chart2/inc/strings.hrc @@ -24,6 +24,7 @@ #define STR_DLG_CHART_WIZARD NC_("STR_DLG_CHART_WIZARD", "Chart Wizard") #define STR_DLG_SMOOTH_LINE_PROPERTIES NC_("STR_DLG_SMOOTH_LINE_PROPERTIES", "Smooth Lines") #define STR_DLG_STEPPED_LINE_PROPERTIES NC_("STR_DLG_STEPPED_LINE_PROPERTIES", "Stepped Lines") +#define STR_DLG_REMOVE_DATA_TABLE NC_("STR_DLG_REMOVE_DATA_TABLE", "This chart currently contains an internal data table. Do you want to proceed, deleting the internal data table, and set a new data range?") #define STR_PAGE_CHARTTYPE NC_("STR_PAGE_CHARTTYPE", "Chart Type") #define STR_PAGE_DATA_RANGE NC_("STR_PAGE_DATA_RANGE", "Data Range") #define STR_PAGE_CHART_ELEMENTS NC_("STR_PAGE_CHART_ELEMENTS", "Chart Elements") diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx index bd58a05b2d8c..430c560dead2 100644 --- a/chart2/source/controller/main/ChartController.cxx +++ b/chart2/source/controller/main/ChartController.cxx @@ -66,12 +66,14 @@ #include <com/sun/star/chart2/XChartTypeContainer.hpp> #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> #include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/chart2/XDataProviderAccess.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> @@ -1330,21 +1332,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( - SchResId(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.XDataProviderAccess") ) + return; + SolarMutexGuard aSolarGuard; - ScopedVclPtrInstance< ::chart::DataSourceDialog > aDlg( GetChartWindow(), xChartDoc, m_xCC ); - if( aDlg->Execute() == RET_OK ) + + ScopedVclPtrInstance< MessageDialog > aQueryBox( GetChartWindow(), SchResId( STR_DLG_REMOVE_DATA_TABLE ), VclMessageType::Question, VclButtonsType::YesNo); + + // 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::XDataProviderAccess > xCreatorDoc( + rModel.getParent(), uno::UNO_QUERY ); + OSL_ENSURE( xCreatorDoc.is(), "Invalid XDataProviderAccess" ); + + 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( GetChartWindow(), 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 a7650ecb2f8b..81c31baa2c0a 100644 --- a/chart2/source/controller/main/ControllerCommandDispatch.cxx +++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx @@ -529,6 +529,8 @@ void ControllerCommandDispatch::updateCommandAvailability() bool bShapeContext = m_xChartController.is() && m_xChartController->isShapeContext(); bool bEnableDataTableDialog = false; + bool bCanCreateDataProvider = false; + if ( m_xChartController.is() ) { Reference< beans::XPropertySet > xProps( m_xChartController->getModel(), uno::UNO_QUERY ); @@ -543,6 +545,19 @@ void ControllerCommandDispatch::updateCommandAvailability() SAL_WARN("chart2", "Exception caught. " << e ); } } + + Reference< chart2::XChartDocument > xChartDoc(m_xChartController->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.XDataProviderAccess"); + } + } } // edit commands @@ -615,8 +630,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_apModelState->bHasDataFromPivotTable); + m_aCommandAvailability[".uno:DataRanges"] = bIsWritable && bModelStateIsValid && !m_apModelState->bHasDataFromPivotTable && bCanCreateDataProvider; m_aCommandAvailability[ ".uno:DiagramData" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasOwnData && bEnableDataTableDialog; // titles diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx index 1a0d3899019c..2c989c474230 100644 --- a/chart2/source/model/main/ChartModel.cxx +++ b/chart2/source/model/main/ChartModel.cxx @@ -762,6 +762,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() { return m_xDataProvider.is() && m_xInternalDataProvider.is(); diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index fd05331584e3..785c79a1667d 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -2023,6 +2023,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/chart2,\ XCoordinateSystem \ XCoordinateSystemContainer \ XDataInterpreter \ + XDataProviderAccess \ XDataSeries \ XDataSeriesContainer \ XDefaultSizeTransmitter \ diff --git a/offapi/com/sun/star/chart2/XDataProviderAccess.idl b/offapi/com/sun/star/chart2/XDataProviderAccess.idl new file mode 100644 index 000000000000..e8d8b902dfd0 --- /dev/null +++ b/offapi/com/sun/star/chart2/XDataProviderAccess.idl @@ -0,0 +1,40 @@ +/* -*- 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_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 { + + +/** Provides access to chart2 data providers for a given document + + @since LibreOffice 6.1 + + */ +interface XDataProviderAccess : com::sun::star::uno::XInterface +{ + + /** creates a data provider for chart2, if possible + + @see com::sun::star::chart2::data::XDataProvider + + */ + 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 ecb7cf494763..aa55a1ad4c35 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/XDataProviderAccess.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/util/XProtectable.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> @@ -86,6 +88,7 @@ class SC_DLLPUBLIC ScModelObj : public SfxBaseModel, public SvxFmMSFactory, ///< derived from XMultiServiceFactory public css::lang::XServiceInfo, public css::util::XChangesNotifier, + public css::chart2::XDataProviderAccess, public css::sheet::opencl::XOpenCLSelection { private: @@ -156,6 +159,10 @@ public: virtual css::uno::Reference< css::sheet::XSpreadsheets > SAL_CALL getSheets() override; + /// XDataProviderAccess + virtual ::css::uno::Reference< css::chart2::data::XDataProvider > SAL_CALL + createDataProvider() override; + /// XStyleFamiliesSupplier virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getStyleFamilies() override; diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index d5560485bc62..901e34a86a31 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -228,6 +228,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 SCDATAPROVIDERACCESS_SERVICE "com.sun.star.chart2.XDataProviderAccess" SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" ) SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" ) @@ -1192,6 +1193,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::XDataProviderAccess ) uno::Any aRet(SfxBaseModel::queryInterface( rType )); if ( !aRet.hasValue() @@ -1338,6 +1340,16 @@ uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() return nullptr; } +css::uno::Reference< ::css::chart2::data::XDataProvider > SAL_CALL ScModelObj::createDataProvider() +{ + 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() @@ -2847,7 +2859,7 @@ sal_Bool SAL_CALL ScModelObj::supportsService( const OUString& rServiceName ) uno::Sequence<OUString> SAL_CALL ScModelObj::getSupportedServiceNames() { - return {SCMODELOBJ_SERVICE, SCDOCSETTINGS_SERVICE, SCDOC_SERVICE}; + return {SCMODELOBJ_SERVICE, SCDOCSETTINGS_SERVICE, SCDOC_SERVICE, SCDATAPROVIDERACCESS_SERVICE}; } // XUnoTunnel |