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 /chart2 | |
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>
Diffstat (limited to 'chart2')
-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 |
5 files changed, 72 insertions, 10 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(); |