From 1430a9e2b52109f3f57cfa7a9bb2f68e0dda1365 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 1 Mar 2009 20:44:32 -0500 Subject: Made the rest of the widgets use pimpl --- sigmodr/widgets/MoveUI.cpp | 161 +++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 78 deletions(-) (limited to 'sigmodr/widgets/MoveUI.cpp') diff --git a/sigmodr/widgets/MoveUI.cpp b/sigmodr/widgets/MoveUI.cpp index 9a9c09dd..5c0e5c89 100644 --- a/sigmodr/widgets/MoveUI.cpp +++ b/sigmodr/widgets/MoveUI.cpp @@ -17,6 +17,7 @@ // Header include #include "MoveUI.h" +#include "MoveUI_p.h" // Sigmodr core widget includes #include @@ -33,10 +34,7 @@ #include // Qt includes -#include #include -#include -#include using namespace Sigcore; using namespace Sigmod; @@ -44,28 +42,50 @@ using namespace Sigmodr::CoreWidgets; using namespace Sigmodr::Widgets; MoveUI::MoveUI(Move* move, QWidget* parent) : - ObjectUI(parent) -{ - setObjects(move, new Move(*move)); -} - -void MoveUI::initGui() -{ - QFile file(":/gui/move.ui"); - file.open(QFile::ReadOnly); - QWidget *formWidget = QUiLoader().load(&file, this); - file.close(); - ui_name = formWidget->findChild("varName"); - ui_priority = formWidget->findChild("varPriority"); - ui_accuracy = formWidget->findChild("varAccuracy"); - ui_power = formWidget->findChild("varPower"); - ui_type = formWidget->findChild("varType"); - ui_powerPoints = formWidget->findChild("varPowerPoints"); - ui_special = formWidget->findChild("varSpecial"); - ui_description = formWidget->findChild("varDescription"); - ui_battleScript = formWidget->findChild("varBattleScript"); - ui_worldScript = formWidget->findChild("varWorldScript"); - ui_priorityScript = formWidget->findChild("varPriorityScript"); + ObjectUI(move, parent), + d(new Private(new Move(*move))) +{ + setWidget(d->makeWidgets(this)); +} + +void MoveUI::apply() +{ + *qobject_cast(m_object) = *d->m_move; + ObjectUI::apply(); +} + +void MoveUI::discard() +{ + *d->m_move = *qobject_cast(m_object); + d->resetGui(); + ObjectUI::discard(); +} + +MoveUI::Private::Private(Move* move) : + ObjectUIPrivate(move), + m_move(move) +{ +} + +MoveUI::Private::~Private() +{ + delete m_move; +} + +QWidget* MoveUI::Private::makeWidgets(ObjectUI* widget) +{ + QWidget *form = openUiFile(":/gui/move.ui", widget); + ui_name = form->findChild("varName"); + ui_priority = form->findChild("varPriority"); + ui_accuracy = form->findChild("varAccuracy"); + ui_power = form->findChild("varPower"); + ui_type = form->findChild("varType"); + ui_powerPoints = form->findChild("varPowerPoints"); + ui_special = form->findChild("varSpecial"); + ui_description = form->findChild("varDescription"); + ui_battleScript = form->findChild("varBattleScript"); + ui_worldScript = form->findChild("varWorldScript"); + ui_priorityScript = form->findChild("varPriorityScript"); connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); connect(ui_priority, SIGNAL(valueChanged(int)), this, SLOT(priorityChanged(int))); connect(ui_accuracy, SIGNAL(valueChanged(Sigcore::Fraction)), this, SLOT(accuracyChanged(Sigcore::Fraction))); @@ -77,104 +97,89 @@ void MoveUI::initGui() connect(ui_battleScript, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(battleScriptChanged(Sigcore::Script))); connect(ui_worldScript, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(worldScriptChanged(Sigcore::Script))); connect(ui_priorityScript, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(priorityScriptChanged(Sigcore::Script))); - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget(formWidget); - setLayout(layout); + return form; } -void MoveUI::refreshGui() +void MoveUI::Private::refreshGui() { const bool blocked = ui_type->blockSignals(true); ui_type->clear(); - for (int i = 0; i < game()->typeCount(); ++i) - ui_type->addItem(game()->type(i)->name()); + for (int i = 0; i < m_move->game()->typeCount(); ++i) + ui_type->addItem(m_move->game()->type(i)->name()); ui_type->blockSignals(blocked); } -void MoveUI::setGui() -{ - ui_name->setText(qobject_cast(modified())->name()); - ui_priority->setValue(qobject_cast(modified())->priority()); - ui_accuracy->setValue(qobject_cast(modified())->accuracy()); - ui_power->setValue(qobject_cast(modified())->power()); - ui_type->setCurrentIndex(game()->typeIndex(qobject_cast(modified())->type())); - ui_powerPoints->setValue(qobject_cast(modified())->powerPoints()); - ui_special->setChecked(qobject_cast(modified())->special() ? Qt::Checked : Qt::Unchecked); - ui_description->setText(qobject_cast(modified())->description()); - ui_battleScript->setValue(qobject_cast(modified())->battleScript()); - ui_worldScript->setValue(qobject_cast(modified())->worldScript()); - ui_priorityScript->setValue(qobject_cast(modified())->priorityScript()); -} - -void MoveUI::apply() -{ - *qobject_cast(original()) = *qobject_cast(modified()); - emit(changed(false)); -} - -void MoveUI::discard() +void MoveUI::Private::resetGui() { - *qobject_cast(modified()) = *qobject_cast(original()); - setGui(); - emit(changed(false)); + ui_name->setText(m_move->name()); + ui_priority->setValue(m_move->priority()); + ui_accuracy->setValue(m_move->accuracy()); + ui_power->setValue(m_move->power()); + ui_type->setCurrentIndex(m_move->game()->typeIndex(m_move->type())); + ui_powerPoints->setValue(m_move->powerPoints()); + ui_special->setChecked(m_move->special() ? Qt::Checked : Qt::Unchecked); + ui_description->setText(m_move->description()); + ui_battleScript->setValue(m_move->battleScript()); + ui_worldScript->setValue(m_move->worldScript()); + ui_priorityScript->setValue(m_move->priorityScript()); } -void MoveUI::nameChanged(const QString& name) +void MoveUI::Private::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); - qobject_cast(modified())->setName(name); + m_move->setName(name); ui_name->setCursorPosition(cursor); } -void MoveUI::priorityChanged(const int priority) +void MoveUI::Private::priorityChanged(const int priority) { - qobject_cast(modified())->setPriority(priority); + m_move->setPriority(priority); } -void MoveUI::accuracyChanged(const Fraction& accuracy) +void MoveUI::Private::accuracyChanged(const Fraction& accuracy) { - qobject_cast(modified())->setAccuracy(accuracy); + m_move->setAccuracy(accuracy); } -void MoveUI::powerChanged(const int power) +void MoveUI::Private::powerChanged(const int power) { - qobject_cast(modified())->setPower(power); + m_move->setPower(power); } -void MoveUI::typeChanged(const int type) +void MoveUI::Private::typeChanged(const int type) { if (0 <= type) - qobject_cast(modified())->setType(game()->type(type)->id()); + m_move->setType(m_move->game()->type(type)->id()); } -void MoveUI::powerPointsChanged(const int powerPoints) +void MoveUI::Private::powerPointsChanged(const int powerPoints) { - qobject_cast(modified())->setPowerPoints(powerPoints); + m_move->setPowerPoints(powerPoints); } -void MoveUI::specialChanged(const bool special) +void MoveUI::Private::specialChanged(const bool special) { - qobject_cast(modified())->setSpecial(special); + m_move->setSpecial(special); } -void MoveUI::descriptionChanged(const QString& description) +void MoveUI::Private::descriptionChanged(const QString& description) { const int cursor = ui_description->cursorPosition(); - qobject_cast(modified())->setDescription(description); + m_move->setDescription(description); ui_description->setCursorPosition(cursor); } -void MoveUI::battleScriptChanged(const Script& battleScript) +void MoveUI::Private::battleScriptChanged(const Script& battleScript) { - qobject_cast(modified())->setBattleScript(battleScript); + m_move->setBattleScript(battleScript); } -void MoveUI::worldScriptChanged(const Script& worldScript) +void MoveUI::Private::worldScriptChanged(const Script& worldScript) { - qobject_cast(modified())->setWorldScript(worldScript); + m_move->setWorldScript(worldScript); } -void MoveUI::priorityScriptChanged(const Script& priorityScript) +void MoveUI::Private::priorityScriptChanged(const Script& priorityScript) { - qobject_cast(modified())->setPriorityScript(priorityScript); + m_move->setPriorityScript(priorityScript); } -- cgit