X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Fpatternlist.cpp;fp=src%2Fbase%2Fpatternlist.cpp;h=41e26aed6b3045261a8b7a94530ec3db24352b1d;hb=2ee84c5948ede7fc2f7b4435c5edef42a030ac05;hp=989d406bf3ef6c2b021344791e58cbc84f033df5;hpb=e7fbafaddba531f7acc44477d97cf07906da343b;p=architektonas diff --git a/src/base/patternlist.cpp b/src/base/patternlist.cpp index 989d406..41e26ae 100644 --- a/src/base/patternlist.cpp +++ b/src/base/patternlist.cpp @@ -12,6 +12,7 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 06/01/2010 Added this text. :-) +// JLH 09/13/2010 Fixed next() function to return a valid pointer. // #include "patternlist.h" @@ -25,13 +26,11 @@ PatternList * PatternList::uniqueInstance = NULL; */ PatternList::PatternList(): patternIterator(patterns) { -#warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!" -// patterns.setAutoDelete(true); - //patternListListeners.setAutoDelete(false); } /*virtual*/ PatternList::~PatternList() { + clearPatterns(); } /** @@ -51,23 +50,19 @@ PatternList::PatternList(): patternIterator(patterns) */ void PatternList::init() { - DEBUG->print("PatternList::initPatterns"); + DEBUG->print("PatternList::initPatterns"); + QStringList list = SYSTEM->getPatternList(); +// patterns.clear(); + clearPatterns(); - QStringList list = SYSTEM->getPatternList(); - Pattern * pattern; - - patterns.clear(); - - for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it) + for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it) { - DEBUG->print("pattern: %s:", (*it).toLatin1().data()); - - QFileInfo fi(*it); - pattern = new Pattern(fi.baseName().toLower()); - patterns.append(pattern); - - DEBUG->print("base: %s", pattern->getFileName().toLatin1().data()); - } + DEBUG->print("pattern: %s:", (*it).toAscii().data()); + QFileInfo fi(*it); + Pattern * pattern = new Pattern(fi.baseName().toLower()); + patterns.append(pattern); + DEBUG->print("base: %s", pattern->getFileName().toAscii().data()); + } } /** @@ -75,7 +70,14 @@ void PatternList::init() */ void PatternList::clearPatterns() { - patterns.clear(); + patternIterator = patterns; + + while (patternIterator.hasNext()) + delete patternIterator.next(); + + // Apparently this is still needed as the list will still be populated with + // stale pointers... + patterns.clear(); } int PatternList::countPatterns() @@ -91,20 +93,10 @@ int PatternList::countPatterns() void PatternList::removePattern(Pattern * pattern) { DEBUG->print("PatternList::removePattern()"); - - // here the pattern is removed from the list but not deleted -// patterns.remove(pattern); -//Apparently we need to delete this shit here because of missing AutoDelete -//function when going from Qt3->4 int i = patterns.indexOf(pattern); if (i != -1) delete patterns.takeAt(i); - - //for (uint i=0; ipatternRemoved(pattern); - //} } /** @@ -114,15 +106,12 @@ void PatternList::removePattern(Pattern * pattern) */ Pattern * PatternList::requestPattern(const QString & name) { - DEBUG->print("PatternList::requestPattern %s", name.toLatin1().data()); - - QString name2 = name.toLower(); Pattern * foundPattern = NULL; - - DEBUG->print("name2: %s", name2.toLatin1().data()); + QString name2 = name.toLower(); + DEBUG->print("PatternList::requestPattern %s", name.toAscii().data()); + DEBUG->print("name2: %s", name2.toAscii().data()); // Search our list of available patterns: -// for(Pattern * p=patterns.first(); p!=NULL; p=patterns.next()) for(int i=0; i