From 16688432f5590eacc715653b7128cc6d01b6e0fb Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 1 Apr 2021 05:40:36 +0300 Subject: [PATCH 36/36] Ruledit: Use QSpinBox for numeric requirement value In requirement editing dialog, text editing field was being used for entering value for requirement types that take numerical value. That wrongly allowed user to enter any text, not just numbers. See osdn #41893 Signed-off-by: Marko Lindqvist --- tools/ruledit/req_edit.cpp | 20 ++++++++++++-------- tools/ruledit/req_edit.h | 5 +++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/ruledit/req_edit.cpp b/tools/ruledit/req_edit.cpp index 26a4dc4c81..e6ffc84b19 100644 --- a/tools/ruledit/req_edit.cpp +++ b/tools/ruledit/req_edit.cpp @@ -18,9 +18,9 @@ // Qt #include #include -#include #include #include +#include // utility #include "fcintl.h" @@ -92,9 +92,11 @@ req_edit::req_edit(ruledit_gui *ui_in, QString target, edit_value_enum_button->setMenu(edit_value_enum_menu); edit_value_enum_menu->setVisible(false); active_layout->addWidget(edit_value_enum_button, 3); - edit_value_nbr_field = new QLineEdit(); + edit_value_nbr_field = new QSpinBox(); + edit_value_nbr_field->setRange(-100000, 100000); edit_value_nbr_field->setVisible(false); - connect(edit_value_nbr_field, SIGNAL(returnPressed()), this, SLOT(univ_value_edit())); + connect(edit_value_nbr_field, SIGNAL(valueEntered(int)), this, + SLOT(univ_value_edit(int))); active_layout->addWidget(edit_value_nbr_field, 4); lbl = new QLabel(R__("Range:")); @@ -231,7 +233,7 @@ void req_edit::select_req() struct uvb_data { - QLineEdit *number; + QSpinBox *number; QToolButton *enum_button; QMenu *menu; struct universal *univ; @@ -248,7 +250,7 @@ static void universal_value_cb(const char *value, bool current, void *cbdata) int kind, val; universal_extraction(data->univ, &kind, &val); - data->number->setText(QString::number(val)); + data->number->setValue(val); data->number->setVisible(true); } else { data->enum_button->setVisible(true); @@ -365,13 +367,15 @@ void req_edit::univ_value_enum_menu(QAction *action) /**********************************************************************//** User entered numerical requirement value. **************************************************************************/ -void req_edit::univ_value_edit() +void req_edit::univ_value_edit(int value) { if (selected != nullptr) { - QByteArray num_bytes = edit_value_nbr_field->text().toUtf8(); + char buf[32]; + + fc_snprintf(buf, sizeof(buf), "%d", value); universal_value_from_str(&selected->source, - num_bytes.data()); + buf); update_selected(); refresh(); diff --git a/tools/ruledit/req_edit.h b/tools/ruledit/req_edit.h index eda24b53eb..968af2edb9 100644 --- a/tools/ruledit/req_edit.h +++ b/tools/ruledit/req_edit.h @@ -21,6 +21,7 @@ // Qt #include #include +#include #include // common @@ -60,7 +61,7 @@ signals: QToolButton *edit_type_button; QToolButton *edit_value_enum_button; QMenu *edit_value_enum_menu; - QLineEdit *edit_value_nbr_field; + QSpinBox *edit_value_nbr_field; QToolButton *edit_range_button; QToolButton *edit_present_button; @@ -75,7 +76,7 @@ signals: void req_range_menu(QAction *action); void req_present_menu(QAction *action); void univ_value_enum_menu(QAction *action); - void univ_value_edit(); + void univ_value_edit(int value); void incoming_rec_vec_change(const requirement_vector *vec); -- 2.30.2