diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-09-05 20:41:05 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-09-05 20:41:05 +0000 |
| commit | b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7 (patch) | |
| tree | 6609f31b1635d948cf7a216c7fea72cfb3c905a0 /sigmodr/PokemodTree.cpp | |
| parent | b99ffef4aa68dd5f0af64de9aec0f610e267d8cc (diff) | |
| download | sigen-b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7.tar.gz sigen-b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7.tar.xz sigen-b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7.zip | |
[FIX] Moving stuff for the move to the new name, Sigma Game Engine (sigen for short)
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@249 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigmodr/PokemodTree.cpp')
| -rw-r--r-- | sigmodr/PokemodTree.cpp | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/sigmodr/PokemodTree.cpp b/sigmodr/PokemodTree.cpp new file mode 100644 index 00000000..bd3dcd65 --- /dev/null +++ b/sigmodr/PokemodTree.cpp @@ -0,0 +1,156 @@ +/* + * 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 "PokemodTree.h" + +// Model includes +#include "models/BaseModel.h" + +// Pokemodr includes +#include "ObjectUI.h" +#include "PokemodTreeModel.h" + +// Pokemod includes +#include "../pokemod/Object.h" +#include "../pokemod/Pokemod.h" + +// Qt includes +#include <QtGui/QHeaderView> + +Pokemodr::PokemodTree::PokemodTree(QWidget* parent) : + QTreeView(parent) +{ + header()->hide(); + setModel(new Pokemodr::PokemodTreeModel(this)); + setRootIndex(model()->index(-1, 0, QModelIndex())); +} + +QString Pokemodr::PokemodTree::description(const QModelIndex& index) +{ + return QString("%1: %2").arg(model()->data(index, Pokemodr::BaseModel::TypeRole).toString(), model()->data(index, Qt::DisplayRole).toString()); +} + +Pokemodr::ObjectUI* Pokemodr::PokemodTree::editorWidget(const QModelIndex& index) +{ + Pokemodr::ObjectUI* widget = qobject_cast<Pokemodr::ObjectUI*>(model()->data(index, Pokemodr::BaseModel::WidgetRole).value<QWidget*>()); + return widget; +} + +KMenu* Pokemodr::PokemodTree::contextMenu(const QModelIndex& index) +{ + return model()->data(index, Pokemodr::BaseModel::ContextMenuRole).value<KMenu*>(); +} + +const Pokemod::Pokemod* Pokemodr::PokemodTree::currentPokemod() const +{ + QModelIndex index = currentIndex(); + if (index.isValid()) + { + const Pokemod::Object* object = static_cast<BaseModel*>(index.internalPointer())->object(); + if (object) + return qobject_cast<const Pokemod::Pokemod*>(object->pokemod()); + } + return NULL; +} + +QDomDocument Pokemodr::PokemodTree::copy(const QModelIndex& index) +{ + QDomDocument xml; + xml.setContent(model()->data(index, Pokemodr::BaseModel::XmlRole).toString()); + return xml; +} + +void Pokemodr::PokemodTree::paste(const QModelIndex& index, const QDomDocument& data) +{ + model()->setData(index, data.toString(), Pokemodr::BaseModel::XmlRole); +} + +QList<const Pokemod::Pokemod*> Pokemodr::PokemodTree::openedPokemods() const +{ + return m_pokemods.keys(); +} + +void Pokemodr::PokemodTree::addPokemod(Pokemod::Pokemod* pokemod) +{ + qobject_cast<PokemodTreeModel*>(model())->addPokemod(pokemod); + m_pokemods[pokemod] = UrlDirty(KUrl(), false); +} + +void Pokemodr::PokemodTree::addPokemod(Pokemod::Pokemod* pokemod, const KUrl& url) +{ + qobject_cast<PokemodTreeModel*>(model())->addPokemod(pokemod); + m_pokemods[pokemod] = UrlDirty(url, false); +} + +void Pokemodr::PokemodTree::deletePokemod(const Pokemod::Pokemod* pokemod) +{ + if (m_pokemods.contains(pokemod)) + { + qobject_cast<PokemodTreeModel*>(model())->deletePokemod(pokemod); + m_pokemods.remove(pokemod); + } +} + +bool Pokemodr::PokemodTree::isOpen(const KUrl& url) const +{ + foreach (UrlDirty pair, m_pokemods.values()) + { + if (url == pair.first) + return true; + } + return false; +} + +KUrl Pokemodr::PokemodTree::url(const Pokemod::Pokemod* pokemod) const +{ + if (m_pokemods.contains(pokemod)) + return m_pokemods[pokemod].first; + return KUrl(); +} + +QStringList Pokemodr::PokemodTree::urls() const +{ + QStringList urls; + foreach (UrlDirty pair, m_pokemods.values()) + urls << pair.first.prettyUrl(); + return urls; +} + +void Pokemodr::PokemodTree::setUrl(const Pokemod::Pokemod* pokemod, const KUrl& url) +{ + if (m_pokemods.contains(pokemod)) + m_pokemods[pokemod] = UrlDirty(url, false); +} + +bool Pokemodr::PokemodTree::dirty(const Pokemod::Pokemod* pokemod) const +{ + if (m_pokemods.contains(pokemod)) + return m_pokemods[pokemod].second; + return false; +} + +void Pokemodr::PokemodTree::setDirty(const Pokemod::Pokemod* pokemod, const bool dirty) +{ + if (m_pokemods.contains(pokemod)) + m_pokemods[pokemod].second = dirty; +} + +void Pokemodr::PokemodTree::setDirty() +{ + setDirty(currentPokemod(), true); +} |
