calc59: #i114256# Don't move DataPilot fields to orientations that the source doesn't support

This commit is contained in:
Niklas Nebel 2010-09-01 17:53:25 +02:00
parent 7efea44937
commit 892fc048a3
10 changed files with 111 additions and 14 deletions

View file

@ -186,7 +186,7 @@ public:
bool IsDataDescriptionCell(const ScAddress& rPos);
bool IsDimNameInUse(const ::rtl::OUString& rName) const;
String GetDimName( long nDim, BOOL& rIsDataLayout );
String GetDimName( long nDim, BOOL& rIsDataLayout, sal_Int32* pFlags = NULL );
BOOL IsDuplicated( long nDim );
long GetDimCount();
void GetHeaderPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTableHeaderData& rData);
@ -259,6 +259,8 @@ public:
PivotField* pRefColFields = NULL, SCSIZE nRefColCount = 0,
PivotField* pRefRowFields = NULL, SCSIZE nRefRowCount = 0,
PivotField* pRefPageFields = NULL, SCSIZE nRefPageCount = 0 );
static bool IsOrientationAllowed( USHORT nOrient, sal_Int32 nDimFlags );
};

View file

@ -141,6 +141,7 @@ struct ScDPLabelData
SCsCOL mnCol;
USHORT mnFuncMask; /// Page/Column/Row subtotal function.
sal_Int32 mnUsedHier; /// Used hierarchy.
sal_Int32 mnFlags; /// Flags from the DataPilotSource dimension
bool mbShowAll; /// true = Show all (also empty) results.
bool mbIsValue; /// true = Sum or count in data field.

View file

@ -565,6 +565,7 @@
#define SC_UNO_FIELD_SUBTOTALNAME "FieldSubtotalName"
#define SC_UNO_GRANDTOTAL_NAME "GrandTotalName"
#define SC_UNO_HAS_HIDDEN_MEMBER "HasHiddenMember"
#define SC_UNO_FLAGS "Flags"
// (preliminary:)
#define SC_UNO_REFVALUE "ReferenceValue"

View file

@ -65,6 +65,7 @@
#include <com/sun/star/sheet/DataPilotTableHeaderData.hpp>
#include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
#include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
#include <com/sun/star/sheet/DimensionFlags.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
@ -845,7 +846,7 @@ bool ScDPObject::IsDimNameInUse(const OUString& rName) const
return false;
}
String ScDPObject::GetDimName( long nDim, BOOL& rIsDataLayout )
String ScDPObject::GetDimName( long nDim, BOOL& rIsDataLayout, sal_Int32* pFlags )
{
rIsDataLayout = FALSE;
String aRet;
@ -879,6 +880,10 @@ String ScDPObject::GetDimName( long nDim, BOOL& rIsDataLayout )
rIsDataLayout = TRUE;
else
aRet = String( aName );
if (pFlags)
*pFlags = ScUnoHelpFunctions::GetLongProperty( xDimProp,
rtl::OUString::createFromAscii(SC_UNO_FLAGS), 0 );
}
}
}
@ -2003,6 +2008,8 @@ BOOL ScDPObject::FillLabelData(ScPivotParam& rParam)
GetHierarchies(nDim, pNewLabel->maHiers);
GetMembers(nDim, GetUsedHierarchy(nDim), pNewLabel->maMembers);
lcl_FillLabelData(*pNewLabel, xDimProp);
pNewLabel->mnFlags = ScUnoHelpFunctions::GetLongProperty( xDimProp,
rtl::OUString::createFromAscii(SC_UNO_FLAGS), 0 );
rParam.maLabelArray.push_back(pNewLabel);
}
}
@ -2231,6 +2238,32 @@ void ScDPObject::ConvertOrientation( ScDPSaveData& rSaveData,
}
}
// static
bool ScDPObject::IsOrientationAllowed( USHORT nOrient, sal_Int32 nDimFlags )
{
bool bAllowed = true;
switch (nOrient)
{
case sheet::DataPilotFieldOrientation_PAGE:
bAllowed = ( nDimFlags & sheet::DimensionFlags::NO_PAGE_ORIENTATION ) == 0;
break;
case sheet::DataPilotFieldOrientation_COLUMN:
bAllowed = ( nDimFlags & sheet::DimensionFlags::NO_COLUMN_ORIENTATION ) == 0;
break;
case sheet::DataPilotFieldOrientation_ROW:
bAllowed = ( nDimFlags & sheet::DimensionFlags::NO_ROW_ORIENTATION ) == 0;
break;
case sheet::DataPilotFieldOrientation_DATA:
bAllowed = ( nDimFlags & sheet::DimensionFlags::NO_DATA_ORIENTATION ) == 0;
break;
default:
{
// allowed to remove from previous orientation
}
}
return bAllowed;
}
// -----------------------------------------------------------------------
// static

