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=0000000000000000000000000000000000000000;hb=9f6ad3fe0b9cb30115a5d38e8af3aebed0d70c08;hp=41e26aed6b3045261a8b7a94530ec3db24352b1d;hpb=43c13b052d069ba435277d93867380d00c04931f;p=architektonas diff --git a/src/base/patternlist.cpp b/src/base/patternlist.cpp deleted file mode 100644 index 41e26ae..0000000 --- a/src/base/patternlist.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// patternlist.cpp -// -// Part of the Architektonas Project -// Originally part of QCad Community Edition by Andrew Mustun -// Extensively rewritten and refactored by James L. Hammons -// Portions copyright (C) 2001-2003 RibbonSoft -// Copyright (C) 2010 Underground Software -// See the README and GPLv2 files for licensing and warranty information -// -// JLH = James L. Hammons -// -// 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" - -#include "system.h" - -PatternList * PatternList::uniqueInstance = NULL; - -/** - * Default constructor. - */ -PatternList::PatternList(): patternIterator(patterns) -{ -} - -/*virtual*/ PatternList::~PatternList() -{ - clearPatterns(); -} - -/** - * @return Instance to the unique pattern list. - */ -/*static*/ PatternList * PatternList::instance() -{ - if (uniqueInstance == NULL) - uniqueInstance = new PatternList(); - - return uniqueInstance; -} - -/** - * Initializes the pattern list by creating empty Pattern - * objects, one for each pattern that could be found. - */ -void PatternList::init() -{ - DEBUG->print("PatternList::initPatterns"); - QStringList list = SYSTEM->getPatternList(); -// patterns.clear(); - clearPatterns(); - - for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it) - { - 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()); - } -} - -/** - * Removes all patterns in the patternlist. - */ -void PatternList::clearPatterns() -{ - 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() -{ - return patterns.count(); -} - -/** - * Removes a pattern from the list. - * Listeners are notified after the pattern was removed from - * the list but before it gets deleted. - */ -void PatternList::removePattern(Pattern * pattern) -{ - DEBUG->print("PatternList::removePattern()"); - int i = patterns.indexOf(pattern); - - if (i != -1) - delete patterns.takeAt(i); -} - -/** - * @return Pointer to the pattern with the given name or - * \p NULL if no such pattern was found. The pattern will be loaded into - * memory if it's not already. - */ -Pattern * PatternList::requestPattern(const QString & name) -{ - Pattern * foundPattern = NULL; - 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(int i=0; igetFileName() == name2) - { - // Make sure this pattern is loaded into memory: - p->loadPattern(); - foundPattern = p; - break; - } - } - - return foundPattern; -} - -//! @return First pattern of the list. -Pattern * PatternList::firstPattern() -{ - // Looks like this is necessary--constructor doesn't do it... - // Constructor is necessary, apparently, even though we do this. - patternIterator = patterns; - return nextPattern(); -} - -/** - * @return Next pattern from the list after - * calling firstPattern() or nextPattern(). - */ -Pattern * PatternList::nextPattern() -{ - // We absolutely HAVE to do a hasNext() check or we'll hand back a bogus - // pointer/object. Not good! - return (patternIterator.hasNext() ? patternIterator.next() : NULL); -} - -bool PatternList::contains(const QString & name) -{ - QString name2 = name.toLower(); - - // Search our list of available patterns: - for(int i=0; igetFileName() == name2) - return true; - } - - return false; -} - -/** - * Dumps the patterns to stdout. - */ -std::ostream & operator<<(std::ostream & os, PatternList & l) -{ - os << "Patternlist: \n"; - - for(Pattern * p=l.firstPattern(); p!=NULL; p=l.nextPattern()) - os << *p << "\n"; - - return os; -}