diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-26 01:32:07 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-26 01:32:07 +0000 |
| commit | ff8c440c3a2aeb0e1abc6f93e9dd7775533382ff (patch) | |
| tree | 302ac68425cecc61d429c64cf8676ad37d1d4f12 /pokemodr/models/CoinListGroupModel.cpp | |
| parent | 7e3bf1853184f96eb5be47dd78ebe21fdc170a01 (diff) | |
| download | sigen-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/CoinListGroupModel.cpp')
| -rw-r--r-- | pokemodr/models/CoinListGroupModel.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/pokemodr/models/CoinListGroupModel.cpp b/pokemodr/models/CoinListGroupModel.cpp index 56eeaae3..74f6d3c0 100644 --- a/pokemodr/models/CoinListGroupModel.cpp +++ b/pokemodr/models/CoinListGroupModel.cpp @@ -22,21 +22,49 @@ #include "CoinListModel.h" // Pokemod includes +#include "../../pokemod/CoinList.h" #include "../../pokemod/Pokemod.h" +// KDE includes +#include <KMenu> + CoinListGroupModel::CoinListGroupModel(BaseModel* parent, Pokemod* pokemod) : GroupModel(parent, pokemod, "Coin Lists") { - setupData(); + for (int i = 0; i < pokemod->coinListCount(); ++i) + addObject(pokemod->coinList(i)); } CoinListGroupModel::~CoinListGroupModel() { } -void CoinListGroupModel::setupData() +QVariant CoinListGroupModel::data(const int role) const { - Pokemod* pokemod = static_cast<Pokemod*>(m_object); - for (int i = 0; i < pokemod->coinListCount(); ++i) - m_objects.append(new CoinListModel(this, pokemod->coinList(i))); + if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Add Coin List", this, SLOT(addObject())); + return QVariant::fromValue(static_cast<void*>(menu)); + } + return GroupModel::data(role); +} + +void CoinListGroupModel::addObject(Object* object) +{ + if (!object) + object = static_cast<Pokemod*>(m_object)->newCoinList(); + if (object->className() == "CoinList") + m_objects.append(new CoinListModel(this, static_cast<CoinList*>(object))); +} + +void CoinListGroupModel::deleteObject(BaseObjectModel* model) +{ + const int index = m_objects.indexOf(model); + if (0 <= index) + { + static_cast<Pokemod*>(m_object)->deleteCoinList(index); + m_objects[index]->deleteLater(); + m_objects.removeAt(index); + } } |
