summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-05-01 22:25:29 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-05-01 22:25:29 -0400
commitd43500d8f348a77a7db32e6f16594dacf3b52ad9 (patch)
tree091807eed93c40bdefa0d21d531668512768b201
parentca4425dfe13eba4e595d1d77a2548521c2dc0e2e (diff)
Add TreeItem for new MVC
-rw-r--r--sigmodr/tree/CMakeLists.txt1
-rw-r--r--sigmodr/tree/TreeItem.cpp154
-rw-r--r--sigmodr/tree/TreeItem.h144
3 files changed, 299 insertions, 0 deletions
diff --git a/sigmodr/tree/CMakeLists.txt b/sigmodr/tree/CMakeLists.txt
index 084c6b21..63f1ba57 100644
--- a/sigmodr/tree/CMakeLists.txt
+++ b/sigmodr/tree/CMakeLists.txt
@@ -5,6 +5,7 @@ set(sigmodrtree_HEADERS
SigmodrTree.h
)
set(sigmodrtree_SRCS
+ TreeItem.cpp
AbilityGroupModel.cpp
AbilityModel.cpp
AuthorGroupModel.cpp
diff --git a/sigmodr/tree/TreeItem.cpp b/sigmodr/tree/TreeItem.cpp
new file mode 100644
index 00000000..4652bb38
--- /dev/null
+++ b/sigmodr/tree/TreeItem.cpp
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2009 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 "TreeItem.h"
+
+// Sigmod includes
+#include <sigmod/Object.h>
+
+using namespace Sigmod;
+using namespace Sigmodr::Tree;
+
+TreeItem::TreeItem(const ItemType type, Object* object, TreeItem* parent) :
+ m_type(type),
+ m_object(object),
+ m_parent(parent)
+{
+}
+
+TreeItem::~TreeItem()
+{
+ foreach (TreeItem* item, m_children)
+ delete item;
+}
+
+int TreeItem::row()
+{
+ if (m_parent)
+ return m_parent->m_children.indexOf(this);
+ return -1;
+}
+
+TreeItem* TreeItem::parent()
+{
+ return m_parent;
+}
+
+QString TreeItem::text() const
+{
+ // TODO
+}
+
+Qt::ItemFlags TreeItem::flags() const
+{
+ // TODO
+}
+
+KMenu* TreeItem::menu()
+{
+ // TODO
+}
+
+bool TreeItem::canAddTo() const
+{
+ switch (m_type)
+ {
+ case GroupGame ... GroupWeather:
+ case EntryGame:
+ case EntryCoinList:
+ case EntryMap:
+ case EntryMapTrainer:
+ case EntryMapWildList:
+ case EntrySpecies:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool TreeItem::canRemove() const
+{
+ switch (m_type)
+ {
+ case GroupGame ... GroupWeather:
+ case EntryRules:
+ return false;
+ default:
+ return true;
+ }
+}
+
+bool TreeItem::canCopy() const
+{
+ switch (m_type)
+ {
+ case GroupGame ... GroupWeather:
+ return false;
+ default:
+ return true;
+ }
+}
+
+int TreeItem::childCount() const
+{
+ return m_children.size();
+}
+
+TreeItem* TreeItem::addChild()
+{
+ // TODO
+}
+
+TreeItem* TreeItem::childAt(const int child)
+{
+ if ((0 <= child) && (child <= m_children.size()))
+ return m_children[child];
+ return NULL;
+}
+
+void TreeItem::removeChild(const int child)
+{
+ // TODO
+}
+
+const Game* TreeItem::game() const
+{
+ if (m_object)
+ return m_object->game();
+ return NULL;
+}
+
+QStringList TreeItem::acceptedMimeTypes() const
+{
+ // TODO
+}
+
+QString TreeItem::mimeType() const
+{
+ // TODO
+}
+
+QByteArray TreeItem::copyData() const
+{
+ // TODO
+}
+
+bool TreeItem::dropData(QMimeData* data)
+{
+ // TODO
+}
diff --git a/sigmodr/tree/TreeItem.h b/sigmodr/tree/TreeItem.h
new file mode 100644
index 00000000..d8250edf
--- /dev/null
+++ b/sigmodr/tree/TreeItem.h
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2009 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/>.
+ */
+
+#ifndef SIGMODRTREE_TREEITEM
+#define SIGMODRTREE_TREEITEM
+
+// Sigmodr tree includes
+#include "Global.h"
+
+// Qt includes
+#include <QtCore/QList>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+
+// Forward declarations
+class QMimeData;
+class KMenu;
+namespace Sigmod
+{
+class Game;
+class Object;
+}
+
+namespace Sigmodr
+{
+namespace Tree
+{
+class SIGMODRTREE_NO_EXPORT TreeItem
+{
+ public:
+ int row();
+ TreeItem* parent();
+
+ QString text() const;
+ Qt::ItemFlags flags() const;
+
+ KMenu* menu();
+
+ bool canAddTo() const;
+ bool canRemove() const;
+ bool canCopy() const;
+
+ int childCount() const;
+ TreeItem* addChild();
+ TreeItem* childAt(const int child);
+ void removeChild(const int child);
+
+ const Sigmod::Game* game() const;
+
+ QStringList acceptedMimeTypes() const;
+ QString mimeType() const;
+ QByteArray copyData() const;
+ bool dropData(QMimeData* data);
+ protected:
+ enum ItemType
+ {
+ GroupGame = 0,
+ GroupAbility = 1,
+ GroupAuthor = 2,
+ GroupBadge = 3,
+ GroupCoinList = 4,
+ GroupEggGroup = 5,
+ GroupGlobalScript = 6,
+ GroupItem = 7,
+ GroupItemType = 8,
+ GroupMap = 9,
+ GroupMapEffect = 10,
+ GroupMapTrainer = 11,
+ GroupMapWarp = 12,
+ GroupMapWildList = 13,
+ GroupMove = 14,
+ GroupNature = 15,
+ GroupSkin = 16,
+ GroupSound = 17,
+ GroupSpecies = 18,
+ GroupSprite = 19,
+ GroupStatusEffect = 20,
+ GroupStore = 21,
+ GroupTile = 22,
+ GroupTime = 23,
+ GroupTrainer = 24,
+ GroupType = 25,
+ GroupWeather = 26,
+
+ EntryGame = 100,
+ EntryRules = 101,
+ EntryAbility = 102,
+ EntryAuthor = 103,
+ EntryBadge = 104,
+ EntryCoinList = 105,
+ EntryCoinListItem = 106,
+ EntryEggGroup = 107,
+ EntryGlobalScript = 108,
+ EntryItem = 109,
+ EntryItemType = 110,
+ EntryMap = 111,
+ EntryMapEffect = 112,
+ EntryMapTrainer = 113,
+ EntryMapTrainerTeamMember = 114,
+ EntryMapWarp = 115,
+ EntryMapWildList = 116,
+ EntryMapWildListEncounter = 117,
+ EntryMove = 118,
+ EntryNature = 119,
+ EntrySkin = 120,
+ EntrySound = 121,
+ EntrySpecies = 122,
+ EntrySpeciesMove = 123,
+ EntrySprite = 124,
+ EntryStatusEffect = 125,
+ EntryStore = 126,
+ EntryTile = 127,
+ EntryTime = 128,
+ EntryTrainer = 129,
+ EntryType = 130,
+ EntryWeather = 131
+ };
+
+ TreeItem(const ItemType type, Sigmod::Object* object, TreeItem* parent);
+ virtual ~TreeItem();
+
+ const ItemType m_type;
+ Sigmod::Object* m_object;
+ TreeItem* m_parent;
+ QList<TreeItem*> m_children;
+};
+}
+}
+
+#endif