diff options
Diffstat (limited to 'pokemod/CoinList.cpp')
-rw-r--r-- | pokemod/CoinList.cpp | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp index 48bfbc5c..53002fa0 100644 --- a/pokemod/CoinList.cpp +++ b/pokemod/CoinList.cpp @@ -28,6 +28,7 @@ #include <QStringListIterator> #include "Pokemod.h" +#include "CoinListObject.h" #include "Item.h" #include "ItemEffect.h" #include "CoinList.h" @@ -51,6 +52,12 @@ CoinList::CoinList(const Pokemod* par, const QString& fname, const int _id) : load(fname, _id); } +CoinList::~CoinList() +{ + for (QListIterator<CoinListObject*> i(items); i.hasNext(); ) + delete i.next(); +} + bool CoinList::validate() const { bool valid = true; @@ -81,15 +88,15 @@ bool CoinList::validate() const QMap<int, int> idChecker; QMap<int, int> itemChecker; QMap<int, int> speciesChecker; - for (QListIterator<CoinListObject> i(items); i.hasNext(); i.next()) + for (QListIterator<CoinListObject*> i(items); i.hasNext(); i.next()) { - if (!i.peekNext().isValid()) + if (!i.peekNext()->isValid()) valid = false; - ++idChecker[i.peekNext().getId()]; - if (i.peekNext().getType() == CoinListObject::Item) - ++itemChecker[i.peekNext().getObject()]; - else if (i.peekNext().getType() == CoinListObject::Species) - ++speciesChecker[i.peekNext().getObject()]; + ++idChecker[i.peekNext()->getId()]; + if (i.peekNext()->getType() == CoinListObject::Item) + ++itemChecker[i.peekNext()->getObject()]; + else if (i.peekNext()->getType() == CoinListObject::Species) + ++speciesChecker[i.peekNext()->getObject()]; } for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) { @@ -159,8 +166,8 @@ void CoinList::save() const throw(Exception) ini.addField("name", name); ini.addField("value", value); ini.save(QString("%1/coinlist/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<CoinListObject> i(items); i.hasNext(); ) - i.next().save(name); + for (QListIterator<CoinListObject*> i(items); i.hasNext(); ) + i.next()->save(name); } void CoinList::setName(const QString& n) @@ -200,14 +207,14 @@ const CoinListObject* CoinList::getItem(const int i) const throw(IndexException) { if (getItemCount() <= i) throw(IndexException(className)); - return &items.at(i); + return items.at(i); } CoinListObject* CoinList::getItem(const int i) throw(IndexException) { if (getItemCount() <= i) throw(IndexException(className)); - return &items[i]; + return items[i]; } const CoinListObject* CoinList::getItemByID(const int i) const throw(IndexException) @@ -224,7 +231,7 @@ int CoinList::getItemIndex(const int _id) const { for (int i = 0; i < getItemCount(); ++i) { - if (items[i].getId() == _id) + if (items[i]->getId() == _id) return i; } return -1; @@ -237,26 +244,27 @@ int CoinList::getItemCount() const CoinListObject* CoinList::newItem() { - items.append(CoinListObject(pokemod, getNewId())); - return &items[getItemCount() - 1]; + items.append(new CoinListObject(pokemod, getNewId())); + return items[getItemCount() - 1]; } CoinListObject* CoinList::newItem(const QString& fname) { - items.append(CoinListObject(pokemod, fname, getNewId())); - return &items[getItemCount() - 1]; + items.append(new CoinListObject(pokemod, fname, getNewId())); + return items[getItemCount() - 1]; } CoinListObject* CoinList::newItem(const CoinListObject& o) { - items.append(CoinListObject(pokemod, o, getNewId())); - return &items[getItemCount() - 1]; + items.append(new CoinListObject(pokemod, o, getNewId())); + return items[getItemCount() - 1]; } void CoinList::deleteItem(const int i) throw(IndexException) { if (getItemCount() <= i) throw(IndexException(className)); + delete items[i]; items.removeAt(i); } @@ -267,6 +275,6 @@ CoinList& CoinList::operator=(const CoinList& rhs) name = rhs.name; items.clear(); for (int i = 0; i < rhs.getItemCount(); ++i) - items.append(CoinListObject(pokemod, *rhs.getItem(i), rhs.getItem(i)->getId())); + items.append(new CoinListObject(pokemod, *rhs.getItem(i), rhs.getItem(i)->getId())); return *this; } |