/* * Copyright 2008 Ben Boeckel * * 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 . */ // Qt includes #include // General includes #include #include // Pokemod includes #include #include #include #include // Header include #include "CoinListObjectUI.h" CoinListObjectUI::CoinListObjectUI(CoinListObject* coinListObject, QWidget* parent) : ObjectUI(parent), m_lastType(-1), m_object(coinListObject), m_object_mod(new CoinListObject(*coinListObject)) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(m_object, m_object_mod); connect(this, SIGNAL(changed(bool)), boxButtons, SLOT(setEnabled(bool))); init(); } void CoinListObjectUI::initGui() { varType->addItems(CoinListObject::TypeStr); } void CoinListObjectUI::setGui() { bool resetObjects = (m_object_mod->type() != m_lastType); varType->setCurrentIndex(m_object_mod->type()); m_lastType = m_object_mod->type(); if (resetObjects) { varObject->clear(); if (m_object_mod->type() == CoinListObject::Item) { for (int i = 0; i < m_object->pokemod()->itemCount(); ++i) { const Item* item = m_object->pokemod()->item(i); varObject->addItem(item->name()); varObject->setItemData(i, item->id()); } } else { for (int i = 0; i < m_object->pokemod()->speciesCount(); ++i) { const Species* species = m_object->pokemod()->species(i); varObject->addItem(species->name()); varObject->setItemData(i, species->id()); } } } varObject->setCurrentIndex(varObject->findData(m_object_mod->object())); varAmount->setValue(m_object_mod->amount()); varCost->setValue(m_object_mod->cost()); } void CoinListObjectUI::on_buttonApply_clicked() { *m_object = *m_object_mod; emit(changed(false)); } void CoinListObjectUI::on_buttonDiscard_clicked() { *m_object_mod = *m_object; setGui(); emit(changed(false)); } void CoinListObjectUI::on_varType_currentIndexChanged(const int type) { try { m_object_mod->setType(type); emit(changed(true)); } catch (BoundsException& exception) { BugCatcher::report(exception); } setGui(); } void CoinListObjectUI::on_varObject_currentIndexChanged(const int obey) { try { m_object_mod->setObject(varObject->itemData(obey).toInt()); emit(changed(true)); } catch (BoundsException& exception) { BugCatcher::report(exception); setGui(); } } void CoinListObjectUI::on_varAmount_valueChanged(const int amount) { try { m_object_mod->setAmount(amount); emit(changed(true)); } catch (BoundsException& exception) { BugCatcher::report(exception); setGui(); } } void CoinListObjectUI::on_varCost_valueChanged(const int cost) { try { m_object_mod->setCost(cost); emit(changed(true)); } catch (BoundsException& exception) { BugCatcher::report(exception); setGui(); } }