From 9c2cec628b9e8fef8dd5f5a39f701662cd2ee3b8 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <6d0847b9@opayq.com> Date: Fri, 8 Jun 2018 17:31:11 +0300 Subject: [PATCH] Make sure only powers of two are entered for the page size (#1405) * Make sure only powers of two are entered for the page size * Replace QSpinBox with QComboBox Having a QSpinBox didn't make too much sense when we only have 8 valid values. Forcing the user to type a valid value would have required a warning message too, along with translations. Having a QComboBox makes it clear (obviously) what values we are expecting, without any risk of invalid values or confusion. * Add thousands separator for page size values --- src/CipherDialog.cpp | 19 ++++++++++++++++++- src/CipherDialog.ui | 14 ++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/CipherDialog.cpp b/src/CipherDialog.cpp index 51285683..ea51731d 100644 --- a/src/CipherDialog.cpp +++ b/src/CipherDialog.cpp @@ -4,6 +4,8 @@ #include #include +#include + CipherDialog::CipherDialog(QWidget* parent, bool encrypt) : QDialog(parent), ui(new Ui::CipherDialog), @@ -12,6 +14,21 @@ CipherDialog::CipherDialog(QWidget* parent, bool encrypt) : { ui->setupUi(this); + int minimumPageSizeExponent = 9; + int maximumPageSizeExponent = 16; + int defaultPageSizeExponent = 10; + + for(int exponent = minimumPageSizeExponent; exponent <= maximumPageSizeExponent; exponent++) + { + int pageSize = static_cast(qPow(2, exponent)); + ui->comboPageSize->addItem(QLocale().toString(pageSize), pageSize); + + if (exponent == defaultPageSizeExponent) + ui->comboPageSize->setCurrentIndex(exponent - minimumPageSizeExponent); + } + + ui->comboPageSize->setMinimumWidth(ui->editPassword->width()); + if(encrypt) { ui->labelDialogDescription->setText(tr("Please set a key to encrypt the database.\nNote that if you change any of the other, optional, settings you'll need " @@ -47,7 +64,7 @@ QString CipherDialog::password() const int CipherDialog::pageSize() const { - return ui->spinPageSize->value(); + return ui->comboPageSize->itemData(ui->comboPageSize->currentIndex()).toInt(); } void CipherDialog::checkInputFields() diff --git a/src/CipherDialog.ui b/src/CipherDialog.ui index 30bdc9ec..30516d1f 100644 --- a/src/CipherDialog.ui +++ b/src/CipherDialog.ui @@ -66,17 +66,7 @@ - - - 512 - - - 65536 - - - 1024 - - + @@ -129,7 +119,7 @@ editPassword comboKeyFormat editPassword2 - spinPageSize + comboPageSize