diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-28 00:59:52 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-28 00:59:52 +0000 |
| commit | 4d705de01059eb04b19db68a11cea1c57084c57a (patch) | |
| tree | fa6deaba07d19041c21deca010b006931dc6abe0 | |
| parent | 8cbe19a3e1845657ccdfddbd3c4fffcaadb9ff55 (diff) | |
[FIX] Typechart now works
[FIX] Matrix fixed up
[FIX] Pokemod map widget fixed up
[FIX] FractionWidget sets stuff on ctor
[FIX] Assertion used in pokemod rather than returning NULL
[FIX] Fixed a bad compare in Type
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@180 6ecfd1a5-f3ed-3746-8530-beee90d26b22
| -rw-r--r-- | Changelog | 12 | ||||
| -rw-r--r-- | pokemod/CoinList.cpp | 9 | ||||
| -rw-r--r-- | pokemod/Map.cpp | 36 | ||||
| -rw-r--r-- | pokemod/MapTrainer.cpp | 9 | ||||
| -rw-r--r-- | pokemod/MapWildList.cpp | 9 | ||||
| -rw-r--r-- | pokemod/Matrix.h | 141 | ||||
| -rw-r--r-- | pokemod/Object.h | 13 | ||||
| -rw-r--r-- | pokemod/Pokemod.cpp | 236 | ||||
| -rw-r--r-- | pokemod/Pokemod.h | 10 | ||||
| -rw-r--r-- | pokemod/Species.cpp | 27 | ||||
| -rw-r--r-- | pokemod/Type.cpp | 2 | ||||
| -rw-r--r-- | pokemodr/FractionWidget.cpp | 28 | ||||
| -rw-r--r-- | pokemodr/MapUI.cpp | 19 | ||||
| -rw-r--r-- | pokemodr/PokeModrUI.cpp | 4 | ||||
| -rw-r--r-- | pokemodr/PokemodUI.cpp | 49 | ||||
| -rw-r--r-- | pokemodr/PokemodUI.h | 5 | ||||
| -rw-r--r-- | pokemodr/TODO | 4 | ||||
| -rw-r--r-- | pokemodr/TypechartModel.h | 95 | ||||
| -rw-r--r-- | pokemodr/TypechartWidgetItem.h | 64 | ||||
| -rw-r--r-- | pokemodr/gui/move.ui | 3 | ||||
| -rw-r--r-- | pokemodr/gui/pokemod.ui | 8 | ||||
| -rw-r--r-- | pokemodr/models/MapModel.cpp | 3 | ||||
| -rw-r--r-- | pokemodr/models/SpeciesModel.cpp | 3 | ||||
| -rw-r--r-- | pokemodr/pokemodr.pro | 2 |
24 files changed, 364 insertions, 427 deletions
@@ -1,4 +1,16 @@ ----------------- +Rev: 180 +Date: 27 May 2008 +User: MathStuf +----------------- +[FIX] Typechart now works +[FIX] Matrix fixed up +[FIX] Pokemod map widget fixed up +[FIX] FractionWidget sets stuff on ctor +[FIX] Assertion used in pokemod rather than returning NULL +[FIX] Fixed a bad compare in Type + +----------------- Rev: 179 Date: 27 May 2008 User: MathStuf diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp index d238807d..f3bff007 100644 --- a/pokemod/CoinList.cpp +++ b/pokemod/CoinList.cpp @@ -124,15 +124,13 @@ Script CoinList::script() const const CoinListObject* CoinList::object(const int index) const { - if (objectCount() <= index) - return NULL; + Q_ASSERT(index < objectCount()); return m_objects.at(index); } CoinListObject* CoinList::object(const int index) { - if (objectCount() <= index) - return NULL; + Q_ASSERT(index < objectCount()); return m_objects[index]; } @@ -184,8 +182,7 @@ CoinListObject* CoinList::newObject(CoinListObject* object) void CoinList::deleteObject(const int index) { - if (objectCount() <= index) - return; + Q_ASSERT(index < objectCount()); delete m_objects[index]; m_objects.removeAt(index); } diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp index d66552e6..8c388861 100644 --- a/pokemod/Map.cpp +++ b/pokemod/Map.cpp @@ -262,15 +262,13 @@ Point Map::size() const const MapEffect* Map::effect(const int index) const { - if (effectCount() <= index) - return NULL; + Q_ASSERT(index < effectCount()); return m_effects.at(index); } MapEffect* Map::effect(const int index) { - if (effectCount() <= index) - return NULL; + Q_ASSERT(index < effectCount()); return m_effects[index]; } @@ -322,8 +320,7 @@ MapEffect* Map::newEffect(MapEffect* effect) void Map::deleteEffect(const int index) { - if (effectCount() <= index) - return; + Q_ASSERT(index < effectCount()); delete m_effects[index]; m_effects.removeAt(index); } @@ -343,15 +340,13 @@ int Map::newEffectId() const const MapTrainer* Map::trainer(const int index) const { - if (trainerCount() <= index) - return NULL; + Q_ASSERT(index < trainerCount()); return m_trainers.at(index); } MapTrainer* Map::trainer(const int index) { - if (trainerCount() <= index) - return NULL; + Q_ASSERT(index < trainerCount()); return m_trainers[index]; } @@ -403,8 +398,7 @@ MapTrainer* Map::newTrainer(MapTrainer* trainer) void Map::deleteTrainer(const int index) { - if (trainerCount() <= index) - return; + Q_ASSERT(index < trainerCount()); delete m_trainers[index]; m_trainers.removeAt(index); } @@ -424,15 +418,13 @@ int Map::newTrainerId() const const MapWarp* Map::warp(const int index) const { - if (warpCount() <= index) - return NULL; + Q_ASSERT(index < warpCount()); return m_warps.at(index); } MapWarp* Map::warp(const int index) { - if (warpCount() <= index) - return NULL; + Q_ASSERT(index < warpCount()); return m_warps[index]; } @@ -484,8 +476,7 @@ MapWarp* Map::newWarp(MapWarp* warp) void Map::deleteWarp(const int index) { - if (warpCount() <= index) - return; + Q_ASSERT(index < warpCount()); delete m_warps[index]; m_warps.removeAt(index); } @@ -505,15 +496,13 @@ int Map::newWarpId() const const MapWildList* Map::wildList(const int index) const { - if (wildListCount() <= index) - return NULL; + Q_ASSERT(index < wildListCount()); return m_wildLists.at(index); } MapWildList* Map::wildList(const int index) { - if (wildListCount() <= index) - return NULL; + Q_ASSERT(index < wildListCount()); return m_wildLists[index]; } @@ -565,8 +554,7 @@ MapWildList* Map::newWildList(MapWildList* wildList) void Map::deleteWildList(const int index) { - if (wildListCount() <= index) - return; + Q_ASSERT(index < wildListCount()); delete m_wildLists[index]; m_wildLists.removeAt(index); } diff --git a/pokemod/MapTrainer.cpp b/pokemod/MapTrainer.cpp index 8b679960..d6b5f1e0 100644 --- a/pokemod/MapTrainer.cpp +++ b/pokemod/MapTrainer.cpp @@ -187,15 +187,13 @@ int MapTrainer::leadTeamMember() const const MapTrainerTeamMember* MapTrainer::teamMember(const int index) const { - if (teamMemberCount() <= index) - return NULL; + Q_ASSERT(index < teamMemberCount()); return m_teamMember.at(index); } MapTrainerTeamMember* MapTrainer::teamMember(const int index) { - if (teamMemberCount() <= index) - return NULL; + Q_ASSERT(index < teamMemberCount()); return m_teamMember[index]; } @@ -247,8 +245,7 @@ MapTrainerTeamMember* MapTrainer::newTeamMember(MapTrainerTeamMember* teamMember void MapTrainer::deleteTeamMember(const int index) { - if (teamMemberCount() <= index) - return; + Q_ASSERT(index < teamMemberCount()); delete m_teamMember[index]; m_teamMember.removeAt(index); } diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index b9fec1f1..c5610252 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -148,15 +148,13 @@ bool MapWildList::time(const int time) const const MapWildListEncounter* MapWildList::encounter(const int index) const { - if (encounterCount() <= index) - return NULL; + Q_ASSERT(index < encounterCount()); return m_encounters.at(index); } MapWildListEncounter* MapWildList::encounter(const int index) { - if (encounterCount() <= index) - return NULL; + Q_ASSERT(index < encounterCount()); return m_encounters[index]; } @@ -208,8 +206,7 @@ MapWildListEncounter* MapWildList::newEncounter(MapWildListEncounter* encounter) void MapWildList::deleteEncounter(const int index) { - if (encounterCount() <= index) - return; + Q_ASSERT(index < encounterCount()); delete m_encounters[index]; m_encounters.removeAt(index); } diff --git a/pokemod/Matrix.h b/pokemod/Matrix.h index 3e007e07..32ce9299 100644 --- a/pokemod/Matrix.h +++ b/pokemod/Matrix.h @@ -27,9 +27,7 @@ template<class T> class Matrix { public: - Matrix() : - m_width(0), - m_height(0) + Matrix() { } Matrix(const int height, const int width, const T& value = T()) @@ -43,127 +41,112 @@ template<class T> class Matrix void addRow(const T& value = T()) { - m_width += !m_width; - m_matrix.append(QVector<T>(m_width, value)); - ++m_height; + if (size() == Point(0, 0)) + m_matrix.append(QVector<T>(1, value)); + else + m_matrix.append(QVector<T>(width(), value)); } void addColumn(const T& value = T()) { - if (!m_height) + if (size() == Point(0, 0)) + m_matrix.append(QVector<T>(1, value)); + else { - m_matrix.append(QVector<T>(1)); - ++m_height; + foreach (QVector<T> row, m_matrix) + row.append(value); } - foreach (QVector<T> row, m_matrix) - row.append(value); - ++m_width; } void insertRow(const int row, const T& value = T()) { - if (m_height < row) - return; - m_width += !m_width; - m_matrix.insert(row, QVector<T>(m_width, value)); - ++m_height; + if (size() == Point(0, 0)) + m_matrix.append(QVector<T>(1, value)); + else + { + Q_ASSERT(row <= height()); + m_matrix.insert(row, QVector<T>(width(), value)); + } } void insertColumn(const int column, const T& value = T()) { - if (m_width < column) - return; - if (!m_height) + if (size() == Point(0, 0)) + m_matrix.append(QVector<T>(1, value)); + else { - m_matrix.append(QVector<T>(1)); - ++m_height; + Q_ASSERT(column <= width()); + foreach (QVector<T> row, m_matrix) + row.insert(column, value); } - foreach (QVector<T> row, m_matrix) - row.insert(column, value); - ++m_width; } void deleteRow(const int row) { - if (m_height <= row) - return; - m_matrix.remove(row); - if (!(--m_height)) + if (height() == 1) + m_matrix.clear(); + else { - while (m_width) - deleteColumn(0); + Q_ASSERT(row < height()); + m_matrix.remove(row); } } void deleteColumn(const int column) { - if (m_width <= column) - return; - foreach (QVector<T> row, m_matrix) - row.remove(column); - if (!(--m_width)) + if (width() == 1) + m_matrix.clear(); + else { - while (m_height) - deleteRow(0); + Q_ASSERT(column < width()); + foreach (QVector<T> row, m_matrix) + row.remove(column); } } void clear() { - m_width = 0; - m_height = 0; m_matrix.clear(); } void set(const int row, const int column, const T& value) { - if ((m_height <= row) || (m_width <= column)) - return; + Q_ASSERT(row < height()); + Q_ASSERT(column < width()); (m_matrix[row])[column] = value; } - void resize(const int height, const int width, const T& value = T()) + void resize(const int newHeight, const int newWidth, const T& value = T()) { - int newHeight = height; - int newWidth = width; - if (!newWidth ^ !newHeight) + if (height() < newHeight) { - if (newWidth) - ++newHeight; - if (newHeight) - ++newWidth; - } - if (m_height < newHeight) - { - while (m_height < newHeight) + while (height() < newHeight) addRow(value); } else { - while (newHeight < m_height) + while (newHeight < height()) deleteRow(newHeight); } - if (m_height < newHeight) + if (width() < newWidth) { - while (m_width < newWidth) + while (width() < newWidth) addColumn(value); } else { - while (newWidth < m_width) + while (newWidth < width()) deleteColumn(newWidth); } } T at(const int row, const int column) const { - if ((m_height <= row) || (m_width <= column)) - return T(); + Q_ASSERT(row < height()); + Q_ASSERT(column < width()); return m_matrix.at(row).at(column); } QVector<T> row(const int row) const { - if (height <= row) - return QVector<T>(); + Q_ASSERT(row < height()); return m_matrix.at(row); } QVector<T> column(const int column) const { - if (m_width <= column) - return QVector<T>(); + Q_ASSERT(column < width()); QVector<T> col; foreach (QVector<T> row, m_matrix) col.append(row.at(column)); @@ -171,20 +154,23 @@ template<class T> class Matrix } int height() const { - return m_height; + return m_matrix.size(); } int width() const { - return m_width; + if (m_matrix.size()) + return m_matrix[0].size(); + return 0; } Point size() const { - return Point(m_width, m_height); + return Point(height(), width()); } T& operator()(const int row, const int column) { - Q_ASSERT((row < m_height) || (column < m_width)); + Q_ASSERT(row < height()); + Q_ASSERT(column < width()); return m_matrix[row][column]; } T operator()(const int row, const int column) const @@ -195,10 +181,10 @@ template<class T> class Matrix { if (this == &rhs) return *this; - resize(rhs.m_height, rhs.m_width); - for (int i = 0; i < m_height; ++i) + resize(rhs.height(), rhs.width()); + for (int i = 0; i < height(); ++i) { - for (int j = 0; j < m_width; ++j) + for (int j = 0; j < width(); ++j) m_matrix[i][j] = rhs.m_matrix[i][j]; } return *this; @@ -207,16 +193,7 @@ template<class T> class Matrix { if (this == &rhs) return true; - if ((m_height != rhs.m_height) || (m_width == rhs.m_width)) - return false; - for (int i = 0; i < m_height; ++i) - { - for (int j = 0; j < m_width; ++j) - { - if (m_matrix[i][j] != rhs.m_matrix[i][j]) - return false; - } - } + return m_matrix == rhs.m_matrix; return true; } bool operator!=(const Matrix<T>& rhs) const @@ -224,8 +201,6 @@ template<class T> class Matrix return !(*this == rhs); } protected: - int m_width; - int m_height; QVector< QVector<T> > m_matrix; }; diff --git a/pokemod/Object.h b/pokemod/Object.h index 503d562e..6c64b455 100644 --- a/pokemod/Object.h +++ b/pokemod/Object.h @@ -126,6 +126,19 @@ class Object : public QObject setter(row, column, LOAD_##type(xml_##variable)); \ xml_##variable = xml_##variable.nextSiblingElement("element"); \ } +#define LOAD_Typechart(setter, type, variable) \ + QDomElement xml_##variable = LOAD_NODE(#variable); \ + int height_##variable = xml_##variable.attribute("height", "1").toInt(); \ + int width_##variable = xml_##variable.attribute("width", "1").toInt(); \ + xml_##variable = LOAD_NODE(#variable).firstChildElement("element"); \ + while (!xml_##variable.isNull()) \ + { \ + int row = xml_##variable.attribute("row", "-1").toInt(); \ + int column = xml_##variable.attribute("column", "-1").toInt(); \ + if ((0 <= row) && (row < height_##variable) && (0 <= column) && (column < width_##variable)) \ + setter(row, column, LOAD_##type(xml_##variable)); \ + xml_##variable = xml_##variable.nextSiblingElement("element"); \ + } #define LOAD_SUB(setter, class) \ QDomElement xml_##class = xml.firstChildElement(#class); \ while (!xml_##class.isNull()) \ diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index 414cb578..dd342ce7 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -64,7 +64,7 @@ Pokemod::Pokemod() : m_flySkin(192, 128), m_fishSkin(192, 128), m_surfFishSkin(192, 128), - m_typeChart(0, 0), + m_typechart(0, 0), m_rules(new Rules(this)) { } @@ -104,7 +104,7 @@ void Pokemod::validate() if (mapById(m_startMap)->warpIndex(m_startWarp) == INT_MAX) emit(error("Invalid starting warp")); } - if ((m_typeChart.width() != typeCount()) || (m_typeChart.height() != typeCount())) + if ((m_typechart.width() != typeCount()) || (m_typechart.height() != typeCount())) emit(error("Type chart is invalid")); m_rules->validate(); QSet<int> idChecker; @@ -438,7 +438,7 @@ void Pokemod::load(const QDomElement& xml, const int) LOAD_SUB(newTrainer, Trainer); LOAD_SUB(newType, Type); LOAD_SUB(newWeather, Weather); - LOAD_MATRIX(setTypeChart, Fraction, typeChart); + LOAD_Typechart(setTypechart, Fraction, typechart); } QDomElement Pokemod::save() const @@ -456,7 +456,7 @@ QDomElement Pokemod::save() const SAVE(QPixmap, fishSkin); SAVE(QPixmap, surfFishSkin); SAVE_Rules(rules); - SAVE_MATRIX(Fraction, typeChart); + SAVE_MATRIX(Fraction, typechart); SAVE_SUB(Ability, abilities); SAVE_SUB(Author, authors); SAVE_SUB(Badge, badges); @@ -592,9 +592,9 @@ void Pokemod::setSurfFishSkin(const QPixmap& surfFishSkin) emit(changed()); } -void Pokemod::setTypeChart(const int attack, const int defense, const Fraction& multiplier) +void Pokemod::setTypechart(const int attack, const int defense, const Fraction& multiplier) { - CHECK_ARRAY(typeChart(attack, defense), multiplier); + CHECK_ARRAY(typechart(attack, defense), multiplier); } void Pokemod::setRules(const Rules& rules) @@ -662,19 +662,19 @@ QPixmap Pokemod::surfFishSkin() const return m_surfFishSkin; } -const Matrix<Fraction>* Pokemod::typeChart() const +const Matrix<Fraction>& Pokemod::typechart() const { - return &m_typeChart; + return m_typechart; } -Matrix<Fraction>* Pokemod::typeChart() +Matrix<Fraction>& Pokemod::typechart() { - return &m_typeChart; + return m_typechart; } -Fraction Pokemod::typeChart(const int attack, const int defense) const +Fraction Pokemod::typechart(const int attack, const int defense) const { - return m_typeChart(attack, defense); + return m_typechart(attack, defense); } const Rules* Pokemod::rules() const @@ -689,15 +689,13 @@ Rules* Pokemod::rules() const Ability* Pokemod::ability(const int index) const { - if (abilityCount() <= index) - return NULL; + Q_ASSERT(index < abilityCount()); return m_abilities.at(index); } Ability* Pokemod::ability(const int index) { - if (abilityCount() <= index) - return NULL; + Q_ASSERT(index < abilityCount()); return m_abilities[index]; } @@ -749,8 +747,7 @@ Ability* Pokemod::newAbility(Ability* ability) void Pokemod::deleteAbility(const int index) { - if (abilityCount() <= index) - return; + Q_ASSERT(index < abilityCount()); delete m_abilities[index]; m_abilities.removeAt(index); } @@ -770,15 +767,13 @@ int Pokemod::newAbilityId() const const Author* Pokemod::author(const int index) const { - if (authorCount() <= index) - return NULL; + Q_ASSERT(index < authorCount()); return m_authors.at(index); } Author* Pokemod::author(const int index) { - if (authorCount() <= index) - return NULL; + Q_ASSERT(index < authorCount()); return m_authors[index]; } @@ -830,8 +825,7 @@ Author* Pokemod::newAuthor(Author* author) void Pokemod::deleteAuthor(const int index) { - if (authorCount() <= index) - return; + Q_ASSERT(index < authorCount()); delete m_authors[index]; m_authors.removeAt(index); } @@ -851,15 +845,13 @@ int Pokemod::newAuthorId() const const Badge* Pokemod::badge(const int index) const { - if (badgeCount() <= index) - return NULL; + Q_ASSERT(index < badgeCount()); return m_badges.at(index); } Badge* Pokemod::badge(const int index) { - if (badgeCount() <= index) - return NULL; + Q_ASSERT(index < badgeCount()); return m_badges[index]; } @@ -911,8 +903,7 @@ Badge* Pokemod::newBadge(Badge* badge) void Pokemod::deleteBadge(const int index) { - if (badgeCount() <= index) - return; + Q_ASSERT(index < badgeCount()); delete m_badges[index]; m_badges.removeAt(index); } @@ -932,15 +923,13 @@ int Pokemod::newBadgeId() const const CoinList* Pokemod::coinList(const int index) const { - if (coinListCount() <= index) - return NULL; + Q_ASSERT(index < coinListCount()); return m_coinLists.at(index); } CoinList* Pokemod::coinList(const int index) { - if (coinListCount() <= index) - return NULL; + Q_ASSERT(index < coinListCount()); return m_coinLists[index]; } @@ -992,8 +981,7 @@ CoinList* Pokemod::newCoinList(CoinList* coinList) void Pokemod::deleteCoinList(const int index) { - if (coinListCount() <= index) - return; + Q_ASSERT(index < coinListCount()); delete m_coinLists[index]; m_coinLists.removeAt(index); } @@ -1013,15 +1001,13 @@ int Pokemod::newCoinListId() const const EggGroup* Pokemod::eggGroup(const int index) const { - if (eggGroupCount() <= index) - return NULL; + Q_ASSERT(index < eggGroupCount()); return m_eggGroups.at(index); } EggGroup* Pokemod::eggGroup(const int index) { - if (eggGroupCount() <= index) - return NULL; + Q_ASSERT(index < eggGroupCount()); return m_eggGroups[index]; } @@ -1073,8 +1059,7 @@ EggGroup* Pokemod::newEggGroup(EggGroup* eggGroup) void Pokemod::deleteEggGroup(const int index) { - if (eggGroupCount() <= index) - return; + Q_ASSERT(index < eggGroupCount()); delete m_eggGroups[index]; m_eggGroups.removeAt(index); } @@ -1094,15 +1079,13 @@ int Pokemod::newEggGroupId() const const GlobalScript* Pokemod::globalScript(const int index) const { - if (globalScriptCount() <= index) - return NULL; + Q_ASSERT(index < globalScriptCount()); return m_globalScripts.at(index); } GlobalScript* Pokemod::globalScript(const int index) { - if (globalScriptCount() <= index) - return NULL; + Q_ASSERT(index < globalScriptCount()); return m_globalScripts[index]; } @@ -1154,8 +1137,7 @@ GlobalScript* Pokemod::newGlobalScript(GlobalScript* globalScript) void Pokemod::deleteGlobalScript(const int index) { - if (globalScriptCount() <= index) - return; + Q_ASSERT(index < globalScriptCount()); delete m_globalScripts[index]; m_globalScripts.removeAt(index); } @@ -1175,15 +1157,13 @@ int Pokemod::newGlobalScriptId() const const Item* Pokemod::item(const int index) const { - if (itemCount() <= index) - return NULL; + Q_ASSERT(index < itemCount()); return m_items.at(index); } Item* Pokemod::item(const int index) { - if (itemCount() <= index) - return NULL; + Q_ASSERT(index < itemCount()); return m_items[index]; } @@ -1235,8 +1215,7 @@ Item* Pokemod::newItem(Item* item) void Pokemod::deleteItem(const int index) { - if (itemCount() <= index) - return; + Q_ASSERT(index < itemCount()); delete m_items[index]; m_items.removeAt(index); } @@ -1256,15 +1235,13 @@ int Pokemod::newItemId() const const ItemType* Pokemod::itemType(const int index) const { - if (itemTypeCount() <= index) - return NULL; + Q_ASSERT(index < itemTypeCount()); return m_itemTypes.at(index); } ItemType* Pokemod::itemType(const int index) { - if (itemTypeCount() <= index) - return NULL; + Q_ASSERT(index < itemTypeCount()); return m_itemTypes[index]; } @@ -1316,8 +1293,7 @@ ItemType* Pokemod::newItemType(ItemType* itemType) void Pokemod::deleteItemType(const int index) { - if (itemTypeCount() <= index) - return; + Q_ASSERT(index < itemTypeCount()); delete m_itemTypes[index]; m_itemTypes.removeAt(index); } @@ -1337,15 +1313,13 @@ int Pokemod::newItemTypeId() const const Map* Pokemod::map(const int index) const { - if (mapCount() <= index) - return NULL; + Q_ASSERT(index < mapCount()); return m_maps.at(index); } Map* Pokemod::map(const int index) { - if (mapCount() <= index) - return NULL; + Q_ASSERT(index < mapCount()); return m_maps[index]; } @@ -1397,8 +1371,7 @@ Map* Pokemod::newMap(Map* map) void Pokemod::deleteMap(const int index) { - if (mapCount() <= index) - return; + Q_ASSERT(index < mapCount()); delete m_maps[index]; m_maps.removeAt(index); } @@ -1418,15 +1391,13 @@ int Pokemod::newMapId() const const Move* Pokemod::move(const int index) const { - if (moveCount() <= index) - return NULL; + Q_ASSERT(index < moveCount()); return m_moves.at(index); } Move* Pokemod::move(const int index) { - if (moveCount() <= index) - return NULL; + Q_ASSERT(index < moveCount()); return m_moves[index]; } @@ -1478,8 +1449,7 @@ Move* Pokemod::newMove(Move* move) void Pokemod::deleteMove(const int index) { - if (moveCount() <= index) - return; + Q_ASSERT(index < moveCount()); delete m_moves[index]; m_moves.removeAt(index); } @@ -1499,15 +1469,13 @@ int Pokemod::newMoveId() const const Nature* Pokemod::nature(const int index) const { - if (natureCount() <= index) - return NULL; + Q_ASSERT(index < natureCount()); return m_natures.at(index); } Nature* Pokemod::nature(const int index) { - if (natureCount() <= index) - return NULL; + Q_ASSERT(index < natureCount()); return m_natures[index]; } @@ -1559,8 +1527,7 @@ Nature* Pokemod::newNature(Nature* nature) void Pokemod::deleteNature(const int index) { - if (natureCount() <= index) - return; + Q_ASSERT(index < natureCount()); delete m_natures[index]; m_natures.removeAt(index); } @@ -1580,15 +1547,13 @@ int Pokemod::newNatureId() const const Sound* Pokemod::sound(const int index) const { - if (soundCount() <= index) - return NULL; + Q_ASSERT(index < soundCount()); return m_sounds.at(index); } Sound* Pokemod::sound(const int index) { - if (soundCount() <= index) - return NULL; + Q_ASSERT(index < soundCount()); return m_sounds[index]; } @@ -1640,8 +1605,7 @@ Sound* Pokemod::newSound(Sound* sound) void Pokemod::deleteSound(const int index) { - if (soundCount() <= index) - return; + Q_ASSERT(index < soundCount()); delete m_sounds[index]; m_sounds.removeAt(index); } @@ -1661,15 +1625,13 @@ int Pokemod::newSoundId() const const Species* Pokemod::species(const int index) const { - if (speciesCount() <= index) - return NULL; + Q_ASSERT(index < speciesCount()); return m_species.at(index); } Species* Pokemod::species(const int index) { - if (speciesCount() <= index) - return NULL; + Q_ASSERT(index < speciesCount()); return m_species[index]; } @@ -1721,8 +1683,7 @@ Species* Pokemod::newSpecies(Species* species) void Pokemod::deleteSpecies(const int index) { - if (speciesCount() <= index) - return; + Q_ASSERT(index < speciesCount()); delete m_species[index]; m_species.removeAt(index); } @@ -1742,15 +1703,13 @@ int Pokemod::newSpeciesId() const const Sprite* Pokemod::sprite(const int index) const { - if (spriteCount() <= index) - return NULL; + Q_ASSERT(index < spriteCount()); return m_sprites.at(index); } Sprite* Pokemod::sprite(const int index) { - if (spriteCount() <= index) - return NULL; + Q_ASSERT(index < spriteCount()); return m_sprites[index]; } @@ -1802,8 +1761,7 @@ Sprite* Pokemod::newSprite(Sprite* sprite) void Pokemod::deleteSprite(const int index) { - if (spriteCount() <= index) - return; + Q_ASSERT(index < spriteCount()); delete m_sprites[index]; m_sprites.removeAt(index); } @@ -1823,15 +1781,13 @@ int Pokemod::newSpriteId() const const Status* Pokemod::status(const int index) const { - if (statusCount() <= index) - return NULL; + Q_ASSERT(index < statusCount()); return m_status.at(index); } Status* Pokemod::status(const int index) { - if (statusCount() <= index) - return NULL; + Q_ASSERT(index < statusCount()); return m_status[index]; } @@ -1883,8 +1839,7 @@ Status* Pokemod::newStatus(Status* status) void Pokemod::deleteStatus(const int index) { - if (statusCount() <= index) - return; + Q_ASSERT(index < statusCount()); delete m_status[index]; m_status.removeAt(index); } @@ -1904,15 +1859,13 @@ int Pokemod::newStatusId() const const Store* Pokemod::store(const int index) const { - if (storeCount() <= index) - return NULL; + Q_ASSERT(index < storeCount()); return m_stores.at(index); } Store* Pokemod::store(const int index) { - if (storeCount() <= index) - return NULL; + Q_ASSERT(index < storeCount()); return m_stores[index]; } @@ -1964,8 +1917,7 @@ Store* Pokemod::newStore(Store* store) void Pokemod::deleteStore(const int index) { - if (storeCount() <= index) - return; + Q_ASSERT(index < storeCount()); delete m_stores[index]; m_stores.removeAt(index); } @@ -1985,15 +1937,13 @@ int Pokemod::newStoreId() const const Tile* Pokemod::tile(const int index) const { - if (tileCount() <= index) - return NULL; + Q_ASSERT(index < tileCount()); return m_tiles.at(index); } Tile* Pokemod::tile(const int index) { - if (tileCount() <= index) - return NULL; + Q_ASSERT(index < tileCount()); return m_tiles[index]; } @@ -2045,8 +1995,7 @@ Tile* Pokemod::newTile(Tile* tile) void Pokemod::deleteTile(const int index) { - if (tileCount() <= index) - return; + Q_ASSERT(index < tileCount()); delete m_tiles[index]; m_tiles.removeAt(index); } @@ -2066,16 +2015,14 @@ int Pokemod::newTileId() const const Time* Pokemod::time(const int index) const { - if (timeCount() <= index) - return NULL; + Q_ASSERT(index < timeCount()); return m_times.at(index); } -Time* Pokemod::time(const int i) +Time* Pokemod::time(const int index) { - if (timeCount() <= i) - return NULL; - return m_times[i]; + Q_ASSERT(index < timeCount()); + return m_times[index]; } const Time* Pokemod::timeById(const int id) const @@ -2126,8 +2073,7 @@ Time* Pokemod::newTime(Time* time) void Pokemod::deleteTime(const int index) { - if (timeCount() <= index) - return; + Q_ASSERT(index < timeCount()); delete m_times[index]; m_times.removeAt(index); } @@ -2147,15 +2093,13 @@ int Pokemod::newTimeId() const const Trainer* Pokemod::trainer(const int index) const { - if (trainerCount() <= index) - return NULL; + Q_ASSERT(index < trainerCount()); return m_trainers.at(index); } Trainer* Pokemod::trainer(const int index) { - if (trainerCount() <= index) - return NULL; + Q_ASSERT(index < trainerCount()); return m_trainers[index]; } @@ -2207,8 +2151,7 @@ Trainer* Pokemod::newTrainer(Trainer* trainer) void Pokemod::deleteTrainer(const int index) { - if (trainerCount() <= index) - return; + Q_ASSERT(index < trainerCount()); delete m_trainers[index]; m_trainers.removeAt(index); } @@ -2228,15 +2171,13 @@ int Pokemod::newTrainerId() const const Type* Pokemod::type(const int index) const { - if (typeCount() <= index) - return NULL; + Q_ASSERT(index < typeCount()); return m_types.at(index); } Type* Pokemod::type(const int index) { - if (typeCount() <= index) - return NULL; + Q_ASSERT(index < typeCount()); return m_types[index]; } @@ -2282,30 +2223,17 @@ Type* Pokemod::newType(const Type& type) Type* Pokemod::newType(Type* type) { - if (typeCount()) - { - m_typeChart.addColumn(Fraction(1, 1)); - m_typeChart.addRow(Fraction(1, 1)); - } - else - m_typeChart.addColumn(Fraction(1, 1)); m_types.append(type); + m_typechart.resize(typeCount(), typeCount(), Fraction(1, 1)); return type; } void Pokemod::deleteType(const int index) { - if (typeCount() <= index) - return; + Q_ASSERT(index < typeCount()); delete m_types[index]; - if (typeCount() == 1) - m_typeChart.deleteColumn(index); - else - { - m_typeChart.deleteColumn(index); - m_typeChart.deleteRow(index); - } m_types.removeAt(index); + m_typechart.resize(typeCount(), typeCount(), Fraction(1, 1)); } void Pokemod::deleteTypeById(const int id) @@ -2323,15 +2251,13 @@ int Pokemod::newTypeId() const const Weather* Pokemod::weather(const int index) const { - if (weatherCount() <= index) - return NULL; + Q_ASSERT(index < weatherCount()); return m_weathers.at(index); } Weather* Pokemod::weather(const int index) { - if (weatherCount() <= index) - return NULL; + Q_ASSERT(index < weatherCount()); return m_weathers[index]; } @@ -2383,8 +2309,7 @@ Weather* Pokemod::newWeather(Weather* weather) void Pokemod::deleteWeather(const int index) { - if (weatherCount() <= index) - return; + Q_ASSERT(index < weatherCount()); delete m_weathers[index]; m_weathers.removeAt(index); } @@ -2412,7 +2337,7 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs) COPY(description); COPY(startMap); COPY(startWarp); - COPY(typeChart); + COPY(typechart); COPY_Rules(rules); COPY_SUB(Ability, abilities); COPY_SUB(Author, authors); @@ -2435,6 +2360,7 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs) COPY_SUB(Trainer, trainers); COPY_SUB(Type, types); COPY_SUB(Weather, weathers); + m_typechart.resize(typeCount(), typeCount()); return *this; } diff --git a/pokemod/Pokemod.h b/pokemod/Pokemod.h index e2e2b11b..522f5a49 100644 --- a/pokemod/Pokemod.h +++ b/pokemod/Pokemod.h @@ -123,7 +123,7 @@ class Pokemod : public Object void setFlySkin(const QPixmap& slySkin); void setFishSkin(const QPixmap& fishSkin); void setSurfFishSkin(const QPixmap& surfFishSkin); - void setTypeChart(const int attack, const int defense, const Fraction& multiplier); + void setTypechart(const int attack, const int defense, const Fraction& multiplier); void setRules(const Rules& rules); void setRules(const QDomElement& xml); @@ -138,9 +138,9 @@ class Pokemod : public Object QPixmap flySkin() const; QPixmap fishSkin() const; QPixmap surfFishSkin() const; - const Matrix<Fraction>* typeChart() const; - Matrix<Fraction>* typeChart(); - Fraction typeChart(const int attack, const int defense) const; + const Matrix<Fraction>& typechart() const; + Matrix<Fraction>& typechart(); + Fraction typechart(const int attack, const int defense) const; const Rules* rules() const; Rules* rules(); @@ -476,7 +476,7 @@ class Pokemod : public Object QPixmap m_flySkin; QPixmap m_fishSkin; QPixmap m_surfFishSkin; - Matrix<Fraction> m_typeChart; + Matrix<Fraction> m_typechart; Rules* m_rules; QList<Ability*> m_abilities; QList<Author*> m_authors; diff --git a/pokemod/Species.cpp b/pokemod/Species.cpp index d3b91b5c..88226bce 100644 --- a/pokemod/Species.cpp +++ b/pokemod/Species.cpp @@ -649,15 +649,13 @@ Script Species::evolution() const const SpeciesAbility* Species::ability(const int index) const { - if (abilityCount() <= index) - return NULL; + Q_ASSERT(index < abilityCount()); return m_abilities.at(index); } SpeciesAbility* Species::ability(const int index) { - if (abilityCount() <= index) - return NULL; + Q_ASSERT(index < abilityCount()); return m_abilities[index]; } @@ -709,8 +707,7 @@ SpeciesAbility* Species::newAbility(SpeciesAbility* ability) void Species::deleteAbility(const int index) { - if (abilityCount() <= index) - return; + Q_ASSERT(index < abilityCount()); delete m_abilities[index]; m_abilities.removeAt(index); } @@ -730,15 +727,13 @@ int Species::newAbilityId() const const SpeciesItem* Species::item(const int index) const { - if (itemCount() <= index) - return NULL; + Q_ASSERT(index < itemCount()); return m_items.at(index); } SpeciesItem* Species::item(const int index) { - if (itemCount() <= index) - return NULL; + Q_ASSERT(index < itemCount()); return m_items[index]; } @@ -790,8 +785,7 @@ SpeciesItem* Species::newItem(SpeciesItem* item) void Species::deleteItem(const int index) { - if (itemCount() <= index) - return; + Q_ASSERT(index < itemCount()); delete m_items[index]; m_items.removeAt(index); } @@ -811,15 +805,13 @@ int Species::newItemId() const const SpeciesMove* Species::move(const int index) const { - if (moveCount() <= index) - return NULL; + Q_ASSERT(index < moveCount()); return m_moves.at(index); } SpeciesMove* Species::move(const int index) { - if (moveCount() <= index) - return NULL; + Q_ASSERT(index < moveCount()); return m_moves[index]; } @@ -871,8 +863,7 @@ SpeciesMove* Species::newMove(SpeciesMove* move) void Species::deleteMove(const int index) { - if (moveCount() <= index) - return; + Q_ASSERT(index < moveCount()); delete m_moves[index]; m_moves.removeAt(index); } diff --git a/pokemod/Type.cpp b/pokemod/Type.cpp index 24ff76e8..7f138bc2 100644 --- a/pokemod/Type.cpp +++ b/pokemod/Type.cpp @@ -74,7 +74,7 @@ void Type::setName(const QString& name) void Type::setStab(const Fraction& stab) { - if (1 < stab) + if (stab < 1) { emit(error(bounds("stab"))); return; diff --git a/pokemodr/FractionWidget.cpp b/pokemodr/FractionWidget.cpp index c1e818ec..371af316 100644 --- a/pokemodr/FractionWidget.cpp +++ b/pokemodr/FractionWidget.cpp @@ -19,8 +19,7 @@ #include "FractionWidget.h" FractionWidget::FractionWidget(QWidget* parent, const Fraction& value) : - QWidget(parent), - m_behavior(-1) + QWidget(parent) { setupUi(this); connect(this, SIGNAL(valueChanged(const Fraction&)), SLOT(updateValue())); @@ -40,9 +39,6 @@ Fraction FractionWidget::value() const void FractionWidget::setBehavior(const int behavior) { m_behavior = behavior; - m_value = Fraction(1, 1); - varDenominator->setValue(1); - varNumerator->setValue(1); emit(valueChanged(m_value)); } @@ -53,36 +49,34 @@ void FractionWidget::setValue(const Fraction& value) m_value = value; varDenominator->setValue(m_value.denominator()); varNumerator->setValue(m_value.numerator()); - if (0 < m_behavior) - { + if (-1 < m_behavior) varNumerator->setMaximum(INT_MAX); - varDenominator->setMaximum(m_value.numerator()); - } else - { varNumerator->setMaximum(m_value.denominator()); + if (m_behavior < 1) varDenominator->setMaximum(INT_MAX); - } + else + varDenominator->setMaximum(m_value.numerator()); emit(valueChanged(m_value)); } void FractionWidget::on_varNumerator_valueChanged(const int numerator) { m_value.setNumerator(numerator); - if (0 < m_behavior) - varDenominator->setMaximum(numerator); - else + if (m_behavior < 1) varDenominator->setMaximum(INT_MAX); + else + varDenominator->setMaximum(m_value.numerator()); emit(valueChanged(m_value)); } void FractionWidget::on_varDenominator_valueChanged(const int denominator) { m_value.setDenominator(denominator); - if (m_behavior < 0) - varNumerator->setMaximum(denominator); - else + if (-1 < m_behavior) varNumerator->setMaximum(INT_MAX); + else + varNumerator->setMaximum(m_value.denominator()); emit(valueChanged(m_value)); } diff --git a/pokemodr/MapUI.cpp b/pokemodr/MapUI.cpp index 3314746d..de9d87f3 100644 --- a/pokemodr/MapUI.cpp +++ b/pokemodr/MapUI.cpp @@ -51,12 +51,13 @@ MapUI::~MapUI() void MapUI::initGui() { varType->addItems(Map::TypeStr); - varTilemap->horizontalHeader()->setResizeMode(QHeaderView::Fixed); - varTilemap->verticalHeader()->setResizeMode(QHeaderView::Fixed); - varTilemap->horizontalHeader()->setDefaultSectionSize(64); - varTilemap->verticalHeader()->setDefaultSectionSize(64); - varTilemap->setModel(m_model); - varTilemap->setItemDelegate(m_delegate); + // TODO: Map stuff +// varTilemap->horizontalHeader()->setResizeMode(QHeaderView::Fixed); +// varTilemap->verticalHeader()->setResizeMode(QHeaderView::Fixed); +// varTilemap->horizontalHeader()->setDefaultSectionSize(64); +// varTilemap->verticalHeader()->setDefaultSectionSize(64); +// varTilemap->setModel(m_model); +// varTilemap->setItemDelegate(m_delegate); } void MapUI::refreshGui() @@ -73,10 +74,10 @@ void MapUI::setGui() { varName->setText(static_cast<Map*>(modified())->name()); boxFlyWarp->setChecked((static_cast<Map*>(modified())->flyWarp() == INT_MAX) ? Qt::Unchecked : Qt::Checked); - varFlyWarp->setCurrentIndex(varFlyWarp->findData(static_cast<Map*>(modified())->flyWarp())); +// varFlyWarp->setCurrentIndex(varFlyWarp->findData(static_cast<Map*>(modified())->flyWarp())); varType->setCurrentIndex(static_cast<Map*>(modified())->type()); - buttonDeleteColumn->setEnabled(0 < m_model->columnCount()); - buttonDeleteRow->setEnabled(0 < m_model->rowCount()); +// buttonDeleteColumn->setEnabled(0 < m_model->columnCount()); +// buttonDeleteRow->setEnabled(0 < m_model->rowCount()); } void MapUI::apply() diff --git a/pokemodr/PokeModrUI.cpp b/pokemodr/PokeModrUI.cpp index 214eb673..fd1ed594 100644 --- a/pokemodr/PokeModrUI.cpp +++ b/pokemodr/PokeModrUI.cpp @@ -189,6 +189,7 @@ bool PokeModrUI::savePokemod(const Pokemod* pokemod, const KUrl& url) if (file.open(QIODevice::ReadWrite)) { file.write(Object::xml(pokemod).toByteArray()); + treePokemod->setDirty(pokemod, false); file.close(); return true; } @@ -202,7 +203,10 @@ bool PokeModrUI::savePokemod(const Pokemod* pokemod, const KUrl& url) { temp.write(Object::xml(pokemod).toByteArray()); if (KIO::NetAccess::upload(temp.fileName(), url, this)) + { + treePokemod->setDirty(pokemod, false); return true; + } else KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error"); } diff --git a/pokemodr/PokemodUI.cpp b/pokemodr/PokemodUI.cpp index 88d7111b..8479fd15 100644 --- a/pokemodr/PokemodUI.cpp +++ b/pokemodr/PokemodUI.cpp @@ -20,7 +20,7 @@ // PokeModr includes #include "FileDialog.h" -#include "TypechartWidgetItem.h" +#include "TypechartModel.h" // Pokemod includes #include "../pokemod/Map.h" @@ -40,6 +40,14 @@ PokemodUI::~PokemodUI() { } +void PokemodUI::initGui() +{ + QStringList types; + for (int i = 0; i < static_cast<Pokemod*>(original())->typeCount(); ++i) + types << static_cast<Pokemod*>(original())->type(i)->name(); + varTypechart->setModel(new TypechartModel(static_cast<Pokemod*>(original())->typechart(), types)); +} + void PokemodUI::refreshGui() { varMap->clear(); @@ -48,19 +56,7 @@ void PokemodUI::refreshGui() const Map* map = static_cast<Pokemod*>(original())->map(i); varMap->addItem(map->name(), map->id()); } - varTypechart->setRowCount(static_cast<Pokemod*>(original())->typeCount()); - varTypechart->setColumnCount(static_cast<Pokemod*>(original())->typeCount()); - QStringList types; - Matrix<Fraction>* typeChart = static_cast<Pokemod*>(original())->typeChart(); - for (int i = 0; i < static_cast<Pokemod*>(original())->typeCount(); ++i) - { - types << static_cast<Pokemod*>(original())->type(i)->name(); - // TODO: set the typechart correctly -// for (int j = 0; j < static_cast<Pokemod*>(original())->typeCount(); ++j) -// varTypechart->item(i, j)->setData(Qt::EditRole, QVariant::fromValue(typeChart->at(i, j))); - } - varTypechart->setVerticalHeaderLabels(types); - varTypechart->setHorizontalHeaderLabels(types); + varEffectiveness->setEnabled(false); } void PokemodUI::setGui() @@ -74,9 +70,10 @@ void PokemodUI::setGui() if (resetWarps) { varWarp->clear(); - const Map* map = static_cast<Pokemod*>(original())->mapById(static_cast<Pokemod*>(modified())->startMap()); - if (map) + const int mapIndex = static_cast<Pokemod*>(original())->mapIndex(static_cast<Pokemod*>(modified())->startMap()); + if (mapIndex != INT_MAX) { + const Map* map = static_cast<Pokemod*>(original())->map(mapIndex); for (int i = 0; i < map->warpCount(); ++i) { const MapWarp* warp = map->warp(i); @@ -127,12 +124,12 @@ void PokemodUI::on_varDescription_textChanged(const QString& description) void PokemodUI::on_varMap_activated(const int map) { - static_cast<Pokemod*>(modified())->setStartMap(map); + static_cast<Pokemod*>(modified())->setStartMap(varMap->itemData(map).toInt()); } void PokemodUI::on_varWarp_activated(const int warp) { - static_cast<Pokemod*>(modified())->setStartWarp(warp); + static_cast<Pokemod*>(modified())->setStartWarp(varWarp->itemData(warp).toInt()); } void PokemodUI::on_varWalkSkin_pressed() @@ -201,10 +198,16 @@ void PokemodUI::on_varSurfFishSkin_pressed() delete dialog; } -void PokemodUI::on_varTypechart_currentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous) +void PokemodUI::on_varTypechart_clicked(const QModelIndex& index) { - disconnect(varEffectiveness, SIGNAL(valueChanged(Fraction)), static_cast<TypechartWidgetItem*>(previous), SLOT(setValue(Fraction))); - TypechartWidgetItem* widgetItem = static_cast<TypechartWidgetItem*>(current); -// varEffectiveness->setValue(widgetItem->data(Qt::EditRole).value<Fraction>()); - connect(varEffectiveness, SIGNAL(valueChanged(Fraction)), widgetItem, SLOT(setValue(Fraction))); + m_index = index; + varEffectiveness->setEnabled(true); + varEffectiveness->setValue(varTypechart->model()->data(m_index, Qt::EditRole).value<Fraction>()); +} + +void PokemodUI::on_varEffectiveness_valueChanged(const Fraction& multiplier) +{ + varTypechart->model()->setData(m_index, QVariant::fromValue(multiplier), Qt::EditRole); + emit(changed()); + setGui(); } diff --git a/pokemodr/PokemodUI.h b/pokemodr/PokemodUI.h index 12f4f913..91a562ee 100644 --- a/pokemodr/PokemodUI.h +++ b/pokemodr/PokemodUI.h @@ -48,12 +48,15 @@ class PokemodUI : public ObjectUI, private Ui::formPokemod void on_varSurfSkin_pressed(); void on_varFishSkin_pressed(); void on_varSurfFishSkin_pressed(); - void on_varTypechart_currentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); + void on_varTypechart_clicked(const QModelIndex& index); + void on_varEffectiveness_valueChanged(const Fraction& multiplier); private slots: + void initGui(); void refreshGui(); void setGui(); private: int m_lastMap; + QModelIndex m_index; }; #endif diff --git a/pokemodr/TODO b/pokemodr/TODO index 10602709..10b697b7 100644 --- a/pokemodr/TODO +++ b/pokemodr/TODO @@ -7,10 +7,8 @@ When adding to an expanded item, its view is not updated ========= -Can't edit KListWidgets +Can't edit KListWidgets correctly -BadgeUI - Stats behaving oddly MapUI Crash when opening MoveUI diff --git a/pokemodr/TypechartModel.h b/pokemodr/TypechartModel.h new file mode 100644 index 00000000..e28be2de --- /dev/null +++ b/pokemodr/TypechartModel.h @@ -0,0 +1,95 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMODR_TYPECHARTMODEL__ +#define __POKEMODR_TYPECHARTMODEL__ + +// Pokemod includes +#include "../pokemod/Fraction.h" +#include "../pokemod/Matrix.h" + +// Qt includes +#include <QAbstractTableModel> +#include <QStringList> +#include <QVariant> + +class TypechartModel : public QAbstractTableModel +{ + Q_OBJECT + + public: + TypechartModel(Matrix<Fraction>& typechart, const QStringList& types) : + QAbstractTableModel(), + m_typechart(typechart), + m_types(types) + { + } + + QVariant data(const QModelIndex& index, int role) const + { + if (!index.isValid()) + return QVariant(); + if (role == Qt::DisplayRole) + return QString::number(m_typechart.at(index.row(), index.column()), 'g', 3); + else if (role == Qt::EditRole) + return QVariant::fromValue(m_typechart.at(index.row(), index.column())); + return QVariant(); + } + + QVariant headerData(int section, Qt::Orientation /*orientation*/, int role = Qt::DisplayRole) const + { + if (role == Qt::DisplayRole) + return m_types.at(section); + return QVariant(); + } + + int rowCount(const QModelIndex& /*parent*/) const + { + return m_typechart.height(); + } + + int columnCount(const QModelIndex& /*parent*/) const + { + return m_typechart.width(); + } + + Qt::ItemFlags flags(const QModelIndex& index) const + { + if (!index.isValid()) + return 0; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + } + + bool setData(const QModelIndex& index, const QVariant& value, int role) + { + if (!index.isValid()) + return false; + if (role == Qt::EditRole) + { + if (value.canConvert<Fraction>()) + { + m_typechart(index.row(), index.column()) = value.value<Fraction>(); + emit(dataChanged(index, index)); + } + } + } + private: + Matrix<Fraction>& m_typechart; + const QStringList m_types; +}; + +#endif diff --git a/pokemodr/TypechartWidgetItem.h b/pokemodr/TypechartWidgetItem.h deleted file mode 100644 index 5e1890c2..00000000 --- a/pokemodr/TypechartWidgetItem.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef __TYPECHARTWIDGETITEM__ -#define __TYPECHARTWIDGETITEM__ - -// Pokemod includes -#include "../pokemod/Fraction.h" - -// Qt includes -#include <QObject> -#include <QTableWidgetItem> -#include <QVariant> - -#define DBL_PREC_SHORT 3 - -class TypechartWidgetItem : public QObject, public QTableWidgetItem -{ - Q_OBJECT - - public: - TypechartWidgetItem(Fraction& multiplier) : - QTableWidgetItem(QTableWidgetItem::UserType), - m_multiplier(multiplier) - { - } - - QVariant data(const int role) - { - if (role == Qt::EditRole) - return QVariant::fromValue(m_multiplier); - else if (role == Qt::DisplayRole) - return QString::number(m_multiplier, 'g', DBL_PREC_SHORT); - return QVariant(); - } - void setData(int role, const QVariant& value) - { - if (role == Qt::EditRole) - m_multiplier = value.value<Fraction>(); - } - public slots: - void setValue(const Fraction& multiplier) - { - m_multiplier = multiplier; - } - private: - Fraction& m_multiplier; -}; - -#endif diff --git a/pokemodr/gui/move.ui b/pokemodr/gui/move.ui index 3d33571c..38503b7d 100644 --- a/pokemodr/gui/move.ui +++ b/pokemodr/gui/move.ui @@ -32,6 +32,9 @@ <property name="toolTip" > <string>The chance that the move hits</string> </property> + <property name="behavior" > + <number>-1</number> + </property> </widget> </item> </layout> diff --git a/pokemodr/gui/pokemod.ui b/pokemodr/gui/pokemod.ui index 30463316..5e173383 100644 --- a/pokemodr/gui/pokemod.ui +++ b/pokemodr/gui/pokemod.ui @@ -409,16 +409,22 @@ </attribute> <layout class="QVBoxLayout" > <item> - <widget class="QTableWidget" name="varTypechart" /> + <widget class="QTableView" name="varTypechart" /> </item> <item> <widget class="QGroupBox" name="boxEffectiveness" > + <property name="title" > + <string>Effectiveness</string> + </property> <layout class="QVBoxLayout" > <item> <widget class="FractionWidget" name="varEffectiveness" > <property name="toolTip" > <string>Multiplier for attacks of the attacking type against the defending type</string> </property> + <property name="behavior" > + <number>0</number> + </property> </widget> </item> </layout> diff --git a/pokemodr/models/MapModel.cpp b/pokemodr/models/MapModel.cpp index 609c9a90..040f2871 100644 --- a/pokemodr/models/MapModel.cpp +++ b/pokemodr/models/MapModel.cpp @@ -27,7 +27,7 @@ // PokeModr includes #include "../MapUI.h" -// Map includes +// Pokemod includes #include "../../pokemod/Map.h" // Qt includes @@ -39,6 +39,7 @@ MapModel::MapModel(BaseModel* parent, Map* map) : GroupObjectModel(parent, map) { + setupData(); } MapModel::~MapModel() diff --git a/pokemodr/models/SpeciesModel.cpp b/pokemodr/models/SpeciesModel.cpp index 14f4f785..dc4415c2 100644 --- a/pokemodr/models/SpeciesModel.cpp +++ b/pokemodr/models/SpeciesModel.cpp @@ -29,9 +29,6 @@ // Pokemod includes #include "../../pokemod/Pokemod.h" #include "../../pokemod/Species.h" -#include "../../pokemod/SpeciesAbility.h" -#include "../../pokemod/SpeciesItem.h" -#include "../../pokemod/SpeciesMove.h" // Qt includes #include <QFile> diff --git a/pokemodr/pokemodr.pro b/pokemodr/pokemodr.pro index 82b652cb..14bdd4d6 100644 --- a/pokemodr/pokemodr.pro +++ b/pokemodr/pokemodr.pro @@ -185,7 +185,7 @@ HEADERS += AbilityUI.h \ TilemapModel.h \ TileUI.h \ TimeUI.h \ - TypechartWidgetItem.h \ + TypechartModel.h \ TrainerUI.h \ TypeUI.h \ WeatherUI.h \ |
