Kaydet (Commit) 3d62ea9a authored tarafından Noel Power's avatar Noel Power

import group field group name user captions fdo#45310

üst 50be8ec9
......@@ -49,6 +49,9 @@ class WorksheetHelper;
// ============================================================================
typedef ::std::pair< sal_Int32, rtl::OUString > IdCaptionPair;
typedef ::std::vector< IdCaptionPair > IdCaptionPairList;
class PivotCacheItem
{
public:
......@@ -103,6 +106,9 @@ public:
inline bool isUnused() const { return mbUnused; }
private:
friend class PivotCacheItemList;
// #FIXME hack Sets the value of this item to the given string ( and overwrites type if necessary
void setStringValue( const rtl::OUString& sName );
::com::sun::star::uno::Any maValue; /// Value of the item.
sal_Int32 mnType; /// Value type (OOXML token identifier).
bool mbUnused;
......@@ -131,6 +137,7 @@ public:
const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const;
/** Returns the names of all items. */
void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const;
void applyItemCaptions( const IdCaptionPairList& vCaptions );
private:
/** Creates and returns a new item at the end of the items list. */
......@@ -262,6 +269,8 @@ public:
void importPCDFRangePr( BiffInputStream& rStrm );
/** Imports the mapping between group items and base items from the PCDFDISCRETEPR record. */
void importPCDFDiscretePr( BiffInputStream& rStrm );
/** Apply user Captions to imported group data */
void applyItemCaptions( const IdCaptionPairList& vCaptions );
/** Returns true, if the field is based on source data, or false if it is grouped or calculated. */
inline bool isDatabaseField() const { return maFieldModel.mbDatabaseField; }
......@@ -318,7 +327,6 @@ public:
void importPCItemIndex( BiffInputStream& rStrm,
WorksheetHelper& rSheetHelper, sal_Int32 nCol, sal_Int32 nRow ) const;
private:
/** Tries to write the passed value to the passed sheet position. */
void writeItemToSourceDataCell( WorksheetHelper& rSheetHelper,
......
......@@ -49,6 +49,7 @@ struct PTFieldItemModel
{
sal_Int32 mnCacheItem; /// Index to shared item in pivot cache.
sal_Int32 mnType; /// Type of the item.
rtl::OUString msCaption; /// User caption of the item
bool mbShowDetails; /// True = show item details (items of child fields).
bool mbHidden; /// True = item is hidden.
......
......@@ -302,6 +302,12 @@ void PivotCacheItem::readError( BiffInputStream& rStrm )
mnType = XML_e;
}
void PivotCacheItem::setStringValue( const OUString& sString )
{
mnType = XML_s;
maValue <<= sString;
}
OUString PivotCacheItem::getName() const
{
switch( mnType )
......@@ -393,6 +399,15 @@ const PivotCacheItem* PivotCacheItemList::getCacheItem( sal_Int32 nItemIdx ) con
return ContainerHelper::getVectorElement( maItems, nItemIdx );
}
void PivotCacheItemList::applyItemCaptions( const IdCaptionPairList& vCaptions )
{
for( IdCaptionPairList::const_iterator aIt = vCaptions.begin(), aEnd = vCaptions.end(); aIt != aEnd; ++aIt )
{
if ( static_cast<sal_uInt32>( aIt->first ) < maItems.size() )
maItems[ aIt->first ].setStringValue( aIt->second );
}
}
void PivotCacheItemList::getCacheItemNames( ::std::vector< OUString >& orItemNames ) const
{
orItemNames.clear();
......@@ -753,6 +768,14 @@ const PivotCacheItem* PivotCacheField::getCacheItem( sal_Int32 nItemIdx ) const
return 0;
}
void PivotCacheField::applyItemCaptions( const IdCaptionPairList& vCaptions )
{
if( hasGroupItems() )
maGroupItems.applyItemCaptions( vCaptions );
if( hasSharedItems() )
maSharedItems.applyItemCaptions( vCaptions );
}
void PivotCacheField::getCacheItemNames( ::std::vector< OUString >& orItemNames ) const
{
if( hasGroupItems() )
......
......@@ -370,6 +370,7 @@ void PivotTableField::importItem( const AttributeList& rAttribs )
aModel.mnType = rAttribs.getToken( XML_t, XML_data );
aModel.mbShowDetails = rAttribs.getBool( XML_sd, true );
aModel.mbHidden = rAttribs.getBool( XML_h, false );
aModel.msCaption = rAttribs.getXString( XML_n, OUString() );
maItems.push_back( aModel );
}
......@@ -548,6 +549,7 @@ void PivotTableField::finalizeImport( const Reference< XDataPilotDescriptor >& r
}
else if( pCacheField->hasParentGrouping() )
{
// create a list of all item names, needed to map between original and group items
::std::vector< OUString > aItems;
pCacheField->getCacheItemNames( aItems );
......@@ -585,6 +587,17 @@ void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotF
{
if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
{
// data field can have user defined groupname captions, apply them
// if they do
IdCaptionPairList captionList;
for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt )
{
if ( aIt->mnType == XML_data && aIt->msCaption.getLength() )
captionList.push_back( IdCaptionPair( aIt->mnCacheItem, aIt->msCaption ) );
}
// #FIXME find another way out of this const nightmare prison
if ( !captionList.empty() )
const_cast<PivotCacheField*>( pCacheField )->applyItemCaptions( captionList );
maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, rBaseCacheField, orItemNames );
// on success, try to create nested group fields
Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment