From 966620429ee19b84e95653011fd62d3a48a44e89 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Tue, 27 Nov 2018 15:54:18 -0500 Subject: [PATCH] structured bindings are awesome! --- GUI/setdialog.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/GUI/setdialog.cpp b/GUI/setdialog.cpp index d86ae14..f16d8e1 100644 --- a/GUI/setdialog.cpp +++ b/GUI/setdialog.cpp @@ -12,17 +12,18 @@ SetDialog::SetDialog(QWidget* parent) : QFormLayout* layout = findChild("layout"); - auto addSpinBox = [&](QString label, int value) + using Bindable = std::tuple; + for (auto[spinBox, value, label] : { + Bindable{ flushDelay, TextThread::flushDelay, FLUSH_DELAY }, + Bindable{ maxBufferSize, TextThread::maxBufferSize, MAX_BUFFER_SIZE }, + Bindable{ defaultCodepage, TextThread::defaultCodepage, DEFAULT_CODEPAGE } + }) { - auto spinbox = new QSpinBox(this); - spinbox->setMaximum(INT_MAX); - spinbox->setValue(value); - layout->insertRow(0, label, spinbox); - return spinbox; - }; - flushDelay = addSpinBox(FLUSH_DELAY, TextThread::flushDelay); - maxBufferSize = addSpinBox(MAX_BUFFER_SIZE, TextThread::maxBufferSize); - defaultCodepage = addSpinBox(DEFAULT_CODEPAGE, TextThread::defaultCodepage); + spinBox = new QSpinBox(this); + spinBox->setMaximum(INT_MAX); + spinBox->setValue(value); + layout->insertRow(0, label, spinBox); + } } SetDialog::~SetDialog() @@ -37,4 +38,4 @@ void SetDialog::on_buttonBox_accepted() settings.setValue(MAX_BUFFER_SIZE, TextThread::maxBufferSize = maxBufferSize->value()); settings.setValue(DEFAULT_CODEPAGE, TextThread::defaultCodepage = defaultCodepage->value()); settings.sync(); -} \ No newline at end of file +}