diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-01-05 14:54:52 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2021-01-06 11:50:55 +0100 |
commit | 3286d9a70bda46da2685a23ff6f353fbb1e055f4 (patch) | |
tree | 7461c25f3a55e33f8c5556aad2aa6cd7d890614c | |
parent | 4e7ab90a0a1380b3ec618306c434373b56f2d67b (diff) |
pivot table: make partial sum message box async
Change-Id: I63011526d60f332ee56edebf5bf48b30ad6b2a94
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108807
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 99 |
1 files changed, 63 insertions, 36 deletions
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 26ef479f914f..eb81697a4dfd 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -2797,6 +2797,50 @@ void RunPivotLayoutDialog(ScModule* pScMod, } } +void SetupRangeForPivotTableDialog(const ScRange& rRange, + ScAddress& rDestPos, + ScDocument* pDoc, + const char* pSrcErrorId, + std::unique_ptr<ScDPObject>& pNewDPObject) +{ + ScSheetSourceDesc aShtDesc(pDoc); + aShtDesc.SetSourceRange(rRange); + pSrcErrorId = aShtDesc.CheckSourceRange(); + if (!pSrcErrorId) + { + pNewDPObject.reset(new ScDPObject(pDoc)); + pNewDPObject->SetSheetDesc( aShtDesc ); + } + + // output below source data + if ( rRange.aEnd.Row()+2 <= pDoc->MaxRow() - 4 ) + rDestPos = ScAddress( rRange.aStart.Col(), + rRange.aEnd.Row()+2, + rRange.aStart.Tab() ); +} + +void ErrorOrRunPivotLayoutDialog(const char* pSrcErrorId, + ScAddress& rDestPos, + ScModule* pScMod, + ScTabViewShell* pTabViewShell, + std::unique_ptr<ScDPObject>& pNewDPObject) +{ + if (pSrcErrorId) + { + // Error occurred during data creation. Launch an error and bail out. + std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(), + VclMessageType::Info, VclButtonsType::Ok, + ScResId(pSrcErrorId))); + xInfoBox->run(); + return; + } + + if ( pNewDPObject ) + pNewDPObject->SetOutRange( rDestPos ); + + RunPivotLayoutDialog(pScMod, pTabViewShell, pNewDPObject); +} + } void ScCellShell::ExecuteDataPilotDialog() @@ -2910,11 +2954,11 @@ void ScCellShell::ExecuteDataPilotDialog() } else { - std::unique_ptr<ScDPObject> pNewDPObject; const char* pSrcErrorId = nullptr; if (pTypeDlg->IsNamedRange()) { + std::unique_ptr<ScDPObject> pNewDPObject; OUString aName = pTypeDlg->GetSelectedNamedRange(); ScSheetSourceDesc aShtDesc(pDoc); aShtDesc.SetRangeName(aName); @@ -2924,6 +2968,8 @@ void ScCellShell::ExecuteDataPilotDialog() pNewDPObject.reset(new ScDPObject(pDoc)); pNewDPObject->SetSheetDesc(aShtDesc); } + + ErrorOrRunPivotLayoutDialog(pSrcErrorId, aDestPos, pScMod, pTabViewShell, pNewDPObject); } else // selection { @@ -2945,51 +2991,32 @@ void ScCellShell::ExecuteDataPilotDialog() pTabViewShell->MarkRange(aRange); } - bool bOK = true; if ( pDoc->HasSubTotalCells( aRange ) ) { // confirm selection if it contains SubTotal cells - std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(), + std::shared_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, ScResId(STR_DATAPILOT_SUBTOTAL))); xQueryBox->set_default_response(RET_YES); - if (xQueryBox->run() == RET_NO) - bOK = false; + xQueryBox->runAsync(xQueryBox, [aRange, pDoc, pTypeDlg, aDestPos, + pScMod, pTabViewShell, pSrcErrorId] (int nResult2) mutable { + if (nResult2 == RET_NO) + return; + + std::unique_ptr<ScDPObject> pNewDPObject; + SetupRangeForPivotTableDialog(aRange, aDestPos, pDoc, pSrcErrorId, pNewDPObject); + ErrorOrRunPivotLayoutDialog(pSrcErrorId, aDestPos, pScMod, pTabViewShell, pNewDPObject); + }); + + pTypeDlg->disposeOnce(); + return; } - if (bOK) - { - ScSheetSourceDesc aShtDesc(pDoc); - aShtDesc.SetSourceRange(aRange); - pSrcErrorId = aShtDesc.CheckSourceRange(); - if (!pSrcErrorId) - { - pNewDPObject.reset(new ScDPObject(pDoc)); - pNewDPObject->SetSheetDesc( aShtDesc ); - } - // output below source data - if ( aRange.aEnd.Row()+2 <= pDoc->MaxRow() - 4 ) - aDestPos = ScAddress( aRange.aStart.Col(), - aRange.aEnd.Row()+2, - aRange.aStart.Tab() ); - } + std::unique_ptr<ScDPObject> pNewDPObject; + SetupRangeForPivotTableDialog(aRange, aDestPos, pDoc, pSrcErrorId, pNewDPObject); + ErrorOrRunPivotLayoutDialog(pSrcErrorId, aDestPos, pScMod, pTabViewShell, pNewDPObject); } } - - if (pSrcErrorId) - { - // Error occurred during data creation. Launch an error and bail out. - std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(), - VclMessageType::Info, VclButtonsType::Ok, - ScResId(pSrcErrorId))); - xInfoBox->run(); - return; - } - - if ( pNewDPObject ) - pNewDPObject->SetOutRange( aDestPos ); - - RunPivotLayoutDialog(pScMod, pTabViewShell, pNewDPObject); } } |