diff options
Diffstat (limited to 'src/entry.cpp')
-rw-r--r-- | src/entry.cpp | 82 |
1 files changed, 52 insertions, 30 deletions
diff --git a/src/entry.cpp b/src/entry.cpp index e2a21c6..ec3c736 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -15,6 +15,7 @@ * */ +#include <algorithm> #include <stdlib.h> #include <qfile.h> #include "entry.h" @@ -37,8 +38,6 @@ Entry::Entry() num++; m_parent=0; section = EMPTY_SEC; - m_sublist = new QList<Entry>; - m_sublist->setAutoDelete(TRUE); extends = new QList<BaseInfo>; extends->setAutoDelete(TRUE); groups = new QList<Grouping>; @@ -137,17 +136,14 @@ Entry::Entry(const Entry &e) id = e.id; m_parent = e.m_parent; - m_sublist = new QList<Entry>; - m_sublist->setAutoDelete(TRUE); - // deep copy of the child entry list - QListIterator<Entry> eli(*e.m_sublist); - Entry *cur; - for (;(cur=eli.current());++eli) + // deep copy child entries + m_sublist.reserve(e.m_sublist.size()); + for (const auto &cur : e.m_sublist) { - m_sublist->append(new Entry(*cur)); + m_sublist.push_back(std::make_unique<Entry>(*cur)); } - + // deep copy base class list QListIterator<BaseInfo> bli(*e.extends); BaseInfo *bi; @@ -192,9 +188,7 @@ Entry::~Entry() //printf("Entry::~Entry(%p) num=%d\n",this,num); //printf("Deleting entry %d name %s type %x children %d\n", // num,name.data(),section,sublist->count()); - - delete m_sublist; // each element is now own by a EntryNav so we do no longer own - // our children. + delete extends; delete groups; delete anchors; @@ -206,15 +200,44 @@ Entry::~Entry() num--; } -void Entry::addSubEntry(Entry *current) +void Entry::moveToSubEntryAndRefresh(Entry *¤t) +{ + current->m_parent=this; + m_sublist.emplace_back(current); + current = new Entry; +} + +void Entry::moveToSubEntryAndRefresh(std::unique_ptr<Entry> ¤t) +{ + current->m_parent=this; + m_sublist.push_back(std::move(current)); + current = std::make_unique<Entry>(); +} + +void Entry::moveToSubEntryAndKeep(Entry *current) +{ + current->m_parent=this; + m_sublist.emplace_back(current); +} + +void Entry::moveToSubEntryAndKeep(std::unique_ptr<Entry> ¤t) { - //printf("Entry %d with name %s type 0x%x added to %s type 0x%x\n", - // current->num,current->name.data(),current->section, - // name.data(),section); - //printf("Entry::addSubEntry(%s:%p) to %s\n",current->name.data(), - // current,name.data()); current->m_parent=this; - m_sublist->append(current); + m_sublist.push_back(std::move(current)); +} + +void Entry::copyToSubEntry(Entry *current) +{ + Entry *copy = new Entry(*current); + copy->m_parent=this; + m_sublist.emplace_back(copy); +} + +void Entry::copyToSubEntry(const std::unique_ptr<Entry> ¤t) +{ + std::unique_ptr<Entry> copy = std::make_unique<Entry>(*current); + copy->m_parent=this; + m_sublist.push_back(std::move(copy)); } void Entry::reset() @@ -271,7 +294,7 @@ void Entry::reset() groupDocType = GROUPDOC_NORMAL; id.resize(0); metaData.resize(0); - m_sublist->clear(); + m_sublist.clear(); extends->clear(); groups->clear(); anchors->clear(); @@ -293,14 +316,9 @@ int Entry::getSize() void Entry::setFileDef(FileDef *fd) { m_fileDef = fd; - if (m_sublist) + for (const auto &childNode : m_sublist) { - QListIterator<Entry> eli(*m_sublist); - Entry *childNode; - for (eli.toFirst();(childNode=eli.current());++eli) - { childNode->setFileDef(fd); - } } } @@ -317,10 +335,14 @@ void Entry::addSpecialListItem(const char *listName,int itemId) sli->append(ili); } -Entry *Entry::removeSubEntry(Entry *e) +void Entry::removeSubEntry(Entry *e) { - int i = m_sublist->find(e); - return i!=-1 ? m_sublist->take(i) : 0; + auto it = std::find_if(m_sublist.begin(),m_sublist.end(), + [e](const std::unique_ptr<Entry>&elem) { return elem.get()==e; }); + if (it!=m_sublist.end()) + { + m_sublist.erase(it); + } } //------------------------------------------------------------------ |