diff options
Diffstat (limited to 'sigmodr/widgets/WeatherUI.cpp')
| -rw-r--r-- | sigmodr/widgets/WeatherUI.cpp | 69 |
1 files changed, 36 insertions, 33 deletions
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 <sigmodr/corewidgets/ScriptWidget.h> @@ -27,64 +28,66 @@ // KDE includes #include <KLineEdit> -// Qt includes -#include <QtCore/QFile> -#include <QtGui/QVBoxLayout> -#include <QtUiTools/QUiLoader> - 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<KLineEdit*>("varName"); - ui_script = formWidget->findChild<ScriptWidget*>("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<Weather*>(m_object) = *d->m_weather; + ObjectUI::apply(); } -void WeatherUI::setGui() +void WeatherUI::discard() { - ui_name->setText(qobject_cast<Weather*>(modified())->name()); - ui_script->setValue(qobject_cast<Weather*>(modified())->script()); + *d->m_weather = *qobject_cast<Weather*>(m_object); + d->resetGui(); + ObjectUI::discard(); } -void WeatherUI::apply() +WeatherUI::Private::Private(Weather* weather) : + ObjectUIPrivate(weather), + m_weather(weather) { - *qobject_cast<Weather*>(original()) = *qobject_cast<Weather*>(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<KLineEdit*>("varName"); + ui_script = form->findChild<ScriptWidget*>("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<Weather*>(modified()) = *qobject_cast<Weather*>(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<Weather*>(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<Weather*>(modified())->setScript(script); + m_weather->setScript(script); } |
