#include "dialog_userinput.h" #include "ui_dialog_userinput.h" Dialog_UserInput::Dialog_UserInput(ui_helper::value_type type, const QString &title, const QString &desc, QWidget *parent) : QDialog(parent), ui(new Ui::Dialog_UserInput), m_type(type), m_title(title), m_desc(desc) { ui->setupUi(this); if (type == ui_helper::VAL_TYPE_BOOL) { ui->radioButton_yes->setVisible(true); ui->radioButton_no->setVisible(true); ui->lineEdit->setVisible(false); } else if (type == ui_helper::VAL_TYPE_INT || type == ui_helper::VAL_TYPE_FLOAT || type == ui_helper::VAL_TYPE_STRING) { ui->radioButton_yes->setVisible(false); ui->radioButton_no->setVisible(false); ui->lineEdit->setVisible(true); } setWindowTitle(m_title); ui->label->setText(m_desc); } Dialog_UserInput::~Dialog_UserInput() { delete ui; } parameter *Dialog_UserInput::getParam() { UserInputParams *param = new UserInputParams(m_type); if (m_type == ui_helper::VAL_TYPE_BOOL) { if (ui->radioButton_yes->isChecked()) param->m_bData = true; else if (ui->radioButton_no->isChecked()) param->m_bData = false; } else if (m_type == ui_helper::VAL_TYPE_INT) { param->m_iData = ui->lineEdit->text().toInt(); } else if (m_type == ui_helper::VAL_TYPE_FLOAT) { param->m_fData = ui->lineEdit->text().toDouble(); } else if (m_type == ui_helper::VAL_TYPE_STRING) { param->m_sData = ui->lineEdit->text().toStdWString(); } return param; } void Dialog_UserInput::on_pbtn_yes_clicked() { getParam(); accept(); } void Dialog_UserInput::on_pbtn_no_clicked() { reject(); } UserInputParams::UserInputParams(ui_helper::value_type type) { m_type = type; } UserInputParams::~UserInputParams() { } size_t UserInputParams::get_size() { if (m_type == ui_helper::VAL_TYPE_BOOL) return sizeof(bool); if (m_type == ui_helper::VAL_TYPE_INT) return sizeof(int); if (m_type == ui_helper::VAL_TYPE_FLOAT) return sizeof(double); if (m_type == ui_helper::VAL_TYPE_STRING) return m_sData.size() + 1; return 0; } void *UserInputParams::get_data() { if (m_type == ui_helper::VAL_TYPE_BOOL) return &m_bData; if (m_type == ui_helper::VAL_TYPE_INT) return &m_iData; if (m_type == ui_helper::VAL_TYPE_FLOAT) return &m_fData; if (m_type == ui_helper::VAL_TYPE_STRING) return (void*)m_sData.c_str(); return nullptr; }