summaryrefslogtreecommitdiffstats
path: root/pokemodr/models/MapWildListModel.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-05-26 01:32:07 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-05-26 01:32:07 +0000
commitff8c440c3a2aeb0e1abc6f93e9dd7775533382ff (patch)
tree302ac68425cecc61d429c64cf8676ad37d1d4f12 /pokemodr/models/MapWildListModel.cpp
parent7e3bf1853184f96eb5be47dd78ebe21fdc170a01 (diff)
downloadsigen-ff8c440c3a2aeb0e1abc6f93e9dd7775533382ff.tar.gz
sigen-ff8c440c3a2aeb0e1abc6f93e9dd7775533382ff.tar.xz
sigen-ff8c440c3a2aeb0e1abc6f93e9dd7775533382ff.zip
[FIX] Context menus added
[FIX] No more copy/cut/paste for objects; only available from context menus [FIX] Can now add objects during runtime git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@174 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/models/MapWildListModel.cpp')
-rw-r--r--pokemodr/models/MapWildListModel.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/pokemodr/models/MapWildListModel.cpp b/pokemodr/models/MapWildListModel.cpp
index 181d0ccd..a2154def 100644
--- a/pokemodr/models/MapWildListModel.cpp
+++ b/pokemodr/models/MapWildListModel.cpp
@@ -27,10 +27,14 @@
// Pokemod includes
#include "../../pokemod/Map.h"
#include "../../pokemod/MapWildList.h"
+#include "../../pokemod/MapWildListEncounter.h"
// Qt includes
#include <QFile>
+// KDE includes
+#include <KMenu>
+
MapWildListModel::MapWildListModel(BaseModel* parent, MapWildList* wildList) :
GroupObjectModel(parent, wildList)
{
@@ -61,9 +65,41 @@ QVariant MapWildListModel::data(int role) const
QWidget* widget = new MapWildListUI(static_cast<MapWildList*>(m_object), NULL);
return QVariant::fromValue(widget);
}
+ else if (role == BaseModel::ContextMenuRole)
+ {
+ KMenu* menu = new KMenu;
+ menu->addAction("Add Encounter", this, SLOT(addObject()));
+ menu->addSeparator();
+ menu->addAction("Delete Wild List", this, SLOT(deleteSelf()));
+ return QVariant::fromValue(static_cast<void*>(menu));
+ }
return GroupObjectModel::data(role);
}
+void MapWildListModel::addObject(Object* object)
+{
+ if (!object)
+ object = static_cast<MapWildList*>(m_object)->newEncounter();
+ if (object->className() == "MapWildListEncounter")
+ m_objects.append(new MapWildListEncounterModel(this, static_cast<MapWildListEncounter*>(object)));
+}
+
+void MapWildListModel::deleteObject(BaseModel* model)
+{
+ const int index = m_objects.indexOf(model);
+ if (0 <= index)
+ {
+ static_cast<MapWildList*>(m_object)->deleteEncounter(index);
+ m_objects[index]->deleteLater();
+ m_objects.removeAt(index);
+ }
+}
+
+void MapWildListModel::deleteSelf()
+{
+// static_cast<GroupModel*>(m_parent)->deleteObject(this);
+}
+
bool MapWildListModel::setData(const QVariant& value, int role)
{
if (role == BaseModel::XmlRole)