6
sc/source/core/data/dptabsrc.cxx Executable file → Normal file
View file

@ -1576,6 +1576,7 @@ uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDPDimension::getPropertySetIn
static SfxItemPropertyMapEntry aDPDimensionMap_Impl[] =
{
{MAP_CHAR_LEN(SC_UNO_FILTER), 0, &getCppuType((uno::Sequence<sheet::TableFilterField>*)0), 0, 0 },
{MAP_CHAR_LEN(SC_UNO_FLAGS), 0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNO_FUNCTION), 0, &getCppuType((sheet::GeneralFunction*)0), 0, 0 },
{MAP_CHAR_LEN(SC_UNO_ISDATALA), 0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY, 0 },
{MAP_CHAR_LEN(SC_UNO_NUMBERFO), 0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY, 0 },
@ -1753,6 +1754,11 @@ uno::Any SAL_CALL ScDPDimension::getPropertyValue( const rtl::OUString& aPropert
aRet <<= mpSubtotalName.get() ? *mpSubtotalName : OUString::createFromAscii("");
else if (aNameStr.EqualsAscii(SC_UNO_HAS_HIDDEN_MEMBER))
aRet <<= mbHasHiddenMember;
else if (aNameStr.EqualsAscii(SC_UNO_FLAGS))
{
sal_Int32 nFlags = 0; // tabular data: all orientations are possible
aRet <<= nFlags;
}
else
{
DBG_ERROR("unknown property");

View file

@ -82,6 +82,7 @@ ScDPLabelData::ScDPLabelData( const String& rName, short nCol, bool bIsValue ) :
mnCol( nCol ),
mnFuncMask( PIVOT_FUNC_NONE ),
mnUsedHier( 0 ),
mnFlags( 0 ),
mbShowAll( false ),
mbIsValue( bIsValue )
{

View file

@ -735,8 +735,9 @@ ScDPShowDetailDlg::ScDPShowDetailDlg( Window* pParent, ScDPObject& rDPObj, USHOR
for (long nDim=0; nDim<nDimCount; nDim++)
{
BOOL bIsDataLayout;
String aName = rDPObj.GetDimName( nDim, bIsDataLayout );
if ( !bIsDataLayout && !rDPObj.IsDuplicated( nDim ) )
sal_Int32 nDimFlags = 0;
String aName = rDPObj.GetDimName( nDim, bIsDataLayout, &nDimFlags );
if ( !bIsDataLayout && !rDPObj.IsDuplicated( nDim ) && ScDPObject::IsOrientationAllowed( nOrient, nDimFlags ) )
{
const ScDPSaveDimension* pDimension = pSaveData ? pSaveData->GetExistingDimensionByName(aName) : 0;
if ( !pDimension || (pDimension->GetOrientation() != nOrient) )

View file

@ -567,7 +567,9 @@ void ScDPLayoutDlg::AddField( size_t nFromIndex, ScDPFieldType eToType, const Po
}
}
if ( (toArr->back().get() == NULL)
bool bAllowed = IsOrientationAllowed( fData.mnCol, eToType );
if ( bAllowed
&& (toArr->back().get() == NULL)
&& (!Contains( toArr, fData.mnCol, nAt )) )
{
// ggF. in anderem Fenster entfernen
@ -714,7 +716,8 @@ void ScDPLayoutDlg::MoveField( ScDPFieldType eFromType, size_t nFromIndex, ScDPF
{
ScDPFuncData fData( *((*fromArr)[nFromIndex]) );
if ( Contains( fromArr, fData.mnCol, nAt ) )
bool bAllowed = IsOrientationAllowed( fData.mnCol, eToType );
if ( bAllowed && Contains( fromArr, fData.mnCol, nAt ) )
{
fromWnd->DelField( nAt );
Remove( fromArr, nAt );
@ -935,21 +938,42 @@ PointerStyle ScDPLayoutDlg::NotifyMouseMove( const Point& rAt )
if ( bIsDrag )
{
Point aPos = ScreenToOutputPixel( rAt );
ScDPFieldType eCheckTarget = TYPE_SELECT;
if ( aRectPage.IsInside( aPos ) )
ePtr = lclGetPointerForField( TYPE_PAGE );
eCheckTarget = TYPE_PAGE;
else if ( aRectCol.IsInside( aPos ) )
ePtr = lclGetPointerForField( TYPE_COL );
eCheckTarget = TYPE_COL;
else if ( aRectRow.IsInside( aPos ) )
ePtr = lclGetPointerForField( TYPE_ROW );
eCheckTarget = TYPE_ROW;
else if ( aRectData.IsInside( aPos ) )
ePtr = lclGetPointerForField( TYPE_DATA );
eCheckTarget = TYPE_DATA;
else if ( eDnDFromType != TYPE_SELECT )
ePtr = POINTER_PIVOT_DELETE;
else if ( aRectSelect.IsInside( aPos ) )
ePtr = lclGetPointerForField( TYPE_SELECT );
else
ePtr = POINTER_NOTALLOWED;
if ( eCheckTarget != TYPE_SELECT )
{
// check if the target orientation is allowed for this field
bool bAllowed = true;
ScDPFuncDataVec* fromArr = NULL;
switch ( eDnDFromType )
{
case TYPE_PAGE: fromArr = &aPageArr; break;
case TYPE_COL: fromArr = &aColArr; break;
case TYPE_ROW: fromArr = &aRowArr; break;
case TYPE_DATA: fromArr = &aDataArr; break;
case TYPE_SELECT: fromArr = &aSelectArr; break;
}
ScDPFuncData fData( *((*fromArr)[nDnDFromIndex]) );
if (IsOrientationAllowed( fData.mnCol, eCheckTarget ))
ePtr = lclGetPointerForField( eCheckTarget );
else
ePtr = POINTER_NOTALLOWED;
}
}
return ePtr;
@ -1218,6 +1242,28 @@ String ScDPLayoutDlg::GetLabelString( SCsCOL nCol )
return String();
}
//----------------------------------------------------------------------------
bool ScDPLayoutDlg::IsOrientationAllowed( SCsCOL nCol, ScDPFieldType eType )
{
bool bAllowed = true;
ScDPLabelData* pData = GetLabelData( nCol );
DBG_ASSERT( pData, "LabelData not found" );
if (pData)
{
sheet::DataPilotFieldOrientation eOrient = sheet::DataPilotFieldOrientation_HIDDEN;
switch (eType)
{
case TYPE_PAGE: eOrient = sheet::DataPilotFieldOrientation_PAGE; break;
case TYPE_COL: eOrient = sheet::DataPilotFieldOrientation_COLUMN; break;
case TYPE_ROW: eOrient = sheet::DataPilotFieldOrientation_ROW; break;
case TYPE_DATA: eOrient = sheet::DataPilotFieldOrientation_DATA; break;
case TYPE_SELECT: eOrient = sheet::DataPilotFieldOrientation_HIDDEN; break;
}
bAllowed = ScDPObject::IsOrientationAllowed( (USHORT)eOrient, pData->mnFlags );
}
return bAllowed;
}
//----------------------------------------------------------------------------

View file

@ -198,6 +198,7 @@ private:
Point DlgPos2WndPos ( const Point& rPt, Window& rWnd );
ScDPLabelData* GetLabelData ( SCsCOL nCol, size_t* pPos = NULL );
String GetLabelString ( SCsCOL nCol );
bool IsOrientationAllowed( SCsCOL nCol, ScDPFieldType eType );
String GetFuncString ( USHORT& rFuncMask, BOOL bIsValue = TRUE );
BOOL Contains ( ScDPFuncDataVec* pArr, SCsCOL nCol, size_t& nAt );
void Remove ( ScDPFuncDataVec* pArr, size_t nAt );

View file

@ -309,10 +309,17 @@ void ScGridWindow::DPTestMouse( const MouseEvent& rMEvt, BOOL bMove )
aPosRect, nOrient, nDimPos );
UpdateDragRect( bHasRange && bMove, aPosRect );
BOOL bIsDataLayout;
sal_Int32 nDimFlags = 0;
String aDimName = pDragDPObj->GetDimName( nDPField, bIsDataLayout, &nDimFlags );
bool bAllowed = !bHasRange || ScDPObject::IsOrientationAllowed( nOrient, nDimFlags );
if (bMove) // set mouse pointer
{
PointerStyle ePointer = POINTER_PIVOT_DELETE;
if ( bHasRange )
if ( !bAllowed )
ePointer = POINTER_NOTALLOWED;
else if ( bHasRange )
switch (nOrient)
{
case sheet::DataPilotFieldOrientation_COLUMN: ePointer = POINTER_PIVOT_COL; break;
@ -327,15 +334,13 @@ void ScGridWindow::DPTestMouse( const MouseEvent& rMEvt, BOOL bMove )
if (!bHasRange)
nOrient = sheet::DataPilotFieldOrientation_HIDDEN;
BOOL bIsDataLayout;
String aDimName = pDragDPObj->GetDimName( nDPField, bIsDataLayout );
if ( bIsDataLayout && ( nOrient != sheet::DataPilotFieldOrientation_COLUMN &&
nOrient != sheet::DataPilotFieldOrientation_ROW ) )
{
// removing data layout is not allowed
pViewData->GetView()->ErrorMessage(STR_PIVOT_MOVENOTALLOWED);
}
else
else if ( bAllowed )
{
ScDPSaveData aSaveData( *pDragDPObj->GetSaveData() );