1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include "pivotsource.hxx"
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())
52 maSelectedPagesList
.emplace_back(pObj
, rSelected
);
57 struct SelectedPageProcessor
59 void operator() ( PivotTableSources::SelectedPages
& rItem
)
61 // Set selected pages after building all dimension members.
65 rItem
.mpDP
->BuildAllDimensionMembers();
66 ScDPSaveData
* pSaveData
= rItem
.mpDP
->GetSaveData();
70 for (const auto& [rDimName
, rSelected
] : rItem
.maSelectedPages
)
72 ScDPSaveDimension
* pDim
= pSaveData
->GetExistingDimensionByName(rDimName
);
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: */