/* * 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 . */ // Header include #include "StoreUI.h" // Pokemod includes #include "../pokemod/Item.h" #include "../pokemod/Pokemod.h" #include "../pokemod/Store.h" StoreUI::StoreUI(Store* store, QWidget* parent) : ObjectUI(parent) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(store, new Store(*store)); init(); } StoreUI::~StoreUI() { } void StoreUI::refreshGui() { varItems->clear(); for (int i = 0; i < static_cast(original()->pokemod())->itemCount(); ++i) { const Item* item = static_cast(original()->pokemod())->item(i); QListWidgetItem* widgetItem = new QListWidgetItem(item->name(), varItems); widgetItem->setData(Qt::UserRole, item->id()); } } void StoreUI::setGui() { varName->setText(static_cast(modified())->name()); for (int i = 0; i < varItems->count(); ++i) { QListWidgetItem* widgetItem = varItems->item(i); widgetItem->setSelected(static_cast(modified())->item(widgetItem->data(Qt::UserRole).toInt())); } } void StoreUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void StoreUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void StoreUI::on_varName_textChanged(const QString& name) { static_cast(modified())->setName(name); } void StoreUI::on_varItems_itemSelectionChanged() { for (int i = 0; i < varItems->count(); ++i) { const QListWidgetItem* widgetItem = varItems->item(i); static_cast(modified())->setItem(widgetItem->data(Qt::UserRole).toInt(), widgetItem->isSelected()); } }