summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-06-01 16:08:13 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-06-01 16:08:13 +0000
commitf3e081acd87439efadd5ff4181916e06cc07f051 (patch)
treefacbe27e9e32aedc83884dbf05c132238fb35bf0
parent6ffec6899f70ecffe5f1584adbf680f43d6ea662 (diff)
downloadsigen-f3e081acd87439efadd5ff4181916e06cc07f051.tar.gz
sigen-f3e081acd87439efadd5ff4181916e06cc07f051.tar.xz
sigen-f3e081acd87439efadd5ff4181916e06cc07f051.zip
[FIX] Tilemap model now works
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@187 6ecfd1a5-f3ed-3746-8530-beee90d26b22
-rw-r--r--Changelog7
-rw-r--r--pokemodr/MapUI.cpp56
-rw-r--r--pokemodr/MapUI.h5
-rw-r--r--pokemodr/TODO2
-rw-r--r--pokemodr/TileDelegate.cpp57
-rw-r--r--pokemodr/TileDelegate.h43
-rw-r--r--pokemodr/TilemapModel.cpp155
-rw-r--r--pokemodr/TilemapModel.h110
-rw-r--r--pokemodr/gui/map.ui9
-rw-r--r--pokemodr/gui/pokemod.ui6
-rw-r--r--pokemodr/pokemodr.pro3
11 files changed, 150 insertions, 303 deletions
diff --git a/Changelog b/Changelog
index 6815c631..670533f1 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,11 @@
-----------------
+Rev: 187
+Date: 1 June 2008
+User: MathStuf
+-----------------
+[FIX] Tilemap model now works
+
+-----------------
Rev: 186
Date: 28 May 2008
User: MathStuf
diff --git a/pokemodr/MapUI.cpp b/pokemodr/MapUI.cpp
index de9d87f3..df05db97 100644
--- a/pokemodr/MapUI.cpp
+++ b/pokemodr/MapUI.cpp
@@ -19,45 +19,36 @@
#include "MapUI.h"
// PokeModr includes
-#include "TileDelegate.h"
#include "TilemapModel.h"
// Pokemod includes
#include "../pokemod/Map.h"
#include "../pokemod/MapWarp.h"
#include "../pokemod/Pokemod.h"
+#include "../pokemod/Tile.h"
// Qt includes
#include <QHeaderView>
-// KDE includes
-#include <KIcon>
-
MapUI::MapUI(Map* map, QWidget* parent) :
- ObjectUI(parent),
- m_delegate(new TileDelegate(this))
+ ObjectUI(parent)
{
setupUi(this);
setObjects(map, new Map(*map));
- m_model = new TilemapModel(this, static_cast<Map*>(modified())->map(), pokemod());
}
MapUI::~MapUI()
{
- delete m_model;
- delete m_delegate;
}
void MapUI::initGui()
{
varType->addItems(Map::TypeStr);
- // 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);
+ varTilemap->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
+ varTilemap->verticalHeader()->setResizeMode(QHeaderView::Fixed);
+ varTilemap->horizontalHeader()->setDefaultSectionSize(64);
+ varTilemap->verticalHeader()->setDefaultSectionSize(64);
+ varTilemap->setModel(new TilemapModel(static_cast<Map*>(modified())->map(), pokemod()));
}
void MapUI::refreshGui()
@@ -68,6 +59,13 @@ void MapUI::refreshGui()
const MapWarp* warp = static_cast<Map*>(original())->warp(i);
varFlyWarp->addItem(warp->name(), warp->id());
}
+ varTile->clear();
+ for (int i = 0; i < pokemod()->tileCount(); ++i)
+ {
+ const Tile* tile = pokemod()->tile(i);
+ varTile->addItem(tile->sprite(), tile->name(), tile->id());
+ }
+ varTile->setEnabled(false);
}
void MapUI::setGui()
@@ -115,38 +113,52 @@ void MapUI::on_varType_activated(const int type)
static_cast<Map*>(modified())->setType(type);
}
+void MapUI::on_varTilemap_clicked(const QModelIndex& index)
+{
+ m_index = index;
+ varTile->setEnabled(true);
+ varTile->setCurrentIndex(varTile->findData(varTilemap->model()->data(m_index, Qt::EditRole)));
+}
+
void MapUI::on_buttonAddColumn_pressed()
{
- m_model->addColumn();
+ varTilemap->model()->insertColumns(varTilemap->model()->columnCount(), 1);
emit(changed(true));
}
void MapUI::on_buttonAddRow_pressed()
{
- m_model->addRow();
+ varTilemap->model()->insertRows(varTilemap->model()->rowCount(), 1);
emit(changed(true));
}
void MapUI::on_buttonDeleteColumn_pressed()
{
- m_model->removeColumns(varTilemap->currentIndex().column(), 1);
+ varTilemap->model()->removeColumns(m_index.column(), 1);
emit(changed(true));
}
void MapUI::on_buttonDeleteRow_pressed()
{
- m_model->removeRows(varTilemap->currentIndex().row(), 1);
+ varTilemap->model()->removeRows(m_index.row(), 1);
emit(changed(true));
}
void MapUI::on_buttonInsertColumn_pressed()
{
- m_model->insertColumns(varTilemap->currentIndex().column(), 1);
+ varTilemap->model()->insertColumns(m_index.column(), 1);
emit(changed(true));
}
void MapUI::on_buttonInsertRow_pressed()
{
- m_model->insertRows(varTilemap->currentIndex().row(), 1);
+ varTilemap->model()->insertRows(m_index.row(), 1);
emit(changed(true));
}
+
+void MapUI::on_varTile_activated(const int tile)
+{
+ varTilemap->model()->setData(m_index, varTile->itemData(tile), Qt::EditRole);
+ emit(changed(true));
+ setGui();
+}
diff --git a/pokemodr/MapUI.h b/pokemodr/MapUI.h
index be96ff7f..d57995fd 100644
--- a/pokemodr/MapUI.h
+++ b/pokemodr/MapUI.h
@@ -44,19 +44,20 @@ class MapUI : public ObjectUI, private Ui::formMap
void on_boxFlyWarp_toggled();
void on_varFlyWarp_activated(const int flyWarp);
void on_varType_activated(const int type);
+ void on_varTilemap_clicked(const QModelIndex& index);
void on_buttonAddColumn_pressed();
void on_buttonAddRow_pressed();
void on_buttonDeleteColumn_pressed();
void on_buttonDeleteRow_pressed();
void on_buttonInsertColumn_pressed();
void on_buttonInsertRow_pressed();
+ void on_varTile_activated(const int tile);
private slots:
void initGui();
void refreshGui();
void setGui();
private:
- TilemapModel* m_model;
- TileDelegate* m_delegate;
+ QModelIndex m_index;
};
#endif
diff --git a/pokemodr/TODO b/pokemodr/TODO
index 334d0e1c..9195be58 100644
--- a/pokemodr/TODO
+++ b/pokemodr/TODO
@@ -1,5 +1,3 @@
-TilemapModel is (probably) wrong
-
Models:
ContextMenu - Fix up deleting
diff --git a/pokemodr/TileDelegate.cpp b/pokemodr/TileDelegate.cpp
deleted file mode 100644
index f744fb74..00000000
--- a/pokemodr/TileDelegate.cpp
+++ /dev/null
@@ -1,57 +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/>.
- */
-
-// Header include
-#include "TileDelegate.h"
-
-// PokeModr includes
-#include "ObjectUI.h"
-#include "MapUI.h"
-#include "TilemapModel.h"
-
-// Pokemod includes
-#include "../pokemod/Pokemod.h"
-#include "../pokemod/Tile.h"
-
-// KDE includes
-#include <KComboBox>
-
-QWidget* TileDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const
-{
- KComboBox* editor = new KComboBox(parent);
- return editor;
-}
-
-void TileDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
-{
- for (int i = 0; i < static_cast<const Pokemod*>(static_cast<const ObjectUI*>(editor->parent())->original()->pokemod())->tileCount(); ++i)
- {
- const Tile* tile = static_cast<const Pokemod*>(static_cast<const ObjectUI*>(editor->parent())->original()->pokemod())->tile(i);
- static_cast<KComboBox*>(editor)->addItem(tile->sprite(), tile->name(), tile->id());
- }
- static_cast<KComboBox*>(editor)->setCurrentIndex(index.data(Qt::EditRole).toInt());
-}
-
-void TileDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
-{
- static_cast<TilemapModel*>(model)->setData(index, static_cast<KComboBox*>(editor)->itemData(static_cast<KComboBox*>(editor)->currentIndex()));
-}
-
-void TileDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex&) const
-{
- editor->setGeometry(option.rect);
-}
diff --git a/pokemodr/TileDelegate.h b/pokemodr/TileDelegate.h
deleted file mode 100644
index 03cf22d6..00000000
--- a/pokemodr/TileDelegate.h
+++ /dev/null
@@ -1,43 +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 __POKEMODR_TILEDELEGATE__
-#define __POKEMODR_TILEDELEGATE__
-
-// Qt includes
-#include <QItemDelegate>
-#include <QObject>
-
-class TileDelegate : public QItemDelegate
-{
- Q_OBJECT
-
- public:
- TileDelegate(QObject* parent = 0) :
- QItemDelegate(parent)
- {
- }
-
- QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const;
-
- void setEditorData(QWidget* editor, const QModelIndex& index) const;
- void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
-
- void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex&) const;
-};
-
-#endif
diff --git a/pokemodr/TilemapModel.cpp b/pokemodr/TilemapModel.cpp
deleted file mode 100644
index cddaa035..00000000
--- a/pokemodr/TilemapModel.cpp
+++ /dev/null
@@ -1,155 +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/>.
- */
-
-// Header include
-#include "TilemapModel.h"
-
-// PokeModr includes
-#include "ObjectUI.h"
-#include "MapUI.h"
-
-// Pokemod includes
-#include "../pokemod/Tile.h"
-
-// KDE includes
-#include <KComboBox>
-
-TilemapModel::TilemapModel(QObject* parent, Matrix<int>* map, const Pokemod* pokemod) :
- QAbstractTableModel(parent),
- m_map(map),
- m_pokemod(pokemod)
-{
-}
-
-int TilemapModel::rowCount(const QModelIndex&) const
-{
- return m_map->height();
-}
-
-int TilemapModel::columnCount(const QModelIndex&) const
-{
- return m_map->width();
-}
-
-QVariant TilemapModel::data(const QModelIndex& index, int role) const
-{
- if (!index.isValid())
- return QVariant();
- if (role == Qt::DisplayRole)
- {
- int idx = m_pokemod->tileIndex(m_map->at(index.row(), index.column()));
- if (idx != INT_MAX)
- return m_pokemod->tile(idx)->sprite();
- }
- if (role == Qt::EditRole)
- return m_map->at(index.row(), index.column());
- if (role == Qt::ToolTipRole)
- {
- int idx = m_pokemod->tileIndex(m_map->at(index.row(), index.column()));
- if (idx != INT_MAX)
- return m_pokemod->tile(idx)->name();
- }
- return QVariant();
-}
-
-QVariant TilemapModel::headerData(int section, Qt::Orientation, int role) const
-{
- if (role != Qt::DisplayRole)
- return QVariant();
- return QString::number(section);
-}
-
-bool TilemapModel::setData(const QModelIndex& index, const QVariant& value, int role)
-{
- if (role != Qt::EditRole)
- return false;
-// emit(setDataChanged(index, index));
- m_map->set(index.row(), index.column(), m_pokemod->tile(value.toInt())->id());
- emit(dataChanged(index, index));
- return true;
-}
-
-Qt::ItemFlags TilemapModel::flags(const QModelIndex&) const
-{
- return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
-}
-
-bool TilemapModel::addRow()
-{
- return insertRows(m_map->height(), 1);
-}
-
-bool TilemapModel::addColumn()
-{
- return insertColumns(m_map->width(), 1);
-}
-
-bool TilemapModel::insertRows(int row, int count, const QModelIndex&)
-{
- emit(beginInsertRows(QModelIndex(), row, row + count));
- if (m_map->width())
- {
- for (int i = 0; i < count; ++i)
- m_map->insertRow(row);
- }
- else
- {
- m_map->addColumn();
- insertColumns(0, 0);
- }
- emit(endInsertRows());
- return true;
-}
-
-bool TilemapModel::insertColumns(int column, int count, const QModelIndex&)
-{
- emit(beginInsertColumns(QModelIndex(), column, column + count));
- if (m_map->height())
- {
- for (int i = 0; i < count; ++i)
- m_map->insertColumn(column);
- }
- else
- {
- m_map->addRow();
- insertRows(0, 0);
- }
- emit(endInsertColumns());
- return true;
-}
-
-bool TilemapModel::removeRows(int row, int count, const QModelIndex&)
-{
- if (m_map->height() == 1)
- removeColumns(0, m_map->width());
- emit(beginRemoveRows(QModelIndex(), row, row + count - 1));
- for (int i = 0; i < count; ++i)
- m_map->deleteRow(row);
- emit(endRemoveRows());
- return true;
-}
-
-bool TilemapModel::removeColumns(int column, int count, const QModelIndex&)
-{
- if (m_map->width() == 1)
- removeRows(0, m_map->height());
- emit(beginRemoveColumns(QModelIndex(), column, column + count - 1));
- for (int i = 0; i < count; ++i)
- m_map->deleteColumn(column);
- emit(endRemoveColumns());
- return true;
-}
diff --git a/pokemodr/TilemapModel.h b/pokemodr/TilemapModel.h
index 5b1fe46d..19403a6a 100644
--- a/pokemodr/TilemapModel.h
+++ b/pokemodr/TilemapModel.h
@@ -21,10 +21,10 @@
// Pokemod includes
#include "../pokemod/Matrix.h"
#include "../pokemod/Pokemod.h"
+#include "../pokemod/Tile.h"
// Qt includes
#include <QAbstractTableModel>
-#include <QObject>
#include <QVariant>
class TilemapModel : public QAbstractTableModel
@@ -32,29 +32,105 @@ class TilemapModel : public QAbstractTableModel
Q_OBJECT
public:
- TilemapModel(QObject* parent, Matrix<int>* map, const Pokemod* pokemod);
+ TilemapModel(Matrix<int>* tilemap, const Pokemod* pokemod) :
+ QAbstractTableModel(),
+ m_tilemap(*tilemap),
+ m_pokemod(pokemod)
+ {
+ }
- void apply();
- void discard();
+ QVariant data(const QModelIndex& index, int role) const
+ {
+ if (!index.isValid())
+ return QVariant();
+ if (role == Qt::DisplayRole)
+ {
+ const int tileIndex = m_pokemod->tileIndex(m_tilemap(index.row(), index.column()));
+ if (tileIndex != INT_MAX)
+ return m_pokemod->tile(tileIndex)->sprite();
+ }
+ else if (role == Qt::EditRole)
+ return m_tilemap.at(index.row(), index.column());
+ return QVariant();
+ }
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
- int columnCount(const QModelIndex& parent = QModelIndex()) const;
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ QVariant headerData(int section, Qt::Orientation /*orientation*/, int role = Qt::DisplayRole) const
+ {
+ if (role == Qt::DisplayRole)
+ return section;
+ return QVariant();
+ }
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ int rowCount(const QModelIndex& /*parent*/) const
+ {
+ return m_tilemap.height();
+ }
- bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+ int columnCount(const QModelIndex& /*parent*/) const
+ {
+ return m_tilemap.width();
+ }
- Qt::ItemFlags flags(const QModelIndex&) const;
+ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex())
+ {
+ 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 insertColumns(int column, int count, const QModelIndex& parent = QModelIndex())
+ {
+ 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 removeRows(int row, int count, const QModelIndex& parent = QModelIndex())
+ {
+ 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 removeColumns(int column, int count, const QModelIndex& parent = QModelIndex())
+ {
+ 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;
+ }
- bool addRow();
- bool addColumn();
- bool insertRows(int row, int count, const QModelIndex& = QModelIndex());
- bool insertColumns(int column, int count, const QModelIndex& = QModelIndex());
- bool removeRows(int row, int count, const QModelIndex& = QModelIndex());
- bool removeColumns(int column, int count, const QModelIndex& = QModelIndex());
+ 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)
+ {
+ m_tilemap(index.row(), index.column()) = value.toInt();
+ emit(dataChanged(index, index));
+ }
+ }
private:
- Matrix<int>* m_map;
+ Matrix<int>& m_tilemap;
const Pokemod* m_pokemod;
};
diff --git a/pokemodr/gui/map.ui b/pokemodr/gui/map.ui
index c1a47f36..2f70c803 100644
--- a/pokemodr/gui/map.ui
+++ b/pokemodr/gui/map.ui
@@ -63,7 +63,11 @@
</property>
<layout class="QGridLayout" >
<item rowspan="6" row="0" column="0" >
- <widget class="QTableView" name="varTilemap" />
+ <widget class="QTableView" name="varTilemap" >
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ </widget>
</item>
<item row="0" column="1" >
<widget class="KPushButton" name="buttonAddRow" >
@@ -107,6 +111,9 @@
</property>
</widget>
</item>
+ <item row="6" column="0" colspan="2" >
+ <widget class="KComboBox" name="varTile" />
+ </item>
</layout>
</widget>
</item>
diff --git a/pokemodr/gui/pokemod.ui b/pokemodr/gui/pokemod.ui
index 7d54564f..055f19df 100644
--- a/pokemodr/gui/pokemod.ui
+++ b/pokemodr/gui/pokemod.ui
@@ -409,7 +409,11 @@
</attribute>
<layout class="QVBoxLayout" >
<item>
- <widget class="QTableView" name="varTypechart" />
+ <widget class="QTableView" name="varTypechart" >
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ </widget>
</item>
<item>
<widget class="QGroupBox" name="boxEffectiveness" >
diff --git a/pokemodr/pokemodr.pro b/pokemodr/pokemodr.pro
index 14bdd4d6..40ac5ebb 100644
--- a/pokemodr/pokemodr.pro
+++ b/pokemodr/pokemodr.pro
@@ -69,8 +69,6 @@ SOURCES += AbilityUI.cpp \
SpriteUI.cpp \
StatusUI.cpp \
StoreUI.cpp \
- TileDelegate.cpp \
- TilemapModel.cpp \
TileUI.cpp \
TimeUI.cpp \
TrainerUI.cpp \
@@ -181,7 +179,6 @@ HEADERS += AbilityUI.h \
SpriteUI.h \
StatusUI.h \
StoreUI.h \
- TileDelegate.h \
TilemapModel.h \
TileUI.h \
TimeUI.h \