From 00fecef0aebaa379dfc176ddc5d6488fae0e8272 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 27 May 2008 00:47:02 +0000 Subject: [FIX] Status and Weather classes in pokemod instead of hardcoded [FIX] Added a Sprite class to allow for animations and whatnot git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@178 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemodr/models/StatusModel.cpp | 94 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 pokemodr/models/StatusModel.cpp (limited to 'pokemodr/models/StatusModel.cpp') diff --git a/pokemodr/models/StatusModel.cpp b/pokemodr/models/StatusModel.cpp new file mode 100644 index 00000000..c049c79f --- /dev/null +++ b/pokemodr/models/StatusModel.cpp @@ -0,0 +1,94 @@ +/* + * Copyright 2008 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 "StatusModel.h" + +// Model includes +#include "GroupModel.h" + +// PokeModr includes +#include "../StatusUI.h" + +// Pokemod includes +#include "../../pokemod/Status.h" + +// Qt includes +#include + +// KDE includes +#include + +StatusModel::StatusModel(BaseModel* parent, Status* status) : + ObjectModel(parent, status) +{ +} + +StatusModel::~StatusModel() +{ +} + +QVariant StatusModel::data(int role) const +{ + if (role == Qt::DisplayRole) + return static_cast(m_object)->name(); + 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 StatusUI(static_cast(m_object), NULL); + return QVariant::fromValue(widget); + } + else if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Delete Status", this, SLOT(deleteSelf())); + return QVariant::fromValue(static_cast(menu)); + } + return ObjectModel::data(role); +} + +bool StatusModel::setData(const QVariant& value, int role) +{ + if (role == BaseModel::XmlRole) + { + if (value.canConvert()) + { + 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()) + { + m_object->load(xml.documentElement()); + return true; + } + file.close(); + } + } + } + return false; +} + +void StatusModel::deleteSelf() +{ +// static_cast(m_parent)->deleteObject(this); +} -- cgit