///////////////////////////////////////////////////////////////////////////// // Name: pokegen/StoreUI.cpp // Purpose: Store UI form handling // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Mon Feb 11 22:59:48 2008 // Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions // Licence: // 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 . ///////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include "StoreUI.h" StoreUI::StoreUI(Store* s, QWidget* parent) : ObjectUI(parent), store(s), store_mod(new Store(s->getPokemod(), *s, s->getId())) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(store, store_mod); connect(this, SIGNAL(changed(bool)), boxButtons, SLOT(setEnabled(bool))); init(); } void StoreUI::refreshGui() { varItems->clear(); for (int i = 0; i < store->getPokemod()->getItemCount(); ++i) { const Item* it = store->getPokemod()->getItem(i); QListWidgetItem* lwi = new QListWidgetItem(it->getName(), varItems); lwi->setData(Qt::UserRole, it->getId()); } } void StoreUI::setGui() { varName->setText(store_mod->getName()); for (int i = 0; i < varItems->count(); ++i) { QListWidgetItem* lwi = varItems->item(i); lwi->setSelected(store_mod->getItem(lwi->data(Qt::UserRole).toInt())); } } void StoreUI::on_buttonApply_clicked() { *store = *store_mod; emit(changed(false)); } void StoreUI::on_buttonDiscard_clicked() { *store_mod = *store; setGui(); emit(changed(false)); } void StoreUI::on_varName_textChanged(const QString& n) { store_mod->setName(n); emit(changed(true)); } void StoreUI::on_varItems_itemSelectionChanged() { try { for (int i = 0; i < varItems->count(); ++i) { const QListWidgetItem* lwi = varItems->item(i); store_mod->setItem(lwi->data(Qt::UserRole).toInt(), lwi->isSelected()); } emit(changed(true)); } catch (BoundsException& e) { BugCatcher::report(e); setGui(); } }