From e1c33653bbf391c178b4048bf0b3c1daf7a93e18 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sun, 2 Aug 2015 21:47:20 +0200 Subject: [PATCH] Fixed template loading in AddJob dialog. --- src/win_addJob.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/win_addJob.cpp b/src/win_addJob.cpp index b0e391b..01649b7 100644 --- a/src/win_addJob.cpp +++ b/src/win_addJob.cpp @@ -91,6 +91,27 @@ Q_DECLARE_METATYPE(const void*) +/////////////////////////////////////////////////////////////////////////////// +// Disable Monitoring RAII +/////////////////////////////////////////////////////////////////////////////// + +class DisableHelperRAII +{ +public: + DisableHelperRAII(bool *const flag) : m_flag(flag) + { + *m_flag = false; + } + + ~DisableHelperRAII(void) + { + *m_flag = true; + } + +private: + bool *const m_flag; +}; + /////////////////////////////////////////////////////////////////////////////// // Validator /////////////////////////////////////////////////////////////////////////////// @@ -245,7 +266,7 @@ AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *const options, Recentl m_preferences(preferences), m_defaults(new OptionsModel(sysinfo)), ui(new Ui::AddJobDialog()), - m_monitorConfigChanges(true) + m_monitorConfigChanges(false) { //Init the dialog, from the .ui file ui->setupUi(this); @@ -328,6 +349,10 @@ AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *const options, Recentl //Setup template selector loadTemplateList(); connect(ui->cbxTemplate, SIGNAL(currentIndexChanged(int)), this, SLOT(templateSelected())); + + //Force initial UI update + encoderIndexChanged(ui->cbxEncoderType->currentIndex()); + m_monitorConfigChanges = true; } AddJobDialog::~AddJobDialog(void) @@ -1035,7 +1060,7 @@ void AddJobDialog::updateComboBox(QComboBox *const cbox, const int &data) { for(int i = 0; i < cbox->model()->rowCount(); i++) { - if(model->itemData(model->index(i, 0, QModelIndex())).value(Qt::UserRole).toInt() == index) + if(cbox->itemData(i).toInt() == data) { index = i; break; @@ -1047,8 +1072,7 @@ void AddJobDialog::updateComboBox(QComboBox *const cbox, const int &data) void AddJobDialog::restoreOptions(const OptionsModel *options) { - //Ignore config changes while restoring template! - m_monitorConfigChanges = false; + DisableHelperRAII disbale(&m_monitorConfigChanges); updateComboBox(ui->cbxEncoderType, options->encType()); updateComboBox(ui->cbxEncoderArch, options->encArch()); @@ -1064,12 +1088,6 @@ void AddJobDialog::restoreOptions(const OptionsModel *options) ui->editCustomX264Params ->setText(options->customEncParams()); ui->editCustomAvs2YUVParams->setText(options->customAvs2YUV()); - - //Force UI update - encoderIndexChanged(ui->cbxEncoderType->currentIndex()); - - //Make sure we will monitor config changes again! - m_monitorConfigChanges = true; } void AddJobDialog::saveOptions(OptionsModel *options)