diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-09-06 04:12:30 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-09-06 04:12:30 +0000 |
| commit | 0b4b89cf8efdc15e5a8d4b6cb24a5c8a025227d9 (patch) | |
| tree | a2031b9d0016fcbd49a51c0d1a2292d1f2d8b566 /sigmodr/models/SigmodModel.cpp | |
| parent | b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7 (diff) | |
| download | sigen-0b4b89cf8efdc15e5a8d4b6cb24a5c8a025227d9.tar.gz sigen-0b4b89cf8efdc15e5a8d4b6cb24a5c8a025227d9.tar.xz sigen-0b4b89cf8efdc15e5a8d4b6cb24a5c8a025227d9.zip | |
[FIX] Renamed everything (in use) away from Poké- prefixes
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@250 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigmodr/models/SigmodModel.cpp')
| -rw-r--r-- | sigmodr/models/SigmodModel.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/sigmodr/models/SigmodModel.cpp b/sigmodr/models/SigmodModel.cpp new file mode 100644 index 00000000..a1f43718 --- /dev/null +++ b/sigmodr/models/SigmodModel.cpp @@ -0,0 +1,159 @@ +/* + * 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 "SigmodModel.h" + +// Model 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 includes +#include "../SigmodUI.h" + +// Sigmod includes +#include "../../sigmod/Sigmod.h" + +// Qt includes +#include <QtCore/QFile> + +// KDE includes +#include <KMenu> + +Sigmodr::SigmodModel::SigmodModel(BaseModel* parent, Sigmod::Sigmod* sigmod) : + GroupObjectModel(parent, sigmod) +{ + setupData(); +} + +Sigmodr::SigmodModel::~SigmodModel() +{ + clearData(); +} + +QVariant Sigmodr::SigmodModel::data(int role) const +{ + if (role == Qt::DisplayRole) + return qobject_cast<Sigmod::Sigmod*>(m_object)->title(); + else if (role == Sigmodr::BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == Sigmodr::BaseModel::WidgetRole) + { + QWidget* widget = new SigmodUI(qobject_cast<Sigmod::Sigmod*>(m_object), NULL); + return QVariant::fromValue(widget); + } + else if (role == Sigmodr::BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + return QVariant::fromValue(menu); + } + return Sigmodr::GroupObjectModel::data(role); +} + +bool Sigmodr::SigmodModel::setData(const QVariant& value, int role) +{ + if (role == Sigmodr::BaseModel::XmlRole) + { + if (value.canConvert<QString>()) + { + QFile file(value.toString()); + QDomDocument xml; + if ((file.open(QIODevice::ReadOnly) && xml.setContent(&file)) || xml.setContent(value.toString())) + { + if (xml.doctype().name() == m_object->className()) + { + clearData(); + m_object->load(xml.documentElement()); + setupData(); + return true; + } + else if (xml.doctype().name() == "Rules") + { + qobject_cast<Sigmod::Sigmod*>(m_object)->setRules(xml.documentElement()); + return true; + } + file.close(); + } + } + } + return false; +} + +void Sigmodr::SigmodModel::addObject(Sigmod::Object* /*object*/) +{ +} + +void Sigmodr::SigmodModel::deleteObject(BaseModel* /*model*/) +{ +} + +void Sigmodr::SigmodModel::deleteSelf() +{ +} + +void Sigmodr::SigmodModel::setupData() +{ + Sigmod::Sigmod* sigmod = qobject_cast<Sigmod::Sigmod*>(m_object); + m_objects.append(new RulesModel(this, sigmod->rules())); + m_objects.append(new AbilityGroupModel(this, sigmod)); + m_objects.append(new AuthorGroupModel(this, sigmod)); + m_objects.append(new BadgeGroupModel(this, sigmod)); + m_objects.append(new CoinListGroupModel(this, sigmod)); + m_objects.append(new EggGroupGroupModel(this, sigmod)); + m_objects.append(new GlobalScriptGroupModel(this, sigmod)); + m_objects.append(new ItemGroupModel(this, sigmod)); + m_objects.append(new ItemTypeGroupModel(this, sigmod)); + m_objects.append(new MapGroupModel(this, sigmod)); + m_objects.append(new MoveGroupModel(this, sigmod)); + m_objects.append(new NatureGroupModel(this, sigmod)); + m_objects.append(new SkinGroupModel(this, sigmod)); + m_objects.append(new SoundGroupModel(this, sigmod)); + m_objects.append(new SpeciesGroupModel(this, sigmod)); + m_objects.append(new SpriteGroupModel(this, sigmod)); + m_objects.append(new StatusGroupModel(this, sigmod)); + m_objects.append(new StoreGroupModel(this, sigmod)); + m_objects.append(new TileGroupModel(this, sigmod)); + m_objects.append(new TimeGroupModel(this, sigmod)); + m_objects.append(new TrainerGroupModel(this, sigmod)); + m_objects.append(new TypeGroupModel(this, sigmod)); + m_objects.append(new WeatherGroupModel(this, sigmod)); +} |
