/src/libreoffice/sc/source/ui/operation/UpdatePivotTableOperation.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include <operation/UpdatePivotTableOperation.hxx> |
11 | | #include <operation/PivotTableOperationCommon.hxx> |
12 | | |
13 | | #include <vcl/svapp.hxx> |
14 | | #include <vcl/vclenum.hxx> |
15 | | #include <vcl/weld/MessageDialog.hxx> |
16 | | #include <vcl/weld/WaitObject.hxx> |
17 | | #include <vcl/weld/Window.hxx> |
18 | | |
19 | | #include <undodat.hxx> |
20 | | #include <scresid.hxx> |
21 | | #include <hints.hxx> |
22 | | |
23 | | namespace sc |
24 | | { |
25 | | UpdatePivotTableOperation::UpdatePivotTableOperation(ScDocShell& rDocShell, ScDPObject& rDPObject, |
26 | | bool bRecord, bool bApi) |
27 | 0 | : PivotTableOperation(OperationType::PivotTableUpdate, rDocShell, bRecord, bApi) |
28 | 0 | , mrDPObject(rDPObject) |
29 | 0 | { |
30 | 0 | } |
31 | | |
32 | | bool UpdatePivotTableOperation::runImplementation() |
33 | 0 | { |
34 | 0 | ScDocShellModificator aModificator(mrDocShell); |
35 | 0 | weld::WaitObject aWait(ScDocShell::GetActiveDialogParent()); |
36 | |
|
37 | 0 | ScDocument& rDoc = mrDocShell.GetDocument(); |
38 | | |
39 | | // Use default view's DPObject when called from a sheet view |
40 | 0 | ScDPObject* pDPObject = findDefaultViewDPObject(mrDPObject); |
41 | 0 | if (!pDPObject) |
42 | 0 | pDPObject = &mrDPObject; |
43 | | |
44 | | // Apply the SaveData from the input DPObject (which may have layout changes) |
45 | 0 | if (pDPObject != &mrDPObject && mrDPObject.GetSaveData()) |
46 | 0 | pDPObject->SetSaveData(*mrDPObject.GetSaveData()); |
47 | |
|
48 | 0 | if (!sc::pivot::isEditable(mrDocShell, pDPObject->GetOutRange(), mbApi, |
49 | 0 | sc::EditAction::UpdatePivotTable)) |
50 | 0 | return false; |
51 | | |
52 | 0 | ScDocumentUniquePtr pOldUndoDoc; |
53 | 0 | ScDocumentUniquePtr pNewUndoDoc; |
54 | |
|
55 | 0 | ScDPObject aUndoDPObject(*pDPObject); // For undo or revert on failure. |
56 | |
|
57 | 0 | if (mbRecord && !rDoc.IsUndoEnabled()) |
58 | 0 | mbRecord = false; |
59 | |
|
60 | 0 | if (mbRecord) |
61 | 0 | sc::pivot::createUndoDoc(pOldUndoDoc, rDoc, pDPObject->GetOutRange()); |
62 | |
|
63 | 0 | pDPObject->SetAllowMove(false); |
64 | 0 | pDPObject->ReloadGroupTableData(); |
65 | 0 | if (!pDPObject->SyncAllDimensionMembers()) |
66 | 0 | return false; |
67 | | |
68 | 0 | pDPObject->InvalidateData(); // before getting the new output area |
69 | | |
70 | | // make sure the table has a name (not set by dialog) |
71 | 0 | if (pDPObject->GetName().isEmpty()) |
72 | 0 | pDPObject->SetName(rDoc.GetDPCollection()->CreateNewName()); |
73 | |
|
74 | 0 | ScRange aNewOut; |
75 | 0 | if (!sc::pivot::checkNewOutputRange(*pDPObject, mrDocShell, aNewOut, mbApi, |
76 | 0 | sc::EditAction::UpdatePivotTable)) |
77 | 0 | { |
78 | 0 | *pDPObject = aUndoDPObject; |
79 | 0 | return false; |
80 | 0 | } |
81 | | |
82 | 0 | if (mbRecord) |
83 | 0 | sc::pivot::createUndoDoc(pNewUndoDoc, rDoc, aNewOut); |
84 | | |
85 | | // Use spill checking output if the destination range has non-empty cells, |
86 | | // write #SPILL! into the origin cell instead of overwriting. |
87 | | // Skip the spill check during XML import |
88 | 0 | pDPObject->Output(aNewOut.aStart, !rDoc.IsImportingXML()); |
89 | 0 | mrDocShell.PostPaintGridAll(); |
90 | |
|
91 | 0 | if (mbRecord) |
92 | 0 | { |
93 | 0 | mrDocShell.GetUndoManager()->AddUndoAction(std::make_unique<ScUndoDataPilot>( |
94 | 0 | mrDocShell, std::move(pOldUndoDoc), std::move(pNewUndoDoc), &aUndoDPObject, pDPObject, |
95 | 0 | false)); |
96 | 0 | } |
97 | |
|
98 | 0 | syncSheetViews(); |
99 | | |
100 | | // notify API objects |
101 | 0 | rDoc.BroadcastUno(ScDataPilotModifiedHint(pDPObject->GetName())); |
102 | 0 | aModificator.SetDocumentModified(); |
103 | 0 | return true; |
104 | 0 | } |
105 | | } |
106 | | |
107 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |