From 4a7e1c6b45f75db276be616df2ab87eddfd4e802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 5 Jul 2012 18:14:51 +0000 Subject: [PATCH] paysages : Fixed GUI saving/loading and the use of a bad Qt trick. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@382 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- gui_qt/baseform.cpp | 46 +++++++++++++++++-------------------------- gui_qt/baseform.h | 8 ++++++-- gui_qt/mainwindow.cpp | 27 ++++++++++++++----------- gui_qt/mainwindow.h | 1 + 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index aaea595..866a7c1 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -26,7 +26,6 @@ BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget this->_with_layers = with_layers; setLayout(new QHBoxLayout()); - setObjectName("_base_form_"); control = new QWidget(this); control->setLayout(new QVBoxLayout()); @@ -135,22 +134,18 @@ void BaseForm::hideButtons() void BaseForm::savePack(PackStream* stream) { // Save previews status - // TODO Ensure same order in save and load - QList list_previews = _previews->findChildren("_form_preview_"); - for (int i = 0; i < list_previews.size(); i++) + for (int i = 0; i < _previews_list.size(); i++) { - list_previews[i]->savePack(stream); + _previews_list[i]->savePack(stream); } } void BaseForm::loadPack(PackStream* stream) { // Load previews status - // TODO Ensure same order in save and load - QList list_previews = _previews->findChildren("_form_preview_"); - for (int i = 0; i < list_previews.size(); i++) + for (int i = 0; i < _previews_list.size(); i++) { - list_previews[i]->loadPack(stream); + _previews_list[i]->loadPack(stream); } } @@ -166,16 +161,15 @@ void BaseForm::configChangeEvent() _button_revert->setEnabled(true); } - QList inputs = _form->findChildren("_form_input_"); - for (int i = 0; i < inputs.size(); i++) + for (int i = 0; i < _inputs_list.size(); i++) { if (_with_layers && _layer_list->count() == 0) { - inputs[i]->checkVisibility(false); + _inputs_list[i]->checkVisibility(false); } else { - inputs[i]->checkVisibility(true); + _inputs_list[i]->checkVisibility(true); } } @@ -187,10 +181,9 @@ void BaseForm::configChangeEvent() void BaseForm::revertConfig() { - QList inputs = _form->findChildren("_form_input_"); - for (int i = 0; i < inputs.size(); i++) + for (int i = 0; i < _inputs_list.size(); i++) { - inputs[i]->revert(); + _inputs_list[i]->revert(); } if (_with_layers) @@ -335,7 +328,7 @@ void BaseForm::addPreview(BasePreview* preview, QString label) _previews->layout()->addWidget(label_widget); _previews->layout()->addWidget(preview); - preview->setObjectName("_form_preview_"); + _previews_list.append(preview); } QPushButton* BaseForm::addButton(QString label) @@ -367,7 +360,7 @@ BaseInput* BaseForm::addInput(BaseInput* input) connect(input, SIGNAL(valueChanged()), this, SLOT(configChangeEvent())); - input->setObjectName("_form_input_"); + _inputs_list.append(input); input->revert(); return input; @@ -420,10 +413,9 @@ BaseInput* BaseForm::addInputEnum(QString label, int* value, const QStringList& void BaseForm::updatePreviews() { - QList list_previews = _previews->findChildren("_form_preview_"); - for (int i = 0; i < list_previews.size(); i++) + for (int i = 0; i < _previews_list.size(); i++) { - list_previews[i]->redraw(); + _previews_list[i]->redraw(); } } @@ -471,16 +463,14 @@ void BaseForm::layerRenamedEvent(int, QString) void BaseForm::layerSelectedEvent(int layer) { - QList inputs = _form->findChildren("_form_input_"); - for (int i = 0; i < inputs.size(); i++) + for (int i = 0; i < _inputs_list.size(); i++) { - inputs[i]->revert(); - inputs[i]->checkVisibility(layer >= 0); + _inputs_list[i]->revert(); + _inputs_list[i]->checkVisibility(layer >= 0); } - QList list_previews = _previews->findChildren("_form_preview_"); - for (int i = 0; i < list_previews.size(); i++) + for (int i = 0; i < _previews_list.size(); i++) { - list_previews[i]->redraw(); + _previews_list[i]->redraw(); } } diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index 6dc394d..d6b5d2e 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -69,9 +69,7 @@ protected: virtual void layerSelectedEvent(int layer); private: - bool _auto_update_previews; bool _auto_apply; - QWidget* _previews; QWidget* _form; QWidget* _form_labels; QWidget* _form_previews; @@ -79,6 +77,12 @@ private: QWidget* _buttons; QPushButton* _button_apply; QPushButton* _button_revert; + + QWidget* _previews; + QVector _previews_list; + bool _auto_update_previews; + + QVector _inputs_list; bool _with_layers; QComboBox* _layer_list; diff --git a/gui_qt/mainwindow.cpp b/gui_qt/mainwindow.cpp index c0920b8..2e92452 100644 --- a/gui_qt/mainwindow.cpp +++ b/gui_qt/mainwindow.cpp @@ -81,33 +81,41 @@ QMainWindow(parent) form = new FormTerrain(tabs); tabs->addTab(form, tr("Terrain")); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); + _forms.append(form); form = new FormTextures(tabs); tabs->addTab(form, tr("Textures")); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); + _forms.append(form); form = new FormWater(tabs); tabs->addTab(form, tr("Water")); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); + _forms.append(form); form = new FormSky(tabs); tabs->addTab(form, tr("Sky")); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); + _forms.append(form); form = new FormAtmosphere(tabs); tabs->addTab(form, tr("Atmosphere")); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); + _forms.append(form); form = new FormClouds(tabs); tabs->addTab(form, tr("Clouds")); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); + _forms.append(form); /*form = new FormLighting(tabs); tabs->addTab(form, tr("Lighting")); - QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));*/ + QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); + _forms.append(form);*/ _form_render = new FormRender(tabs); tabs->addTab(_form_render, tr("Render")); + _forms.append(_form_render); toolbar = new QToolBar(this); toolbar->setOrientation(Qt::Vertical); @@ -151,10 +159,9 @@ void MainWindow::refreshAll() logDebug("[MainWindow] Refreshing whole UI"); // Refresh all tabs - QList list_forms = this->findChildren("_base_form_"); - for (int i = 0; i < list_forms.size(); i++) + for (int i = 0; i < _forms.size(); i++) { - list_forms[i]->revertConfig(); + _forms[i]->revertConfig(); } // Refresh preview OSD @@ -273,21 +280,17 @@ void MainWindow::guiLoadCallback(PackStream* stream, void* data) void MainWindow::guiSave(PackStream* stream) { // Save all tabs status - // TODO Ensure same order in save and load - QList list_forms = this->findChildren("_base_form_"); - for (int i = 0; i < list_forms.size(); i++) + for (int i = 0; i < _forms.size(); i++) { - list_forms[i]->savePack(stream); + _forms[i]->savePack(stream); } } void MainWindow::guiLoad(PackStream* stream) { // Load all tabs status - // TODO Ensure same order in save and load - QList list_forms = this->findChildren("_base_form_"); - for (int i = 0; i < list_forms.size(); i++) + for (int i = 0; i < _forms.size(); i++) { - list_forms[i]->loadPack(stream); + _forms[i]->loadPack(stream); } } diff --git a/gui_qt/mainwindow.h b/gui_qt/mainwindow.h index 3fa7c2f..eabbac4 100644 --- a/gui_qt/mainwindow.h +++ b/gui_qt/mainwindow.h @@ -32,6 +32,7 @@ private: void guiSave(PackStream* stream); void guiLoad(PackStream* stream); + QVector _forms; FormRender* _form_render; };