sc/source/ui/docshell/SheetViewOperationsTester.cxx | 57 --------------- sc/source/ui/inc/SheetViewOperationsTester.hxx | 2 sc/source/ui/inc/operation/Operation.hxx | 23 +++--- sc/source/ui/operation/ApplyAttributesOperation.cxx | 9 -- sc/source/ui/operation/DeleteCellOperation.cxx | 5 - sc/source/ui/operation/DeleteContentOperation.cxx | 5 - sc/source/ui/operation/Operation.cxx | 72 +++++++++++++++++++- sc/source/ui/operation/SetEditTextOperation.cxx | 4 - sc/source/ui/operation/SetFormulaOperation.cxx | 4 - sc/source/ui/operation/SetNormalStringOperation.cxx | 5 - sc/source/ui/operation/SetStringOperation.cxx | 3 sc/source/ui/operation/SetValueOperation.cxx | 4 - 12 files changed, 92 insertions(+), 101 deletions(-)
New commits: commit 46d76b43606e3dae88c90a1c811540333148fa2e Author: Tomaž Vajngerl <[email protected]> AuthorDate: Tue Feb 17 23:42:32 2026 +0900 Commit: Miklos Vajna <[email protected]> CommitDate: Wed Feb 18 10:22:47 2026 +0100 sc: Move sync function to abstract Operation class SheetViewOperationsTester is supposed to only test if we can run a operation for the sheet view, so this moves the functionality to sync a sheet view to Oepration abstract class, so every operation has access to it. Change-Id: I8917839d2f24b27dece31246172f0b9fe12e1445 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199549 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/sc/source/ui/docshell/SheetViewOperationsTester.cxx b/sc/source/ui/docshell/SheetViewOperationsTester.cxx index 82b5e38c735b..675d49f9bd6c 100644 --- a/sc/source/ui/docshell/SheetViewOperationsTester.cxx +++ b/sc/source/ui/docshell/SheetViewOperationsTester.cxx @@ -47,63 +47,6 @@ constexpr bool doesUnsyncSheetView(OperationType eOperationType) } // end anonymous namespace -bool SheetViewOperationsTester::doesUnsync(OperationType /*eOperationType*/) { return true; } - -void SheetViewOperationsTester::sync() -{ - if (!mpViewData) - return; - - auto& rDocument = mpViewData->GetDocument(); - SCTAB nTab = mpViewData->GetTabNumber(); - - if (rDocument.IsSheetViewHolder(nTab)) - return; - - std::shared_ptr<sc::SheetViewManager> pManager = rDocument.GetSheetViewManager(nTab); - if (!pManager || pManager->isEmpty()) - return; - - for (std::shared_ptr<SheetView> const& pSheetView : pManager->getSheetViews()) - { - SCTAB nSheetViewTab = pSheetView->getTableNumber(); - - std::optional<ScQueryParam> oQueryParam; - ScDBData* pNoNameData = rDocument.GetAnonymousDBData(nSheetViewTab); - if (pNoNameData && pNoNameData->HasAutoFilter()) - { - if (pNoNameData->HasQueryParam()) - { - oQueryParam.emplace(); - pNoNameData->GetQueryParam(*oQueryParam); - } - } - - rDocument.OverwriteContent(nTab, nSheetViewTab); - - // Reverse the sorting of the default view in the sheet view - if (auto const& rReorderParameters = pSheetView->getReorderParameters()) - { - sc::ReorderParam aReorderParameters(*rReorderParameters); - aReorderParameters.maSortRange.aStart.SetTab(nSheetViewTab); - aReorderParameters.maSortRange.aEnd.SetTab(nSheetViewTab); - aReorderParameters.reverse(); - rDocument.Reorder(aReorderParameters); - } - - auto const& oSortParam = pSheetView->getSortParam(); - if (oSortParam) - { - // We need to reset the sort order for the sheet view as we will sort again - pSheetView->resetSortOrder(); - rDocument.Sort(nSheetViewTab, *oSortParam, false, false, nullptr, nullptr); - } - - if (oQueryParam) - rDocument.Query(nSheetViewTab, *oQueryParam, false, false); - } -} - bool SheetViewOperationsTester::check(OperationType eOperationType) const { if (!mpViewData) diff --git a/sc/source/ui/inc/SheetViewOperationsTester.hxx b/sc/source/ui/inc/SheetViewOperationsTester.hxx index df674c73a37a..d4264b5e718a 100644 --- a/sc/source/ui/inc/SheetViewOperationsTester.hxx +++ b/sc/source/ui/inc/SheetViewOperationsTester.hxx @@ -31,9 +31,7 @@ public: { } - static bool doesUnsync(OperationType eOperationType); bool check(OperationType eOperationType) const; - void sync(); }; } diff --git a/sc/source/ui/inc/operation/Operation.hxx b/sc/source/ui/inc/operation/Operation.hxx index 351ac9ecceb4..cafc00a68583 100644 --- a/sc/source/ui/inc/operation/Operation.hxx +++ b/sc/source/ui/inc/operation/Operation.hxx @@ -14,6 +14,7 @@ class ScMarkData; class ScAddress; +class ScViewData; namespace sc { @@ -38,23 +39,23 @@ protected: OperationType meType = OperationType::Unknown; bool mbApi : 1 = false; bool mbRecord : 1 = false; + ScViewData* mpViewData; -public: - Operation(OperationType eType, bool bRecord, bool bApi) - : meType(eType) - , mbApi(bApi) - , mbRecord(bRecord) - { - } - - bool run(); bool checkSheetViewProtection(); /** Convert address from a sheet view to the address in default view, take sorting into account. */ - static ScAddress convertAddress(ScAddress const& rAddress); + ScAddress convertAddress(ScAddress const& rAddress); /** Convert a mark from a sheet view to the mark in default view, take sorting into account. */ - static ScMarkData convertMark(ScMarkData const& rMarkData); + ScMarkData convertMark(ScMarkData const& rMarkData); + + /** Synchronizes the sheet views and the default view */ + void syncSheetViews(); + +public: + Operation(OperationType eType, bool bRecord, bool bApi); + + bool run(); virtual bool runImplementation() = 0; }; diff --git a/sc/source/ui/operation/ApplyAttributesOperation.cxx b/sc/source/ui/operation/ApplyAttributesOperation.cxx index c79d221ea8e8..06981f4dac4c 100644 --- a/sc/source/ui/operation/ApplyAttributesOperation.cxx +++ b/sc/source/ui/operation/ApplyAttributesOperation.cxx @@ -57,7 +57,6 @@ bool ApplyAttributesOperation::runImplementation() return false; } - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); ScDocShellModificator aModificator(mrDocShell); //! Border @@ -99,7 +98,7 @@ bool ApplyAttributesOperation::runImplementation() else if (nExtFlags & SC_PF_LINES) ScDocFunc::PaintAbove(mrDocShell, aMultiRange); // because of lines above the range - aSheetViewTester.sync(); + syncSheetViews(); aModificator.SetDocumentModified(); } @@ -132,7 +131,6 @@ bool ApplyAttributesWithChangedRangeOperation::runImplementation() ScMarkData aMark = convertMark(mrMark); - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); ScDocShellModificator aModificator(mrDocShell); const ScRange& aMarkRange = aMark.GetMultiMarkArea(); @@ -178,7 +176,7 @@ bool ApplyAttributesWithChangedRangeOperation::runImplementation() rDoc.ApplySelectionPattern(mrPattern, aMark, pEditDataArray); - aSheetViewTester.sync(); + syncSheetViews(); mrDocShell.PostPaint(nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab, PaintPartFlags::Grid, mnExtFlags | SC_PF_TESTMERGE); @@ -214,7 +212,6 @@ bool ApplyAttributesToCellOperation::runImplementation() ScAddress aPosition = convertAddress(mrPosition); - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); ScDocShellModificator aModificator(mrDocShell); SCCOL nCol = aPosition.Col(); @@ -250,7 +247,7 @@ bool ApplyAttributesToCellOperation::runImplementation() } pOldPat.reset(); // is copied in undo (Pool) - aSheetViewTester.sync(); + syncSheetViews(); mrDocShell.PostPaint(nCol, nRow, nTab, nCol, nRow, nTab, PaintPartFlags::Grid, mnExtFlags | SC_PF_TESTMERGE); diff --git a/sc/source/ui/operation/DeleteCellOperation.cxx b/sc/source/ui/operation/DeleteCellOperation.cxx index fbd88156b078..9e5f4bebf9b3 100644 --- a/sc/source/ui/operation/DeleteCellOperation.cxx +++ b/sc/source/ui/operation/DeleteCellOperation.cxx @@ -40,8 +40,6 @@ bool DeleteCellOperation::runImplementation() if (mbRecord && !rDoc.IsUndoEnabled()) mbRecord = false; - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); - // Convert taking sheet view sorting into account ScAddress aPosition = convertAddress(mrPosition); ScMarkData aMarkData = convertMark(mrMark); @@ -104,8 +102,7 @@ bool DeleteCellOperation::runImplementation() aPosition.Row(), aPosition.Tab(), PaintPartFlags::Grid, nExtFlags, nBefore); - if (sc::SheetViewOperationsTester::doesUnsync(meType)) - aSheetViewTester.sync(); + syncSheetViews(); aModificator.SetDocumentModified(); diff --git a/sc/source/ui/operation/DeleteContentOperation.cxx b/sc/source/ui/operation/DeleteContentOperation.cxx index 5981a5a0c66c..5c2e25670c7a 100644 --- a/sc/source/ui/operation/DeleteContentOperation.cxx +++ b/sc/source/ui/operation/DeleteContentOperation.cxx @@ -45,8 +45,6 @@ bool DeleteContentOperation::runImplementation() if (mbRecord && !rDoc.IsUndoEnabled()) mbRecord = false; - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); - ScEditableTester aTester = ScEditableTester::CreateAndTestSelection(rDoc, mrMark); if (!aTester.IsEditable()) { @@ -113,8 +111,7 @@ bool DeleteContentOperation::runImplementation() pDataSpans, bMulti, bDrawUndo); } - if (sc::SheetViewOperationsTester::doesUnsync(meType)) - aSheetViewTester.sync(); + syncSheetViews(); if (!mrDocFunc.AdjustRowHeight(aExtendedRange, true, mbApi)) mrDocShell.PostPaint(aExtendedRange, PaintPartFlags::Grid, nExtFlags); diff --git a/sc/source/ui/operation/Operation.cxx b/sc/source/ui/operation/Operation.cxx index a10877954296..024f4a2b0e12 100644 --- a/sc/source/ui/operation/Operation.cxx +++ b/sc/source/ui/operation/Operation.cxx @@ -18,6 +18,11 @@ #include <SheetView.hxx> #include <sal/log.hxx> +#include <viewdata.hxx> +#include <dbdata.hxx> +#include <queryparam.hxx> +#include <sortparam.hxx> + namespace sc { namespace @@ -40,9 +45,17 @@ std::shared_ptr<SheetView> getCurrentSheetView(ScViewData* pViewData) } } +Operation::Operation(OperationType eType, bool bRecord, bool bApi) + : meType(eType) + , mbApi(bApi) + , mbRecord(bRecord) + , mpViewData(ScDocShell::GetViewData()) +{ +} + ScAddress Operation::convertAddress(ScAddress const& rAddress) { - ScViewData* pViewData = ScDocShell::GetViewData(); + ScViewData* pViewData = mpViewData; std::shared_ptr<SheetView> pSheetView = getCurrentSheetView(pViewData); @@ -75,7 +88,7 @@ ScAddress Operation::convertAddress(ScAddress const& rAddress) ScMarkData Operation::convertMark(ScMarkData const& rMarkData) { - ScViewData* pViewData = ScDocShell::GetViewData(); + ScViewData* pViewData = mpViewData; std::shared_ptr<SheetView> pSheetView = getCurrentSheetView(pViewData); @@ -172,6 +185,61 @@ ScMarkData Operation::convertMark(ScMarkData const& rMarkData) return aNewMark; } +void Operation::syncSheetViews() +{ + if (!mpViewData) + return; + + auto& rDocument = mpViewData->GetDocument(); + SCTAB nTab = mpViewData->GetTabNumber(); + + if (rDocument.IsSheetViewHolder(nTab)) + return; + + std::shared_ptr<sc::SheetViewManager> pManager = rDocument.GetSheetViewManager(nTab); + if (!pManager || pManager->isEmpty()) + return; + + for (std::shared_ptr<SheetView> const& pSheetView : pManager->getSheetViews()) + { + SCTAB nSheetViewTab = pSheetView->getTableNumber(); + + std::optional<ScQueryParam> oQueryParam; + ScDBData* pNoNameData = rDocument.GetAnonymousDBData(nSheetViewTab); + if (pNoNameData && pNoNameData->HasAutoFilter()) + { + if (pNoNameData->HasQueryParam()) + { + oQueryParam.emplace(); + pNoNameData->GetQueryParam(*oQueryParam); + } + } + + rDocument.OverwriteContent(nTab, nSheetViewTab); + + // Reverse the sorting of the default view in the sheet view + if (auto const& rReorderParameters = pSheetView->getReorderParameters()) + { + sc::ReorderParam aReorderParameters(*rReorderParameters); + aReorderParameters.maSortRange.aStart.SetTab(nSheetViewTab); + aReorderParameters.maSortRange.aEnd.SetTab(nSheetViewTab); + aReorderParameters.reverse(); + rDocument.Reorder(aReorderParameters); + } + + auto const& oSortParam = pSheetView->getSortParam(); + if (oSortParam) + { + // We need to reset the sort order for the sheet view as we will sort again + pSheetView->resetSortOrder(); + rDocument.Sort(nSheetViewTab, *oSortParam, false, false, nullptr, nullptr); + } + + if (oQueryParam) + rDocument.Query(nSheetViewTab, *oQueryParam, false, false); + } +} + bool Operation::checkSheetViewProtection() { sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); diff --git a/sc/source/ui/operation/SetEditTextOperation.cxx b/sc/source/ui/operation/SetEditTextOperation.cxx index 9b2f3175ec65..037dfb55bb94 100644 --- a/sc/source/ui/operation/SetEditTextOperation.cxx +++ b/sc/source/ui/operation/SetEditTextOperation.cxx @@ -37,8 +37,6 @@ bool SetEditTextOperation::runImplementation() { ScAddress aPosition = convertAddress(mrPosition); - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); - ScDocShellModificator aModificator(mrDocShell); ScDocument& rDoc = mrDocShell.GetDocument(); bool bUndo = rDoc.IsUndoEnabled(); @@ -60,7 +58,7 @@ bool SetEditTextOperation::runImplementation() std::make_unique<ScUndoSetCell>(&mrDocShell, aPosition, aOldVal, aNewVal)); } - aSheetViewTester.sync(); + syncSheetViews(); if (bHeight) mrDocFunc.AdjustRowHeight(ScRange(aPosition), true, mbApi); diff --git a/sc/source/ui/operation/SetFormulaOperation.cxx b/sc/source/ui/operation/SetFormulaOperation.cxx index 2eb844283cb9..fe3c1310fa96 100644 --- a/sc/source/ui/operation/SetFormulaOperation.cxx +++ b/sc/source/ui/operation/SetFormulaOperation.cxx @@ -41,8 +41,6 @@ bool SetFormulaOperation::runImplementation() ScFormulaCell* pCell(mpFormulaCell); std::unique_ptr<ScFormulaCell> xCell(mpFormulaCell); - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); - ScDocShellModificator aModificator(mrDocShell); ScDocument& rDoc = mrDocShell.GetDocument(); bool bUndo = rDoc.IsUndoEnabled(); @@ -76,7 +74,7 @@ bool SetFormulaOperation::runImplementation() std::make_unique<ScUndoSetCell>(&mrDocShell, aPosition, aOldVal, aNewVal)); } - aSheetViewTester.sync(); + syncSheetViews(); if (bHeight) mrDocFunc.AdjustRowHeight(ScRange(aPosition), true, mbApi); diff --git a/sc/source/ui/operation/SetNormalStringOperation.cxx b/sc/source/ui/operation/SetNormalStringOperation.cxx index 2dfdcbf74fef..9ca0288737fd 100644 --- a/sc/source/ui/operation/SetNormalStringOperation.cxx +++ b/sc/source/ui/operation/SetNormalStringOperation.cxx @@ -39,8 +39,6 @@ bool SetNormalStringOperation::runImplementation() bool bUndo(rDoc.IsUndoEnabled()); - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); - ScAddress aPosition = convertAddress(mrPosition); ScEditableTester aTester = ScEditableTester::CreateAndTestBlock( @@ -90,8 +88,7 @@ bool SetNormalStringOperation::runImplementation() if (bEditDeleted || rDoc.HasAttrib(ScRange(aPosition), HasAttrFlags::NeedHeight)) mrDocFunc.AdjustRowHeight(ScRange(aPosition), true, mbApi); - if (sc::SheetViewOperationsTester::doesUnsync(meType)) - aSheetViewTester.sync(); + syncSheetViews(); mrDocShell.PostPaintCell(aPosition, std::max(nBefore, nAfter)); aModificator.SetDocumentModified(); diff --git a/sc/source/ui/operation/SetStringOperation.cxx b/sc/source/ui/operation/SetStringOperation.cxx index 050492df5179..bdb5b30b14a9 100644 --- a/sc/source/ui/operation/SetStringOperation.cxx +++ b/sc/source/ui/operation/SetStringOperation.cxx @@ -36,7 +36,6 @@ bool SetStringOperation::runImplementation() { ScAddress aPosition = convertAddress(mrPosition); - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); ScDocShellModificator aModificator(mrDocShell); ScDocument& rDoc = mrDocShell.GetDocument(); @@ -61,7 +60,7 @@ bool SetStringOperation::runImplementation() std::make_unique<ScUndoSetCell>(&mrDocShell, aPosition, aOldVal, aNewVal)); } - aSheetViewTester.sync(); + syncSheetViews(); if (bHeight) mrDocFunc.AdjustRowHeight(ScRange(aPosition), true, mbApi); diff --git a/sc/source/ui/operation/SetValueOperation.cxx b/sc/source/ui/operation/SetValueOperation.cxx index a58f45973ad5..e74818006af0 100644 --- a/sc/source/ui/operation/SetValueOperation.cxx +++ b/sc/source/ui/operation/SetValueOperation.cxx @@ -35,8 +35,6 @@ bool SetValueOperation::runImplementation() { ScAddress aPosition = convertAddress(mrPosition); - sc::SheetViewOperationsTester aSheetViewTester(ScDocShell::GetViewData()); - ScDocShellModificator aModificator(mrDocShell); ScDocument& rDoc = mrDocShell.GetDocument(); bool bUndo = rDoc.IsUndoEnabled(); @@ -57,7 +55,7 @@ bool SetValueOperation::runImplementation() std::make_unique<ScUndoSetCell>(&mrDocShell, aPosition, aOldVal, aNewVal)); } - aSheetViewTester.sync(); + syncSheetViews(); if (bHeight) mrDocFunc.AdjustRowHeight(ScRange(aPosition), true, mbApi);
