diff options
Diffstat (limited to 'pokemodr/models/CoinListModel.cpp')
| -rw-r--r-- | pokemodr/models/CoinListModel.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/pokemodr/models/CoinListModel.cpp b/pokemodr/models/CoinListModel.cpp index e12a3908..ab05058e 100644 --- a/pokemodr/models/CoinListModel.cpp +++ b/pokemodr/models/CoinListModel.cpp @@ -26,10 +26,14 @@ // Pokemod includes #include "../../pokemod/CoinList.h" +#include "../../pokemod/CoinListObject.h" // Qt includes #include <QFile> +// KDE includes +#include <KMenu> + CoinListModel::CoinListModel(BaseModel* parent, CoinList* coinList) : GroupObjectModel(parent, coinList) { @@ -56,6 +60,14 @@ QVariant CoinListModel::data(int role) const QWidget* widget = new CoinListUI(static_cast<CoinList*>(m_object), NULL); return QVariant::fromValue(widget); } + else if (role == BaseModel::ContextMenuRole) + { + KMenu* menu = new KMenu; + menu->addAction("Add Object", this, SLOT(addObject())); + menu->addSeparator(); + menu->addAction("Delete Coin List", this, SLOT(deleteSelf())); + return QVariant::fromValue(static_cast<void*>(menu)); + } return GroupObjectModel::data(role); } @@ -83,6 +95,30 @@ bool CoinListModel::setData(const QVariant& value, int role) return false; } +void CoinListModel::addObject(Object* object) +{ + if (!object) + object = static_cast<CoinList*>(m_object)->newObject(); + if (object->className() == "CoinListObject") + m_objects.append(new CoinListObjectModel(this, static_cast<CoinListObject*>(object))); +} + +void CoinListModel::deleteObject(BaseModel* model) +{ + const int index = m_objects.indexOf(model); + if (0 <= index) + { + static_cast<CoinList*>(m_object)->deleteObject(index); + m_objects[index]->deleteLater(); + m_objects.removeAt(index); + } +} + +void CoinListModel::deleteSelf() +{ +// static_cast<GroupModel*>(m_parent)->deleteObject(this); +} + void CoinListModel::setupData() { CoinList* coinList = static_cast<CoinList*>(m_object); |
