diff options
Diffstat (limited to 'chart2/source/controller/main/ChartController_Insert.cxx')
-rw-r--r-- | chart2/source/controller/main/ChartController_Insert.cxx | 504 |
1 files changed, 309 insertions, 195 deletions
diff --git a/chart2/source/controller/main/ChartController_Insert.cxx b/chart2/source/controller/main/ChartController_Insert.cxx index 04c27782c375..5b930ee7190c 100644 --- a/chart2/source/controller/main/ChartController_Insert.cxx +++ b/chart2/source/controller/main/ChartController_Insert.cxx @@ -25,13 +25,15 @@ #include <dlg_InsertLegend.hxx> #include <dlg_InsertErrorBars.hxx> #include <dlg_InsertTitle.hxx> +#include <dlg_InsertDataTable.hxx> #include <dlg_ObjectProperties.hxx> -#include <ChartModel.hxx> -#include <ChartModelHelper.hxx> +#include <Axis.hxx> #include <AxisHelper.hxx> #include <TitleHelper.hxx> -#include <DiagramHelper.hxx> +#include <DataSeries.hxx> +#include <Diagram.hxx> +#include <GridProperties.hxx> #include <chartview/DrawModelWrapper.hxx> #include <chartview/ChartSfxItemIds.hxx> #include <NumberFormatterWrapper.hxx> @@ -49,33 +51,32 @@ #include <ErrorBarItemConverter.hxx> #include <DataSeriesHelper.hxx> #include <ObjectNameProvider.hxx> +#include <Legend.hxx> #include <LegendHelper.hxx> +#include <DataTable.hxx> +#include <RegressionCurveModel.hxx> #include <com/sun/star/chart2/XRegressionCurve.hpp> -#include <com/sun/star/chart2/XRegressionCurveContainer.hpp> -#include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include <svx/ActionDescriptionProvider.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <vcl/svapp.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; namespace { -void lcl_InsertMeanValueLine( const uno::Reference< chart2::XDataSeries > & xSeries ) +void lcl_InsertMeanValueLine( const rtl::Reference< ::chart::DataSeries > & xSeries ) { - uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( - xSeries, uno::UNO_QUERY ); - if( xRegCurveCnt.is()) + if( xSeries.is()) { ::chart::RegressionCurveHelper::addMeanValueLine( - xRegCurveCnt, uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY )); + xSeries, xSeries); } } @@ -86,35 +87,37 @@ namespace chart void ChartController::executeDispatch_InsertAxes() { - UndoGuard aUndoGuard( + auto xUndoGuard = std::make_shared<UndoGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXES )), m_xUndoManager ); try { - InsertAxisOrGridDialogData aDialogInput; - uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel()); - AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, xDiagram ); - AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram ); + auto xDialogInput = std::make_shared<InsertAxisOrGridDialogData>(); + rtl::Reference< Diagram > xDiagram = getFirstDiagram(); + AxisHelper::getAxisOrGridExistence( xDialogInput->aExistenceList, xDiagram ); + AxisHelper::getAxisOrGridPossibilities( xDialogInput->aPossibilityList, xDiagram ); SolarMutexGuard aGuard; - SchAxisDlg aDlg(GetChartFrame(), aDialogInput); - if (aDlg.run() == RET_OK) - { - // lock controllers till end of block - ControllerLockGuardUNO aCLGuard( getModel() ); - - InsertAxisOrGridDialogData aDialogOutput; - aDlg.getResult(aDialogOutput); - std::unique_ptr< ReferenceSizeProvider > pRefSizeProvider( - impl_createReferenceSizeProvider()); - bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram - , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC - , pRefSizeProvider.get() ); - if( bChanged ) - aUndoGuard.commit(); - } + auto aDlg = std::make_shared<SchAxisDlg>(GetChartFrame(), *xDialogInput); + weld::DialogController::runAsync(aDlg, [this, aDlg, xDialogInput=std::move(xDialogInput), + xUndoGuard=std::move(xUndoGuard)](int nResult) { + if ( nResult == RET_OK ) + { + // lock controllers till end of block + ControllerLockGuardUNO aCLGuard( getChartModel() ); + + InsertAxisOrGridDialogData aDialogOutput; + aDlg->getResult(aDialogOutput); + ReferenceSizeProvider aRefSizeProvider(impl_createReferenceSizeProvider()); + bool bChanged = AxisHelper::changeVisibilityOfAxes( getFirstDiagram() + , xDialogInput->aExistenceList, aDialogOutput.aExistenceList, m_xCC + , &aRefSizeProvider ); + if( bChanged ) + xUndoGuard->commit(); + } + }); } catch(const uno::RuntimeException&) { @@ -132,7 +135,7 @@ void ChartController::executeDispatch_InsertGrid() try { InsertAxisOrGridDialogData aDialogInput; - uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel()); + rtl::Reference< Diagram > xDiagram = getFirstDiagram(); AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, xDiagram, false ); AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, false ); @@ -141,7 +144,7 @@ void ChartController::executeDispatch_InsertGrid() if (aDlg.run() == RET_OK) { // lock controllers till end of block - ControllerLockGuardUNO aCLGuard( getModel() ); + ControllerLockGuardUNO aCLGuard( getChartModel() ); InsertAxisOrGridDialogData aDialogOutput; aDlg.getResult( aDialogOutput ); bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram @@ -156,30 +159,146 @@ void ChartController::executeDispatch_InsertGrid() } } +void ChartController::executeDispatch_OpenInsertDataTableDialog() +{ + SolarMutexGuard aGuard; + + auto aUndoDescription = ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Insert, SchResId(STR_DATA_TABLE)); + UndoGuard aUndoGuard(aUndoDescription, m_xUndoManager); + + rtl::Reference<Diagram> xDiagram = getFirstDiagram(); + + InsertDataTableDialog aDialog(GetChartFrame()); + { + // init values + DataTableDialogData aData; + auto xDataTable = xDiagram->getDataTable(); + aData.mbShow = xDataTable.is(); + if (xDataTable.is()) + { + uno::Reference<beans::XPropertySet> xProperties(xDataTable, uno::UNO_QUERY); + + uno::Any aAny = xProperties->getPropertyValue(u"HBorder"_ustr); + if (aAny.has<bool>()) + aData.mbHorizontalBorders = aAny.get<bool>(); + + aAny = xProperties->getPropertyValue(u"VBorder"_ustr); + if (aAny.has<bool>()) + aData.mbVerticalBorders = aAny.get<bool>(); + + aAny = xProperties->getPropertyValue(u"Outline"_ustr); + if (aAny.has<bool>()) + aData.mbOutline = aAny.get<bool>(); + + aAny = xProperties->getPropertyValue(u"Keys"_ustr); + if (aAny.has<bool>()) + aData.mbKeys = aAny.get<bool>(); + } + aDialog.init(aData); + } + + // show the dialog + if (aDialog.run() == RET_OK) + { + bool bChanged = false; + + auto& rDialogData = aDialog.getDataTableDialogData(); + auto xDataTable = xDiagram->getDataTable(); + if (!rDialogData.mbShow && xDataTable.is()) + { + xDiagram->setDataTable(uno::Reference<chart2::XDataTable>()); + bChanged = true; + } + else if (rDialogData.mbShow && !xDataTable.is()) + { + uno::Reference<chart2::XDataTable> xNewDataTable(new DataTable); + if (xNewDataTable.is()) + { + xDiagram->setDataTable(xNewDataTable); + bChanged = true; + } + } + + // Set the properties + xDataTable = xDiagram->getDataTable(); + if (rDialogData.mbShow && xDataTable.is()) + { + uno::Reference<beans::XPropertySet> xProperties(xDataTable, uno::UNO_QUERY); + xProperties->setPropertyValue(u"HBorder"_ustr , uno::Any(rDialogData.mbHorizontalBorders)); + xProperties->setPropertyValue(u"VBorder"_ustr , uno::Any(rDialogData.mbVerticalBorders)); + xProperties->setPropertyValue(u"Outline"_ustr , uno::Any(rDialogData.mbOutline)); + xProperties->setPropertyValue(u"Keys"_ustr , uno::Any(rDialogData.mbKeys)); + bChanged = true; + } + + if (bChanged) + aUndoGuard.commit(); + } +} + +/** Create and insert a data table to the chart */ +void ChartController::executeDispatch_InsertDataTable() +{ + auto aUndoDescription = ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Insert, SchResId(STR_DATA_TABLE)); + UndoGuard aUndoGuard(aUndoDescription, m_xUndoManager); + + + rtl::Reference<Diagram> xDiagram = getFirstDiagram(); + auto xDataTable = xDiagram->getDataTable(); + if (!xDataTable.is()) + { + uno::Reference<chart2::XDataTable> xNewDataTable(new DataTable); + if (xNewDataTable.is()) + { + xDiagram->setDataTable(xNewDataTable); + aUndoGuard.commit(); + } + } +} + +/** Delete a data table from the chart */ +void ChartController::executeDispatch_DeleteDataTable() +{ + auto aUndoDescription = ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Delete, SchResId(STR_DATA_TABLE)); + UndoGuard aUndoGuard(aUndoDescription, m_xUndoManager); + + rtl::Reference<Diagram> xDiagram = getFirstDiagram(); + auto xDataTable = xDiagram->getDataTable(); + if (xDataTable.is()) + { + // insert a empty data table reference + xDiagram->setDataTable(uno::Reference<chart2::XDataTable>()); + aUndoGuard.commit(); + } +} + void ChartController::executeDispatch_InsertTitles() { - UndoGuard aUndoGuard( + auto xUndoGuard = std::make_shared<UndoGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLES )), m_xUndoManager ); try { - TitleDialogData aDialogInput; - aDialogInput.readFromModel( getModel() ); + auto xDialogInput = std::make_shared<TitleDialogData>(); + xDialogInput->readFromModel( getChartModel() ); SolarMutexGuard aGuard; - SchTitleDlg aDlg(GetChartFrame(), aDialogInput); - if (aDlg.run() == RET_OK) - { - // lock controllers till end of block - ControllerLockGuardUNO aCLGuard( getModel() ); - TitleDialogData aDialogOutput(impl_createReferenceSizeProvider()); - aDlg.getResult(aDialogOutput); - bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput ); - if( bChanged ) - aUndoGuard.commit(); - } + auto aDlg = std::make_shared<SchTitleDlg>(GetChartFrame(), *xDialogInput); + weld::DialogController::runAsync(aDlg, [this, aDlg, xDialogInput=std::move(xDialogInput), + xUndoGuard=std::move(xUndoGuard)](int nResult){ + if ( nResult == RET_OK ) + { + // lock controllers till end of block + ControllerLockGuardUNO aCLGuard( getChartModel() ); + TitleDialogData aDialogOutput( impl_createReferenceSizeProvider() ); + aDlg->getResult( aDialogOutput ); + bool bChanged = aDialogOutput.writeDifferenceToModel( getChartModel(), m_xCC, xDialogInput.get() ); + if( bChanged ) + xUndoGuard->commit(); + } + }); } catch(const uno::RuntimeException&) { @@ -194,8 +313,7 @@ void ChartController::executeDispatch_DeleteLegend() ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )), m_xUndoManager ); - ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel()); - LegendHelper::hideLegend(rModel); + LegendHelper::hideLegend(*getChartModel()); aUndoGuard.commit(); } @@ -206,8 +324,7 @@ void ChartController::executeDispatch_InsertLegend() ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )), m_xUndoManager ); - ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel()); - LegendHelper::showLegend(rModel, m_xCC); + LegendHelper::showLegend(*getChartModel(), m_xCC); aUndoGuard.commit(); } @@ -223,12 +340,12 @@ void ChartController::executeDispatch_OpenLegendDialog() //prepare and open dialog SolarMutexGuard aGuard; SchLegendDlg aDlg(GetChartFrame(), m_xCC); - aDlg.init( getModel() ); + aDlg.init( getChartModel() ); if (aDlg.run() == RET_OK) { // lock controllers till end of block - ControllerLockGuardUNO aCLGuard( getModel() ); - aDlg.writeToModel( getModel() ); + ControllerLockGuardUNO aCLGuard( getChartModel() ); + aDlg.writeToModel( getChartModel() ); aUndoGuard.commit(); } } @@ -240,36 +357,32 @@ void ChartController::executeDispatch_OpenLegendDialog() void ChartController::executeDispatch_InsertMenu_DataLabels() { - UndoGuard aUndoGuard( + std::shared_ptr<UndoGuard> aUndoGuard = std::make_shared<UndoGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_DATALABELS )), m_xUndoManager ); //if a series is selected insert labels for that series only: - uno::Reference< chart2::XDataSeries > xSeries = - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()); + rtl::Reference< DataSeries > xSeries = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel()); if( xSeries.is() ) { // add labels - DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries ); + xSeries->insertDataLabelsToSeriesAndAllPoints(); OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" ); OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles( ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle ); - bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true ); - if( bSuccess ) - aUndoGuard.commit(); + ChartController::executeDlg_ObjectProperties_withUndoGuard( aUndoGuard, aObjectCID, true ); return; } - try { wrapper::AllDataLabelItemConverter aItemConverter( - getModel(), + getChartModel(), m_pDrawModelWrapper->GetItemPool(), - m_pDrawModelWrapper->getSdrModel(), - uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )); + m_pDrawModelWrapper->getSdrModel() ); SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet(); aItemConverter.FillItemSet( aItemSet ); @@ -277,8 +390,7 @@ void ChartController::executeDispatch_InsertMenu_DataLabels() SolarMutexGuard aGuard; //get number formatter - uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getModel(), uno::UNO_QUERY ); - NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier ); + NumberFormatterWrapper aNumberFormatterWrapper( getChartModel() ); SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter(); DataLabelsDialog aDlg(GetChartFrame(), aItemSet, pNumberFormatter); @@ -288,10 +400,10 @@ void ChartController::executeDispatch_InsertMenu_DataLabels() SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet(); aDlg.FillItemSet(aOutItemSet); // lock controllers till end of block - ControllerLockGuardUNO aCLGuard( getModel() ); + ControllerLockGuardUNO aCLGuard( getChartModel() ); bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now if( bChanged ) - aUndoGuard.commit(); + aUndoGuard->commit(); } } catch(const uno::RuntimeException&) @@ -307,7 +419,7 @@ void ChartController::executeDispatch_InsertMeanValue() ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )), m_xUndoManager ); lcl_InsertMeanValueLine( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), - getModel() ) ); + getChartModel() ) ); aUndoGuard.commit(); } @@ -318,17 +430,17 @@ void ChartController::executeDispatch_InsertMenu_MeanValues() ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )), m_xUndoManager ); - uno::Reference< chart2::XDataSeries > xSeries = - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< DataSeries > xSeries = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xSeries.is() ) { //if a series is selected insert mean value only for that series: lcl_InsertMeanValueLine( xSeries ); } - else + else if (rtl::Reference<Diagram> xDiagram = getFirstDiagram()) { - std::vector< uno::Reference< chart2::XDataSeries > > aSeries( - DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() ))); + std::vector< rtl::Reference< DataSeries > > aSeries = + xDiagram->getDataSeries(); for( const auto& xSrs : aSeries ) lcl_InsertMeanValueLine( xSrs ); @@ -340,8 +452,8 @@ void ChartController::executeDispatch_InsertMenu_Trendlines() { OUString aCID = m_aSelection.getSelectedCID(); - uno::Reference< chart2::XDataSeries > xSeries = - ObjectIdentifier::getDataSeriesForCID( aCID, getModel() ); + rtl::Reference< DataSeries > xSeries = + ObjectIdentifier::getDataSeriesForCID( aCID, getChartModel() ); if( !xSeries.is() ) return; @@ -351,60 +463,58 @@ void ChartController::executeDispatch_InsertMenu_Trendlines() void ChartController::executeDispatch_InsertTrendline() { - uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY ); + rtl::Reference< DataSeries > xRegressionCurveContainer = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel()); if( !xRegressionCurveContainer.is() ) return; - UndoLiveUpdateGuard aUndoGuard( + auto xUndoGuard = std::make_shared<UndoLiveUpdateGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE )), m_xUndoManager ); - uno::Reference< chart2::XRegressionCurve > xCurve = + rtl::Reference< RegressionCurveModel > xCurve = RegressionCurveHelper::addRegressionCurve( SvxChartRegress::Linear, xRegressionCurveContainer ); - uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); - - if( !xProperties.is()) + if( !xCurve.is()) return; - wrapper::RegressionCurveItemConverter aItemConverter( - xProperties, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(), + auto aItemConverter = std::make_shared<wrapper::RegressionCurveItemConverter>( + xCurve, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(), m_pDrawModelWrapper->getSdrModel(), - uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )); + getChartModel() ); // open dialog - SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet(); - aItemConverter.FillItemSet( aItemSet ); + SfxItemSet aItemSet = aItemConverter->CreateEmptyItemSet(); + aItemConverter->FillItemSet( aItemSet ); ObjectPropertiesDialogParameter aDialogParameter( ObjectIdentifier::createDataCurveCID( ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()), RegressionCurveHelper::getRegressionCurveIndex( xRegressionCurveContainer, xCurve ), false )); - aDialogParameter.init( getModel() ); + aDialogParameter.init( getChartModel() ); ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get()); SolarMutexGuard aGuard; - SchAttribTabDlg aDialog( - GetChartFrame(), &aItemSet, &aDialogParameter, - &aViewElementListProvider, - uno::Reference< util::XNumberFormatsSupplier >( - getModel(), uno::UNO_QUERY ) ); + auto aDialog = std::make_shared<SchAttribTabDlg>(GetChartFrame(), &aItemSet, &aDialogParameter, + &aViewElementListProvider, getChartModel()); // note: when a user pressed "OK" but didn't change any settings in the // dialog, the SfxTabDialog returns "Cancel" - if( aDialog.run() == RET_OK || aDialog.DialogWasClosedWithOK()) - { - const SfxItemSet* pOutItemSet = aDialog.GetOutputItemSet(); - if( pOutItemSet ) + SfxTabDialogController::runAsync(aDialog, [this, aDialog, aItemConverter = std::move(aItemConverter), + xUndoGuard=std::move(xUndoGuard)](int nResult) { + if ( nResult == RET_OK || aDialog->DialogWasClosedWithOK() ) { - ControllerLockGuardUNO aCLGuard( getModel() ); - aItemConverter.ApplyItemSet( *pOutItemSet ); + const SfxItemSet* pOutItemSet = aDialog->GetOutputItemSet(); + if( pOutItemSet ) + { + ControllerLockGuardUNO aCLGuard( getChartModel() ); + aItemConverter->ApplyItemSet( *pOutItemSet ); + } + xUndoGuard->commit(); } - aUndoGuard.commit(); - } + }); } void ChartController::executeDispatch_InsertErrorBars( bool bYError ) @@ -412,12 +522,12 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError ) ObjectType objType = bYError ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X; //if a series is selected insert error bars for that series only: - uno::Reference< chart2::XDataSeries > xSeries = - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< DataSeries > xSeries = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xSeries.is()) { - UndoLiveUpdateGuard aUndoGuard( + auto xUndoGuard = std::make_shared<UndoLiveUpdateGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : STR_OBJECT_ERROR_BARS_X )), @@ -430,47 +540,48 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError ) bYError)); // get an appropriate item converter - wrapper::ErrorBarItemConverter aItemConverter( - getModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(), - m_pDrawModelWrapper->getSdrModel(), - uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )); + auto aItemConverter = std::make_shared<wrapper::ErrorBarItemConverter> ( + getChartModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(), + m_pDrawModelWrapper->getSdrModel() ); // open dialog - SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet(); + SfxItemSet aItemSet = aItemConverter->CreateEmptyItemSet(); aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE,bYError)); - aItemConverter.FillItemSet( aItemSet ); + aItemConverter->FillItemSet( aItemSet ); ObjectPropertiesDialogParameter aDialogParameter( ObjectIdentifier::createClassifiedIdentifierWithParent( objType, u"", m_aSelection.getSelectedCID())); - aDialogParameter.init( getModel() ); + aDialogParameter.init( getChartModel() ); ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get()); SolarMutexGuard aGuard; - SchAttribTabDlg aDlg( + auto aDlg = std::make_shared<SchAttribTabDlg>( GetChartFrame(), &aItemSet, &aDialogParameter, &aViewElementListProvider, - uno::Reference< util::XNumberFormatsSupplier >( - getModel(), uno::UNO_QUERY ) ); - aDlg.SetAxisMinorStepWidthForErrorBarDecimals( - InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), + getChartModel() ); + aDlg->SetAxisMinorStepWidthForErrorBarDecimals( + InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getChartModel(), m_xChartView, m_aSelection.getSelectedCID())); // note: when a user pressed "OK" but didn't change any settings in the // dialog, the SfxTabDialog returns "Cancel" - if (aDlg.run() == RET_OK || aDlg.DialogWasClosedWithOK()) - { - const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet(); - if( pOutItemSet ) + SfxTabDialogController::runAsync(aDlg, [this, aDlg, aItemConverter=std::move(aItemConverter), + xUndoGuard=std::move(xUndoGuard)](int nResult) { + if ( nResult == RET_OK || aDlg->DialogWasClosedWithOK() ) { - ControllerLockGuardUNO aCLGuard( getModel() ); - aItemConverter.ApplyItemSet( *pOutItemSet ); + const SfxItemSet* pOutItemSet = aDlg->GetOutputItemSet(); + if( pOutItemSet ) + { + ControllerLockGuardUNO aCLGuard( getChartModel() ); + aItemConverter->ApplyItemSet( *pOutItemSet ); + } + xUndoGuard->commit(); } - aUndoGuard.commit(); - } + }); } else { //if no series is selected insert error bars for all series - UndoGuard aUndoGuard( + auto xUndoGuard = std::make_shared<UndoGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, ObjectNameProvider::getName_ObjectForAllSeries( objType ) ), @@ -478,32 +589,35 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError ) try { - wrapper::AllSeriesStatisticsConverter aItemConverter( - getModel(), m_pDrawModelWrapper->GetItemPool() ); - SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet(); - aItemConverter.FillItemSet( aItemSet ); + auto xItemConverter = std::make_shared<wrapper::AllSeriesStatisticsConverter>( + getChartModel(), m_pDrawModelWrapper->GetItemPool() ); + SfxItemSet aItemSet = xItemConverter->CreateEmptyItemSet(); + xItemConverter->FillItemSet( aItemSet ); //prepare and open dialog SolarMutexGuard aGuard; - InsertErrorBarsDialog aDlg( + auto aDlg = std::make_shared<InsertErrorBarsDialog>( GetChartFrame(), aItemSet, - uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ), + getChartModel(), bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X); - aDlg.SetAxisMinorStepWidthForErrorBarDecimals( - InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, OUString() ) ); - - if (aDlg.run() == RET_OK) - { - SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet(); - aDlg.FillItemSet( aOutItemSet ); - - // lock controllers till end of block - ControllerLockGuardUNO aCLGuard( getModel() ); - bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now - if( bChanged ) - aUndoGuard.commit(); - } + aDlg->SetAxisMinorStepWidthForErrorBarDecimals( + InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getChartModel(), m_xChartView, u"" ) ); + + weld::DialogController::runAsync(aDlg, [this, aDlg, xItemConverter=std::move(xItemConverter), + xUndoGuard=std::move(xUndoGuard)](int nResult) { + if ( nResult == RET_OK ) + { + SfxItemSet aOutItemSet = xItemConverter->CreateEmptyItemSet(); + aDlg->FillItemSet( aOutItemSet ); + + // lock controllers till end of block + ControllerLockGuardUNO aCLGuard( getChartModel() ); + bool bChanged = xItemConverter->ApplyItemSet( aOutItemSet );//model should be changed now + if( bChanged ) + xUndoGuard->commit(); + } + }); } catch(const uno::RuntimeException&) { @@ -515,11 +629,11 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError ) void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 ) { uno::Reference< chart2::XRegressionCurve > xRegCurve( - ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY ); + ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() ), uno::UNO_QUERY ); if( !xRegCurve.is() ) { - uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY ); + rtl::Reference< DataSeries > xRegCurveCnt = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) ); } if( !xRegCurve.is()) @@ -532,10 +646,10 @@ void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 ) ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )), m_xUndoManager ); - xEqProp->setPropertyValue( "ShowEquation", uno::Any( true )); - xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") )); - xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x)") )); - xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( bInsertR2 )); + xEqProp->setPropertyValue( u"ShowEquation"_ustr, uno::Any( true )); + xEqProp->setPropertyValue( u"XName"_ustr, uno::Any( u"x"_ustr )); + xEqProp->setPropertyValue( u"YName"_ustr, uno::Any( u"f(x)"_ustr )); + xEqProp->setPropertyValue( u"ShowCorrelationCoefficient"_ustr, uno::Any( bInsertR2 )); aUndoGuard.commit(); } } @@ -543,14 +657,14 @@ void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 ) void ChartController::executeDispatch_InsertR2Value() { uno::Reference< beans::XPropertySet > xEqProp = - ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ); + ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() ); if( xEqProp.is()) { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )), m_xUndoManager ); - xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( true )); + xEqProp->setPropertyValue( u"ShowCorrelationCoefficient"_ustr, uno::Any( true )); aUndoGuard.commit(); } } @@ -558,22 +672,22 @@ void ChartController::executeDispatch_InsertR2Value() void ChartController::executeDispatch_DeleteR2Value() { uno::Reference< beans::XPropertySet > xEqProp = - ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ); + ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() ); if( xEqProp.is()) { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )), m_xUndoManager ); - xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false )); + xEqProp->setPropertyValue( u"ShowCorrelationCoefficient"_ustr, uno::Any( false )); aUndoGuard.commit(); } } void ChartController::executeDispatch_DeleteMeanValue() { - uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY ); + rtl::Reference< DataSeries > xRegCurveCnt = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xRegCurveCnt.is()) { UndoGuard aUndoGuard( @@ -587,8 +701,8 @@ void ChartController::executeDispatch_DeleteMeanValue() void ChartController::executeDispatch_DeleteTrendline() { - uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY ); + rtl::Reference< DataSeries > xRegCurveCnt = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xRegCurveCnt.is()) { UndoGuard aUndoGuard( @@ -602,8 +716,8 @@ void ChartController::executeDispatch_DeleteTrendline() void ChartController::executeDispatch_DeleteTrendlineEquation() { - uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY ); + rtl::Reference< DataSeries > xRegCurveCnt = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xRegCurveCnt.is()) { UndoGuard aUndoGuard( @@ -617,8 +731,8 @@ void ChartController::executeDispatch_DeleteTrendlineEquation() void ChartController::executeDispatch_DeleteErrorBars( bool bYError ) { - uno::Reference< chart2::XDataSeries > xDataSeries( - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() )); + rtl::Reference< DataSeries > xDataSeries = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xDataSeries.is()) { UndoGuard aUndoGuard( @@ -632,14 +746,14 @@ void ChartController::executeDispatch_DeleteErrorBars( bool bYError ) void ChartController::executeDispatch_InsertDataLabels() { - uno::Reference< chart2::XDataSeries > xSeries = - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< DataSeries > xSeries = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xSeries.is() ) { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_DATALABELS )), m_xUndoManager ); - DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries ); + xSeries->insertDataLabelsToSeriesAndAllPoints(); aUndoGuard.commit(); } } @@ -649,20 +763,20 @@ void ChartController::executeDispatch_InsertDataLabel() UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LABEL )), m_xUndoManager ); - DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) ); + DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() ) ); aUndoGuard.commit(); } void ChartController::executeDispatch_DeleteDataLabels() { - uno::Reference< chart2::XDataSeries > xSeries = - ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< DataSeries > xSeries = + ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xSeries.is() ) { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_DATALABELS )), m_xUndoManager ); - DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries ); + xSeries->deleteDataLabelsFromSeriesAndAllPoints(); aUndoGuard.commit(); } } @@ -672,7 +786,7 @@ void ChartController::executeDispatch_DeleteDataLabel() UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LABEL )), m_xUndoManager ); - DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) ); + DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() ) ); aUndoGuard.commit(); } @@ -681,7 +795,7 @@ void ChartController::executeDispatch_ResetAllDataPoints() UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format, SchResId( STR_OBJECT_DATAPOINTS )), m_xUndoManager ); - uno::Reference< chart2::XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xSeries.is() ) xSeries->resetAllDataPoints(); aUndoGuard.commit(); @@ -691,7 +805,7 @@ void ChartController::executeDispatch_ResetDataPoint() UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format, SchResId( STR_OBJECT_DATAPOINT )), m_xUndoManager ); - uno::Reference< chart2::XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xSeries.is() ) { sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() ); @@ -704,18 +818,18 @@ void ChartController::executeDispatch_InsertAxisTitle() { try { - uno::Reference< XTitle > xTitle; + rtl::Reference< Title > xTitle; { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLE )), m_xUndoManager ); - Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() ); sal_Int32 nDimensionIndex = -1; sal_Int32 nCooSysIndex = -1; sal_Int32 nAxisIndex = -1; - AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, nAxisIndex ); + AxisHelper::getIndicesForAxis( xAxis, getFirstDiagram(), nCooSysIndex, nDimensionIndex, nAxisIndex ); TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE; if( nDimensionIndex==0 ) @@ -725,8 +839,8 @@ void ChartController::executeDispatch_InsertAxisTitle() else eTitleType = TitleHelper::Z_AXIS_TITLE; - std::unique_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider()); - xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() ); + ReferenceSizeProvider aRefSizeProvider( impl_createReferenceSizeProvider()); + xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getChartModel(), m_xCC, &aRefSizeProvider ); aUndoGuard.commit(); } } @@ -745,7 +859,7 @@ void ChartController::executeDispatch_InsertAxis() try { - Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xAxis.is() ) { AxisHelper::makeAxisVisible( xAxis ); @@ -767,7 +881,7 @@ void ChartController::executeDispatch_DeleteAxis() try { - Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xAxis.is() ) { AxisHelper::makeAxisInvisible( xAxis ); @@ -789,10 +903,10 @@ void ChartController::executeDispatch_InsertMajorGrid() try { - Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xAxis.is() ) { - AxisHelper::makeGridVisible( xAxis->getGridProperties() ); + AxisHelper::makeGridVisible( xAxis->getGridProperties2() ); aUndoGuard.commit(); } } @@ -811,10 +925,10 @@ void ChartController::executeDispatch_DeleteMajorGrid() try { - Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xAxis.is() ) { - AxisHelper::makeGridInvisible( xAxis->getGridProperties() ); + AxisHelper::makeGridInvisible( xAxis->getGridProperties2() ); aUndoGuard.commit(); } } @@ -833,11 +947,11 @@ void ChartController::executeDispatch_InsertMinorGrid() try { - Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xAxis.is() ) { - const Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() ); - for( Reference< beans::XPropertySet > const & props : aSubGrids) + std::vector< rtl::Reference< ::chart::GridProperties > > aSubGrids( xAxis->getSubGridProperties2() ); + for( rtl::Reference< GridProperties > const & props : aSubGrids) AxisHelper::makeGridVisible( props ); aUndoGuard.commit(); } @@ -857,11 +971,11 @@ void ChartController::executeDispatch_DeleteMinorGrid() try { - Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() ); + rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() ); if( xAxis.is() ) { - const Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() ); - for( Reference< beans::XPropertySet > const & props : aSubGrids) + std::vector< rtl::Reference< ::chart::GridProperties > > aSubGrids( xAxis->getSubGridProperties2() ); + for( rtl::Reference< ::chart::GridProperties > const & props : aSubGrids) AxisHelper::makeGridInvisible( props ); aUndoGuard.commit(); } |