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>
This commit is contained in:
Vasily Melenchuk 2017-11-10 18:37:25 +03:00 committed by Thorsten Behrens
parent 8c15140f92
commit 0074951704
9 changed files with 133 additions and 11 deletions

View file

@ -474,6 +474,8 @@ public:
bool isDataFromPivotTable();
void removeDataProviders();
#if HAVE_FEATURE_OPENGL
OpenGLWindow* getOpenGLWindow() { return mpOpenGLWindow;}
#endif

View file

@ -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")

View file

@ -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 )

View file

@ -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

View file

@ -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();

View file

@ -2023,6 +2023,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/chart2,\
XCoordinateSystem \
XCoordinateSystemContainer \
XDataInterpreter \
XDataProviderAccess \
XDataSeries \
XDataSeriesContainer \
XDefaultSizeTransmitter \

View file

@ -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: */

View file

@ -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;

View file

@ -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