[Libreoffice-commits] .: 4 commits - oox/inc oox/source
Noel Power
noelp at kemper.freedesktop.org
Fri Feb 3 04:47:38 PST 2012
oox/inc/oox/xls/drawingbase.hxx | 10 ++++++-
oox/inc/oox/xls/pivotcachebuffer.hxx | 16 ++++++++++-
oox/inc/oox/xls/pivottablebuffer.hxx | 2 +
oox/source/token/properties.txt | 1
oox/source/xls/drawingbase.cxx | 30 +++++++++++++++++++++
oox/source/xls/drawingfragment.cxx | 3 +-
oox/source/xls/pivotcachebuffer.cxx | 50 +++++++++++++++++++++++++++++++----
oox/source/xls/pivottablebuffer.cxx | 26 ++++++++++++++++--
8 files changed, 127 insertions(+), 11 deletions(-)
New commits:
commit 3d62ea9a928c4a814369d5b6c276ac78239aeeeb
Author: Noel Power <noel.power at novell.com>
Date: Fri Jan 27 15:11:29 2012 +0000
import group field group name user captions fdo#45310
diff --git a/oox/inc/oox/xls/pivotcachebuffer.hxx b/oox/inc/oox/xls/pivotcachebuffer.hxx
index 5f73527..b56de30 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 f118476..1d7c10c 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 5132b7d..77b5a0f 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 7e6d298..ef390ca 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 );
commit 50be8ec9ed680c9b5b419d549e981c7a335b0257
Author: Noel Power <noel.power at novell.com>
Date: Thu Jan 26 16:29:07 2012 +0000
fix corrupted numbers in pivottable using group field as data field fdo#45276
diff --git a/oox/source/xls/pivottablebuffer.cxx b/oox/source/xls/pivottablebuffer.cxx
index 850dda8..7e6d298 100644
--- a/oox/source/xls/pivottablebuffer.cxx
+++ b/oox/source/xls/pivottablebuffer.cxx
@@ -1420,8 +1420,15 @@ void PivotTable::finalizeImport()
// all data fields
for( DataFieldVector::iterator aIt = maDataFields.begin(), aEnd = maDataFields.end(); aIt != aEnd; ++aIt )
+ {
+ if( const PivotCacheField* pCacheField = getCacheField( aIt->mnField ) )
+ {
+ if ( pCacheField-> getGroupBaseField() != -1 )
+ aIt->mnField = pCacheField-> getGroupBaseField();
+ }
if( PivotTableField* pField = getTableField( aIt->mnField ) )
pField->convertDataField( *aIt );
+ }
// filters
maFilters.forEachMem( &PivotTableFilter::finalizeImport );
commit 16af091a3339f6d00fe273f9dc5f155126e58881
Author: Noel Power <noel.power at novell.com>
Date: Thu Jan 26 14:28:36 2012 +0000
fix corrupted group field entries in xlsx imported pivot table fdo#45268
diff --git a/oox/inc/oox/xls/pivotcachebuffer.hxx b/oox/inc/oox/xls/pivotcachebuffer.hxx
index 208fbd4..5f73527 100644
--- a/oox/inc/oox/xls/pivotcachebuffer.hxx
+++ b/oox/inc/oox/xls/pivotcachebuffer.hxx
@@ -99,10 +99,13 @@ public:
inline const ::com::sun::star::uno::Any& getValue() const { return maValue; }
/** Returns the string representation of the item. */
::rtl::OUString getName() const;
+ /** Returns true if the item is unused. */
+ inline bool isUnused() const { return mbUnused; }
private:
::com::sun::star::uno::Any maValue; /// Value of the item.
sal_Int32 mnType; /// Value type (OOXML token identifier).
+ bool mbUnused;
};
// ----------------------------------------------------------------------------
@@ -285,6 +288,8 @@ public:
const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const;
/** Returns the names of all shared or group items. */
void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const;
+ /** Returns shared or group items. */
+ PivotCacheItemList getCacheItems() const;
/** Creates inplace numeric grouping settings. */
void convertNumericGrouping(
@@ -295,6 +300,7 @@ public:
/** Creates a new grouped DataPilot field and returns its name. */
::rtl::OUString createParentGroupField(
const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField,
+ const PivotCacheField& rBaseCacheField,
PivotCacheGroupItemVector& orItemNames ) const;
/** Writes the title of the field into the passed sheet at the passed address. */
diff --git a/oox/inc/oox/xls/pivottablebuffer.hxx b/oox/inc/oox/xls/pivottablebuffer.hxx
index 25c7bb1..f118476 100644
--- a/oox/inc/oox/xls/pivottablebuffer.hxx
+++ b/oox/inc/oox/xls/pivottablebuffer.hxx
@@ -170,6 +170,7 @@ public:
/** Finalizes the grouped field after import. */
void finalizeParentGroupingImport(
const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField,
+ const PivotCacheField& rBaseCacheField,
PivotCacheGroupItemVector& orItemNames );
/** Returns the name of the DataPilot field in the fields collection. */
diff --git a/oox/source/xls/pivotcachebuffer.cxx b/oox/source/xls/pivotcachebuffer.cxx
index e4ed2a3..5132b7d 100644
--- a/oox/source/xls/pivotcachebuffer.cxx
+++ b/oox/source/xls/pivotcachebuffer.cxx
@@ -173,7 +173,7 @@ void lclAdjustBinDateTime( DateTime& orDateTime )
// ============================================================================
PivotCacheItem::PivotCacheItem() :
- mnType( XML_m )
+ mnType( XML_m ), mbUnused( false )
{
}
@@ -187,6 +187,7 @@ void PivotCacheItem::readNumeric( const AttributeList& rAttribs )
{
maValue <<= rAttribs.getDouble( XML_v, 0.0 );
mnType = XML_n;
+ mbUnused = rAttribs.getBool( XML_u, false );
}
void PivotCacheItem::readDate( const AttributeList& rAttribs )
@@ -760,6 +761,13 @@ void PivotCacheField::getCacheItemNames( ::std::vector< OUString >& orItemNames
maSharedItems.getCacheItemNames( orItemNames );
}
+PivotCacheItemList PivotCacheField::getCacheItems() const
+{
+ if( hasGroupItems() )
+ return maGroupItems;
+ return maSharedItems;
+}
+
void PivotCacheField::convertNumericGrouping( const Reference< XDataPilotField >& rxDPField ) const
{
OSL_ENSURE( hasGroupItems() && hasNumericGrouping(), "PivotCacheField::convertNumericGrouping - not a numeric group field" );
@@ -822,7 +830,7 @@ OUString PivotCacheField::createDateGroupField( const Reference< XDataPilotField
return xFieldName.is() ? xFieldName->getName() : OUString();
}
-OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotField >& rxBaseDPField, PivotCacheGroupItemVector& orItemNames ) const
+OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotField >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames ) const
{
OSL_ENSURE( hasGroupItems() && !maDiscreteItems.empty(), "PivotCacheField::createParentGroupField - not a group field" );
OSL_ENSURE( maDiscreteItems.size() == orItemNames.size(), "PivotCacheField::createParentGroupField - number of item names does not match grouping info" );
@@ -834,16 +842,25 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie
typedef ::std::vector< GroupItemList > GroupItemMap;
GroupItemMap aItemMap( maGroupItems.size() );
for( IndexVector::const_iterator aBeg = maDiscreteItems.begin(), aIt = aBeg, aEnd = maDiscreteItems.end(); aIt != aEnd; ++aIt )
+ {
if( GroupItemList* pItems = ContainerHelper::getVectorElementAccess( aItemMap, *aIt ) )
+ {
+ if ( const PivotCacheItem* pItem = rBaseCacheField.getCacheItems().getCacheItem( aIt - aBeg ) )
+ {
+ // Skip unspecified or ununsed entries or errors
+ if ( pItem->isUnused() || ( pItem->getType() == XML_m ) || ( pItem->getType() == XML_e ) )
+ continue;
+ }
pItems->push_back( static_cast< sal_Int32 >( aIt - aBeg ) );
+ }
+ }
// process all groups
Reference< XDataPilotField > xDPGroupField;
for( GroupItemMap::iterator aBeg = aItemMap.begin(), aIt = aBeg, aEnd = aItemMap.end(); aIt != aEnd; ++aIt )
{
OSL_ENSURE( !aIt->empty(), "PivotCacheField::createParentGroupField - item/group should not be empty" );
- // if the item count is greater than 1, the item is a group of items
- if( aIt->size() > 1 )
+ if( !aIt->empty() )
{
/* Insert the names of the items that are part of this group. Calc
expects the names of the members of the field whose members are
@@ -860,7 +877,7 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie
/* Check again, that this is not just a group that is not grouped
further with other items. */
- if( aMembers.size() > 1 ) try
+ if( !aMembers.empty() ) try
{
// only the first call of createNameGroup() returns the new field
Reference< XDataPilotField > xDPNewField = xDPGrouping->createNameGroup( ContainerHelper::vectorToSequence( aMembers ) );
diff --git a/oox/source/xls/pivottablebuffer.cxx b/oox/source/xls/pivottablebuffer.cxx
index fefced8..850dda8 100644
--- a/oox/source/xls/pivottablebuffer.cxx
+++ b/oox/source/xls/pivottablebuffer.cxx
@@ -579,13 +579,13 @@ void PivotTableField::finalizeDateGroupingImport( const Reference< XDataPilotFie
}
}
-void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, PivotCacheGroupItemVector& orItemNames )
+void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames )
{
if( maDPFieldName.isEmpty() ) // prevent endless loops if file format is broken
{
if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
{
- maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, orItemNames );
+ maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, rBaseCacheField, orItemNames );
// on success, try to create nested group fields
Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
if( xDPField.is() )
@@ -1455,7 +1455,7 @@ void PivotTable::finalizeParentGroupingImport( const Reference< XDataPilotField
{
// try to create parent group fields that group the items of the passed base field
if( PivotTableField* pParentTableField = maFields.get( rBaseCacheField.getParentGroupField() ).get() )
- pParentTableField->finalizeParentGroupingImport( rxBaseDPField, orItemNames );
+ pParentTableField->finalizeParentGroupingImport( rxBaseDPField, rBaseCacheField, orItemNames );
}
Reference< XDataPilotField > PivotTable::getDataPilotField( const OUString& rFieldName ) const
commit c07e9299bb2c8d5477669568b12708bd2ff12684
Author: Noel Power <noel.power at novell.com>
Date: Thu Jan 26 11:00:15 2012 +0000
improve xlsx shape/chart import, anchor to cell where needed fdo#45266
diff --git a/oox/inc/oox/xls/drawingbase.hxx b/oox/inc/oox/xls/drawingbase.hxx
index c79eb7a..95fae46 100644
--- a/oox/inc/oox/xls/drawingbase.hxx
+++ b/oox/inc/oox/xls/drawingbase.hxx
@@ -32,6 +32,9 @@
#include "oox/drawingml/drawingmltypes.hxx"
#include "oox/xls/worksheethelper.hxx"
+#include <com/sun/star/drawing/XShape.hpp>
+#include <com/sun/star/table/XCell.hpp>
+
namespace oox {
namespace xls {
@@ -108,7 +111,12 @@ public:
/** Calculates the resulting shape anchor in 1/100 mm. */
::com::sun::star::awt::Rectangle calcAnchorRectHmm(
const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
-
+ /** Returns the 'to' cell if it exists */
+ ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > getToCell() const;
+ /** Returns the 'from' cell if it exists */
+ ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > getFromCell() const;
+ /** Applies Cell Anchor to an XShape if needed*/
+ void applyToXShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape>& rxShape );
private:
/** Converts the passed anchor to an absolute position in EMUs. */
::oox::drawingml::EmuPoint calcCellAnchorEmu( const CellAnchorModel& rModel ) const;
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index 9127c38..94a1947 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -9,6 +9,7 @@ AdjustLuminance
AdjustmentValues
Address
Align
+Anchor
AnchorPosition
ApplyFormDesignMode
AreaLinks
diff --git a/oox/source/xls/drawingbase.cxx b/oox/source/xls/drawingbase.cxx
index 3369ba9..91ed337 100644
--- a/oox/source/xls/drawingbase.cxx
+++ b/oox/source/xls/drawingbase.cxx
@@ -32,6 +32,7 @@
#include "oox/helper/attributelist.hxx"
#include "oox/helper/binaryinputstream.hxx"
#include "oox/xls/unitconverter.hxx"
+#include "oox/helper/propertyset.hxx"
namespace oox {
namespace xls {
@@ -281,6 +282,35 @@ Rectangle ShapeAnchor::calcAnchorRectHmm( const Size& rPageSizeHmm ) const
return Rectangle( lclEmuToHmm( aAnchorRect.X ), lclEmuToHmm( aAnchorRect.Y ), lclEmuToHmm( aAnchorRect.Width ), lclEmuToHmm( aAnchorRect.Height ) );
}
+::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
+ShapeAnchor::getToCell() const
+{
+ CellAddress aAddress;
+ aAddress.Sheet = getSheetIndex();
+ aAddress.Row = maTo.mnRow;
+ aAddress.Column = maTo.mnCol;
+ return getCell( aAddress );
+}
+::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
+ShapeAnchor::getFromCell() const
+{
+ CellAddress aAddress;
+ aAddress.Sheet = getSheetIndex();
+ aAddress.Row = maFrom.mnRow;
+ aAddress.Column = maFrom.mnCol;
+ return getCell( aAddress );
+}
+
+void
+ShapeAnchor::applyToXShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape>& rxShape )
+{
+ if ( ( meAnchorType == ANCHOR_TWOCELL || meAnchorType == ANCHOR_ONECELL ) && getFromCell().is() )
+ {
+ PropertySet aShapeProp( rxShape );
+ aShapeProp.setProperty( PROP_Anchor, getFromCell() );
+ }
+}
+
// private --------------------------------------------------------------------
EmuPoint ShapeAnchor::calcCellAnchorEmu( const CellAnchorModel& rModel ) const
diff --git a/oox/source/xls/drawingfragment.cxx b/oox/source/xls/drawingfragment.cxx
index 75cf0c8..1fa504c 100644
--- a/oox/source/xls/drawingfragment.cxx
+++ b/oox/source/xls/drawingfragment.cxx
@@ -273,7 +273,8 @@ void DrawingFragment::onEndElement()
basegfx::B2DHomMatrix aTransformation;
mxShape->addShape( getOoxFilter(), &getTheme(), mxDrawPage, aTransformation, &aShapeRectEmu32 );
-
+ // apply Cell anchoring if necessary
+ mxAnchor->applyToXShape( mxShape->getXShape() );
/* Collect all shape positions in the WorksheetHelper base
class. But first, scale EMUs to 1/100 mm. */
Rectangle aShapeRectHmm(
More information about the Libreoffice-commits
mailing list