diff options
Diffstat (limited to 'pokemod')
| -rw-r--r-- | pokemod/CoinListObject.cpp | 2 | ||||
| -rw-r--r-- | pokemod/Matrix.h | 47 |
2 files changed, 36 insertions, 13 deletions
diff --git a/pokemod/CoinListObject.cpp b/pokemod/CoinListObject.cpp index ff2b8d80..2e0d4066 100644 --- a/pokemod/CoinListObject.cpp +++ b/pokemod/CoinListObject.cpp @@ -22,7 +22,7 @@ #include "CoinList.h" #include "Pokemod.h" -const QStringList CoinListObject::TypeStr = QStringList() << "Item" << "Pokémon"; +const QStringList CoinListObject::TypeStr = QStringList() << "Item" << QString::fromUtf8("Pokémon"); CoinListObject::CoinListObject(const CoinListObject& object) : Object("CoinListObject", object.parent(), object.id()) diff --git a/pokemod/Matrix.h b/pokemod/Matrix.h index 15b70ff0..3e007e07 100644 --- a/pokemod/Matrix.h +++ b/pokemod/Matrix.h @@ -85,7 +85,10 @@ template<class T> class Matrix return; m_matrix.remove(row); if (!(--m_height)) - m_width = 0; + { + while (m_width) + deleteColumn(0); + } } void deleteColumn(const int column) { @@ -94,7 +97,10 @@ template<class T> class Matrix foreach (QVector<T> row, m_matrix) row.remove(column); if (!(--m_width)) - m_height = 0; + { + while (m_height) + deleteRow(0); + } } void clear() { @@ -111,18 +117,35 @@ template<class T> class Matrix } void resize(const int height, const int width, const T& value = T()) { - // FIXME: destructive to data even when expanding - clear(); - m_width = width; - m_height = height; - if (!m_width ^ !m_height) + int newHeight = height; + int newWidth = width; + if (!newWidth ^ !newHeight) + { + if (newWidth) + ++newHeight; + if (newHeight) + ++newWidth; + } + if (m_height < newHeight) + { + while (m_height < newHeight) + addRow(value); + } + else + { + while (newHeight < m_height) + deleteRow(newHeight); + } + if (m_height < newHeight) + { + while (m_width < newWidth) + addColumn(value); + } + else { - if (m_width) - ++m_height; - if (m_height) - ++m_width; + while (newWidth < m_width) + deleteColumn(newWidth); } - m_matrix = QVector< QVector<T> >(m_height, QVector<T>(m_width, value)); } T at(const int row, const int column) const |
