3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/01/2010 Added this text. :-)
17 #include "patternlist.h"
21 RS_PatternList * RS_PatternList::uniqueInstance = NULL;
24 * Default constructor.
26 RS_PatternList::RS_PatternList(): patternIterator(patterns)
28 #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!"
29 // patterns.setAutoDelete(true);
30 //patternListListeners.setAutoDelete(false);
33 /*virtual*/ RS_PatternList::~RS_PatternList()
38 * @return Instance to the unique pattern list.
40 /*static*/ RS_PatternList * RS_PatternList::instance()
42 if (uniqueInstance == NULL)
43 uniqueInstance = new RS_PatternList();
45 return uniqueInstance;
49 * Initializes the pattern list by creating empty RS_Pattern
50 * objects, one for each pattern that could be found.
52 void RS_PatternList::init()
54 RS_DEBUG->print("RS_PatternList::initPatterns");
56 QStringList list = RS_SYSTEM->getPatternList();
61 for(QStringList::Iterator it=list.begin(); it!=list.end(); ++it)
63 RS_DEBUG->print("pattern: %s:", (*it).toLatin1().data());
66 pattern = new RS_Pattern(fi.baseName().toLower());
67 patterns.append(pattern);
69 RS_DEBUG->print("base: %s", pattern->getFileName().toLatin1().data());
74 * Removes all patterns in the patternlist.
76 void RS_PatternList::clearPatterns()
81 int RS_PatternList::countPatterns()
83 return patterns.count();
87 * Removes a pattern from the list.
88 * Listeners are notified after the pattern was removed from
89 * the list but before it gets deleted.
91 void RS_PatternList::removePattern(RS_Pattern * pattern)
93 RS_DEBUG->print("RS_PatternList::removePattern()");
95 // here the pattern is removed from the list but not deleted
96 // patterns.remove(pattern);
97 //Apparently we need to delete this shit here because of missing AutoDelete
98 //function when going from Qt3->4
99 int i = patterns.indexOf(pattern);
102 delete patterns.takeAt(i);
104 //for (uint i=0; i<patternListListeners.count(); ++i) {
105 // RS_PatternListListener* l = patternListListeners.at(i);
106 // l->patternRemoved(pattern);
111 * @return Pointer to the pattern with the given name or
112 * \p NULL if no such pattern was found. The pattern will be loaded into
113 * memory if it's not already.
115 RS_Pattern * RS_PatternList::requestPattern(const QString & name)
117 RS_DEBUG->print("RS_PatternList::requestPattern %s", name.toLatin1().data());
119 QString name2 = name.toLower();
120 RS_Pattern * foundPattern = NULL;
122 RS_DEBUG->print("name2: %s", name2.toLatin1().data());
124 // Search our list of available patterns:
125 // for(RS_Pattern * p=patterns.first(); p!=NULL; p=patterns.next())
126 for(int i=0; i<patterns.size(); i++)
128 RS_Pattern * p = patterns[i];
130 if (p->getFileName() == name2)
132 // Make sure this pattern is loaded into memory:
139 //if (foundPattern==NULL && name!="standard") {
140 // foundPattern = requestPattern("standard");
146 //! @return First pattern of the list.
147 RS_Pattern * RS_PatternList::firstPattern()
149 patternIterator.toFront();
150 return patternIterator.next();
154 * @return Next pattern from the list after
155 * calling firstPattern() or nextPattern().
157 RS_Pattern * RS_PatternList::nextPattern()
159 return patternIterator.next();
162 bool RS_PatternList::contains(const QString & name)
164 QString name2 = name.toLower();
166 // Search our list of available patterns:
167 // for(RS_Pattern * p=patterns.first(); p!=NULL; p=patterns.next())
168 for(int i=0; i<patterns.size(); i++)
170 RS_Pattern * p = patterns[i];
172 if (p->getFileName() == name2)
180 * Dumps the patterns to stdout.
182 std::ostream & operator<<(std::ostream & os, RS_PatternList & l)
184 os << "Patternlist: \n";
185 for(RS_Pattern * p=l.firstPattern(); p!=NULL; p=l.nextPattern())