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"
16 PivotTableSources::SelectedPages::SelectedPages( ScDPObject
* pObj
, const SelectedPagesType
& rSelected
) :
17 mpDP(pObj
), maSelectedPages(rSelected
) {}
19 PivotTableSources::SheetSource::SheetSource( ScDPObject
* pObj
, const ScSheetSourceDesc
& rDesc
) :
20 mpDP(pObj
), maDesc(rDesc
) {}
22 PivotTableSources::DBSource::DBSource( ScDPObject
* pObj
, const ScImportSourceDesc
& rDesc
) :
23 mpDP(pObj
), maDesc(rDesc
) {}
25 PivotTableSources::ServiceSource::ServiceSource( ScDPObject
* pObj
, const ScDPServiceDesc
& rDesc
) :
26 mpDP(pObj
), maDesc(rDesc
) {}
28 PivotTableSources::PivotTableSources() {}
30 void PivotTableSources::appendSheetSource( ScDPObject
* pObj
, const ScSheetSourceDesc
& rDesc
)
32 maSheetSources
.push_back(SheetSource(pObj
, rDesc
));
35 void PivotTableSources::appendDBSource( ScDPObject
* pObj
, const ScImportSourceDesc
& rDesc
)
37 maDBSources
.push_back(DBSource(pObj
, rDesc
));
40 void PivotTableSources::appendServiceSource( ScDPObject
* pObj
, const ScDPServiceDesc
& rDesc
)
42 maServiceSources
.push_back(ServiceSource(pObj
, rDesc
));
45 void PivotTableSources::appendSelectedPages( ScDPObject
* pObj
, const SelectedPagesType
& rSelected
)
47 if (rSelected
.empty())
50 maSelectedPagesList
.push_back(SelectedPages(pObj
, rSelected
));
55 struct SelectedPageProcessor
: std::unary_function
<PivotTableSources::SelectedPages
, void>
57 void operator() ( PivotTableSources::SelectedPages
& rItem
)
59 // Set selected pages after building all dimension members.
63 rItem
.mpDP
->BuildAllDimensionMembers();
64 ScDPSaveData
* pSaveData
= rItem
.mpDP
->GetSaveData();
68 PivotTableSources::SelectedPagesType::const_iterator it
= rItem
.maSelectedPages
.begin(), itEnd
= rItem
.maSelectedPages
.end();
69 for (; it
!= itEnd
; ++it
)
71 const OUString
& rDimName
= it
->first
;
72 const OUString
& rSelected
= it
->second
;
73 ScDPSaveDimension
* pDim
= pSaveData
->GetExistingDimensionByName(rDimName
);
77 pDim
->SetCurrentPage(&rSelected
);
82 struct PivotSheetDescSetter
: std::unary_function
<sc::PivotTableSources::SheetSource
, void>
84 void operator() ( sc::PivotTableSources::SheetSource
& rSrc
)
86 ScDPObject
* pObj
= rSrc
.mpDP
;
87 pObj
->SetSheetDesc(rSrc
.maDesc
);
91 struct PivotDBDescSetter
: std::unary_function
<sc::PivotTableSources::DBSource
, void>
93 void operator() ( sc::PivotTableSources::DBSource
& rSrc
)
95 ScDPObject
* pObj
= rSrc
.mpDP
;
96 pObj
->SetImportDesc(rSrc
.maDesc
);
100 struct PivotServiceDataSetter
: std::unary_function
<sc::PivotTableSources::ServiceSource
, void>
102 void operator() ( sc::PivotTableSources::ServiceSource
& rSrc
)
104 ScDPObject
* pObj
= rSrc
.mpDP
;
105 pObj
->SetServiceData(rSrc
.maDesc
);
111 void PivotTableSources::process()
113 std::for_each(maSheetSources
.begin(), maSheetSources
.end(), PivotSheetDescSetter());
114 std::for_each(maDBSources
.begin(), maDBSources
.end(), PivotDBDescSetter());
115 std::for_each(maServiceSources
.begin(), maServiceSources
.end(), PivotServiceDataSetter());
116 std::for_each(maSelectedPagesList
.begin(), maSelectedPagesList
.end(), SelectedPageProcessor());
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */