Rename copyFromList to setWordList

Also change the behaviour in that it adopts the pointers, saves a few news and deletes
This commit is contained in:
Albert Astals Cid 2011-08-23 16:10:43 +02:00
parent 33f9c203b1
commit 2ff2cd9434
2 changed files with 14 additions and 25 deletions

View file

@ -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);
}

View file

@ -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