diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-01 20:44:32 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-01 20:44:32 -0500 |
| commit | 1430a9e2b52109f3f57cfa7a9bb2f68e0dda1365 (patch) | |
| tree | 4e577a25fadedb054e58921a1ced00941d488c90 /sigmodr/widgets/StoreUI.cpp | |
| parent | 4ed55e72070115125732f5125d3da8efd09ffb2b (diff) | |
Made the rest of the widgets use pimpl
Diffstat (limited to 'sigmodr/widgets/StoreUI.cpp')
| -rw-r--r-- | sigmodr/widgets/StoreUI.cpp | 90 |
1 files changed, 46 insertions, 44 deletions
diff --git a/sigmodr/widgets/StoreUI.cpp b/sigmodr/widgets/StoreUI.cpp index a4be89db..097e0134 100644 --- a/sigmodr/widgets/StoreUI.cpp +++ b/sigmodr/widgets/StoreUI.cpp @@ -17,6 +17,7 @@ // Header include #include "StoreUI.h" +#include "StoreUI_p.h" // Sigmod includes #include <sigmod/Game.h> @@ -28,44 +29,61 @@ #include <KLineEdit> // Qt includes -#include <QtCore/QFile> #include <QtGui/QListWidgetItem> -#include <QtGui/QVBoxLayout> -#include <QtUiTools/QUiLoader> using namespace Sigmod; using namespace Sigmodr::Widgets; StoreUI::StoreUI(Store* store, QWidget* parent) : - ObjectUI(parent) + ObjectUI(store, parent), + d(new Private(new Store(*store))) { - setObjects(store, new Store(*store)); + setWidget(d->makeWidgets(this)); } -void StoreUI::initGui() +void StoreUI::apply() +{ + *qobject_cast<Store*>(m_object) = *d->m_store; + ObjectUI::apply(); +} + +void StoreUI::discard() +{ + *d->m_store = *qobject_cast<Store*>(m_object); + d->resetGui(); + ObjectUI::discard(); +} + +StoreUI::Private::Private(Store* store) : + ObjectUIPrivate(store), + m_store(store) +{ +} + +StoreUI::Private::~Private() { - QFile file(":/gui/store.ui"); - file.open(QFile::ReadOnly); - QWidget *formWidget = QUiLoader().load(&file, this); - file.close(); - ui_name = formWidget->findChild<KLineEdit*>("varName"); - ui_items = formWidget->findChild<KActionSelector*>("varItems"); + delete m_store; +} + +QWidget* StoreUI::Private::makeWidgets(ObjectUI* widget) +{ + QWidget *form = openUiFile(":/gui/store.ui", widget); + ui_name = form->findChild<KLineEdit*>("varName"); + ui_items = form->findChild<KActionSelector*>("varItems"); connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); connect(ui_items, SIGNAL(added(QListWidgetItem*)), this, SLOT(itemAdded(QListWidgetItem*))); connect(ui_items, SIGNAL(removed(QListWidgetItem*)), this, SLOT(itemRemoved(QListWidgetItem*))); - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget(formWidget); - setLayout(layout); + return form; } -void StoreUI::refreshGui() +void StoreUI::Private::refreshGui() { const bool blockedItems = ui_items->blockSignals(true); ui_items->availableListWidget()->clear(); ui_items->selectedListWidget()->clear(); - for (int i = 0; i < game()->itemCount(); ++i) + for (int i = 0; i < m_store->game()->itemCount(); ++i) { - const Item* item = game()->item(i); + const Item* item = m_store->game()->item(i); QListWidgetItem* widgetItem = new QListWidgetItem(item->name(), ui_items->availableListWidget()); widgetItem->setData(Qt::UserRole, item->id()); } @@ -73,53 +91,37 @@ void StoreUI::refreshGui() ui_items->setButtonsEnabled(); } -void StoreUI::setGui() +void StoreUI::Private::resetGui() { - ui_name->setText(qobject_cast<Store*>(modified())->name()); + ui_name->setText(m_store->name()); for (int i = 0; i < ui_items->availableListWidget()->count(); ++i) { QListWidgetItem* widgetItem = ui_items->availableListWidget()->item(i); - if (qobject_cast<Store*>(modified())->item(widgetItem->data(Qt::UserRole).toInt())) + if (m_store->item(widgetItem->data(Qt::UserRole).toInt())) ui_items->selectedListWidget()->addItem(ui_items->availableListWidget()->takeItem(i--)); } for (int i = 0; i < ui_items->selectedListWidget()->count(); ++i) { QListWidgetItem* widgetItem = ui_items->selectedListWidget()->item(i); - if (!qobject_cast<Store*>(modified())->item(widgetItem->data(Qt::UserRole).toInt())) + if (!m_store->item(widgetItem->data(Qt::UserRole).toInt())) ui_items->availableListWidget()->addItem(ui_items->selectedListWidget()->takeItem(i--)); } ui_items->setButtonsEnabled(); } -void StoreUI::apply() -{ - *qobject_cast<Store*>(original()) = *qobject_cast<Store*>(modified()); - emit(changed(false)); -} - -void StoreUI::discard() -{ - *qobject_cast<Store*>(modified()) = *qobject_cast<Store*>(original()); - setGui(); - emit(changed(false)); -} - -void StoreUI::nameChanged(const QString& name) +void StoreUI::Private::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); - qobject_cast<Store*>(modified())->setName(name); + m_store->setName(name); ui_name->setCursorPosition(cursor); } -void StoreUI::itemAdded(QListWidgetItem* item) +void StoreUI::Private::itemAdded(QListWidgetItem* item) { - qobject_cast<Store*>(modified())->setItem(item->data(Qt::UserRole).toInt(), true); - setGui(); + m_store->setItem(item->data(Qt::UserRole).toInt(), true); } -void StoreUI::itemRemoved(QListWidgetItem* item) +void StoreUI::Private::itemRemoved(QListWidgetItem* item) { - qobject_cast<Store*>(modified())->setItem(item->data(Qt::UserRole).toInt(), false); - setGui(); + m_store->setItem(item->data(Qt::UserRole).toInt(), false); } - |
