+++ /dev/null
-// 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 <jlhamm@acm.org>
-//
-// 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; i<patterns.size(); i++)
- {
- Pattern * p = patterns[i];
-
- if (p->getFileName() == 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; i<patterns.size(); i++)
- {
- Pattern * p = patterns[i];
-
- if (p->getFileName() == 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;
-}