Line data Source code
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 "pivotsource.hxx"
11 :
12 : #include <dpsave.hxx>
13 :
14 : namespace sc {
15 :
16 4 : PivotTableSources::SelectedPages::SelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected ) :
17 4 : mpDP(pObj), maSelectedPages(rSelected) {}
18 :
19 14 : PivotTableSources::SheetSource::SheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc ) :
20 14 : mpDP(pObj), maDesc(rDesc) {}
21 :
22 0 : PivotTableSources::DBSource::DBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc ) :
23 0 : mpDP(pObj), maDesc(rDesc) {}
24 :
25 0 : PivotTableSources::ServiceSource::ServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc ) :
26 0 : mpDP(pObj), maDesc(rDesc) {}
27 :
28 10 : PivotTableSources::PivotTableSources() {}
29 :
30 14 : void PivotTableSources::appendSheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc )
31 : {
32 14 : maSheetSources.push_back(SheetSource(pObj, rDesc));
33 14 : }
34 :
35 0 : void PivotTableSources::appendDBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc )
36 : {
37 0 : maDBSources.push_back(DBSource(pObj, rDesc));
38 0 : }
39 :
40 0 : void PivotTableSources::appendServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc )
41 : {
42 0 : maServiceSources.push_back(ServiceSource(pObj, rDesc));
43 0 : }
44 :
45 14 : void PivotTableSources::appendSelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected )
46 : {
47 14 : if (rSelected.empty())
48 24 : return;
49 :
50 4 : maSelectedPagesList.push_back(SelectedPages(pObj, rSelected));
51 : }
52 :
53 : namespace {
54 :
55 : struct SelectedPageProcessor : std::unary_function<PivotTableSources::SelectedPages, void>
56 : {
57 4 : void operator() ( PivotTableSources::SelectedPages& rItem )
58 : {
59 : // Set selected pages after building all dimension members.
60 4 : if (!rItem.mpDP)
61 0 : return;
62 :
63 4 : rItem.mpDP->BuildAllDimensionMembers();
64 4 : ScDPSaveData* pSaveData = rItem.mpDP->GetSaveData();
65 4 : if (!pSaveData)
66 0 : return;
67 :
68 4 : PivotTableSources::SelectedPagesType::const_iterator it = rItem.maSelectedPages.begin(), itEnd = rItem.maSelectedPages.end();
69 8 : for (; it != itEnd; ++it)
70 : {
71 4 : const OUString& rDimName = it->first;
72 4 : const OUString& rSelected = it->second;
73 4 : ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName(rDimName);
74 4 : if (!pDim)
75 0 : continue;
76 :
77 4 : pDim->SetCurrentPage(&rSelected);
78 : }
79 : }
80 : };
81 :
82 : struct PivotSheetDescSetter : std::unary_function<sc::PivotTableSources::SheetSource, void>
83 : {
84 14 : void operator() ( sc::PivotTableSources::SheetSource& rSrc )
85 : {
86 14 : ScDPObject* pObj = rSrc.mpDP;
87 14 : pObj->SetSheetDesc(rSrc.maDesc);
88 14 : }
89 : };
90 :
91 : struct PivotDBDescSetter : std::unary_function<sc::PivotTableSources::DBSource, void>
92 : {
93 0 : void operator() ( sc::PivotTableSources::DBSource& rSrc )
94 : {
95 0 : ScDPObject* pObj = rSrc.mpDP;
96 0 : pObj->SetImportDesc(rSrc.maDesc);
97 0 : }
98 : };
99 :
100 : struct PivotServiceDataSetter : std::unary_function<sc::PivotTableSources::ServiceSource, void>
101 : {
102 0 : void operator() ( sc::PivotTableSources::ServiceSource& rSrc )
103 : {
104 0 : ScDPObject* pObj = rSrc.mpDP;
105 0 : pObj->SetServiceData(rSrc.maDesc);
106 0 : }
107 : };
108 :
109 : }
110 :
111 10 : void PivotTableSources::process()
112 : {
113 10 : std::for_each(maSheetSources.begin(), maSheetSources.end(), PivotSheetDescSetter());
114 10 : std::for_each(maDBSources.begin(), maDBSources.end(), PivotDBDescSetter());
115 10 : std::for_each(maServiceSources.begin(), maServiceSources.end(), PivotServiceDataSetter());
116 10 : std::for_each(maSelectedPagesList.begin(), maSelectedPagesList.end(), SelectedPageProcessor());
117 10 : }
118 :
119 228 : }
120 :
121 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|