include/svx/svdpage.hxx | 57 ++++++------ xmloff/source/draw/shapeimport.cxx | 165 +++++++++++++++++-------------------- 2 files changed, 104 insertions(+), 118 deletions(-)
New commits: commit af1c00c6428ec07d4e3d90b60772a600660a9651 Author: Noel Grandin <n...@peralex.com> Date: Mon Jun 22 13:59:49 2015 +0200 move sorting code closer together to make it easier to understand. Also switch iteration to range-based for loops. Change-Id: I39a3f565f40458fd5598bb2e97fe71a0fec1c09c diff --git a/xmloff/source/draw/shapeimport.cxx b/xmloff/source/draw/shapeimport.cxx index d7581a2..c155b54 100644 --- a/xmloff/source/draw/shapeimport.cxx +++ b/xmloff/source/draw/shapeimport.cxx @@ -778,18 +778,18 @@ public: vector<ZOrderHint> maZOrderList; vector<ZOrderHint> maUnsortedList; - sal_Int32 mnCurrentZ; - ShapeSortContext* mpParentContext; - const OUString msZOrder; + sal_Int32 mnCurrentZ; + ShapeSortContext* mpParentContext; ShapeSortContext( uno::Reference< drawing::XShapes >& rShapes, ShapeSortContext* pParentContext = NULL ); + void popGroupAndSort(); +private: void moveShape( sal_Int32 nSourcePos, sal_Int32 nDestPos ); }; ShapeSortContext::ShapeSortContext( uno::Reference< drawing::XShapes >& rShapes, ShapeSortContext* pParentContext ) -: mxShapes( rShapes ), mnCurrentZ( 0 ), mpParentContext( pParentContext ), - msZOrder("ZOrder") +: mxShapes( rShapes ), mnCurrentZ( 0 ), mpParentContext( pParentContext ) { } @@ -799,127 +799,116 @@ void ShapeSortContext::moveShape( sal_Int32 nSourcePos, sal_Int32 nDestPos ) uno::Reference< beans::XPropertySet > xPropSet; aAny >>= xPropSet; - if( xPropSet.is() && xPropSet->getPropertySetInfo()->hasPropertyByName( msZOrder ) ) + if( xPropSet.is() && xPropSet->getPropertySetInfo()->hasPropertyByName( OUString("ZOrder") ) ) { aAny <<= nDestPos; - xPropSet->setPropertyValue( msZOrder, aAny ); + xPropSet->setPropertyValue( OUString("ZOrder"), aAny ); - vector<ZOrderHint>::iterator aIter = maZOrderList.begin(); - vector<ZOrderHint>::iterator aEnd = maZOrderList.end(); - - while( aIter != aEnd ) + for( ZOrderHint& rHint : maZOrderList ) { - if( (*aIter).nIs < nSourcePos ) + if( rHint.nIs < nSourcePos ) { - DBG_ASSERT( (*aIter).nIs >= nDestPos, "Shape sorting failed" ); - (*aIter).nIs++; + DBG_ASSERT(rHint.nIs >= nDestPos, "Shape sorting failed" ); + rHint.nIs++; } - ++aIter; } - aIter = maUnsortedList.begin(); - aEnd = maUnsortedList.end(); - - while( aIter != aEnd ) + for( ZOrderHint& rHint : maUnsortedList ) { - if( (*aIter).nIs < nSourcePos ) + if( rHint.nIs < nSourcePos ) { - DBG_ASSERT( (*aIter).nIs >= nDestPos, "shape sorting failed" ); - (*aIter).nIs++; + DBG_ASSERT( rHint.nIs >= nDestPos, "shape sorting failed" ); + rHint.nIs++; } - ++aIter; } } } -void XMLShapeImportHelper::pushGroupForSorting( uno::Reference< drawing::XShapes >& rShapes ) +// sort shapes +void ShapeSortContext::popGroupAndSort() { - mpImpl->mpSortContext = new ShapeSortContext( rShapes, mpImpl->mpSortContext ); -} - -void XMLShapeImportHelper::popGroupAndSort() -{ - DBG_ASSERT( mpImpl->mpSortContext, "No context to sort!" ); - if( mpImpl->mpSortContext == NULL ) + // only do something if we have shapes to sort + if( maZOrderList.empty() ) return; - try - { - vector<ZOrderHint>& rZList = mpImpl->mpSortContext->maZOrderList; - vector<ZOrderHint>& rUnsortedList = mpImpl->mpSortContext->maUnsortedList; - - // sort shapes - if( !rZList.empty() ) - { - // only do something if we have shapes to sort + // check if there are more shapes than inserted with ::shapeWithZIndexAdded() + // This can happen if there where already shapes on the page before import + // Since the writer may delete some of this shapes during import, we need + // to do this here and not in our c'tor anymore - // check if there are more shapes than inserted with ::shapeWithZIndexAdded() - // This can happen if there where already shapes on the page before import - // Since the writer may delete some of this shapes during import, we need - // to do this here and not in our c'tor anymore + // check if we have more shapes than we know of + sal_Int32 nCount = mxShapes->getCount(); - // check if we have more shapes than we know of - sal_Int32 nCount = mpImpl->mpSortContext->mxShapes->getCount(); + nCount -= maZOrderList.size(); + nCount -= maUnsortedList.size(); - nCount -= rZList.size(); - nCount -= rUnsortedList.size(); + if( nCount > 0 ) + { + // first update offsets of added shapes + for (ZOrderHint& rHint : maZOrderList) + rHint.nIs += nCount; + for (ZOrderHint& rHint : maUnsortedList) + rHint.nIs += nCount; - if( nCount > 0 ) - { - // first update offsets of added shapes - vector<ZOrderHint>::iterator aIter( rZList.begin() ); - while( aIter != rZList.end() ) - (*aIter++).nIs += nCount; + // second add the already existing shapes in the unsorted list + ZOrderHint aNewHint; + do + { + nCount--; - aIter = rUnsortedList.begin(); - while( aIter != rUnsortedList.end() ) - (*aIter++).nIs += nCount; + aNewHint.nIs = nCount; + aNewHint.nShould = -1; - // second add the already existing shapes in the unsorted list - ZOrderHint aNewHint; + maUnsortedList.insert(maUnsortedList.begin(), aNewHint); + } + while( nCount ); + } - do - { - nCount--; + // sort z-ordered shapes by nShould field + std::sort(maZOrderList.begin(), maZOrderList.end()); - aNewHint.nIs = nCount; - aNewHint.nShould = -1; + // this is the current index, all shapes before that + // index are finished + sal_Int32 nIndex = 0; + for (ZOrderHint& rHint : maZOrderList) + { + while( nIndex < rHint.nShould && !maUnsortedList.empty() ) + { + ZOrderHint aGapHint( *maUnsortedList.begin() ); + maUnsortedList.erase(maUnsortedList.begin()); - rUnsortedList.insert(rUnsortedList.begin(), aNewHint); - } - while( nCount ); - } + moveShape( aGapHint.nIs, nIndex++ ); + } - // sort z ordered shapes - std::sort(rZList.begin(), rZList.end()); + if(rHint.nIs != nIndex ) + moveShape( rHint.nIs, nIndex ); - // this is the current index, all shapes before that - // index are finished - sal_Int32 nIndex = 0; - while( !rZList.empty() ) - { - while( nIndex < (*rZList.begin()).nShould && !rUnsortedList.empty() ) - { - ZOrderHint aGapHint( *rUnsortedList.begin() ); - rUnsortedList.erase(rUnsortedList.begin()); + nIndex++; + } + maZOrderList.clear(); +} - mpImpl->mpSortContext->moveShape( aGapHint.nIs, nIndex++ ); - } +void XMLShapeImportHelper::pushGroupForSorting( uno::Reference< drawing::XShapes >& rShapes ) +{ + mpImpl->mpSortContext = new ShapeSortContext( rShapes, mpImpl->mpSortContext ); +} - if( (*rZList.begin()).nIs != nIndex ) - mpImpl->mpSortContext->moveShape( (*rZList.begin()).nIs, nIndex ); +void XMLShapeImportHelper::popGroupAndSort() +{ + DBG_ASSERT( mpImpl->mpSortContext, "No context to sort!" ); + if( mpImpl->mpSortContext == NULL ) + return; - rZList.erase(rZList.begin()); - nIndex++; - } - } + try + { + mpImpl->mpSortContext->popGroupAndSort(); } catch( uno::Exception& ) { OSL_FAIL("exception while sorting shapes, sorting failed!"); } - // put parent on top and delete current context, were done + // put parent on top and delete current context, we are done ShapeSortContext* pContext = mpImpl->mpSortContext; mpImpl->mpSortContext = pContext->mpParentContext; delete pContext; commit bc7fba24dae271919cff15c73a87449bdd06a50a Author: Noel Grandin <n...@peralex.com> Date: Mon Jun 22 09:25:16 2015 +0200 clean up svdpage.hxx a little Change-Id: I5da9f408a80fd5990336aac847574f74164b6f7b diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx index 4647772..2c83427 100644 --- a/include/svx/svdpage.hxx +++ b/include/svx/svdpage.hxx @@ -83,8 +83,7 @@ class SVX_DLLPUBLIC SdrObjList SdrObjList &operator=(const SdrObjList& rSrcList) SAL_DELETED_FUNCTION; private: - typedef ::std::vector<SdrObject*> SdrObjectContainerType; - SdrObjectContainerType maList; + ::std::vector<SdrObject*> maList; protected: friend class SdrObjListIter; @@ -96,8 +95,8 @@ friend class SdrEditView; Rectangle aOutRect; Rectangle aSnapRect; SdrObjListKind eListKind; - bool bObjOrdNumsDirty; - bool bRectsDirty; + bool bObjOrdNumsDirty; + bool bRectsDirty; protected: void RecalcRects(); @@ -127,19 +126,17 @@ public: void SetUpList(SdrObjList* pNewUpList) { pUpList=pNewUpList; } SdrObject* GetOwnerObj() const { return pOwnerObj; } void SetOwnerObj(SdrObject* pNewOwner) { pOwnerObj=pNewOwner; } - SdrPage* GetPage() const; - void SetPage(SdrPage* pNewPage); - SdrModel* GetModel() const; - virtual void SetModel(SdrModel* pNewModel); + SdrPage* GetPage() const; + void SetPage(SdrPage* pNewPage); + SdrModel* GetModel() const; + virtual void SetModel(SdrModel* pNewModel); /// recalculate order numbers / ZIndex - void RecalcObjOrdNums(); - bool IsObjOrdNumsDirty() const { return bObjOrdNumsDirty; } - virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE - , const SdrInsertReason* pReason=NULL - ); - virtual void InsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE - , const SdrInsertReason* pReason=NULL - ); + void RecalcObjOrdNums(); + bool IsObjOrdNumsDirty() const { return bObjOrdNumsDirty; } + virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE, + const SdrInsertReason* pReason=NULL); + virtual void InsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE, + const SdrInsertReason* pReason=NULL); /// remove from list without delete virtual SdrObject* NbcRemoveObject(size_t nObjNum); virtual SdrObject* RemoveObject(size_t nObjNum); @@ -248,8 +245,8 @@ public: Otherwise this list is expected to contain all the shapes in the called SdrObjList. */ - void SetNavigationOrder (const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XIndexAccess>& rxOrder); + void SetNavigationOrder (const css::uno::Reference< + css::container::XIndexAccess>& rxOrder); void dumpAsXml(struct _xmlTextWriter* pWriter) const; @@ -333,7 +330,7 @@ public: SdrPageGridFrameList(): aList() {} ~SdrPageGridFrameList() { Clear(); } void Clear(); - sal_uInt16 GetCount() const { return sal_uInt16(aList.size()); } + sal_uInt16 GetCount() const { return sal_uInt16(aList.size()); } void Insert(const SdrPageGridFrame& rGF) { aList.push_back(new SdrPageGridFrame(rGF)); } void Insert(const SdrPageGridFrame& rGF, sal_uInt16 nPos) { @@ -453,7 +450,7 @@ protected: SdrLayerAdmin* pLayerAdmin; private: SdrPageProperties* mpSdrPageProperties; - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > mxUnoPage; + css::uno::Reference< css::uno::XInterface > mxUnoPage; public: SdrPageProperties& getSdrPageProperties() { return *mpSdrPageProperties; } @@ -464,8 +461,8 @@ protected: // new MasterPageDescriptorVector sdr::MasterPageDescriptor* mpMasterPageDescriptor; - SetOfByte aPrefVisiLayers; - sal_uInt16 nPageNum; + SetOfByte aPrefVisiLayers; + sal_uInt16 nPageNum; // bitfield bool mbMaster : 1; // flag if this is a MasterPage @@ -475,9 +472,9 @@ protected: // #i93597# bool mbPageBorderOnlyLeftRight : 1; - void SetUnoPage(::com::sun::star::uno::Reference< - ::com::sun::star::drawing::XDrawPage> const&); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createUnoPage(); + void SetUnoPage(css::uno::Reference< + css::drawing::XDrawPage> const&); + virtual css::uno::Reference< css::uno::XInterface > createUnoPage(); // Copying of pages is split into two parts: construction and copying of page objects, // because the copying might need access to fully initialized page. Clone() is responsible @@ -493,10 +490,10 @@ public: virtual ~SdrPage(); virtual SdrPage* Clone() const SAL_OVERRIDE; virtual SdrPage* Clone(SdrModel* pNewModel) const; - bool IsMasterPage() const { return mbMaster; } - void SetInserted(bool bNew = true); - bool IsInserted() const { return mbInserted; } - void SetChanged(); + bool IsMasterPage() const { return mbMaster; } + void SetInserted(bool bNew = true); + bool IsInserted() const { return mbInserted; } + void SetChanged(); // #i68775# React on PageNum changes (from Model in most cases) void SetPageNum(sal_uInt16 nNew); @@ -551,7 +548,7 @@ public: bool IsObjectsNotPersistent() const { return mbObjectsNotPersistent; } void SetObjectsNotPersistent(bool b) { mbObjectsNotPersistent = b; } - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getUnoPage(); + css::uno::Reference< css::uno::XInterface > getUnoPage(); virtual SfxStyleSheet* GetTextStyleSheetForObject( SdrObject* pObj ) const; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits