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/WeatherUI.cpp | 69 ++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 33 deletions(-) (limited to 'sigmodr/widgets/WeatherUI.cpp') diff --git a/sigmodr/widgets/WeatherUI.cpp b/sigmodr/widgets/WeatherUI.cpp index 8255432d..74d01eb4 100644 --- a/sigmodr/widgets/WeatherUI.cpp +++ b/sigmodr/widgets/WeatherUI.cpp @@ -17,6 +17,7 @@ // Header include #include "WeatherUI.h" +#include "WeatherUI_p.h" // Sigmodr core widget includes #include @@ -27,64 +28,66 @@ // KDE includes #include -// Qt includes -#include -#include -#include - using namespace Sigcore; using namespace Sigmod; using namespace Sigmodr::CoreWidgets; using namespace Sigmodr::Widgets; WeatherUI::WeatherUI(Weather* weather, QWidget* parent) : - ObjectUI(parent) + ObjectUI(weather, parent), + d(new Private(new Weather(*weather))) { - setObjects(weather, new Weather(*weather)); + setWidget(d->makeWidgets(this)); } -void WeatherUI::initGui() +void WeatherUI::apply() { - QFile file(":/gui/weather.ui"); - file.open(QFile::ReadOnly); - QWidget *formWidget = QUiLoader().load(&file, this); - file.close(); - ui_name = formWidget->findChild("varName"); - ui_script = formWidget->findChild("varScript"); - connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); - connect(ui_script, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(scriptChanged(Sigcore::Script))); - QVBoxLayout* layout = new QVBoxLayout; - layout->addWidget(formWidget); - setLayout(layout); + *qobject_cast(m_object) = *d->m_weather; + ObjectUI::apply(); } -void WeatherUI::setGui() +void WeatherUI::discard() { - ui_name->setText(qobject_cast(modified())->name()); - ui_script->setValue(qobject_cast(modified())->script()); + *d->m_weather = *qobject_cast(m_object); + d->resetGui(); + ObjectUI::discard(); } -void WeatherUI::apply() +WeatherUI::Private::Private(Weather* weather) : + ObjectUIPrivate(weather), + m_weather(weather) { - *qobject_cast(original()) = *qobject_cast(modified()); - emit(changed(false)); } -void WeatherUI::discard() +WeatherUI::Private::~Private() +{ + delete m_weather; +} + +QWidget* WeatherUI::Private::makeWidgets(ObjectUI* widget) +{ + QWidget *form = openUiFile(":/gui/weather.ui", widget); + ui_name = form->findChild("varName"); + ui_script = form->findChild("varScript"); + connect(ui_name, SIGNAL(textChanged(QString)), this, SLOT(nameChanged(QString))); + connect(ui_script, SIGNAL(valueChanged(Sigcore::Script)), this, SLOT(scriptChanged(Sigcore::Script))); + return form; +} + +void WeatherUI::Private::resetGui() { - *qobject_cast(modified()) = *qobject_cast(original()); - setGui(); - emit(changed(false)); + ui_name->setText(m_weather->name()); + ui_script->setValue(m_weather->script()); } -void WeatherUI::nameChanged(const QString& name) +void WeatherUI::Private::nameChanged(const QString& name) { const int cursor = ui_name->cursorPosition(); - qobject_cast(modified())->setName(name); + m_weather->setName(name); ui_name->setCursorPosition(cursor); } -void WeatherUI::scriptChanged(const Script& script) +void WeatherUI::Private::scriptChanged(const Script& script) { - qobject_cast(modified())->setScript(script); + m_weather->setScript(script); } -- cgit