summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorNoel Power <noel.power@novell.com>2012-01-27 15:11:29 +0000
committerNoel Power <noel.power@novell.com>2012-02-03 12:43:44 +0000
commit3d62ea9a928c4a814369d5b6c276ac78239aeeeb (patch)
tree54c4718e98657b418b3f371378a501d98ebfeeda /oox
parent50be8ec9ed680c9b5b419d549e981c7a335b0257 (diff)
import group field group name user captions fdo#45310
Diffstat (limited to 'oox')
-rw-r--r--oox/inc/oox/xls/pivotcachebuffer.hxx10
-rw-r--r--oox/inc/oox/xls/pivottablebuffer.hxx1
-rw-r--r--oox/source/xls/pivotcachebuffer.cxx23
-rw-r--r--oox/source/xls/pivottablebuffer.cxx13
4 files changed, 46 insertions, 1 deletions
diff --git a/oox/inc/oox/xls/pivotcachebuffer.hxx b/oox/inc/oox/xls/pivotcachebuffer.hxx
index 5f73527648bc..b56de3017516 100644
--- a/oox/inc/oox/xls/pivotcachebuffer.hxx
+++ b/oox/inc/oox/xls/pivotcachebuffer.hxx
@@ -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,
diff --git a/oox/inc/oox/xls/pivottablebuffer.hxx b/oox/inc/oox/xls/pivottablebuffer.hxx
index f118476ccbb9..1d7c10cafa5e 100644
--- a/oox/inc/oox/xls/pivottablebuffer.hxx
+++ b/oox/inc/oox/xls/pivottablebuffer.hxx
@@ -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.
diff --git a/oox/source/xls/pivotcachebuffer.cxx b/oox/source/xls/pivotcachebuffer.cxx
index 5132b7d43a16..77b5a0fc1fc2 100644
--- a/oox/source/xls/pivotcachebuffer.cxx
+++ b/oox/source/xls/pivotcachebuffer.cxx
@@ -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() )
diff --git a/oox/source/xls/pivottablebuffer.cxx b/oox/source/xls/pivottablebuffer.cxx
index 7e6d29801461..ef390cafd006 100644
--- a/oox/source/xls/pivottablebuffer.cxx
+++ b/oox/source/xls/pivottablebuffer.cxx
@@ -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 );