diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-02-24 22:36:40 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-02-24 22:36:40 +0000 |
commit | 1e02a507f0b481465f5b47441479b98a81aee079 (patch) | |
tree | a6a108f187ec6f134c60470fdf317d0a77b2fdd3 /pokemod/Item.cpp | |
parent | 26c9e526435474aa3e7f8e1be39dfb474dd8b368 (diff) | |
download | sigen-1e02a507f0b481465f5b47441479b98a81aee079.tar.gz sigen-1e02a507f0b481465f5b47441479b98a81aee079.tar.xz sigen-1e02a507f0b481465f5b47441479b98a81aee079.zip |
[FIX] KTabWidget now used rather than QTabWidget (though this kills Qt Designer interaction :\ )
[FIX] Minor fixes in PokeModr class
[DEL] Ref.{h, cpp}
[FIX] Ref enumerations now in Pokemod class
[FIX] new/delete used for subclasses in pokemod now
[FIX] Inclusion hell in pokemod (should compile faster)
[FIX] Spelling typos
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@82 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Item.cpp')
-rw-r--r-- | pokemod/Item.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp index f6293cf7..f2a594d6 100644 --- a/pokemod/Item.cpp +++ b/pokemod/Item.cpp @@ -28,6 +28,7 @@ #include <QStringListIterator> #include "Pokemod.h" +#include "ItemEffect.h" #include "Item.h" Item::Item(const Pokemod* par, const int _id) : @@ -52,6 +53,12 @@ Item::Item(const Pokemod* par, const QString& fname, const int _id) : load(fname, _id); } +Item::~Item() +{ + for (QListIterator<ItemEffect*> i(effects); i.hasNext(); ) + delete i.next(); +} + bool Item::validate() const { bool valid = true; @@ -74,11 +81,11 @@ bool Item::validate() const if (getEffectCount()) { QMap<int, int> idChecker; - for (QListIterator<ItemEffect> i(effects); i.hasNext(); i.next()) + for (QListIterator<ItemEffect*> i(effects); i.hasNext(); i.next()) { - if (!i.peekNext().isValid()) + if (!i.peekNext()->isValid()) valid = false; - ++idChecker[i.peekNext().getId()]; + ++idChecker[i.peekNext()->getId()]; } for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) { @@ -138,8 +145,8 @@ void Item::save() const throw(Exception) ini.addField("price", price); ini.addField("description", description); ini.save(QString("%1/item/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<ItemEffect> i(effects); i.hasNext(); ) - i.next().save(name); + for (QListIterator<ItemEffect*> i(effects); i.hasNext(); ) + i.next()->save(name); } void Item::setName(const QString& n) @@ -200,14 +207,14 @@ const ItemEffect* Item::getEffect(const int i) const throw(IndexException) { if (getEffectCount() <= i) throw(IndexException(className)); - return &effects.at(i); + return effects.at(i); } ItemEffect* Item::getEffectByID(const int i) throw(IndexException) { if (getEffectCount() <= i) throw(IndexException(className)); - return &effects[i]; + return effects[i]; } const ItemEffect* Item::getEffectByID(const int i) const throw(IndexException) @@ -224,7 +231,7 @@ int Item::getEffectIndex(const int _id) const { for (int i = 0; i < getEffectCount(); ++i) { - if (effects[i].getId() == _id) + if (effects[i]->getId() == _id) return i; } return -1; @@ -237,26 +244,27 @@ int Item::getEffectCount() const ItemEffect* Item::newEffect() { - effects.append(ItemEffect(pokemod, getNewId())); - return &effects[getEffectCount() - 1]; + effects.append(new ItemEffect(pokemod, getNewId())); + return effects[getEffectCount() - 1]; } ItemEffect* Item::newEffect(const QString& fname) { - effects.append(ItemEffect(pokemod, fname, getNewId())); - return &effects[getEffectCount() - 1]; + effects.append(new ItemEffect(pokemod, fname, getNewId())); + return effects[getEffectCount() - 1]; } ItemEffect* Item::newEffect(const ItemEffect& e) { - effects.append(ItemEffect(pokemod, e, getNewId())); - return &effects[getEffectCount() - 1]; + effects.append(new ItemEffect(pokemod, e, getNewId())); + return effects[getEffectCount() - 1]; } void Item::deleteEffect(const int i) throw(IndexException) { if (getEffectCount() <= i) throw(IndexException(className)); + delete effects[i]; effects.removeAt(i); } @@ -271,6 +279,6 @@ Item& Item::operator=(const Item& rhs) description = rhs.description; effects.clear(); for (int i = 0; i < rhs.getEffectCount(); ++i) - effects.append(ItemEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); + effects.append(new ItemEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); return *this; } |