From 4ed55e72070115125732f5125d3da8efd09ffb2b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sun, 1 Mar 2009 17:57:05 -0500 Subject: Fixed more widgets to use pimpl --- sigmodr/widgets/MapUI.cpp | 74 +++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'sigmodr/widgets/MapUI.cpp') diff --git a/sigmodr/widgets/MapUI.cpp b/sigmodr/widgets/MapUI.cpp index 17426e98..8dd0356c 100644 --- a/sigmodr/widgets/MapUI.cpp +++ b/sigmodr/widgets/MapUI.cpp @@ -17,6 +17,7 @@ // Header include #include "MapUI.h" +#include "MapUI_p.h" // Sigmod includes #include @@ -29,68 +30,67 @@ #include #include -// Qt includes -#include -#include -#include - // FIXME: Update map editing to new collage map using namespace Sigmod; using namespace Sigmodr::Widgets; MapUI::MapUI(Map* map, QWidget* parent) : - ObjectUI(parent) + ObjectUI(map, parent), + d(new Private(new Map(*map))) { - setObjects(map, new Map(*map)); -// varMap->setMap(map); -// connect(varMap, SIGNAL(changed()), this, SIGNAL(changed())); + setWidget(d->makeWidgets(this)); } -void MapUI::initGui() +void MapUI::apply() { - QFile file(":/gui/map.ui"); - file.open(QFile::ReadOnly); - QWidget *formWidget = QUiLoader().load(&file, this); - file.close(); - ui_name = formWidget->findChild("varName"); - ui_type = formWidget->findChild("varType"); - connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); - connect(ui_type, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int))); - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget(formWidget); - setLayout(layout); - ui_type->addItems(Map::TypeStr); + *qobject_cast(m_object) = *d->m_map; + ObjectUI::apply(); } -void MapUI::setGui() +void MapUI::discard() { - ui_name->setText(qobject_cast(modified())->name()); - ui_type->setCurrentIndex(qobject_cast(modified())->type()); -// varMap->reset(); + *d->m_map = *qobject_cast(m_object); + d->resetGui(); + ObjectUI::discard(); } -void MapUI::apply() +MapUI::Private::Private(Map* map) : + ObjectUIPrivate(map), + m_map(map) { - *qobject_cast(original()) = *qobject_cast(modified()); - emit(changed(false)); } -void MapUI::discard() +MapUI::Private::~Private() +{ + delete m_map; +} + +QWidget* MapUI::Private::makeWidgets(ObjectUI* widget) +{ + QWidget *form = openUiFile(":/gui/map.ui", widget); + ui_name = form->findChild("varName"); + ui_type = form->findChild("varType"); + connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); + connect(ui_type, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int))); + ui_type->addItems(Map::TypeStr); + return form; +} + +void MapUI::Private::resetGui() { - *qobject_cast(modified()) = *qobject_cast(original()); - setGui(); - emit(changed(false)); + ui_name->setText(m_map->name()); + ui_type->setCurrentIndex(m_map->type()); } -void MapUI::nameChanged(const QString& name) +void MapUI::Private::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); - qobject_cast(modified())->setName(name); + m_map->setName(name); ui_name->setCursorPosition(cursor); } -void MapUI::typeChanged(const int type) +void MapUI::Private::typeChanged(const int type) { - qobject_cast(modified())->setType(static_cast(type)); + m_map->setType(static_cast(type)); } -- cgit