1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/////////////////////////////////////////////////////////////////////////////
// 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 <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////
#include <QListWidgetItem>
#include <QMetaObject>
#include <QVariant>
#include <BugCatcher.h>
#include <Exception.h>
#include <Item.h>
#include <Pokemod.h>
#include <Store.h>
#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();
}
}
|