Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / xml / pivotsource.cxx
blobff856fc5e3a64f2ada889c06c78df6c9c1acbcab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "pivotsource.hxx"
12 #include <dpsave.hxx>
14 #include <algorithm>
16 namespace sc {
18 PivotTableSources::SelectedPages::SelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected ) :
19 mpDP(pObj), maSelectedPages(rSelected) {}
21 PivotTableSources::SheetSource::SheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc ) :
22 mpDP(pObj), maDesc(rDesc) {}
24 PivotTableSources::DBSource::DBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc ) :
25 mpDP(pObj), maDesc(rDesc) {}
27 PivotTableSources::ServiceSource::ServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc ) :
28 mpDP(pObj), maDesc(rDesc) {}
30 PivotTableSources::PivotTableSources() {}
32 void PivotTableSources::appendSheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc )
34 maSheetSources.emplace_back(pObj, rDesc);
37 void PivotTableSources::appendDBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc )
39 maDBSources.emplace_back(pObj, rDesc);
42 void PivotTableSources::appendServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc )
44 maServiceSources.emplace_back(pObj, rDesc);
47 void PivotTableSources::appendSelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected )
49 if (rSelected.empty())
50 return;
52 maSelectedPagesList.emplace_back(pObj, rSelected);
55 namespace {
57 struct SelectedPageProcessor
59 void operator() ( PivotTableSources::SelectedPages& rItem )
61 // Set selected pages after building all dimension members.
62 if (!rItem.mpDP)
63 return;
65 rItem.mpDP->BuildAllDimensionMembers();
66 ScDPSaveData* pSaveData = rItem.mpDP->GetSaveData();
67 if (!pSaveData)
68 return;
70 for (const auto& [rDimName, rSelected] : rItem.maSelectedPages)
72 ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName(rDimName);
73 if (!pDim)
74 continue;
76 pDim->SetCurrentPage(&rSelected);
81 struct PivotSheetDescSetter
83 void operator() ( sc::PivotTableSources::SheetSource& rSrc )
85 ScDPObject* pObj = rSrc.mpDP;
86 pObj->SetSheetDesc(rSrc.maDesc);
90 struct PivotDBDescSetter
92 void operator() ( sc::PivotTableSources::DBSource& rSrc )
94 ScDPObject* pObj = rSrc.mpDP;
95 pObj->SetImportDesc(rSrc.maDesc);
99 struct PivotServiceDataSetter
101 void operator() ( sc::PivotTableSources::ServiceSource& rSrc )
103 ScDPObject* pObj = rSrc.mpDP;
104 pObj->SetServiceData(rSrc.maDesc);
110 void PivotTableSources::process()
112 std::for_each(maSheetSources.begin(), maSheetSources.end(), PivotSheetDescSetter());
113 std::for_each(maDBSources.begin(), maDBSources.end(), PivotDBDescSetter());
114 std::for_each(maServiceSources.begin(), maServiceSources.end(), PivotServiceDataSetter());
115 std::for_each(maSelectedPagesList.begin(), maSelectedPagesList.end(), SelectedPageProcessor());
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */