Correctly set pivot's popup flag when importing from Excel docs.

This commit is contained in:
Kohei Yoshida 2012-02-14 12:06:21 -05:00
parent 691f2451c8
commit 4eedf5dc54
3 changed files with 77 additions and 28 deletions

View file

@ -240,8 +240,10 @@ public:
class ScDPSaveData
{
public:
typedef boost::ptr_vector<ScDPSaveDimension> DimsType;
private:
boost::ptr_vector<ScDPSaveDimension> aDimList;
DimsType aDimList;
ScDPDimensionSaveData* pDimensionData; // settings that create new dimensions
sal_uInt16 nColumnGrandMode;
sal_uInt16 nRowGrandMode;
@ -270,8 +272,19 @@ public:
SC_DLLPUBLIC void SetGrandTotalName(const ::rtl::OUString& rName);
SC_DLLPUBLIC const ::rtl::OUString* GetGrandTotalName() const;
const boost::ptr_vector<ScDPSaveDimension>& GetDimensions() const
{ return aDimList; }
SC_DLLPUBLIC const DimsType& GetDimensions() const;
/**
* Get all dimensions in a given orientation. The order represents the
* actual order of occurrence. The returned list also includes data
* layout dimension.
*
* @param eOrientation orientation
* @param rDims (out) list of dimensions for specified orientation
*/
SC_DLLPUBLIC void GetAllDimensionsByOrientation(
com::sun::star::sheet::DataPilotFieldOrientation eOrientation,
std::vector<const ScDPSaveDimension*>& rDims) const;
void AddDimension(ScDPSaveDimension* pDim)
{ aDimList.push_back(pDim); }

View file

@ -818,6 +818,28 @@ const OUString* ScDPSaveData::GetGrandTotalName() const
return mpGrandTotalName.get();
}
const ScDPSaveData::DimsType& ScDPSaveData::GetDimensions() const
{
return aDimList;
}
void ScDPSaveData::GetAllDimensionsByOrientation(
sheet::DataPilotFieldOrientation eOrientation, std::vector<const ScDPSaveDimension*>& rDims) const
{
std::vector<const ScDPSaveDimension*> aDims;
DimsType::const_iterator it = aDimList.begin(), itEnd = aDimList.end();
for (; it != itEnd; ++it)
{
const ScDPSaveDimension& rDim = *it;
if (rDim.GetOrientation() != static_cast<sal_uInt16>(eOrientation))
continue;
aDims.push_back(&rDim);
}
rDims.swap(aDims);
}
ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const ::rtl::OUString& rName)
{
boost::ptr_vector<ScDPSaveDimension>::const_iterator iter;

View file

@ -60,6 +60,8 @@
#include <vector>
using namespace com::sun::star;
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using ::com::sun::star::sheet::DataPilotFieldOrientation;
@ -1476,9 +1478,11 @@ void XclImpPivotTable::ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveD
ScDocument& rDoc = GetDoc();
vector<ScAddress> aPageBtns;
aGeometry.getPageFieldPositions(aPageBtns);
vector<ScAddress>::const_iterator itr = aPageBtns.begin(), itrEnd = aPageBtns.end();
vector<const ScDPSaveDimension*> aFieldDims;
vector<ScAddress> aFieldBtns;
aGeometry.getPageFieldPositions(aFieldBtns);
vector<ScAddress>::const_iterator itr = aFieldBtns.begin(), itrEnd = aFieldBtns.end();
for (; itr != itrEnd; ++itr)
{
sal_uInt16 nMFlag = SC_MF_BUTTON;
@ -1491,32 +1495,42 @@ void XclImpPivotTable::ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveD
rDoc.ApplyFlagsTab(itr->Col()+1, itr->Row(), itr->Col()+1, itr->Row(), itr->Tab(), SC_MF_AUTO);
}
vector<ScAddress> aColBtns;
aGeometry.getColumnFieldPositions(aColBtns);
itr = aColBtns.begin();
itrEnd = aColBtns.end();
for (; itr != itrEnd; ++itr)
aGeometry.getColumnFieldPositions(aFieldBtns);
rSaveData.GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aFieldDims);
if (aFieldBtns.size() == aFieldDims.size())
{
sal_Int16 nMFlag = SC_MF_BUTTON | SC_MF_BUTTON_POPUP;
rtl::OUString aName;
rDoc.GetString(itr->Col(), itr->Row(), itr->Tab(), aName);
if (rSaveData.HasInvisibleMember(aName))
nMFlag |= SC_MF_HIDDEN_MEMBER;
rDoc.ApplyFlagsTab(itr->Col(), itr->Row(), itr->Col(), itr->Row(), itr->Tab(), nMFlag);
itr = aFieldBtns.begin();
itrEnd = aFieldBtns.end();
vector<const ScDPSaveDimension*>::const_iterator itDim = aFieldDims.begin();
for (; itr != itrEnd; ++itr, ++itDim)
{
sal_Int16 nMFlag = SC_MF_BUTTON;
const ScDPSaveDimension* pDim = *itDim;
if (pDim->HasInvisibleMember())
nMFlag |= SC_MF_HIDDEN_MEMBER;
if (!pDim->IsDataLayout())
nMFlag |= SC_MF_BUTTON_POPUP;
rDoc.ApplyFlagsTab(itr->Col(), itr->Row(), itr->Col(), itr->Row(), itr->Tab(), nMFlag);
}
}
vector<ScAddress> aRowBtns;
aGeometry.getRowFieldPositions(aRowBtns);
itr = aRowBtns.begin();
itrEnd = aRowBtns.end();
for (; itr != itrEnd; ++itr)
aGeometry.getRowFieldPositions(aFieldBtns);
rSaveData.GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aFieldDims);
if (aFieldBtns.size() == aFieldDims.size())
{
sal_Int16 nMFlag = SC_MF_BUTTON | SC_MF_BUTTON_POPUP;
rtl::OUString aName;
rDoc.GetString(itr->Col(), itr->Row(), itr->Tab(), aName);
if (rSaveData.HasInvisibleMember(aName))
nMFlag |= SC_MF_HIDDEN_MEMBER;
rDoc.ApplyFlagsTab(itr->Col(), itr->Row(), itr->Col(), itr->Row(), itr->Tab(), nMFlag);
itr = aFieldBtns.begin();
itrEnd = aFieldBtns.end();
vector<const ScDPSaveDimension*>::const_iterator itDim = aFieldDims.begin();
for (; itr != itrEnd; ++itr, ++itDim)
{
sal_Int16 nMFlag = SC_MF_BUTTON;
const ScDPSaveDimension* pDim = *itDim;
if (pDim->HasInvisibleMember())
nMFlag |= SC_MF_HIDDEN_MEMBER;
if (!pDim->IsDataLayout())
nMFlag |= SC_MF_BUTTON_POPUP;
rDoc.ApplyFlagsTab(itr->Col(), itr->Row(), itr->Col(), itr->Row(), itr->Tab(), nMFlag);
}
}
}