summaryrefslogtreecommitdiffstats
path: root/pokemodr/TilemapModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pokemodr/TilemapModel.cpp')
-rw-r--r--pokemodr/TilemapModel.cpp47
1 files changed, 36 insertions, 11 deletions
diff --git a/pokemodr/TilemapModel.cpp b/pokemodr/TilemapModel.cpp
index 5312fb21..d90fcbe9 100644
--- a/pokemodr/TilemapModel.cpp
+++ b/pokemodr/TilemapModel.cpp
@@ -35,11 +35,6 @@ TilemapModel::TilemapModel(QObject* parent, Matrix<int>* tilemap, const Pokemod*
map(tilemap),
pokemod(mod)
{
- setGui();
-}
-
-void TilemapModel::setGui()
-{
}
int TilemapModel::rowCount(const QModelIndex&) const
@@ -86,26 +81,54 @@ Qt::ItemFlags TilemapModel::flags(const QModelIndex&) const
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
+bool TilemapModel::addRow()
+{
+ return insertRows(map->getHeight(), 1);
+}
+
+bool TilemapModel::addColumn()
+{
+ return insertColumns(map->getWidth(), 1);
+}
+
bool TilemapModel::insertRows(int row, int count, const QModelIndex&)
{
- emit(beginInsertRows(QModelIndex(), row, row + count - 1));
- for (int i = 0; i < count; ++i)
- map->insertRow(row);
+ emit(beginInsertRows(QModelIndex(), row, row + count));
+ if (map->getWidth())
+ {
+ for (int i = 0; i < count; ++i)
+ map->insertRow(row);
+ }
+ else
+ {
+ map->addCol();
+ insertColumns(0, 0);
+ }
emit(endInsertRows());
return true;
}
bool TilemapModel::insertColumns(int column, int count, const QModelIndex&)
{
- emit(beginInsertColumns(QModelIndex(), column, column + count - 1));
- for (int i = 0; i < count; ++i)
- map->insertCol(column);
+ emit(beginInsertColumns(QModelIndex(), column, column + count));
+ if (map->getHeight())
+ {
+ for (int i = 0; i < count; ++i)
+ map->insertCol(column);
+ }
+ else
+ {
+ map->addRow();
+ insertRows(0, 0);
+ }
emit(endInsertColumns());
return true;
}
bool TilemapModel::removeRows(int row, int count, const QModelIndex&)
{
+ if (map->getHeight() == 1)
+ removeColumns(0, map->getWidth());
emit(beginRemoveRows(QModelIndex(), row, row + count - 1));
for (int i = 0; i < count; ++i)
map->deleteRow(row);
@@ -115,6 +138,8 @@ bool TilemapModel::removeRows(int row, int count, const QModelIndex&)
bool TilemapModel::removeColumns(int column, int count, const QModelIndex&)
{
+ if (map->getWidth() == 1)
+ removeRows(0, map->getHeight());
emit(beginRemoveColumns(QModelIndex(), column, column + count - 1));
for (int i = 0; i < count; ++i)
map->deleteCol(column);