From 560054e99ecd692b89fd8fbedcf69d08e45f41bd Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 25 Feb 2009 01:24:42 -0500 Subject: Moved SigmodModel files to GameModel --- sigmodr/tree/CMakeLists.txt | 4 +- sigmodr/tree/GameModel.cpp | 163 +++++++++++++++++++++++++++++++++++++++++++ sigmodr/tree/GameModel.h | 58 +++++++++++++++ sigmodr/tree/RootModel.cpp | 2 +- sigmodr/tree/RootModel.h | 3 +- sigmodr/tree/SigmodModel.cpp | 163 ------------------------------------------- sigmodr/tree/SigmodModel.h | 58 --------------- 7 files changed, 225 insertions(+), 226 deletions(-) create mode 100644 sigmodr/tree/GameModel.cpp create mode 100644 sigmodr/tree/GameModel.h delete mode 100644 sigmodr/tree/SigmodModel.cpp delete mode 100644 sigmodr/tree/SigmodModel.h diff --git a/sigmodr/tree/CMakeLists.txt b/sigmodr/tree/CMakeLists.txt index 81e767ed..6d6a4164 100644 --- a/sigmodr/tree/CMakeLists.txt +++ b/sigmodr/tree/CMakeLists.txt @@ -14,6 +14,7 @@ set(sigmodrtree_HEADERS CoinListItemModel.h EggGroupGroupModel.h EggGroupModel.h + GameModel.h Global.h GlobalScriptGroupModel.h GlobalScriptModel.h @@ -43,7 +44,6 @@ set(sigmodrtree_HEADERS ObjectModel.h RootModel.h RulesModel.h - SigmodModel.h SigmodrTree.h SigmodrTreeModel.h SkinGroupModel.h @@ -84,6 +84,7 @@ set(sigmodrtree_SRCS CoinListItemModel.cpp EggGroupGroupModel.cpp EggGroupModel.cpp + GameModel.cpp GlobalScriptGroupModel.cpp GlobalScriptModel.cpp Grouping.cpp @@ -112,7 +113,6 @@ set(sigmodrtree_SRCS ObjectModel.cpp RootModel.cpp RulesModel.cpp - SigmodModel.cpp SigmodrTree.cpp SigmodrTreeModel.cpp SkinGroupModel.cpp diff --git a/sigmodr/tree/GameModel.cpp b/sigmodr/tree/GameModel.cpp new file mode 100644 index 00000000..5d9b75ac --- /dev/null +++ b/sigmodr/tree/GameModel.cpp @@ -0,0 +1,163 @@ +/* + * 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 + +Sigmodr::Tree::GameModel::GameModel(BaseModel* parent, Sigmod::Game* game) : + GroupObjectModel(parent, game) +{ + setupData(); +} + +Sigmodr::Tree::GameModel::~GameModel() +{ + clearData(); +} + +QVariant Sigmodr::Tree::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 SigmodUI(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 Sigmodr::Tree::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 Sigmodr::Tree::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 Sigmodr::Tree::GameModel::addObject(Sigmod::Object* object) +{ + Q_UNUSED(object) +} + +void Sigmodr::Tree::GameModel::deleteObject(BaseModel* model) +{ + Q_UNUSED(model) +} + +void Sigmodr::Tree::GameModel::deleteSelf() +{ +} + +void Sigmodr::Tree::GameModel::setupData() +{ + Sigmod::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)); +} diff --git a/sigmodr/tree/GameModel.h b/sigmodr/tree/GameModel.h new file mode 100644 index 00000000..72af2787 --- /dev/null +++ b/sigmodr/tree/GameModel.h @@ -0,0 +1,58 @@ +/* + * 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 . + */ + +#ifndef SIGMODRTREE_GAMEMODEL +#define SIGMODRTREE_GAMEMODEL + +// Sigmodr tree includes +#include "GroupObjectModel.h" + +// Forward declarations +namespace Sigmod +{ +class Game; +} + +namespace Sigmodr +{ +namespace Tree +{ +class SIGMODRTREE_IMPORT GameModel : public GroupObjectModel +{ + Q_OBJECT + + public: + GameModel(BaseModel* parent, Sigmod::Game* game); + ~GameModel(); + + QVariant data(int role = Qt::DisplayRole) const; + + bool setData(const QVariant& value, int role = Qt::EditRole); + + QString types() const; + public slots: + void addObject(Sigmod::Object* object = NULL); + void deleteObject(BaseModel* model); + + void deleteSelf(); + protected: + void setupData(); +}; +} +} + +#endif diff --git a/sigmodr/tree/RootModel.cpp b/sigmodr/tree/RootModel.cpp index c5549267..76202045 100644 --- a/sigmodr/tree/RootModel.cpp +++ b/sigmodr/tree/RootModel.cpp @@ -19,7 +19,7 @@ #include "RootModel.h" // Sigmodr tree includes -#include "SigmodModel.h" +#include "GameModel.h" // Sigmod includes #include diff --git a/sigmodr/tree/RootModel.h b/sigmodr/tree/RootModel.h index 2e454d6d..87597042 100644 --- a/sigmodr/tree/RootModel.h +++ b/sigmodr/tree/RootModel.h @@ -20,14 +20,13 @@ // Sigmodr tree includes #include "GroupModel.h" -#include "SigmodModel.h" namespace Sigmodr { namespace Tree { // Forward declarations -class SigmodModel; +class GameModel; class SIGMODRTREE_IMPORT RootModel : public GroupModel { diff --git a/sigmodr/tree/SigmodModel.cpp b/sigmodr/tree/SigmodModel.cpp deleted file mode 100644 index 5d9b75ac..00000000 --- a/sigmodr/tree/SigmodModel.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * 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 - -Sigmodr::Tree::GameModel::GameModel(BaseModel* parent, Sigmod::Game* game) : - GroupObjectModel(parent, game) -{ - setupData(); -} - -Sigmodr::Tree::GameModel::~GameModel() -{ - clearData(); -} - -QVariant Sigmodr::Tree::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 SigmodUI(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 Sigmodr::Tree::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 Sigmodr::Tree::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 Sigmodr::Tree::GameModel::addObject(Sigmod::Object* object) -{ - Q_UNUSED(object) -} - -void Sigmodr::Tree::GameModel::deleteObject(BaseModel* model) -{ - Q_UNUSED(model) -} - -void Sigmodr::Tree::GameModel::deleteSelf() -{ -} - -void Sigmodr::Tree::GameModel::setupData() -{ - Sigmod::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)); -} diff --git a/sigmodr/tree/SigmodModel.h b/sigmodr/tree/SigmodModel.h deleted file mode 100644 index 72af2787..00000000 --- a/sigmodr/tree/SigmodModel.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 . - */ - -#ifndef SIGMODRTREE_GAMEMODEL -#define SIGMODRTREE_GAMEMODEL - -// Sigmodr tree includes -#include "GroupObjectModel.h" - -// Forward declarations -namespace Sigmod -{ -class Game; -} - -namespace Sigmodr -{ -namespace Tree -{ -class SIGMODRTREE_IMPORT GameModel : public GroupObjectModel -{ - Q_OBJECT - - public: - GameModel(BaseModel* parent, Sigmod::Game* game); - ~GameModel(); - - QVariant data(int role = Qt::DisplayRole) const; - - bool setData(const QVariant& value, int role = Qt::EditRole); - - QString types() const; - public slots: - void addObject(Sigmod::Object* object = NULL); - void deleteObject(BaseModel* model); - - void deleteSelf(); - protected: - void setupData(); -}; -} -} - -#endif -- cgit