/* * Copyright 2008-2009 Ben Boeckel * * 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 . */ // Header include #include "GameModel.h" // Sigmodr tree includes #include "AbilityGroupModel.h" #include "AuthorGroupModel.h" #include "BadgeGroupModel.h" #include "CoinListGroupModel.h" #include "EggGroupGroupModel.h" #include "GlobalScriptGroupModel.h" #include "ItemGroupModel.h" #include "ItemTypeGroupModel.h" #include "MapGroupModel.h" #include "MoveGroupModel.h" #include "NatureGroupModel.h" #include "RulesModel.h" #include "SkinGroupModel.h" #include "SoundGroupModel.h" #include "SpeciesGroupModel.h" #include "SpriteGroupModel.h" #include "StatusGroupModel.h" #include "StoreGroupModel.h" #include "TileGroupModel.h" #include "TimeGroupModel.h" #include "TrainerGroupModel.h" #include "TypeGroupModel.h" #include "WeatherGroupModel.h" // Sigmodr widget includes #include // Sigmod includes #include // KDE includes #include using namespace Sigmod; using namespace Sigmodr::Widgets; using namespace Sigmodr::Tree; GameModel::GameModel(BaseModel* parent, Game* game) : GroupObjectModel(parent, game) { setupData(); } GameModel::~GameModel() { clearData(); } QVariant GameModel::data(int role) const { if (role == Qt::DisplayRole) return qobject_cast(m_object)->title(); else if (role == BaseModel::XmlRole) { QDomDocument xml(m_object->className()); xml.appendChild(m_object->save()); return xml.toString(); } else if (role == BaseModel::WidgetRole) { QWidget* widget = new GameUI(qobject_cast(m_object), NULL); return QVariant::fromValue(widget); } else if (role == BaseModel::ContextMenuRole) { KMenu* menu = new KMenu; return QVariant::fromValue(menu); } return GroupObjectModel::data(role); } bool GameModel::setData(const QVariant& value, int role) { if (role == BaseModel::XmlRole) { QString data = value.toString(); if (!data.isEmpty()) { QDomDocument xml; if (loadFromData(data, &xml)) { if (xml.doctype().name() == m_object->className()) { clearData(); m_object->load(xml.documentElement()); setupData(); return true; } foreach (BaseModel* model, m_objects) { GroupModel* group = qobject_cast(model); if (group && group->setData(value, role)) return true; } } } } return false; } QString GameModel::types() const { return type().append(QString(";Rules;Ability;Author;Badge;CoinList;EggGroup;GlobalScript;Item;ItemType;Map;Move;Nature;Skin;Sound;Species;Sprite;Status;Store;Tile;Time;Trainer;Type;Weather")); } void GameModel::addObject(Object* object) { Q_UNUSED(object) } void GameModel::deleteObject(BaseModel* model) { Q_UNUSED(model) } void GameModel::deleteSelf() { } void GameModel::setupData() { Game* game = qobject_cast(m_object); addChild(new RulesModel(this, game->rules())); addChild(new AbilityGroupModel(this, game)); addChild(new AuthorGroupModel(this, game)); addChild(new BadgeGroupModel(this, game)); addChild(new CoinListGroupModel(this, game)); addChild(new EggGroupGroupModel(this, game)); addChild(new GlobalScriptGroupModel(this, game)); addChild(new ItemGroupModel(this, game)); addChild(new ItemTypeGroupModel(this, game)); addChild(new MapGroupModel(this, game)); addChild(new MoveGroupModel(this, game)); addChild(new NatureGroupModel(this, game)); addChild(new SkinGroupModel(this, game)); addChild(new SoundGroupModel(this, game)); addChild(new SpeciesGroupModel(this, game)); addChild(new SpriteGroupModel(this, game)); addChild(new StatusGroupModel(this, game)); addChild(new StoreGroupModel(this, game)); addChild(new TileGroupModel(this, game)); addChild(new TimeGroupModel(this, game)); addChild(new TrainerGroupModel(this, game)); addChild(new TypeGroupModel(this, game)); addChild(new WeatherGroupModel(this, game)); }