summaryrefslogtreecommitdiffstats
path: root/sigmodr/TilemapModel.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-10-13 17:25:26 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-10-13 17:25:26 +0000
commit1a5c60b60eb6e3209ec1c59d20a65bf413330500 (patch)
tree6f0e051e3ef2622b6e77d262861b5da16c4395de /sigmodr/TilemapModel.cpp
parent03e65c78d1bc08bdaee86cf09a4dd8735b6a9fdd (diff)
downloadsigen-1a5c60b60eb6e3209ec1c59d20a65bf413330500.tar.gz
sigen-1a5c60b60eb6e3209ec1c59d20a65bf413330500.tar.xz
sigen-1a5c60b60eb6e3209ec1c59d20a65bf413330500.zip
[FIX] Now using KDE4_* macros in CMake
[FIX] The LaTeX is outdated, removing [FIX] Split up TypechartModel and TilemapModel into header and source git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@276 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigmodr/TilemapModel.cpp')
-rw-r--r--sigmodr/TilemapModel.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/sigmodr/TilemapModel.cpp b/sigmodr/TilemapModel.cpp
new file mode 100644
index 00000000..44940619
--- /dev/null
+++ b/sigmodr/TilemapModel.cpp
@@ -0,0 +1,136 @@
+/*
+ * 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/>.
+ */
+
+// Header include
+#include "TilemapModel.h"
+
+// Sigmod includes
+#include "../sigmod/Sigmod.h"
+#include "../sigmod/Sprite.h"
+#include "../sigmod/Tile.h"
+
+// Qt includes
+#include <QtGui/QPixmap>
+
+Sigmodr::TilemapModel::TilemapModel(Sigmod::Matrix<int>* tilemap, const Sigmod::Sigmod* sigmod) :
+ QAbstractTableModel(),
+ m_tilemap(*tilemap),
+ m_sigmod(sigmod)
+{
+}
+
+QVariant Sigmodr::TilemapModel::data(const QModelIndex& index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+ if (role == Qt::DisplayRole)
+ {
+ const int tileIndex = m_sigmod->tileIndex(m_tilemap(index.row(), index.column()));
+ if (tileIndex != INT_MAX)
+ {
+ const Sigmod::Tile* tile = m_sigmod->tile(tileIndex);
+ if (m_sigmod->spriteIndex(tile->sprite()) == INT_MAX)
+ return QPixmap(64, 64);
+ else
+ return QPixmap::fromImage(m_sigmod->spriteById(tile->sprite())->sprite());
+ }
+ }
+ else if (role == Qt::EditRole)
+ return m_tilemap(index.row(), index.column());
+ return QVariant();
+}
+
+QVariant Sigmodr::TilemapModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const
+{
+ if (role == Qt::DisplayRole)
+ return section;
+ return QVariant();
+}
+
+int Sigmodr::TilemapModel::rowCount(const QModelIndex& /*parent*/) const
+{
+ return m_tilemap.height();
+}
+
+int Sigmodr::TilemapModel::columnCount(const QModelIndex& /*parent*/) const
+{
+ return m_tilemap.width();
+}
+
+bool Sigmodr::TilemapModel::insertRows(int row, int count, const QModelIndex& parent)
+{
+ emit(beginInsertRows(parent, row, row + count - 1));
+ for (int i = 0; i < count; ++i)
+ m_tilemap.insertRow(row);
+ emit(endInsertRows());
+ if (m_tilemap.height() == 1)
+ reset();
+ return true;
+}
+
+bool Sigmodr::TilemapModel::insertColumns(int column, int count, const QModelIndex& parent)
+{
+ emit(beginInsertColumns(parent, column, column + count - 1));
+ for (int i = 0; i < count; ++i)
+ m_tilemap.insertColumn(column);
+ emit(endInsertColumns());
+ if (m_tilemap.width() == 1)
+ reset();
+ return true;
+}
+
+bool Sigmodr::TilemapModel::removeRows(int row, int count, const QModelIndex& parent)
+{
+ emit(beginRemoveRows(parent, row, row + count - 1));
+ for (int i = 0; i < count; ++i)
+ m_tilemap.deleteRow(row);
+ emit(endRemoveRows());
+ if (!m_tilemap.height())
+ reset();
+ return true;
+}
+
+bool Sigmodr::TilemapModel::removeColumns(int column, int count, const QModelIndex& parent)
+{
+ emit(beginRemoveColumns(parent, column, column + count - 1));
+ for (int i = 0; i < count; ++i)
+ m_tilemap.deleteColumn(column);
+ emit(endRemoveColumns());
+ if (!m_tilemap.width())
+ reset();
+ return true;
+}
+
+Qt::ItemFlags Sigmodr::TilemapModel::flags(const QModelIndex& index) const
+{
+ if (!index.isValid())
+ return 0;
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+
+bool Sigmodr::TilemapModel::setData(const QModelIndex& index, const QVariant& value, int role)
+{
+ if (!index.isValid())
+ return false;
+ if (role == Qt::EditRole)
+ {
+ m_tilemap(index.row(), index.column()) = value.toInt();
+ emit(dataChanged(index, index));
+ return true;
+ }
+ return false;
+}