Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / data / dpsdbtab.cxx
blob9f50a68e4f295735adc302c02a3174c76bcaa984
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "dpsdbtab.hxx"
21 #include "global.hxx"
22 #include "globstr.hrc"
23 #include "dpfilteredcache.hxx"
24 #include "dptabres.hxx"
25 #include "document.hxx"
26 #include "dpobject.hxx"
28 #include <com/sun/star/sheet/DataImportMode.hpp>
29 #include <com/sun/star/sdb/CommandType.hpp>
31 using namespace com::sun::star;
33 using ::std::vector;
34 using ::com::sun::star::uno::Sequence;
35 using ::com::sun::star::uno::Any;
37 sal_Int32 ScImportSourceDesc::GetCommandType() const
39 sal_Int32 nSdbType = -1;
41 switch ( nType )
43 case sheet::DataImportMode_SQL: nSdbType = sdb::CommandType::COMMAND; break;
44 case sheet::DataImportMode_TABLE: nSdbType = sdb::CommandType::TABLE; break;
45 case sheet::DataImportMode_QUERY: nSdbType = sdb::CommandType::QUERY; break;
46 default:
49 return nSdbType;
52 const ScDPCache* ScImportSourceDesc::CreateCache(const ScDPDimensionSaveData* pDimData) const
54 if (!mpDoc)
55 return NULL;
57 sal_Int32 nSdbType = GetCommandType();
58 if (nSdbType < 0)
59 return NULL;
61 ScDPCollection::DBCaches& rCaches = mpDoc->GetDPCollection()->GetDBCaches();
62 return rCaches.getCache(nSdbType, aDBName, aObject, pDimData);
65 ScDatabaseDPData::ScDatabaseDPData(
66 ScDocument* pDoc, const ScDPCache& rCache) :
67 ScDPTableData(pDoc),
68 aCacheTable(rCache)
72 ScDatabaseDPData::~ScDatabaseDPData()
76 void ScDatabaseDPData::DisposeData()
78 //! use OpenDatabase here?
79 aCacheTable.clear();
82 long ScDatabaseDPData::GetColumnCount()
84 CreateCacheTable();
85 return GetCacheTable().getColSize();
89 OUString ScDatabaseDPData::getDimensionName(long nColumn)
91 if (getIsDataLayoutDimension(nColumn))
93 //! different internal and display names?
94 //return "Data";
95 return ScGlobal::GetRscString(STR_PIVOT_DATA);
98 CreateCacheTable();
99 return aCacheTable.getFieldName(static_cast<SCCOL>(nColumn));
102 sal_Bool ScDatabaseDPData::getIsDataLayoutDimension(long nColumn)
104 return ( nColumn == GetCacheTable().getColSize());
107 sal_Bool ScDatabaseDPData::IsDateDimension(long /* nDim */)
109 //! later...
110 return false;
113 void ScDatabaseDPData::SetEmptyFlags( sal_Bool /* bIgnoreEmptyRows */, sal_Bool /* bRepeatIfEmpty */ )
115 // not used for database data
116 //! disable flags
119 void ScDatabaseDPData::CreateCacheTable()
121 if (!aCacheTable.empty())
122 // cache table already created.
123 return;
125 aCacheTable.fillTable();
128 void ScDatabaseDPData::FilterCacheTable(const vector<ScDPFilteredCache::Criterion>& rCriteria, const boost::unordered_set<sal_Int32>& rCatDims)
130 CreateCacheTable();
131 aCacheTable.filterByPageDimension(
132 rCriteria, (IsRepeatIfEmpty() ? rCatDims : boost::unordered_set<sal_Int32>()));
135 void ScDatabaseDPData::GetDrillDownData(const vector<ScDPFilteredCache::Criterion>& rCriteria, const boost::unordered_set<sal_Int32>& rCatDims, Sequence< Sequence<Any> >& rData)
137 CreateCacheTable();
138 sal_Int32 nRowSize = aCacheTable.getRowSize();
139 if (!nRowSize)
140 return;
142 aCacheTable.filterTable(
143 rCriteria, rData, IsRepeatIfEmpty() ? rCatDims : boost::unordered_set<sal_Int32>());
146 void ScDatabaseDPData::CalcResults(CalcInfo& rInfo, bool bAutoShow)
148 CreateCacheTable();
149 CalcResultsFromCacheTable( aCacheTable, rInfo, bAutoShow);
152 const ScDPFilteredCache& ScDatabaseDPData::GetCacheTable() const
154 return aCacheTable;
157 void ScDatabaseDPData::ReloadCacheTable()
159 aCacheTable.clear();
160 CreateCacheTable();
163 // -----------------------------------------------------------------------
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */