summaryrefslogtreecommitdiffstats
path: root/sigmodr/SigmodTree.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-09-06 04:12:30 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-09-06 04:12:30 +0000
commit0b4b89cf8efdc15e5a8d4b6cb24a5c8a025227d9 (patch)
treea2031b9d0016fcbd49a51c0d1a2292d1f2d8b566 /sigmodr/SigmodTree.cpp
parentb81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7 (diff)
downloadsigen-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/SigmodTree.cpp')
-rw-r--r--sigmodr/SigmodTree.cpp156
1 files changed, 156 insertions, 0 deletions
diff --git a/sigmodr/SigmodTree.cpp b/sigmodr/SigmodTree.cpp
new file mode 100644
index 00000000..b0d32ca8
--- /dev/null
+++ b/sigmodr/SigmodTree.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 "SigmodTree.h"
+
+// Model includes
+#include "models/BaseModel.h"
+
+// Sigmodr includes
+#include "ObjectUI.h"
+#include "SigmodTreeModel.h"
+
+// Sigmod includes
+#include "../sigmod/Object.h"
+#include "../sigmod/Sigmod.h"
+
+// Qt includes
+#include <QtGui/QHeaderView>
+
+Sigmodr::SigmodTree::SigmodTree(QWidget* parent) :
+ QTreeView(parent)
+{
+ header()->hide();
+ setModel(new Sigmodr::SigmodTreeModel(this));
+ setRootIndex(model()->index(-1, 0, QModelIndex()));
+}
+
+QString Sigmodr::SigmodTree::description(const QModelIndex& index)
+{
+ return QString("%1: %2").arg(model()->data(index, Sigmodr::BaseModel::TypeRole).toString(), model()->data(index, Qt::DisplayRole).toString());
+}
+
+Sigmodr::ObjectUI* Sigmodr::SigmodTree::editorWidget(const QModelIndex& index)
+{
+ Sigmodr::ObjectUI* widget = qobject_cast<Sigmodr::ObjectUI*>(model()->data(index, Sigmodr::BaseModel::WidgetRole).value<QWidget*>());
+ return widget;
+}
+
+KMenu* Sigmodr::SigmodTree::contextMenu(const QModelIndex& index)
+{
+ return model()->data(index, Sigmodr::BaseModel::ContextMenuRole).value<KMenu*>();
+}
+
+const Sigmod::Sigmod* Sigmodr::SigmodTree::currentSigmod() const
+{
+ QModelIndex index = currentIndex();
+ if (index.isValid())
+ {
+ const Sigmod::Object* object = static_cast<BaseModel*>(index.internalPointer())->object();
+ if (object)
+ return qobject_cast<const Sigmod::Sigmod*>(object->sigmod());
+ }
+ return NULL;
+}
+
+QDomDocument Sigmodr::SigmodTree::copy(const QModelIndex& index)
+{
+ QDomDocument xml;
+ xml.setContent(model()->data(index, Sigmodr::BaseModel::XmlRole).toString());
+ return xml;
+}
+
+void Sigmodr::SigmodTree::paste(const QModelIndex& index, const QDomDocument& data)
+{
+ model()->setData(index, data.toString(), Sigmodr::BaseModel::XmlRole);
+}
+
+QList<const Sigmod::Sigmod*> Sigmodr::SigmodTree::openedSigmods() const
+{
+ return m_sigmods.keys();
+}
+
+void Sigmodr::SigmodTree::addSigmod(Sigmod::Sigmod* sigmod)
+{
+ qobject_cast<SigmodTreeModel*>(model())->addSigmod(sigmod);
+ m_sigmods[sigmod] = UrlDirty(KUrl(), false);
+}
+
+void Sigmodr::SigmodTree::addSigmod(Sigmod::Sigmod* sigmod, const KUrl& url)
+{
+ qobject_cast<SigmodTreeModel*>(model())->addSigmod(sigmod);
+ m_sigmods[sigmod] = UrlDirty(url, false);
+}
+
+void Sigmodr::SigmodTree::deleteSigmod(const Sigmod::Sigmod* sigmod)
+{
+ if (m_sigmods.contains(sigmod))
+ {
+ qobject_cast<SigmodTreeModel*>(model())->deleteSigmod(sigmod);
+ m_sigmods.remove(sigmod);
+ }
+}
+
+bool Sigmodr::SigmodTree::isOpen(const KUrl& url) const
+{
+ foreach (UrlDirty pair, m_sigmods.values())
+ {
+ if (url == pair.first)
+ return true;
+ }
+ return false;
+}
+
+KUrl Sigmodr::SigmodTree::url(const Sigmod::Sigmod* sigmod) const
+{
+ if (m_sigmods.contains(sigmod))
+ return m_sigmods[sigmod].first;
+ return KUrl();
+}
+
+QStringList Sigmodr::SigmodTree::urls() const
+{
+ QStringList urls;
+ foreach (UrlDirty pair, m_sigmods.values())
+ urls << pair.first.prettyUrl();
+ return urls;
+}
+
+void Sigmodr::SigmodTree::setUrl(const Sigmod::Sigmod* sigmod, const KUrl& url)
+{
+ if (m_sigmods.contains(sigmod))
+ m_sigmods[sigmod] = UrlDirty(url, false);
+}
+
+bool Sigmodr::SigmodTree::dirty(const Sigmod::Sigmod* sigmod) const
+{
+ if (m_sigmods.contains(sigmod))
+ return m_sigmods[sigmod].second;
+ return false;
+}
+
+void Sigmodr::SigmodTree::setDirty(const Sigmod::Sigmod* sigmod, const bool dirty)
+{
+ if (m_sigmods.contains(sigmod))
+ m_sigmods[sigmod].second = dirty;
+}
+
+void Sigmodr::SigmodTree::setDirty()
+{
+ setDirty(currentSigmod(), true);
+}