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
This commit is contained in:
Michaël Lemaire 2012-07-05 18:14:51 +00:00 committed by ThunderK
parent 31f6e36b97
commit 4a7e1c6b45
4 changed files with 40 additions and 42 deletions

View file

@ -26,7 +26,6 @@ BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget
this->_with_layers = with_layers; this->_with_layers = with_layers;
setLayout(new QHBoxLayout()); setLayout(new QHBoxLayout());
setObjectName("_base_form_");
control = new QWidget(this); control = new QWidget(this);
control->setLayout(new QVBoxLayout()); control->setLayout(new QVBoxLayout());
@ -135,22 +134,18 @@ void BaseForm::hideButtons()
void BaseForm::savePack(PackStream* stream) void BaseForm::savePack(PackStream* stream)
{ {
// Save previews status // Save previews status
// TODO Ensure same order in save and load for (int i = 0; i < _previews_list.size(); i++)
QList<BasePreview*> list_previews = _previews->findChildren<BasePreview*>("_form_preview_");
for (int i = 0; i < list_previews.size(); i++)
{ {
list_previews[i]->savePack(stream); _previews_list[i]->savePack(stream);
} }
} }
void BaseForm::loadPack(PackStream* stream) void BaseForm::loadPack(PackStream* stream)
{ {
// Load previews status // Load previews status
// TODO Ensure same order in save and load for (int i = 0; i < _previews_list.size(); i++)
QList<BasePreview*> list_previews = _previews->findChildren<BasePreview*>("_form_preview_");
for (int i = 0; i < list_previews.size(); i++)
{ {
list_previews[i]->loadPack(stream); _previews_list[i]->loadPack(stream);
} }
} }
@ -166,16 +161,15 @@ void BaseForm::configChangeEvent()
_button_revert->setEnabled(true); _button_revert->setEnabled(true);
} }
QList<BaseInput*> inputs = _form->findChildren<BaseInput*>("_form_input_"); for (int i = 0; i < _inputs_list.size(); i++)
for (int i = 0; i < inputs.size(); i++)
{ {
if (_with_layers && _layer_list->count() == 0) if (_with_layers && _layer_list->count() == 0)
{ {
inputs[i]->checkVisibility(false); _inputs_list[i]->checkVisibility(false);
} }
else else
{ {
inputs[i]->checkVisibility(true); _inputs_list[i]->checkVisibility(true);
} }
} }
@ -187,10 +181,9 @@ void BaseForm::configChangeEvent()
void BaseForm::revertConfig() void BaseForm::revertConfig()
{ {
QList<BaseInput*> inputs = _form->findChildren<BaseInput*>("_form_input_"); for (int i = 0; i < _inputs_list.size(); i++)
for (int i = 0; i < inputs.size(); i++)
{ {
inputs[i]->revert(); _inputs_list[i]->revert();
} }
if (_with_layers) if (_with_layers)
@ -335,7 +328,7 @@ void BaseForm::addPreview(BasePreview* preview, QString label)
_previews->layout()->addWidget(label_widget); _previews->layout()->addWidget(label_widget);
_previews->layout()->addWidget(preview); _previews->layout()->addWidget(preview);
preview->setObjectName("_form_preview_"); _previews_list.append(preview);
} }
QPushButton* BaseForm::addButton(QString label) QPushButton* BaseForm::addButton(QString label)
@ -367,7 +360,7 @@ BaseInput* BaseForm::addInput(BaseInput* input)
connect(input, SIGNAL(valueChanged()), this, SLOT(configChangeEvent())); connect(input, SIGNAL(valueChanged()), this, SLOT(configChangeEvent()));
input->setObjectName("_form_input_"); _inputs_list.append(input);
input->revert(); input->revert();
return input; return input;
@ -420,10 +413,9 @@ BaseInput* BaseForm::addInputEnum(QString label, int* value, const QStringList&
void BaseForm::updatePreviews() void BaseForm::updatePreviews()
{ {
QList<BasePreview*> list_previews = _previews->findChildren<BasePreview*>("_form_preview_"); for (int i = 0; i < _previews_list.size(); i++)
for (int i = 0; i < list_previews.size(); i++)
{ {
list_previews[i]->redraw(); _previews_list[i]->redraw();
} }
} }
@ -471,16 +463,14 @@ void BaseForm::layerRenamedEvent(int, QString)
void BaseForm::layerSelectedEvent(int layer) void BaseForm::layerSelectedEvent(int layer)
{ {
QList<BaseInput*> inputs = _form->findChildren<BaseInput*>("_form_input_"); for (int i = 0; i < _inputs_list.size(); i++)
for (int i = 0; i < inputs.size(); i++)
{ {
inputs[i]->revert(); _inputs_list[i]->revert();
inputs[i]->checkVisibility(layer >= 0); _inputs_list[i]->checkVisibility(layer >= 0);
} }
QList<BasePreview*> list_previews = _previews->findChildren<BasePreview*>("_form_preview_"); for (int i = 0; i < _previews_list.size(); i++)
for (int i = 0; i < list_previews.size(); i++)
{ {
list_previews[i]->redraw(); _previews_list[i]->redraw();
} }
} }

View file

@ -69,9 +69,7 @@ protected:
virtual void layerSelectedEvent(int layer); virtual void layerSelectedEvent(int layer);
private: private:
bool _auto_update_previews;
bool _auto_apply; bool _auto_apply;
QWidget* _previews;
QWidget* _form; QWidget* _form;
QWidget* _form_labels; QWidget* _form_labels;
QWidget* _form_previews; QWidget* _form_previews;
@ -79,6 +77,12 @@ private:
QWidget* _buttons; QWidget* _buttons;
QPushButton* _button_apply; QPushButton* _button_apply;
QPushButton* _button_revert; QPushButton* _button_revert;
QWidget* _previews;
QVector<BasePreview*> _previews_list;
bool _auto_update_previews;
QVector<BaseInput*> _inputs_list;
bool _with_layers; bool _with_layers;
QComboBox* _layer_list; QComboBox* _layer_list;

View file

@ -81,33 +81,41 @@ QMainWindow(parent)
form = new FormTerrain(tabs); form = new FormTerrain(tabs);
tabs->addTab(form, tr("Terrain")); tabs->addTab(form, tr("Terrain"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
_forms.append(form);
form = new FormTextures(tabs); form = new FormTextures(tabs);
tabs->addTab(form, tr("Textures")); tabs->addTab(form, tr("Textures"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
_forms.append(form);
form = new FormWater(tabs); form = new FormWater(tabs);
tabs->addTab(form, tr("Water")); tabs->addTab(form, tr("Water"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
_forms.append(form);
form = new FormSky(tabs); form = new FormSky(tabs);
tabs->addTab(form, tr("Sky")); tabs->addTab(form, tr("Sky"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
_forms.append(form);
form = new FormAtmosphere(tabs); form = new FormAtmosphere(tabs);
tabs->addTab(form, tr("Atmosphere")); tabs->addTab(form, tr("Atmosphere"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
_forms.append(form);
form = new FormClouds(tabs); form = new FormClouds(tabs);
tabs->addTab(form, tr("Clouds")); tabs->addTab(form, tr("Clouds"));
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll())); QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
_forms.append(form);
/*form = new FormLighting(tabs); /*form = new FormLighting(tabs);
tabs->addTab(form, tr("Lighting")); 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); _form_render = new FormRender(tabs);
tabs->addTab(_form_render, tr("Render")); tabs->addTab(_form_render, tr("Render"));
_forms.append(_form_render);
toolbar = new QToolBar(this); toolbar = new QToolBar(this);
toolbar->setOrientation(Qt::Vertical); toolbar->setOrientation(Qt::Vertical);
@ -151,10 +159,9 @@ void MainWindow::refreshAll()
logDebug("[MainWindow] Refreshing whole UI"); logDebug("[MainWindow] Refreshing whole UI");
// Refresh all tabs // Refresh all tabs
QList<BaseForm*> list_forms = this->findChildren<BaseForm*>("_base_form_"); for (int i = 0; i < _forms.size(); i++)
for (int i = 0; i < list_forms.size(); i++)
{ {
list_forms[i]->revertConfig(); _forms[i]->revertConfig();
} }
// Refresh preview OSD // Refresh preview OSD
@ -273,21 +280,17 @@ void MainWindow::guiLoadCallback(PackStream* stream, void* data)
void MainWindow::guiSave(PackStream* stream) void MainWindow::guiSave(PackStream* stream)
{ {
// Save all tabs status // Save all tabs status
// TODO Ensure same order in save and load for (int i = 0; i < _forms.size(); i++)
QList<BaseForm*> list_forms = this->findChildren<BaseForm*>("_base_form_");
for (int i = 0; i < list_forms.size(); i++)
{ {
list_forms[i]->savePack(stream); _forms[i]->savePack(stream);
} }
} }
void MainWindow::guiLoad(PackStream* stream) void MainWindow::guiLoad(PackStream* stream)
{ {
// Load all tabs status // Load all tabs status
// TODO Ensure same order in save and load for (int i = 0; i < _forms.size(); i++)
QList<BaseForm*> list_forms = this->findChildren<BaseForm*>("_base_form_");
for (int i = 0; i < list_forms.size(); i++)
{ {
list_forms[i]->loadPack(stream); _forms[i]->loadPack(stream);
} }
} }

View file

@ -32,6 +32,7 @@ private:
void guiSave(PackStream* stream); void guiSave(PackStream* stream);
void guiLoad(PackStream* stream); void guiLoad(PackStream* stream);
QVector<BaseForm*> _forms;
FormRender* _form_render; FormRender* _form_render;
}; };