From ff8c440c3a2aeb0e1abc6f93e9dd7775533382ff Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 26 May 2008 01:32:07 +0000 Subject: [FIX] Context menus added [FIX] No more copy/cut/paste for objects; only available from context menus [FIX] Can now add objects during runtime git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@174 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemodr/models/MapWildListGroupModel.cpp | 38 +++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'pokemodr/models/MapWildListGroupModel.cpp') diff --git a/pokemodr/models/MapWildListGroupModel.cpp b/pokemodr/models/MapWildListGroupModel.cpp index da865777..d4789481 100644 --- a/pokemodr/models/MapWildListGroupModel.cpp +++ b/pokemodr/models/MapWildListGroupModel.cpp @@ -23,20 +23,48 @@ // Map includes #include "../../pokemod/Map.h" +#include "../../pokemod/MapWildList.h" + +// KDE includes +#include MapWildListGroupModel::MapWildListGroupModel(BaseModel* parent, Map* map) : GroupModel(parent, map, "Wild Lists") { - setupData(); + for (int i = 0; i < map->wildListCount(); ++i) + addObject(map->wildList(i)); } MapWildListGroupModel::~MapWildListGroupModel() { } -void MapWildListGroupModel::setupData() +QVariant MapWildListGroupModel::data(const int role) const { - Map* map = static_cast(m_object); - for (int i = 0; i < map->wildListCount(); ++i) - m_objects.append(new MapWildListModel(this, map->wildList(i))); + if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Add Wild List", this, SLOT(addObject())); + return QVariant::fromValue(static_cast(menu)); + } + return GroupModel::data(role); +} + +void MapWildListGroupModel::addObject(Object* object) +{ + if (!object) + object = static_cast(m_object)->newWildList(); + if (object->className() == "MapWildList") + m_objects.append(new MapWildListModel(this, static_cast(object))); +} + +void MapWildListGroupModel::deleteObject(BaseObjectModel* model) +{ + const int index = m_objects.indexOf(model); + if (0 <= index) + { + static_cast(m_object)->deleteWildList(index); + m_objects[index]->deleteLater(); + m_objects.removeAt(index); + } } -- cgit