summaryrefslogtreecommitdiff
path: root/svx/source/svdraw
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail..com>2019-08-15 00:31:25 -0800
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-10-28 10:22:59 +0100
commit9f86b320a997c77069cf93dcb32fb71f09ad1348 (patch)
treec7767f9da6a3fbd465d80f36fee8ec2a9bd567fa /svx/source/svdraw
parent2d8efd1afe03a4009600e914910144b70982e98d (diff)
tdf#125191 Give object copies unique names
This patch makes a unique name for a copy of an object having a user given name. Change-Id: I14a7f45cc02962fc34a1532dd5db1cb9657b41d3 Reviewed-on: https://gerrit.libreoffice.org/77500 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx/source/svdraw')
-rw-r--r--svx/source/svdraw/svdedtv.cxx3
-rw-r--r--svx/source/svdraw/svdmodel.cxx3
-rw-r--r--svx/source/svdraw/svdobj.cxx40
-rw-r--r--svx/source/svdraw/svdpage.cxx54
-rw-r--r--svx/source/svdraw/svdxcgv.cxx5
5 files changed, 102 insertions, 3 deletions
diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx
index d83910a86746..6dfb249d911c 100644
--- a/svx/source/svdraw/svdedtv.cxx
+++ b/svx/source/svdraw/svdedtv.cxx
@@ -903,13 +903,14 @@ void SdrEditView::CopyMarkedObj()
GetMarkedObjectListWriteAccess().Clear();
size_t nCloneErrCnt=0;
+ std::unordered_set<rtl::OUString> aNameSet;
const size_t nMarkCount=aSourceObjectsForCopy.GetMarkCount();
for (size_t nm=0; nm<nMarkCount; ++nm) {
SdrMark* pM=aSourceObjectsForCopy.GetMark(nm);
SdrObject* pSource(pM->GetMarkedSdrObj());
SdrObject* pO(pSource->CloneSdrObject(pSource->getSdrModelFromSdrObject()));
if (pO!=nullptr) {
- pM->GetPageView()->GetObjList()->InsertObject(pO, SAL_MAX_SIZE);
+ pM->GetPageView()->GetObjList()->InsertObjectThenMakeNameUnique(pO, aNameSet);
if( bUndo )
AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoCopyObject(*pO));
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index eec87abcdf73..e49833f13c5c 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -1309,6 +1309,9 @@ void SdrModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
pPage->SetInserted();
pPage->SetPageNum(nPos);
+ if (mbMakePageObjectsNamesUnique)
+ pPage->MakePageObjectsNamesUnique();
+
if (nPos<nCount) bPagNumsDirty=true;
SetChanged();
SdrHint aHint(SdrHintKind::PageOrderChange, pPage);
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index 7b3d0bac73c8..eaa5abfa177a 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -136,6 +136,8 @@
#include <svdobjplusdata.hxx>
#include <svdobjuserdatalist.hxx>
+#include <unordered_set>
+
#include <boost/optional.hpp>
#include <libxml/xmlwriter.h>
#include <memory>
@@ -3016,6 +3018,44 @@ bool SdrObject::IsTextBox() const
return false;
}
+void SdrObject::MakeNameUnique(std::unordered_set<OUString>& rNameSet)
+{
+ if (GetName().isEmpty())
+ return;
+
+ if (rNameSet.empty())
+ {
+ SdrPage* pPage;
+ SdrObject* pObj;
+ for (sal_uInt16 nPage(0); nPage < mrSdrModelFromSdrObject.GetPageCount(); ++nPage)
+ {
+ pPage = mrSdrModelFromSdrObject.GetPage(nPage);
+ SdrObjListIter aIter(pPage, SdrIterMode::DeepWithGroups);
+ while (aIter.IsMore())
+ {
+ pObj = aIter.Next();
+ if (pObj != this)
+ rNameSet.insert(pObj->GetName());
+ }
+ }
+ }
+
+ OUString sName(GetName());
+ OUString sRootName(GetName());
+ sal_Int32 index = sName.lastIndexOf("_");
+ if ( index > 0)
+ sRootName = sRootName.copy(0, index);
+
+ sal_uInt32 n = 0;
+ while (rNameSet.find(sName) != rNameSet.end())
+ {
+ sName = sRootName + "_" + OUString::number(n++);
+ }
+ rNameSet.insert(sName);
+
+ SetName(sName);
+}
+
SdrObject* SdrObjFactory::CreateObjectFromFactory(SdrModel& rSdrModel, SdrInventor nInventor, sal_uInt16 nObjIdentifier)
{
SdrObjCreatorParams aParams { nInventor, nObjIdentifier, rSdrModel };
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 8794c2355dd0..a6cef0633542 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -19,6 +19,7 @@
#include <memory>
#include <cassert>
+#include <unordered_set>
#include <svx/svdpage.hxx>
@@ -328,6 +329,32 @@ void SdrObjList::NbcInsertObject(SdrObject* pObj, size_t nPos)
pObj->InsertedStateChange(); // calls the UserCall (among others)
}
+void SdrObjList::InsertObjectThenMakeNameUnique(SdrObject* pObj)
+{
+ std::unordered_set<rtl::OUString> aNameSet;
+ InsertObjectThenMakeNameUnique(pObj, aNameSet);
+}
+
+void SdrObjList::InsertObjectThenMakeNameUnique(SdrObject* pObj, std::unordered_set<OUString>& rNameSet, size_t nPos)
+{
+ InsertObject(pObj, nPos);
+ if (!pObj->GetName().isEmpty())
+ {
+ pObj->MakeNameUnique(rNameSet);
+ SdrObjList* pSdrObjList = pObj->GetSubList(); // group
+ if (pSdrObjList)
+ {
+ SdrObject* pListObj;
+ SdrObjListIter aIter(pSdrObjList, SdrIterMode::DeepWithGroups);
+ while (aIter.IsMore())
+ {
+ pListObj = aIter.Next();
+ pListObj->MakeNameUnique(rNameSet);
+ }
+ }
+ }
+}
+
void SdrObjList::InsertObject(SdrObject* pObj, size_t nPos)
{
DBG_ASSERT(pObj!=nullptr,"SdrObjList::InsertObject(NULL)");
@@ -1573,6 +1600,33 @@ void SdrPage::TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage)
}
}
+void SdrPage::MakePageObjectsNamesUnique()
+{
+ std::unordered_set<OUString> aNameSet;
+ for (size_t no(0); no < GetObjCount(); ++no)
+ {
+ SdrObject* pObj(GetObj(no));
+ if(nullptr != pObj)
+ {
+ if (!pObj->GetName().isEmpty())
+ {
+ pObj->MakeNameUnique(aNameSet);
+ SdrObjList* pSdrObjList = pObj->GetSubList(); // group
+ if (pSdrObjList)
+ {
+ SdrObject* pListObj;
+ SdrObjListIter aIter(pSdrObjList, SdrIterMode::DeepWithGroups);
+ while (aIter.IsMore())
+ {
+ pListObj = aIter.Next();
+ pListObj->MakeNameUnique(aNameSet);
+ }
+ }
+ }
+ }
+ }
+}
+
const SdrPageGridFrameList* SdrPage::GetGridFrameList(const SdrPageView* /*pPV*/, const tools::Rectangle* /*pRect*/) const
{
return nullptr;
diff --git a/svx/source/svdraw/svdxcgv.cxx b/svx/source/svdraw/svdxcgv.cxx
index a65d38c8738d..f18d536b7bf2 100644
--- a/svx/source/svdraw/svdxcgv.cxx
+++ b/svx/source/svdraw/svdxcgv.cxx
@@ -18,6 +18,7 @@
*/
#include <vector>
+#include <unordered_set>
#include <editeng/editdata.hxx>
#include <editeng/editeng.hxx>
#include <rtl/strbuf.hxx>
@@ -301,7 +302,7 @@ bool SdrExchangeView::Paste(
// #i13033#
// New mechanism to re-create the connections of cloned connectors
CloneList aCloneList;
-
+ std::unordered_set<rtl::OUString> aNameSet;
for (size_t nOb=0; nOb<nObjCount; ++nOb)
{
const SdrObject* pSrcOb=pSrcPg->GetObj(nOb);
@@ -346,7 +347,7 @@ bool SdrExchangeView::Paste(
pNewObj->SetLayer(nLayer);
}
- pDstLst->InsertObject(pNewObj, SAL_MAX_SIZE);
+ pDstLst->InsertObjectThenMakeNameUnique(pNewObj, aNameSet);
if( bUndo )
AddUndo(getSdrModelFromSdrView().GetSdrUndoFactory().CreateUndoNewObject(*pNewObj));