chart2/source/controller/main/ChartController.cxx | 18 - chart2/source/controller/main/ChartController_Insert.cxx | 168 +++++++-------- 2 files changed, 98 insertions(+), 88 deletions(-)
New commits: commit 2d51d987b2473fcc6a0ec19053c45e020b22d750 Author: codewithvk <vivek.jav...@collabora.com> AuthorDate: Sun Jan 28 13:43:09 2024 +0530 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Feb 7 07:28:09 2024 +0100 Async Dialogs for Few Chart Properties Updated the chart properties dialogs to work asynchronously. The changes affect the following dialogs: Chart Type: Accessible by double-clicking on a chart to select it, then right-clicking to open the context menu. Selecting 'Chart type...' opens the dialog for modifying chart types. Insert Axes: Triggered by double-clicking on a chart to select it, then right-clicking and choosing 'Insert/Delete Axes' from the context menu. This dialog allows users to add or remove chart axes. Insert Titles: Opens when you double-click on a chart, right-click, and select 'Insert Titles...' from the context menu. It's used for adding titles to the chart and its axes. Insert Trendline: For column charts, you can double-click on a column, right-click, and choose 'Insert trendline..' to open this dialog. Insert Error Bars: In a column chart, after selecting a column, right-clicking and choosing 'Insert X Error Bars..' or 'Insert Y Error Bars..' opens the dialog for adding error bars to the chart. Signed-off-by: codewithvk <vivek.jav...@collabora.com> Change-Id: Id7bb8682150f2e3115420d9259c6afd41682641e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162655 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 71a3cfb71dddba8098d74d7bb1dd414e4696914b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163010 diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx index ae09e6813dd5..b9e2755a8d8b 100644 --- a/chart2/source/controller/main/ChartController.cxx +++ b/chart2/source/controller/main/ChartController.cxx @@ -1339,17 +1339,19 @@ void SAL_CALL ChartController::releaseContextMenuInterceptor( void ChartController::executeDispatch_ChartType() { - UndoLiveUpdateGuard aUndoGuard( - SchResId( STR_ACTION_EDIT_CHARTTYPE ), m_xUndoManager ); + auto aUndoGuard = std::make_shared<UndoLiveUpdateGuard>(SchResId(STR_ACTION_EDIT_CHARTTYPE), + m_xUndoManager); SolarMutexGuard aSolarGuard; //prepare and open dialog - ChartTypeDialog aDlg(GetChartFrame(), getChartModel()); - if (aDlg.run() == RET_OK) - { - impl_adaptDataSeriesAutoResize(); - aUndoGuard.commit(); - } + auto aDlg = std::make_shared<ChartTypeDialog>(GetChartFrame(), getChartModel()); + aDlg->runAsync(aDlg, [this, aUndoGuard](int nResult) { + if (nResult == RET_OK) + { + impl_adaptDataSeriesAutoResize(); + aUndoGuard->commit(); + } + }); } void ChartController::executeDispatch_SourceData() diff --git a/chart2/source/controller/main/ChartController_Insert.cxx b/chart2/source/controller/main/ChartController_Insert.cxx index 60b059ceffa1..671baed907a7 100644 --- a/chart2/source/controller/main/ChartController_Insert.cxx +++ b/chart2/source/controller/main/ChartController_Insert.cxx @@ -90,35 +90,37 @@ namespace chart void ChartController::executeDispatch_InsertAxes() { - UndoGuard aUndoGuard( + auto aUndoGuard = std::make_shared<UndoGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXES )), m_xUndoManager ); try { - InsertAxisOrGridDialogData aDialogInput; + auto aDialogInput = std::make_shared<InsertAxisOrGridDialogData>(); rtl::Reference< Diagram > xDiagram = getFirstDiagram(); - AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, xDiagram ); - AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram ); + AxisHelper::getAxisOrGridExistence( aDialogInput->aExistenceList, xDiagram ); + AxisHelper::getAxisOrGridPossibilities( aDialogInput->aPossibilityList, xDiagram ); SolarMutexGuard aGuard; - SchAxisDlg aDlg(GetChartFrame(), aDialogInput); - if (aDlg.run() == RET_OK) - { - // lock controllers till end of block - ControllerLockGuardUNO aCLGuard( getChartModel() ); + auto aDlg = std::make_shared<SchAxisDlg>(GetChartFrame(), *aDialogInput); + aDlg->runAsync(aDlg, [this, aDlg, aDialogInput, aUndoGuard](int nResult) { + if ( nResult == RET_OK ) + { + // lock controllers till end of block + ControllerLockGuardUNO aCLGuard( getChartModel() ); - 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(); - } + InsertAxisOrGridDialogData aDialogOutput; + aDlg->getResult(aDialogOutput); + std::unique_ptr< ReferenceSizeProvider > pRefSizeProvider( + impl_createReferenceSizeProvider()); + bool bChanged = AxisHelper::changeVisibilityOfAxes( getFirstDiagram() + , aDialogInput->aExistenceList, aDialogOutput.aExistenceList, m_xCC + , pRefSizeProvider.get() ); + if( bChanged ) + aUndoGuard->commit(); + } + }); } catch(const uno::RuntimeException&) { @@ -275,28 +277,30 @@ void ChartController::executeDispatch_DeleteDataTable() void ChartController::executeDispatch_InsertTitles() { - UndoGuard aUndoGuard( + auto aUndoGuard = std::make_shared<UndoGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLES )), m_xUndoManager ); try { - TitleDialogData aDialogInput; - aDialogInput.readFromModel( getChartModel() ); + auto aDialogInput = std::make_shared<TitleDialogData>(); + aDialogInput->readFromModel( getChartModel() ); SolarMutexGuard aGuard; - SchTitleDlg aDlg(GetChartFrame(), aDialogInput); - if (aDlg.run() == 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, &aDialogInput ); - if( bChanged ) - aUndoGuard.commit(); - } + auto aDlg = std::make_shared<SchTitleDlg>(GetChartFrame(), *aDialogInput); + aDlg->runAsync(aDlg, [this, aDlg, aDialogInput, aUndoGuard](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, aDialogInput.get() ); + if( bChanged ) + aUndoGuard->commit(); + } + }); } catch(const uno::RuntimeException&) { @@ -471,7 +475,7 @@ void ChartController::executeDispatch_InsertTrendline() if( !xRegressionCurveContainer.is() ) return; - UndoLiveUpdateGuard aUndoGuard( + auto aUndoGuard = std::make_shared<UndoLiveUpdateGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE )), m_xUndoManager ); @@ -484,14 +488,14 @@ void ChartController::executeDispatch_InsertTrendline() if( !xCurve.is()) return; - wrapper::RegressionCurveItemConverter aItemConverter( + auto aItemConverter = std::make_shared<wrapper::RegressionCurveItemConverter>( xCurve, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(), m_pDrawModelWrapper->getSdrModel(), 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()), @@ -499,23 +503,23 @@ void ChartController::executeDispatch_InsertTrendline() aDialogParameter.init( getChartModel() ); ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get()); SolarMutexGuard aGuard; - SchAttribTabDlg aDialog( - GetChartFrame(), &aItemSet, &aDialogParameter, - &aViewElementListProvider, - getChartModel() ); + 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 ) + aDialog->runAsync(aDialog, [this, aDialog, aItemConverter, aUndoGuard](int nResult) { + if ( nResult == RET_OK || aDialog->DialogWasClosedWithOK() ) { - ControllerLockGuardUNO aCLGuard( getChartModel() ); - aItemConverter.ApplyItemSet( *pOutItemSet ); + const SfxItemSet* pOutItemSet = aDialog->GetOutputItemSet(); + if( pOutItemSet ) + { + ControllerLockGuardUNO aCLGuard( getChartModel() ); + aItemConverter->ApplyItemSet( *pOutItemSet ); + } + aUndoGuard->commit(); } - aUndoGuard.commit(); - } + }); } void ChartController::executeDispatch_InsertErrorBars( bool bYError ) @@ -528,7 +532,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError ) if( xSeries.is()) { - UndoLiveUpdateGuard aUndoGuard( + auto aUndoGuard = std::make_shared<UndoLiveUpdateGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : STR_OBJECT_ERROR_BARS_X )), @@ -541,46 +545,48 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError ) bYError)); // get an appropriate item converter - wrapper::ErrorBarItemConverter aItemConverter( + auto aItemConverter = std::make_shared<wrapper::ErrorBarItemConverter> ( getChartModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(), m_pDrawModelWrapper->getSdrModel(), getChartModel() ); // 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( getChartModel() ); ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get()); SolarMutexGuard aGuard; - SchAttribTabDlg aDlg( + auto aDlg = std::make_shared<SchAttribTabDlg>( GetChartFrame(), &aItemSet, &aDialogParameter, &aViewElementListProvider, getChartModel() ); - aDlg.SetAxisMinorStepWidthForErrorBarDecimals( + 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 ) + aDlg->runAsync(aDlg, [this, aDlg, aItemConverter, aUndoGuard](int nResult) { + if ( nResult == RET_OK || aDlg->DialogWasClosedWithOK() ) { - ControllerLockGuardUNO aCLGuard( getChartModel() ); - aItemConverter.ApplyItemSet( *pOutItemSet ); + const SfxItemSet* pOutItemSet = aDlg->GetOutputItemSet(); + if( pOutItemSet ) + { + ControllerLockGuardUNO aCLGuard( getChartModel() ); + aItemConverter->ApplyItemSet( *pOutItemSet ); + } + aUndoGuard->commit(); } - aUndoGuard.commit(); - } + }); } else { //if no series is selected insert error bars for all series - UndoGuard aUndoGuard( + auto aUndoGuard = std::make_shared<UndoGuard>( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert, ObjectNameProvider::getName_ObjectForAllSeries( objType ) ), @@ -588,32 +594,34 @@ void ChartController::executeDispatch_InsertErrorBars( bool bYError ) try { - wrapper::AllSeriesStatisticsConverter aItemConverter( + auto aItemConverter = std::make_shared<wrapper::AllSeriesStatisticsConverter>( getChartModel(), m_pDrawModelWrapper->GetItemPool() ); - SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet(); - aItemConverter.FillItemSet( aItemSet ); + SfxItemSet aItemSet = aItemConverter->CreateEmptyItemSet(); + aItemConverter->FillItemSet( aItemSet ); //prepare and open dialog SolarMutexGuard aGuard; - InsertErrorBarsDialog aDlg( + auto aDlg = std::make_shared<InsertErrorBarsDialog>( GetChartFrame(), aItemSet, getChartModel(), bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X); - aDlg.SetAxisMinorStepWidthForErrorBarDecimals( + aDlg->SetAxisMinorStepWidthForErrorBarDecimals( InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getChartModel(), m_xChartView, u"" ) ); - if (aDlg.run() == RET_OK) - { - SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet(); - aDlg.FillItemSet( aOutItemSet ); - - // lock controllers till end of block - ControllerLockGuardUNO aCLGuard( getChartModel() ); - bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now - if( bChanged ) - aUndoGuard.commit(); - } + aDlg->runAsync(aDlg, [this, aDlg, aItemConverter, aUndoGuard](int nResult) { + if ( nResult == RET_OK ) + { + SfxItemSet aOutItemSet = aItemConverter->CreateEmptyItemSet(); + aDlg->FillItemSet( aOutItemSet ); + + // lock controllers till end of block + ControllerLockGuardUNO aCLGuard( getChartModel() ); + bool bChanged = aItemConverter->ApplyItemSet( aOutItemSet );//model should be changed now + if( bChanged ) + aUndoGuard->commit(); + } + }); } catch(const uno::RuntimeException&) {