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;
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<BasePreview*> list_previews = _previews->findChildren<BasePreview*>("_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<BasePreview*> list_previews = _previews->findChildren<BasePreview*>("_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<BaseInput*> inputs = _form->findChildren<BaseInput*>("_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<BaseInput*> inputs = _form->findChildren<BaseInput*>("_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<BasePreview*> list_previews = _previews->findChildren<BasePreview*>("_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<BaseInput*> inputs = _form->findChildren<BaseInput*>("_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<BasePreview*> list_previews = _previews->findChildren<BasePreview*>("_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();
}
}

View file

@ -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<BasePreview*> _previews_list;
bool _auto_update_previews;
QVector<BaseInput*> _inputs_list;
bool _with_layers;
QComboBox* _layer_list;

View file

@ -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<BaseForm*> list_forms = this->findChildren<BaseForm*>("_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<BaseForm*> list_forms = this->findChildren<BaseForm*>("_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<BaseForm*> list_forms = this->findChildren<BaseForm*>("_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);
}
}

View file

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