diff options
author | Noel Grandin <noel@peralex.com> | 2021-09-08 11:45:08 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-09-09 13:01:23 +0200 |
commit | a9cd44f8deeccbb8afc7209fdf86fbc26ea7a464 (patch) | |
tree | d0e276b0a07e7e58b8ff14140245ef3df8b2c6ef /svx | |
parent | 7b4b032daa2381e5c2f102d4e9619adf38968f94 (diff) |
tdf#144052 speedup inserting large charts
we don't need to immediately re-order objects when setting the
Z-order, just set the dirty flag and we can calculate the proper order
layout.
This takes the time for the chart to appear from multiple minutes
to 20sec for me.
Change-Id: If80569da09469423f19f9fe82b40dfbdac14f161
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121806
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/svdraw/svdpage.cxx | 56 | ||||
-rw-r--r-- | svx/source/unodraw/unoshape.cxx | 6 |
2 files changed, 57 insertions, 5 deletions
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index 40044d78aa4f..0c56086d1097 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -561,6 +561,62 @@ SdrObject* SdrObjList::SetObjectOrdNum(size_t nOldObjNum, size_t nNewObjNum) return pObj; } +void SdrObjList::SetExistingObjectOrdNum(SdrObject* pObj, size_t nNewObjNum) +{ + assert(std::find(maList.begin(), maList.end(), pObj) != maList.end() && "This method requires that the child object already be inserted"); + assert(pObj->IsInserted() && "SdrObjList::SetObjectOrdNum: the object does not have status Inserted."); + + // I am deliberately bypassing getOrdNum() because I dont want to unnecessarily + // trigger RecalcObjOrdNums() + const sal_uInt32 nOldOrdNum = pObj->m_nOrdNum; + if (!mbObjOrdNumsDirty && nOldOrdNum == nNewObjNum) + return; + + // Update the navigation positions. + if (HasObjectNavigationOrder()) + { + tools::WeakReference<SdrObject> aReference (pObj); + auto iObject = ::std::find( + mxNavigationOrder->begin(), + mxNavigationOrder->end(), + aReference); + mxNavigationOrder->erase(iObject); + mbIsNavigationOrderDirty = true; + // The new object does not have a user defined position so append it + // to the list. + pObj->SetNavigationPosition(mxNavigationOrder->size()); + mxNavigationOrder->push_back(pObj); + } + if (nOldOrdNum < maList.size() && maList[nOldOrdNum] == pObj) + maList.erase(maList.begin()+nOldOrdNum); + else + { + auto it = std::find(maList.begin(), maList.end(), pObj); + maList.erase(it); + } + // Insert object into object list. Because the insert() method requires + // a valid iterator as insertion position, we have to use push_back() to + // insert at the end of the list. + if (nNewObjNum >= maList.size()) + maList.push_back(pObj); + else + maList.insert(maList.begin()+nNewObjNum, pObj); + + mbObjOrdNumsDirty=true; + + // No need to delete visualisation data since same object + // gets inserted again. Also a single ActionChanged is enough + pObj->ActionChanged(); + + pObj->SetOrdNum(nNewObjNum); + mbObjOrdNumsDirty=true; + + // TODO: We need a different broadcast here. + if (pObj->getSdrPageFromSdrObject()!=nullptr) + pObj->getSdrModelFromSdrObject().Broadcast(SdrHint(SdrHintKind::ObjectChange, *pObj)); + pObj->getSdrModelFromSdrObject().SetChanged(); +} + void SdrObjList::sort( std::vector<sal_Int32>& sortOrder) { // no negative indexes and indexes larger than maList size are allowed diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index 6445b81e06db..759f61d107ac 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -2126,11 +2126,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertyMapEn { SdrObjList* pObjList = GetSdrObject()->getParentSdrObjListFromSdrObject(); if( pObjList ) - { - SdrObject* pCheck = - pObjList->SetObjectOrdNum( GetSdrObject()->GetOrdNum(), static_cast<size_t>(nNewOrdNum) ); - DBG_ASSERT( pCheck == GetSdrObject(), "GetOrdNum() failed!" ); - } + pObjList->SetExistingObjectOrdNum( GetSdrObject(), static_cast<size_t>(nNewOrdNum) ); return true; } break; |