From 2ff2cd9434f27937efda9135e3642d98a036ea9a Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 23 Aug 2011 16:10:43 +0200 Subject: [PATCH] Rename copyFromList to setWordList Also change the behaviour in that it adopts the pointers, saves a few news and deletes --- core/textpage.cpp | 31 ++++++++++--------------------- core/textpage_p.h | 8 ++++---- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/core/textpage.cpp b/core/textpage.cpp index 4c9084700..e3c10cd34 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -999,22 +999,16 @@ static bool compareTinyTextEntityY(TinyTextEntity* first, TinyTextEntity* second /** * Copies a TextList to m_words with the same pointer */ -void TextPagePrivate::copyFromList(const TextList &list) +void TextPagePrivate::setWordList(const TextList &list) { qDeleteAll(m_words); - m_words.clear(); - - for(int i = 0 ; i < list.length() ; i++) - { - TinyTextEntity *ent = list.at(i); - m_words.append( new TinyTextEntity(ent->text(),ent->area) ); - } + m_words = list; } /** * Copies from m_words to list with distinct pointers */ -TextList TextPagePrivate::duplicateWordsList() const +TextList TextPagePrivate::duplicateWordList() const { TextList list; for(int i = 0 ; i < m_words.length() ; i++) @@ -1130,7 +1124,7 @@ void TextPagePrivate::makeWordFromCharacters() * Finally we copy the newList to m_words. */ - const TextList tmpList = duplicateWordsList(); + const TextList tmpList = duplicateWordList(); TextList newList; TextList::ConstIterator it = tmpList.begin(), itEnd = tmpList.end(), tmpIt; @@ -1232,9 +1226,8 @@ void TextPagePrivate::makeWordFromCharacters() if(it == itEnd) break; } - copyFromList(newList); qDeleteAll(tmpList); - qDeleteAll(newList); + setWordList(newList); } /** @@ -1513,7 +1506,7 @@ void TextPagePrivate::XYCutForBoundingBoxes(int tcx, int tcy) const int pageHeight = m_page->m_page->height(); RegionTextList tree; QRect contentRect(m_page->m_page->boundingBox().geometry(pageWidth,pageHeight)); - const TextList words = duplicateWordsList(); + const TextList words = duplicateWordList(); const RegionText root(words,contentRect); // start the tree with the root, it is our only region at the start @@ -1783,9 +1776,8 @@ void TextPagePrivate::XYCutForBoundingBoxes(int tcx, int tcy) tmp.append( new TinyTextEntity(ent->text(),ent->area) ); } } - //copying elements of tmp to m_words - copyFromList(tmp); - qDeleteAll(tmp); + // set tmp as new m_words + setWordList(tmp); // we are not removing tmp because, the elements of tmp are in m_XY_cut_tree, we will finally free from m_XY_cut_tree m_XY_cut_tree = tree; @@ -1878,9 +1870,7 @@ void TextPagePrivate::addNecessarySpace() tmp.append(new TinyTextEntity(ent->text(),ent->area)); } } - copyFromList(tmp); - // deletes all TinyTextEntity from the m_XY_cut_tree - qDeleteAll(tmp); + setWordList(tmp); } /** @@ -1929,8 +1919,7 @@ void TextPagePrivate::breakWordIntoCharacters() tmp.append(list); } } - copyFromList(tmp); - qDeleteAll(tmp); + setWordList(tmp); } diff --git a/core/textpage_p.h b/core/textpage_p.h index f2b63dcb4..45306225c 100644 --- a/core/textpage_p.h +++ b/core/textpage_p.h @@ -57,14 +57,14 @@ class TextPagePrivate const TextList::ConstIterator &end ); /** - * Copy a TextList to m_words + * Copy a TextList to m_words, the pointers of list are adopted */ - void copyFromList(const TextList &list); + void setWordList(const TextList &list); /** - * Copy m_words to a TextList + * Copy m_words to a new TextList, it is the caller responsability to free the pointers */ - TextList duplicateWordsList() const; + TextList duplicateWordList() const; /** * Remove odd spaces which are much bigger than normal spaces from m_words